Example usage for org.dom4j Node getText

List of usage examples for org.dom4j Node getText

Introduction

In this page you can find the example usage for org.dom4j Node getText.

Prototype

String getText();

Source Link

Document

Returns the text of this node.

Usage

From source file:edu.umd.cs.findbugs.PluginLoader.java

License:Open Source License

private void loadPluginComponents() throws PluginException {
    Document pluginDescriptor = getPluginDescriptor();
    List<Document> messageCollectionList = getMessageDocuments();
    List<Node> cloudNodeList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/Cloud");
    for (Node cloudNode : cloudNodeList) {

        String cloudClassname = cloudNode.valueOf("@cloudClass");
        String cloudId = cloudNode.valueOf("@id");
        String usernameClassname = cloudNode.valueOf("@usernameClass");
        boolean onlineStorage = Boolean.valueOf(cloudNode.valueOf("@onlineStorage"));
        String propertiesLocation = cloudNode.valueOf("@properties");
        boolean disabled = Boolean.valueOf(cloudNode.valueOf("@disabled"))
                && !cloudId.equals(CloudFactory.DEFAULT_CLOUD);
        if (disabled) {
            continue;
        }//w w  w. j  a v a 2  s  .co m
        boolean hidden = Boolean.valueOf(cloudNode.valueOf("@hidden"))
                && !cloudId.equals(CloudFactory.DEFAULT_CLOUD);

        Class<? extends Cloud> cloudClass = getClass(classLoader, cloudClassname, Cloud.class);

        Class<? extends NameLookup> usernameClass = getClass(classLoader, usernameClassname, NameLookup.class);
        Node cloudMessageNode = findMessageNode(messageCollectionList,
                "/MessageCollection/Cloud[@id='" + cloudId + "']",
                "Missing Cloud description for cloud " + cloudId);
        String description = getChildText(cloudMessageNode, "Description").trim();
        String details = getChildText(cloudMessageNode, "Details").trim();
        PropertyBundle properties = new PropertyBundle();
        if (propertiesLocation != null && propertiesLocation.length() > 0) {
            URL properiesURL = classLoader.getResource(propertiesLocation);
            if (properiesURL == null) {
                continue;
            }
            properties.loadPropertiesFromURL(properiesURL);
        }
        List<Node> propertyNodes = XMLUtil.selectNodes(cloudNode, "Property");
        for (Node node : propertyNodes) {
            String key = node.valueOf("@key");
            String value = node.getText().trim();
            properties.setProperty(key, value);
        }

        CloudPlugin cloudPlugin = new CloudPluginBuilder().setFindbugsPluginId(plugin.getPluginId())
                .setCloudid(cloudId).setClassLoader(classLoader).setCloudClass(cloudClass)
                .setUsernameClass(usernameClass).setHidden(hidden).setProperties(properties)
                .setDescription(description).setDetails(details).setOnlineStorage(onlineStorage)
                .createCloudPlugin();
        plugin.addCloudPlugin(cloudPlugin);
    }

    // Create PluginComponents
    try {
        List<Node> componentNodeList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/PluginComponent");
        for (Node componentNode : componentNodeList) {
            @DottedClassName
            String componentKindname = componentNode.valueOf("@componentKind");
            if (componentKindname == null) {
                throw new PluginException(
                        "Missing @componentKind for " + plugin.getPluginId() + " loaded from " + loadedFrom);
            }
            @DottedClassName
            String componentClassname = componentNode.valueOf("@componentClass");
            if (componentClassname == null) {
                throw new PluginException("Missing @componentClassname for " + plugin.getPluginId()
                        + " loaded from " + loadedFrom);
            }
            String componentId = componentNode.valueOf("@id");
            if (componentId == null) {
                throw new PluginException(
                        "Missing @id for " + plugin.getPluginId() + " loaded from " + loadedFrom);
            }

            try {
                String propertiesLocation = componentNode.valueOf("@properties");
                boolean disabled = Boolean.valueOf(componentNode.valueOf("@disabled"));

                Node filterMessageNode = findMessageNode(messageCollectionList,
                        "/MessageCollection/PluginComponent[@id='" + componentId + "']",
                        "Missing Cloud description for PluginComponent " + componentId);
                String description = getChildText(filterMessageNode, "Description").trim();
                String details = getChildText(filterMessageNode, "Details").trim();
                PropertyBundle properties = new PropertyBundle();
                if (propertiesLocation != null && propertiesLocation.length() > 0) {
                    URL properiesURL = classLoaderForResources.getResource(propertiesLocation);
                    if (properiesURL == null) {
                        AnalysisContext.logError("Could not load properties for " + plugin.getPluginId()
                                + " component " + componentId + " from " + propertiesLocation);
                        continue;
                    }
                    properties.loadPropertiesFromURL(properiesURL);
                }
                List<Node> propertyNodes = XMLUtil.selectNodes(componentNode, "Property");
                for (Node node : propertyNodes) {
                    String key = node.valueOf("@key");
                    String value = node.getText();
                    properties.setProperty(key, value);
                }

                Class<?> componentKind = classLoader.loadClass(componentKindname);
                loadComponentPlugin(plugin, componentKind, componentClassname, componentId, disabled,
                        description, details, properties);
            } catch (RuntimeException e) {
                AnalysisContext.logError("Unable to load ComponentPlugin " + componentId + " : "
                        + componentClassname + " implementing " + componentKindname, e);
            }
        }

        // Create FindBugsMains

        if (!FindBugs.isNoMains()) {
            List<Node> findBugsMainList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/FindBugsMain");
            for (Node main : findBugsMainList) {
                String className = main.valueOf("@class");
                if (className == null) {
                    throw new PluginException("Missing @class for FindBugsMain in plugin" + plugin.getPluginId()
                            + " loaded from " + loadedFrom);
                }
                String cmd = main.valueOf("@cmd");
                if (cmd == null) {
                    throw new PluginException("Missing @cmd for for FindBugsMain in plugin "
                            + plugin.getPluginId() + " loaded from " + loadedFrom);
                }
                String kind = main.valueOf("@kind");
                boolean analysis = Boolean.valueOf(main.valueOf("@analysis"));
                Element mainMessageNode = (Element) findMessageNode(messageCollectionList,
                        "/MessageCollection/FindBugsMain[@cmd='" + cmd
                        // + " and @class='" + className
                                + "']/Description",
                        "Missing FindBugsMain description for cmd " + cmd);
                String description = mainMessageNode.getTextTrim();
                try {
                    Class<?> mainClass = classLoader.loadClass(className);
                    plugin.addFindBugsMain(mainClass, cmd, description, kind, analysis);
                } catch (Exception e) {
                    String msg = "Unable to load FindBugsMain " + cmd + " : " + className + " in plugin "
                            + plugin.getPluginId() + " loaded from " + loadedFrom;
                    PluginException e2 = new PluginException(msg, e);
                    AnalysisContext.logError(msg, e2);
                }
            }
        }

        List<Node> detectorNodeList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/Detector");
        int detectorCount = 0;
        for (Node detectorNode : detectorNodeList) {
            String className = detectorNode.valueOf("@class");
            String speed = detectorNode.valueOf("@speed");
            String disabled = detectorNode.valueOf("@disabled");
            String reports = detectorNode.valueOf("@reports");
            String requireJRE = detectorNode.valueOf("@requirejre");
            String hidden = detectorNode.valueOf("@hidden");
            if (speed == null || speed.length() == 0) {
                speed = "fast";
            }
            // System.out.println("Found detector: class="+className+", disabled="+disabled);

            // Create DetectorFactory for the detector
            Class<?> detectorClass = null;
            if (!FindBugs.isNoAnalysis()) {
                detectorClass = classLoader.loadClass(className);

                if (!Detector.class.isAssignableFrom(detectorClass)
                        && !Detector2.class.isAssignableFrom(detectorClass)) {
                    throw new PluginException(
                            "Class " + className + " does not implement Detector or Detector2");
                }
            }
            DetectorFactory factory = new DetectorFactory(plugin, className, detectorClass,
                    !"true".equals(disabled), speed, reports, requireJRE);
            if (Boolean.valueOf(hidden).booleanValue()) {
                factory.setHidden(true);
            }
            factory.setPositionSpecifiedInPluginDescriptor(detectorCount++);
            plugin.addDetectorFactory(factory);

            // Find Detector node in one of the messages files,
            // to get the detail HTML.
            Node node = findMessageNode(messageCollectionList,
                    "/MessageCollection/Detector[@class='" + className + "']/Details",
                    "Missing Detector description for detector " + className);

            Element details = (Element) node;
            String detailHTML = details.getText();
            StringBuilder buf = new StringBuilder();
            buf.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
            buf.append("<HTML><HEAD><TITLE>Detector Description</TITLE></HEAD><BODY>\n");
            buf.append(detailHTML);
            buf.append("</BODY></HTML>\n");
            factory.setDetailHTML(buf.toString());
        }
    } catch (ClassNotFoundException e) {
        throw new PluginException("Could not instantiate detector class: " + e, e);
    }

    // Create ordering constraints
    Node orderingConstraintsNode = pluginDescriptor.selectSingleNode("/FindbugsPlugin/OrderingConstraints");
    if (orderingConstraintsNode != null) {
        // Get inter-pass and intra-pass constraints
        List<Element> elements = XMLUtil.selectNodes(orderingConstraintsNode, "./SplitPass|./WithinPass");
        for (Element constraintElement : elements) {
            // Create the selectors which determine which detectors are
            // involved in the constraint
            DetectorFactorySelector earlierSelector = getConstraintSelector(constraintElement, plugin,
                    "Earlier");
            DetectorFactorySelector laterSelector = getConstraintSelector(constraintElement, plugin, "Later");

            // Create the constraint
            DetectorOrderingConstraint constraint = new DetectorOrderingConstraint(earlierSelector,
                    laterSelector);

            // Keep track of which constraints are single-source
            constraint.setSingleSource(earlierSelector instanceof SingleDetectorFactorySelector);

            // Add the constraint to the plugin
            if ("SplitPass".equals(constraintElement.getName())) {
                plugin.addInterPassOrderingConstraint(constraint);
            } else {
                plugin.addIntraPassOrderingConstraint(constraint);
            }
        }
    }

    // register global Category descriptions

    List<Node> categoryNodeListGlobal = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/BugCategory");
    for (Node categoryNode : categoryNodeListGlobal) {
        String key = categoryNode.valueOf("@category");
        if ("".equals(key)) {
            throw new PluginException("BugCategory element with missing category attribute");
        }
        BugCategory bc = plugin.addOrCreateBugCategory(key);

        boolean hidden = Boolean.valueOf(categoryNode.valueOf("@hidden"));
        if (hidden) {
            bc.setHidden(hidden);
        }
    }

    for (Document messageCollection : messageCollectionList) {
        List<Node> categoryNodeList = XMLUtil.selectNodes(messageCollection, "/MessageCollection/BugCategory");
        if (DEBUG) {
            System.out.println("found " + categoryNodeList.size() + " categories in " + plugin.getPluginId());
        }
        for (Node categoryNode : categoryNodeList) {
            String key = categoryNode.valueOf("@category");
            if ("".equals(key)) {
                throw new PluginException("BugCategory element with missing category attribute");
            }
            BugCategory bc = plugin.addOrCreateBugCategory(key);
            String shortDesc = getChildText(categoryNode, "Description");
            bc.setShortDescription(shortDesc);
            try {
                String abbrev = getChildText(categoryNode, "Abbreviation");
                if (bc.getAbbrev() == null) {
                    bc.setAbbrev(abbrev);
                    if (DEBUG) {
                        System.out.println("category " + key + " abbrev -> " + abbrev);
                    }
                } else if (DEBUG) {
                    System.out.println(
                            "rejected abbrev '" + abbrev + "' for category " + key + ": " + bc.getAbbrev());
                }
            } catch (PluginException pe) {
                if (DEBUG) {
                    System.out.println("missing Abbreviation for category " + key + "/" + shortDesc);
                    // do nothing else -- Abbreviation is required, but handle
                    // its omission gracefully
                }
            }
            try {
                String details = getChildText(categoryNode, "Details");
                if (bc.getDetailText() == null) {
                    bc.setDetailText(details);
                    if (DEBUG) {
                        System.out.println("category " + key + " details -> " + details);
                    }
                } else if (DEBUG) {
                    System.out.println("rejected details [" + details + "] for category " + key + ": ["
                            + bc.getDetailText() + ']');
                }
            } catch (PluginException pe) {
                // do nothing -- LongDescription is optional
            }

        }
    }

    // Create BugPatterns
    List<Node> bugPatternNodeList = XMLUtil.selectNodes(pluginDescriptor, "/FindbugsPlugin/BugPattern");
    for (Node bugPatternNode : bugPatternNodeList) {
        String type = bugPatternNode.valueOf("@type");
        String abbrev = bugPatternNode.valueOf("@abbrev");
        String category = bugPatternNode.valueOf("@category");
        boolean experimental = Boolean.parseBoolean(bugPatternNode.valueOf("@experimental"));

        // Find the matching element in messages.xml (or translations)
        String query = "/MessageCollection/BugPattern[@type='" + type + "']";
        Node messageNode = findMessageNode(messageCollectionList, query,
                "messages.xml missing BugPattern element for type " + type);
        Node bugsUrlNode = messageNode.getDocument()
                .selectSingleNode("/MessageCollection/Plugin/" + (experimental ? "AllBugsUrl" : "BugsUrl"));

        String bugsUrl = bugsUrlNode == null ? null : bugsUrlNode.getText();

        String shortDesc = getChildText(messageNode, "ShortDescription");
        String longDesc = getChildText(messageNode, "LongDescription");
        String detailText = getChildText(messageNode, "Details");
        int cweid = 0;
        try {
            String cweString = bugPatternNode.valueOf("@cweid");
            if (cweString.length() > 0) {
                cweid = Integer.parseInt(cweString);
            }
        } catch (RuntimeException e) {
            assert true; // ignore
        }

        BugPattern bugPattern = new BugPattern(type, abbrev, category, experimental, shortDesc, longDesc,
                detailText, bugsUrl, cweid);

        try {
            String deprecatedStr = bugPatternNode.valueOf("@deprecated");
            boolean deprecated = deprecatedStr.length() > 0 && Boolean.valueOf(deprecatedStr).booleanValue();
            if (deprecated) {
                bugPattern.setDeprecated(deprecated);
            }
        } catch (RuntimeException e) {
            assert true; // ignore
        }

        plugin.addBugPattern(bugPattern);

    }

    // Create BugCodes
    Set<String> definedBugCodes = new HashSet<String>();
    for (Document messageCollection : messageCollectionList) {
        List<Node> bugCodeNodeList = XMLUtil.selectNodes(messageCollection, "/MessageCollection/BugCode");
        for (Node bugCodeNode : bugCodeNodeList) {
            String abbrev = bugCodeNode.valueOf("@abbrev");
            if ("".equals(abbrev)) {
                throw new PluginException("BugCode element with missing abbrev attribute");
            }
            if (definedBugCodes.contains(abbrev)) {
                continue;
            }
            String description = bugCodeNode.getText();

            String query = "/FindbugsPlugin/BugCode[@abbrev='" + abbrev + "']";
            Node fbNode = pluginDescriptor.selectSingleNode(query);
            int cweid = 0;
            if (fbNode != null) {
                try {
                    cweid = Integer.parseInt(fbNode.valueOf("@cweid"));
                } catch (RuntimeException e) {
                    assert true; // ignore
                }
            }
            BugCode bugCode = new BugCode(abbrev, description, cweid);
            plugin.addBugCode(bugCode);
            definedBugCodes.add(abbrev);
        }

    }

    // If an engine registrar is specified, make a note of its classname
    Node node = pluginDescriptor.selectSingleNode("/FindbugsPlugin/EngineRegistrar");
    if (node != null) {
        String engineClassName = node.valueOf("@class");
        if (engineClassName == null) {
            throw new PluginException("EngineRegistrar element with missing class attribute");
        }

        try {
            Class<?> engineRegistrarClass = classLoader.loadClass(engineClassName);
            if (!IAnalysisEngineRegistrar.class.isAssignableFrom(engineRegistrarClass)) {
                throw new PluginException(
                        engineRegistrarClass + " does not implement IAnalysisEngineRegistrar");
            }

            plugin.setEngineRegistrarClass(
                    engineRegistrarClass.<IAnalysisEngineRegistrar>asSubclass(IAnalysisEngineRegistrar.class));
        } catch (ClassNotFoundException e) {
            throw new PluginException("Could not instantiate analysis engine registrar class: " + e, e);
        }

    }
    try {
        URL bugRankURL = getResource(BugRanker.FILENAME);

        if (bugRankURL == null) {
            // see
            // https://sourceforge.net/tracker/?func=detail&aid=2816102&group_id=96405&atid=614693
            // plugin can not have bugrank.txt. In this case, an empty
            // bugranker will be created
            if (DEBUG) {
                System.out.println("No " + BugRanker.FILENAME + " for plugin " + plugin.getPluginId());
            }
        }
        BugRanker ranker = new BugRanker(bugRankURL);
        plugin.setBugRanker(ranker);
    } catch (IOException e) {
        throw new PluginException("Couldn't parse \"" + BugRanker.FILENAME + "\"", e);
    }
}

From source file:edu.umd.cs.findbugs.PluginLoader.java

License:Open Source License

private Plugin constructMinimalPlugin(Document pluginDescriptor, List<Document> messageCollectionList)
        throws DuplicatePluginIdError {
    // Get the unique plugin id (or generate one, if none is present)
    // Unique plugin id
    String pluginId = pluginDescriptor.valueOf(XPATH_PLUGIN_PLUGINID);
    if ("".equals(pluginId)) {
        synchronized (PluginLoader.class) {
            pluginId = "plugin" + nextUnknownId++;
        }/*from   w ww . ja va2 s. c  om*/
    }
    cannotDisable = Boolean.parseBoolean(pluginDescriptor.valueOf("/FindbugsPlugin/@cannotDisable"));

    String de = pluginDescriptor.valueOf("/FindbugsPlugin/@defaultenabled");
    if (de != null && "false".equals(de.toLowerCase().trim())) {
        optionalPlugin = true;
    }
    if (optionalPlugin) {
        cannotDisable = false;
    }
    if (!loadedPluginIds.add(pluginId)) {
        Plugin existingPlugin = Plugin.getByPluginId(pluginId);
        URL u = existingPlugin == null ? null : existingPlugin.getPluginLoader().getURL();
        if (cannotDisable && initialPlugin) {
            throw new DuplicatePluginIdError(pluginId, loadedFrom, u);
        } else {
            throw new DuplicatePluginIdException(pluginId, loadedFrom, u);
        }
    }

    parentId = pluginDescriptor.valueOf("/FindbugsPlugin/@parentid");

    String version = pluginDescriptor.valueOf("/FindbugsPlugin/@version");
    String releaseDate = pluginDescriptor.valueOf("/FindbugsPlugin/@releaseDate");

    if ((releaseDate == null || releaseDate.length() == 0) && isCorePlugin()) {
        releaseDate = Version.CORE_PLUGIN_RELEASE_DATE;
    }
    // Create the Plugin object (but don't assign to the plugin field yet,
    // since we're still not sure if everything will load correctly)
    Date parsedDate = parseDate(releaseDate);
    Plugin constructedPlugin = new Plugin(pluginId, version, parsedDate, this, !optionalPlugin, cannotDisable);
    // Set provider and website, if specified
    String provider = pluginDescriptor.valueOf(XPATH_PLUGIN_PROVIDER).trim();
    if (!"".equals(provider)) {
        constructedPlugin.setProvider(provider);
    }
    String website = pluginDescriptor.valueOf(XPATH_PLUGIN_WEBSITE).trim();
    if (!"".equals(website)) {
        try {
            constructedPlugin.setWebsite(website);
        } catch (URISyntaxException e1) {
            AnalysisContext.logError(
                    "Plugin " + constructedPlugin.getPluginId() + " has invalid website: " + website, e1);
        }
    }

    String updateUrl = pluginDescriptor.valueOf("/FindbugsPlugin/@update-url").trim();
    if (!"".equals(updateUrl)) {
        try {
            constructedPlugin.setUpdateUrl(updateUrl);
        } catch (URISyntaxException e1) {
            AnalysisContext.logError(
                    "Plugin " + constructedPlugin.getPluginId() + " has invalid update check URL: " + website,
                    e1);
        }
    }

    // Set short description, if specified
    Node pluginShortDesc = null;
    try {
        pluginShortDesc = findMessageNode(messageCollectionList, XPATH_PLUGIN_SHORT_DESCRIPTION,
                "no plugin description");
    } catch (PluginException e) {
        // Missing description is not fatal, so ignore
    }
    if (pluginShortDesc != null) {
        constructedPlugin.setShortDescription(pluginShortDesc.getText().trim());
    }
    Node detailedDescription = null;
    try {
        detailedDescription = findMessageNode(messageCollectionList, "/MessageCollection/Plugin/Details",
                "no plugin description");
    } catch (PluginException e) {
        // Missing description is not fatal, so ignore
    }
    if (detailedDescription != null) {
        constructedPlugin.setDetailedDescription(detailedDescription.getText().trim());
    }
    List<Node> globalOptionNodes = XMLUtil.selectNodes(pluginDescriptor,
            "/FindbugsPlugin/GlobalOptions/Property");
    for (Node optionNode : globalOptionNodes) {
        String key = optionNode.valueOf("@key");
        String value = optionNode.getText().trim();
        constructedPlugin.setMyGlobalOption(key, value);
    }
    return constructedPlugin;
}

From source file:edu.umd.cs.findbugs.PluginLoader.java

License:Open Source License

private static String findMessageText(List<Document> messageCollectionList, String xpath, String missingMsg) {
    for (Document document : messageCollectionList) {
        Node node = document.selectSingleNode(xpath);
        if (node != null) {
            return node.getText().trim();
        }/*from  w w w.j a v  a 2  s  . co  m*/
    }
    return missingMsg;
}

From source file:edu.umd.cs.findbugs.PluginLoader.java

License:Open Source License

private static String getChildText(Node node, String childName) throws PluginException {
    Node child = node.selectSingleNode(childName);
    if (child == null) {
        throw new PluginException("Could not find child \"" + childName + "\" for node");
    }// w w  w.j a v  a2  s . co  m
    return child.getText();
}

From source file:edu.umd.cs.marmoset.utilities.ParseWebXml.java

License:Apache License

public static ParseWebXml parse(String webXmlFileName) throws FileNotFoundException, DocumentException {
    File file = new File(webXmlFileName);

    FileInputStream fis = new FileInputStream(file);
    SAXReader reader = new SAXReader();
    Document document = reader.read(fis);

    ParseWebXml webXml = new ParseWebXml();

    Element root = document.getRootElement();

    for (Iterator<?> ii = root.elementIterator("servlet-mapping"); ii.hasNext();) {
        Element elt = (Element) ii.next();
        //System.out.print("name: " +elt.getName());

        String urlPattern = null;
        String servletName = null;
        for (int jj = 0; jj < elt.nodeCount(); jj++) {
            Node node = elt.node(jj);
            if (node.getName() == null)
                continue;
            if (node.getName().equals(SERVLET_NAME)) {
                servletName = node.getText().trim();
                if (webXml.tryToMapServlet(servletName, urlPattern))
                    break;
            } else if (node.getName().equals(SERVLET_URL_PATTERN)) {
                urlPattern = node.getText().trim();
                if (webXml.tryToMapServlet(servletName, urlPattern))
                    break;
            }/*from   w  ww  .j  a  va  2s .  c  o m*/
        }
        //System.out.println(" is mapped thusly: " +servletName +" => "+ urlPattern);
    }

    for (Iterator<?> ii = root.elementIterator("filter-mapping"); ii.hasNext();) {
        Element elt = (Element) ii.next();
        //System.out.print("name: " +elt.getName());

        String filterName = null;
        String urlPattern = null;
        for (int jj = 0; jj < elt.nodeCount(); jj++) {
            Node node = elt.node(jj);
            if (node.getName() == null)
                continue;
            if (node.getName().equals(FILTER_NAME)) {
                filterName = node.getText().trim();
                if (webXml.tryToCreateFilter(filterName, urlPattern))
                    break;
            } else if (node.getName().equals(FILTER_URL_PATTERN)) {
                urlPattern = node.getText().trim();
                if (webXml.tryToCreateFilter(filterName, urlPattern))
                    break;
            }
        }
        //System.out.println(" is mapped thusly: " +filterName+ " => "+ urlPattern);

    }

    return webXml;
}

From source file:eu.planets_project.pp.plato.util.XMLCompare.java

License:Open Source License

private boolean compareTrees(Element node1, Document doc2, boolean ignoreEmptyNodes,
        boolean ignoreEmptyAttributes) {
    boolean isValid = true;

    Element root2 = doc2.getRootElement();

    String path = node1.getUniquePath();

    Element elementDoc2 = (Element) doc2.selectSingleNode(path);

    // the node doesn't exist in doc2
    if (elementDoc2 == null && node1.elements().size() == 0 && "".equals(node1.getTextTrim())) {
        if (ignoreEmptyNodes == false) {
            errorMessages//  w w w. j a va 2 s.  c o m
                    .append("The following empty node doesnt exist in xml file #2: " + node1.getUniquePath())
                    .append(System.getProperty("line.separator"));
            isValid = false;
        }
    } else if (elementDoc2 == null && (node1.elements().size() > 0 || !"".equals(node1.getTextTrim()))) {
        errorMessages.append("The following node (which is not empty) doesn't exist in xml file #2: "
                + node1.getUniquePath() + System.getProperty("line.separator"));
        errorMessages.append("File #1: " + node1.getTextTrim() + System.getProperty("line.separator"));
        errorMessages
                .append("File #2: " + ((elementDoc2 == null) ? "<not existent>" : elementDoc2.getTextTrim())
                        + System.getProperty("line.separator"));

        isValid = false;
    } else if (elementDoc2 == null || !elementDoc2.getTextTrim().equals(node1.getTextTrim())) {
        errorMessages.append("Text of following nodes not equal in both xmls: " + node1.getUniquePath()
                + System.getProperty("line.separator"));
        errorMessages.append("File #1: " + node1.getTextTrim() + System.getProperty("line.separator"));
        errorMessages
                .append("File #2: " + ((elementDoc2 == null) ? "<not existent>" : elementDoc2.getTextTrim())
                        + System.getProperty("line.separator"));

        isValid = false;
    }

    //
    // compare attributes
    //
    List<Attribute> attributes = node1.attributes();

    for (Attribute a : attributes) {

        String attributePath = a.getUniquePath();

        org.dom4j.Node node = root2.selectSingleNode(attributePath);

        if (node == null && "".equals(a.getValue().trim())) {
            // document 1 has an empty attribute (sting length = 0) which
            // does not exist in document 2

            if (ignoreEmptyAttributes == false) {
                errorMessages.append(
                        "Attribute " + a.getName() + " doesn't exist in xml file #2, node " + a.getUniquePath())
                        .append(System.getProperty("line.separator"));
                isValid = false;
            }

            continue;
        }

        if (node == null || !a.getValue().equals(node.getText())) {

            errorMessages.append("Value of following attribute not equal in both xmls: " + a.getUniquePath()
                    + System.getProperty("line.separator"));
            errorMessages.append("File #1: " + a.getValue() + System.getProperty("line.separator"));
            errorMessages.append("File #2: " + ((node != null) ? node.getText() : "<not existent>")
                    + System.getProperty("line.separator"));

            isValid = false;
        }
    }

    List<Element> elements = node1.elements();

    for (Element e : elements) {
        if (!compareTrees(e, doc2, ignoreEmptyNodes, ignoreEmptyAttributes)) {
            isValid = false;
        }
    }

    return isValid;
}

From source file:eu.scape_project.planning.services.taverna.parser.T2FlowParser.java

License:Apache License

/**
 * Reads the ID annotation of the t2flow.
 * /*from  w w  w .  j  a  va 2  s.co m*/
 * @return the id the workflow adheres to
 * @throws TavernaParserException
 */
public String getId() throws TavernaParserException {

    log.debug("Extracting profile ID");

    XPath xpath = DocumentHelper.createXPath("/t2f:workflow/t2f:dataflow[@role='top']/@id");

    xpath.setNamespaceURIs(T2FLOW_NAMESPACE_MAP);
    Node node = xpath.selectSingleNode(doc);
    if (node == null) {
        return null;
    }
    return node.getText();
}

From source file:eu.scape_project.planning.services.taverna.parser.T2FlowParser.java

License:Apache License

/**
 * Reads the name annotation of the t2flow.
 * //from  w ww.  j  av a 2  s .  c  om
 * @return the name of the workflow
 * @throws TavernaParserException
 */
public String getName() throws TavernaParserException {

    log.debug("Extracting workflow name");

    XPath xpath = DocumentHelper.createXPath(
            "/t2f:workflow/t2f:dataflow[@role='top']/t2f:annotations/*/*/*/*/annotationBean[@class='net.sf.taverna.t2.annotation.annotationbeans.DescriptiveTitle']/text");

    xpath.setNamespaceURIs(T2FLOW_NAMESPACE_MAP);
    Node node = xpath.selectSingleNode(doc);
    if (node == null) {
        return null;
    }
    return node.getText();
}

From source file:eu.scape_project.planning.services.taverna.parser.T2FlowParser.java

License:Apache License

/**
 * Reads the description annotation of the t2flow.
 * //from  w w w .  ja v  a 2  s  .c o  m
 * @return the description of the workflow
 * @throws TavernaParserException
 */
public String getDescription() throws TavernaParserException {

    log.debug("Extracting workflow description");

    XPath xpath = DocumentHelper.createXPath(
            "/t2f:workflow/t2f:dataflow[@role='top']/t2f:annotations/*/*/*/*/annotationBean[@class='net.sf.taverna.t2.annotation.annotationbeans.FreeTextDescription']/text");

    xpath.setNamespaceURIs(T2FLOW_NAMESPACE_MAP);
    Node node = xpath.selectSingleNode(doc);
    if (node == null) {
        return null;
    }
    return node.getText();
}

From source file:eu.scape_project.planning.services.taverna.parser.T2FlowParser.java

License:Apache License

/**
 * Reads the author annotation of the t2flow.
 * /*from  w w w  .j av a  2  s. c o m*/
 * @return the author of the workflow
 * @throws TavernaParserException
 */
public String getAuthor() throws TavernaParserException {

    log.debug("Extracting workflow author");

    XPath xpath = DocumentHelper.createXPath(
            "/t2f:workflow/t2f:dataflow[@role='top']/t2f:annotations/*/*/*/*/annotationBean[@class='net.sf.taverna.t2.annotation.annotationbeans.Author']/text");

    xpath.setNamespaceURIs(T2FLOW_NAMESPACE_MAP);
    Node node = xpath.selectSingleNode(doc);
    if (node == null) {
        return null;
    }
    return node.getText();
}