Beispiel #1
0
  /**
   * Appends the XML representation of the given <code>Query</code> to an element.
   *
   * @param query
   */
  private static void appendQuery(Element root, Query query)
      throws IOException, XMLParsingException {

    Element queryElem = XMLTools.appendElement(root, WFS, "wfs:Query");
    if (query.getHandle() != null) {
      queryElem.setAttribute("handle", query.getHandle());
    }
    if (query.getFeatureVersion() != null) {
      queryElem.setAttribute("featureVersion", query.getFeatureVersion());
    }
    QualifiedName[] qn = query.getTypeNames();
    String[] na = new String[qn.length];
    for (int i = 0; i < na.length; i++) {
      na[i] = qn[i].getAsString();
      queryElem.setAttribute("xmlns:" + qn[i].getPrefix(), qn[i].getNamespace().toASCIIString());
    }
    String tn = StringTools.arrayToString(na, ',');
    queryElem.setAttribute("typeName", tn);

    PropertyPath[] propertyNames = query.getPropertyNames();
    for (int i = 0; i < propertyNames.length; i++) {
      Element propertyNameElement = XMLTools.appendElement(queryElem, WFS, "wfs:PropertyName");
      appendPropertyPath(propertyNameElement, propertyNames[i]);
    }
    Function[] fn = query.getFunctions();
    // copy function definitions into query node
    if (fn != null) {
      for (int i = 0; i < fn.length; i++) {
        StringReader sr = new StringReader(fn[i].toXML().toString());
        Document doc;
        try {
          doc = XMLTools.parse(sr);
        } catch (SAXException e) {
          throw new XMLParsingException("could not parse filter function", e);
        }
        XMLTools.copyNode(doc.getDocumentElement(), queryElem);
      }
    }
    // copy filter into query node
    if (query.getFilter() != null) {
      StringReader sr = new StringReader(query.getFilter().toXML().toString());
      Document doc;
      try {
        doc = XMLTools.parse(sr);
      } catch (SAXException e) {
        throw new XMLParsingException("could not parse filter", e);
      }
      Element elem = XMLTools.appendElement(queryElem, OGCNS, "ogc:Filter");
      XMLTools.copyNode(doc.getDocumentElement(), elem);
    }

    SortProperty[] sp = query.getSortProperties();
    if (sp != null) {
      Element sortBy = XMLTools.appendElement(queryElem, OGCNS, "ogc:SortBy");
      for (int i = 0; i < sp.length; i++) {
        Element sortProp = XMLTools.appendElement(sortBy, OGCNS, "ogc:SortProperty");
        XMLTools.appendElement(
            sortProp, OGCNS, "ogc:PropertyName", sp[i].getSortProperty().getAsString());
        if (!sp[i].getSortOrder()) {
          XMLTools.appendElement(sortBy, OGCNS, "ogc:SortOrder", "DESC");
        }
      }
    }
  }