public String tags2LowerCase(String payload) throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    builder.setValidation(false);
    builder.setIgnoringElementContentWhitespace(true);
    Document xmldoc = builder.build(new StringReader(payload));

    XPath xpath = XPath.newInstance("//*");
    List result = xpath.selectNodes(xmldoc);
    Iterator it = result.iterator();
    while (it.hasNext()) {
      Element element = (Element) it.next();
      element.setName(element.getName().toLowerCase());
      element.setNamespace(null);
    }

    XMLOutputter outputter = new XMLOutputter();
    ByteArrayOutputStream parsed = new ByteArrayOutputStream();
    outputter.output(xmldoc, parsed);

    return parsed.toString();
  }
Example #2
0
 /**
  * Include one dataset file.
  *
  * @param incDSFile : Include data set filename.
  * @param dsList :List of dataset names to verify the duplicate.
  * @param allDataSets : Element that includes all dataset definitions.
  * @param dsNameSpace : Data set name space
  * @throws CoordinatorJobException thrown if failed to include one dataset file
  */
 @SuppressWarnings("unchecked")
 private void includeOneDSFile(
     String incDSFile, List<String> dsList, Element allDataSets, Namespace dsNameSpace)
     throws CoordinatorJobException {
   Element tmpDataSets = null;
   try {
     String dsXml = readDefinition(incDSFile);
     LOG.debug("DSFILE :" + incDSFile + "\n" + dsXml);
     tmpDataSets = XmlUtils.parseXml(dsXml);
   } catch (JDOMException e) {
     LOG.warn("Error parsing included dataset [{0}].  Message [{1}]", incDSFile, e.getMessage());
     throw new CoordinatorJobException(ErrorCode.E0700, e.getMessage());
   }
   resolveDataSets(tmpDataSets.getChildren("dataset"));
   for (Element e : (List<Element>) tmpDataSets.getChildren("dataset")) {
     String dsName = e.getAttributeValue("name");
     if (dsList.contains(dsName)) {
       throw new RuntimeException("Duplicate Dataset " + dsName);
     }
     dsList.add(dsName);
     Element tmp = (Element) e.clone();
     // TODO: Don't like to over-write the external/include DS's namespace
     tmp.setNamespace(dsNameSpace);
     tmp.getChild("uri-template").setNamespace(dsNameSpace);
     if (e.getChild("done-flag") != null) {
       tmp.getChild("done-flag").setNamespace(dsNameSpace);
     }
     allDataSets.addContent(tmp);
   }
   // nested include
   for (Element includeElem :
       (List<Element>) tmpDataSets.getChildren("include", tmpDataSets.getNamespace())) {
     String incFile = includeElem.getTextTrim();
     includeOneDSFile(incFile, dsList, allDataSets, dsNameSpace);
   }
 }
  public String getSaveAsPayload(String original) throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    builder.setValidation(false);
    builder.setIgnoringElementContentWhitespace(true);
    Document xmldoc = builder.build(new StringReader(original));
    Document ret = builder.build(new StringReader(original));

    ((Element) ret.getContent(0)).removeContent();

    XPath xpath = XPath.newInstance("//DISK[SAVE_AS]");
    List result = xpath.selectNodes(xmldoc);
    Iterator it = result.iterator();
    while (it.hasNext()) {
      Element element = (Element) it.next();
      element.setNamespace(null);
      ret.getRootElement().addContent((Element) element.clone());
    }

    XMLOutputter outputter = new XMLOutputter();
    ByteArrayOutputStream parsed = new ByteArrayOutputStream();
    outputter.output(ret, parsed);

    return parsed.toString();
  }
Example #4
0
  public static void writeKML(String path) {
    Element root = new Element("kml");
    root.setNamespace(Namespace.getNamespace(null, "http://www.opengis.net/kml/2.2"));
    root.addNamespaceDeclaration(Namespace.getNamespace("gx", "http://www.google.com/kml/ext/2.2"));
    root.addNamespaceDeclaration(Namespace.getNamespace("kml", "http://www.opengis.net/kml/2.2"));
    root.addNamespaceDeclaration(Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"));

    Document doc = new Document(root);

    Element document = new Element("Document");
    root.addContent(document);

    Element style1 = new Element("Style");
    style1.setAttribute("id", "shp_centerpoint");
    document.addContent(style1);

    Element iconstyle = new Element("IconStyle");
    style1.addContent(iconstyle);

    Element scale1 = new Element("scale");
    scale1.setText("0.8");
    iconstyle.addContent(scale1);

    Element icon = new Element("Icon");
    iconstyle.addContent(icon);

    Element href = new Element("href");
    href.setText("http://maps.google.com/mapfiles/kml/paddle/red-circle.png");
    icon.addContent(href);

    Element labelstyle = new Element("LabelStyle");
    style1.addContent(labelstyle);

    Element scale2 = new Element("scale");
    scale2.setText("1");
    labelstyle.addContent(scale2);

    Element color1 = new Element("color");
    color1.setText("FFFFFFFF");
    labelstyle.addContent(color1);

    Element filename = new Element("name");
    String[] split = path.split("/");
    String tmp = split[split.length - 1];
    filename.setText(tmp.substring(0, tmp.length() - 4));
    document.addContent(filename);

    Element folder = new Element("Folder");
    document.addContent(folder);

    Element name1 = new Element("name");
    name1.setText("Labels");
    folder.addContent(name1);

    Element description1 = new Element("description");
    folder.addContent(description1);

    Element open1 = new Element("open");
    open1.setText("0");
    folder.addContent(open1);

    GraphNode gn;
    for (Integer z : popcentroids.keySet()) {
      gn = popcentroids.get(z);
      Element placemark = new Element("Placemark");
      placemark.setAttribute("id", gn.getNodeID() + "lbl");
      folder.addContent(placemark);

      Element snippet = new Element("Snippet");
      snippet.setAttribute("maxLines", "0");
      placemark.addContent(snippet);

      Element name = new Element("name");
      name.setText(gn.getNodeID() + "");
      placemark.addContent(name);

      Element description = new Element("description");
      description.setText(gn.getTAZ() + " " + gn.getTract() + " " + gn.getBG());
      placemark.addContent(description);

      Element visibility = new Element("visibility");
      visibility.setText("1");
      placemark.addContent(visibility);

      Element open = new Element("open");
      open.setText("0");
      placemark.addContent(open);

      Element point = new Element("Point");
      placemark.addContent(point);

      Element extrude = new Element("extrude");
      extrude.setText("0");
      point.addContent(extrude);

      Element tess = new Element("tessalate");
      tess.setText("1");
      point.addContent(tess);

      Element alt = new Element("altitudeMode");
      alt.setText("clampedToGround");
      point.addContent(alt);

      Element coord = new Element("coordinates");
      coord.setText(gn.getCentroid().getX() + "," + gn.getCentroid().getY() + ",0");
      point.addContent(coord);

      Element styleUrl = new Element("styleUrl");
      styleUrl.setText("#shp_centerpoint");
      placemark.addContent(styleUrl);

      XMLOutputter outputter = new XMLOutputter();
      try {
        outputter.output(doc, new FileOutputStream(path));
      } catch (IOException e) {
        System.err.println(e);
      }
    }
  }