Package org.jboss.errai.forge.xml

Examples of org.jboss.errai.forge.xml.XmlParser


  @Override
  public boolean install() {
    try {
      final File file = getResFile(getRelPath());

      final XmlParser xmlParser = xmlParserFactory.newXmlParser(file);

      final XPath xPath = xPathFactory.newXPath();
      final Map<XPathExpression, Collection<Node>> toInsert = getElementsToInsert(xPath, xmlParser);
      final Map<XPathExpression, Node> replacements = getReplacements(xPath, xmlParser);

      for (final Entry<XPathExpression, Collection<Node>> entry : toInsert.entrySet()) {
        xmlParser.addChildNodes(entry.getKey(), entry.getValue());
      }

      for (final Entry<XPathExpression, Node> entry : replacements.entrySet()) {
        xmlParser.replaceNode(entry.getKey(), entry.getValue());
      }

      xmlParser.close();
    }
    catch (Exception e) {
      error("Error: failed to add required inheritance to module.", e);
      return false;
    }
View Full Code Here


    final File file = getResFile(relPath);
    if (!file.exists())
      return false;

    try {
      final XmlParser xmlParser = xmlParserFactory.newXmlParser(file);
      final XPath xPath = xPathFactory.newXPath();
      final Map<XPathExpression, Collection<Node>> insertedToCheck = getElementsToVerify(xPath, xmlParser);
      final Map<XPathExpression, Node> replacedToCheck = getReplacements(xPath, xmlParser);

      for (final XPathExpression expression : insertedToCheck.keySet()) {
        if (xmlParser.hasNode(expression)) {
          for (final Node inserted : insertedToCheck.get(expression)) {
            if (!xmlParser.hasMatchingChild(expression, inserted)) {
              return false;
            }
          }
        }
        else {
          return false;
        }
      }

      for (final XPathExpression expression : replacedToCheck.keySet()) {
        if (!xmlParser.matches(expression, replacedToCheck.get(expression))) {
          return false;
        }
      }
    }
    catch (Exception e) {
View Full Code Here

    if (!file.exists())
      // XXX not sure if this case should return true or false...
      return true;

    try {
      final XmlParser xmlParser = xmlParserFactory.newXmlParser(file);
      final XPath xPath = xPathFactory.newXPath();
      final Map<XPathExpression, Collection<Node>> insertedNodes = getElementsToInsert(xPath, xmlParser);
      final Map<XPathExpression, Node> replacedNodes = getRemovalMap(xPath, xmlParser);

      for (final Entry<XPathExpression, Collection<Node>> entry : insertedNodes.entrySet()) {
        if (xmlParser.hasNode(entry.getKey())) {
          for (final Node inserted : entry.getValue()) {
            xmlParser.removeChildNode(entry.getKey(), inserted);
          }
        }
      }

      for (final Entry<XPathExpression, Node> entry : replacedNodes.entrySet()) {
        if (xmlParser.hasNode(entry.getKey())) {
          xmlParser.replaceNode(entry.getKey(), entry.getValue());
        }
      }
     
      xmlParser.close();
    }
    catch (Exception e) {
      error("Error occurred while attempting to verify xml resource " + file.getAbsolutePath(), e);
      return false;
    }
View Full Code Here

    return super.install();
  }

  public String getModuleName() throws ParserConfigurationException, SAXException, IOException,
          TransformerConfigurationException, XPathExpressionException {
    final XmlParser xmlParser = xmlParserFactory.newXmlParser(getModuleFile(), xmlProperties);
    final XPath xPath = xPathFactory.newXPath();
    final Map<String, String> moduleAttributes = xmlParser.getAttributes(xPath.compile("/module"));

    String name = (moduleAttributes != null) ? moduleAttributes.get("rename-to") : null;
    if (name == null) {
      name = getProject().getFacet(ProjectConfig.class).getProjectProperty(ProjectProperty.MODULE_LOGICAL,
              String.class);
View Full Code Here

    return name;
  }

  public void setModuleName(final String moduleName) throws SAXException, IOException, ParserConfigurationException,
          TransformerException, XPathExpressionException {
    final XmlParser xmlParser = xmlParserFactory.newXmlParser(getModuleFile(), xmlProperties);
    final XPath xPath = xPathFactory.newXPath();
    final Map<String, String> moduleAttributes = xmlParser.getAttributes(xPath.compile("/module"));

    if (moduleName != null && !moduleName.equals("")) {
      moduleAttributes.put("rename-to", moduleName);
    }
    else {
      moduleAttributes.remove("rename-to");
    }

    xmlParser.close();
  }
View Full Code Here

TOP

Related Classes of org.jboss.errai.forge.xml.XmlParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.