예제 #1
0
  public static List getNcMLElements(String path, Document doc) {

    // XPath doesn't support default namespaces, so we add nc as a prefix for the tags within the
    // namespace!!!
    if (!path.startsWith(NS_PREFIX_ON_TAG) && !path.startsWith("/")) path = NS_PREFIX_ON_TAG + path;

    Pattern pattern = Pattern.compile("/\\w");
    Matcher matcher = pattern.matcher(path);

    StringBuilder sb = new StringBuilder();
    int currentChar = 0;
    while (matcher.find()) {

      sb.append(path.substring(currentChar, matcher.start() - currentChar + 1));
      if (!sb.toString().endsWith("/")) sb.append("/");
      sb.append(NS_PREFIX_ON_TAG);
      currentChar = matcher.start() + 1;
    }

    sb.append(path.substring(currentChar, path.length()));

    XPath xpath;
    try {

      xpath = XPath.newInstance(sb.toString());
      xpath.addNamespace(NS_PREFIX, doc.getRootElement().getNamespaceURI());
      return xpath.selectNodes(doc);

    } catch (JDOMException e) {

      e.printStackTrace();
    }

    return null;
  }
예제 #2
0
 public List<String> getLocaleDirectories() throws JDOMException {
   List<Element> langAddedList = ((List<Element>) XPath.selectNodes(loopDoc, "//langAdded"));
   List<String> stringLocaleDirectories = new ArrayList<String>();
   List<Element> localeDirectories = new ArrayList<Element>();
   for (Element langAdded : langAddedList) {
     localeDirectories = langAdded.getChildren("language");
     for (Element localeDirectory : localeDirectories) {
       stringLocaleDirectories.add(localeDirectory.getValue());
     }
   }
   return stringLocaleDirectories;
 }
  public Map getEnvironmentDetails(MavenProjectInfo mavenProjectInfo, String phrescoTargetDir)
      throws JDOMException, IOException {
    System.setProperty(
        "javax.xml.parsers.SAXParserFactory",
        "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
    builder = new SAXBuilder();
    // disabling xml validation
    builder.setValidation(false);
    builder.setIgnoringElementContentWhitespace(true);
    envXML =
        builder.build(
            new File(
                mavenProjectInfo.getBaseDir()
                    + File.separator
                    + mavenProjectInfo
                        .getProject()
                        .getProperties()
                        .getProperty("phresco.environment.xml.file.path")));

    // Get server details
    List<Element> serverDetails = ((List<Element>) XPath.selectNodes(envXML, "//Server"));
    System.out.println("serverDetails => " + serverDetails);

    // Get database details
    List<Element> dbDetails = ((List<Element>) XPath.selectNodes(envXML, "//Database"));
    System.out.println("dbDetails => " + dbDetails);

    for (Element server : serverDetails) {
      stringEnvDetails.put("context", server.getChildText("context"));
      stringEnvDetails.put("deploy_dir", server.getChildText("deploy_dir"));
    }

    for (Element db : dbDetails) {
      stringEnvDetails.put("username", db.getChildText("username"));
      stringEnvDetails.put("password", db.getChildText("password"));
      stringEnvDetails.put("host", db.getChildText("host"));
      stringEnvDetails.put("dbname", db.getChildText("dbname"));
    }
    return stringEnvDetails;
  }