Changeset 27716


Ignore:
Timestamp:
2013-06-27T16:57:35+12:00 (11 years ago)
Author:
sjm84
Message:

Need to store xpath data from the collectionConfig for debug purposes

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java

    r27705 r27716  
    3535import org.greenstone.gsdl3.util.GSFile;
    3636import org.greenstone.gsdl3.util.GSXML;
     37import org.greenstone.gsdl3.util.GSXSLT;
    3738import org.greenstone.gsdl3.util.OAIXML;
     39import org.greenstone.gsdl3.util.SimpleMacroResolver;
    3840import org.greenstone.gsdl3.util.UserContext;
    3941import org.greenstone.gsdl3.util.XMLTransformer;
     
    117119
    118120        Element coll_config_xml = loadCollConfigFile();
     121        GSXSLT.modifyCollectionConfigForDebug(coll_config_xml);
    119122        Element build_config_xml = loadBuildConfigFile();
    120123
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXSLT.java

    r26558 r27716  
    3131import org.w3c.dom.Node;
    3232import org.w3c.dom.NodeList;
     33import org.w3c.dom.UserDataHandler;
    3334
    3435/** various functions for manipulating Greenstone xslt */
     
    243244            {
    244245                debugElement.setAttribute("name", currentTemplate.getAttribute("name"));
     246            }
     247
     248            if (currentTemplate.getUserData("xpath") != null)
     249            {
     250                debugElement.setAttribute("xpath", (String) currentTemplate.getUserData("xpath"));
    245251            }
    246252
     
    604610        return null;
    605611    }
     612
     613    public static void modifyCollectionConfigForDebug(Element coll_config_xml)
     614    {
     615        NodeList xslTemplates = coll_config_xml.getElementsByTagNameNS(GSXML.XSL_NAMESPACE, "template");
     616        NodeList gsfTemplates = coll_config_xml.getElementsByTagNameNS(GSXML.GSF_NAMESPACE, "template");
     617
     618        for (int i = 0; i < xslTemplates.getLength() + gsfTemplates.getLength(); i++)
     619        {
     620            Element currentTemplate = (Element) ((i < xslTemplates.getLength()) ? xslTemplates.item(i) : gsfTemplates.item(i - xslTemplates.getLength()));
     621            Element temp = currentTemplate;
     622            String xPath = "";
     623            while (!temp.getNodeName().toLowerCase().equals("collectionconfig"))
     624            {
     625                temp = (Element) temp.getParentNode();
     626                String nodeName = temp.getNodeName();
     627
     628                int count = 1;
     629                Node counter = temp.getPreviousSibling();
     630                while (counter != null)
     631                {
     632                    if (counter.getNodeType() == Node.ELEMENT_NODE && ((Element) counter).getNodeName().equals(nodeName))
     633                    {
     634                        count++;
     635                    }
     636                    counter = counter.getPreviousSibling();
     637                }
     638                xPath = nodeName + ((count > 1) ? ("[" + count + "]") : "") + "/" + xPath;
     639            }
     640
     641            xPath = xPath.substring(0, xPath.length() - 1);
     642            currentTemplate.setUserData("xpath", xPath, new DataTransferHandler());
     643        }
     644    }
     645
     646    static class DataTransferHandler implements UserDataHandler
     647    {
     648        public void handle(short operation, String key, Object data, Node src, Node dst)
     649        {
     650            if (operation == NODE_IMPORTED || operation == NODE_CLONED)
     651            {
     652                //Thread.dumpStack();
     653                dst.setUserData(key, data, new DataTransferHandler());
     654            }
     655        }
     656    }
    606657}
Note: See TracChangeset for help on using the changeset viewer.