コード例 #1
0
  public void exportAsXML(XMLStreamWriter xmlWriter) throws IOException, XMLStreamException {
    if (xmlWriter == null) {
      String message = Logging.getMessage("Export.UnsupportedOutputObject");
      Logging.logger().warning(message);
      throw new IllegalArgumentException(message);
    }

    xmlWriter.writeStartElement("Record");

    xmlWriter.writeAttribute("id", Integer.toString(this.getRecordNumber()));
    xmlWriter.writeAttribute(
        "shape", this.getShapeType().substring(this.getShapeType().lastIndexOf("Shape") + 5));
    xmlWriter.writeAttribute("parts", Integer.toString(this.getNumberOfParts()));
    xmlWriter.writeAttribute("points", Integer.toString(this.getNumberOfPoints()));
    xmlWriter.writeCharacters("\n");

    for (Map.Entry<String, Object> a : this.getAttributes().getEntries()) {
      xmlWriter.writeStartElement("Attribute");

      xmlWriter.writeAttribute("name", a.getKey() != null ? a.getKey().toString() : "");
      xmlWriter.writeAttribute("value", a.getValue() != null ? a.getValue().toString() : "");

      xmlWriter.writeEndElement(); // Attribute
      xmlWriter.writeCharacters("\n");
    }

    if (this.getNumberOfParts() > 0) {
      VecBuffer vb = this.getPointBuffer(0);
      for (LatLon ll : vb.getLocations()) {
        xmlWriter.writeStartElement("Point");
        xmlWriter.writeAttribute("x", Double.toString(ll.getLatitude().degrees));
        xmlWriter.writeAttribute("y", Double.toString(ll.getLongitude().degrees));
        xmlWriter.writeEndElement(); // Point
        xmlWriter.writeCharacters("\n");
      }
    }

    // TODO: export record-type specific fields

    xmlWriter.writeEndElement(); // Record
  }
コード例 #2
0
  @Override
  public int writeData(OutputStream out, DbData data) throws Exception {
    XMLStreamWriter sw = _staxOutFactory.createXMLStreamWriter(out, "UTF-8");
    sw.writeStartDocument();
    sw.writeStartElement(FIELD_TABLE);
    Iterator<DbRow> it = data.rows();
    while (it.hasNext()) {
      DbRow row = it.next();
      sw.writeStartElement(FIELD_ROW); // <row>

      sw.writeStartElement(DbRow.Field.id.name());
      sw.writeCharacters(String.valueOf(row.getId()));
      sw.writeEndElement();

      sw.writeStartElement(DbRow.Field.firstname.name());
      sw.writeCharacters(row.getFirstname());
      sw.writeEndElement();

      sw.writeStartElement(DbRow.Field.lastname.name());
      sw.writeCharacters(row.getLastname());
      sw.writeEndElement();

      sw.writeStartElement(DbRow.Field.zip.name());
      sw.writeCharacters(String.valueOf(row.getZip()));
      sw.writeEndElement();

      sw.writeStartElement(DbRow.Field.street.name());
      sw.writeCharacters(row.getStreet());
      sw.writeEndElement();

      sw.writeStartElement(DbRow.Field.city.name());
      sw.writeCharacters(row.getCity());
      sw.writeEndElement();

      sw.writeStartElement(DbRow.Field.state.name());
      sw.writeCharacters(row.getState());
      sw.writeEndElement();

      sw.writeEndElement(); // </row>
    }
    sw.writeEndElement();
    sw.writeEndDocument();
    sw.close();
    return -1;
  }
コード例 #3
0
ファイル: XMLDom.java プロジェクト: albertoanguita/jacuzzi
 private static void writeElement(XMLStreamWriter xtw, Element element) throws XMLStreamException {
   xtw.writeStartElement(element.getName());
   for (String attributeName : element.getAttributeNames()) {
     xtw.writeAttribute(attributeName, element.getAttributeValue(attributeName));
   }
   if (element.hasText()) {
     xtw.writeCharacters(element.getText());
   } else {
     for (Element child : element.getChildren()) {
       writeElement(xtw, child);
     }
   }
   xtw.writeEndElement();
 }
コード例 #4
0
  /**
   * Export the placemark attributes to KML as a {@code <Style>} element. The {@code output} object
   * will receive the data. This object must be one of: java.io.Writer<br>
   * java.io.OutputStream<br>
   * javax.xml.stream.XMLStreamWriter
   *
   * @param output Object to receive the generated KML.
   * @throws XMLStreamException If an exception occurs while writing the KML
   * @see #export(String, Object)
   */
  protected void exportAsKML(Object output) throws XMLStreamException {
    XMLStreamWriter xmlWriter = null;
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    boolean closeWriterWhenFinished = true;

    if (output instanceof XMLStreamWriter) {
      xmlWriter = (XMLStreamWriter) output;
      closeWriterWhenFinished = false;
    } else if (output instanceof Writer) {
      xmlWriter = factory.createXMLStreamWriter((Writer) output);
    } else if (output instanceof OutputStream) {
      xmlWriter = factory.createXMLStreamWriter((OutputStream) output);
    }

    if (xmlWriter == null) {
      String message = Logging.getMessage("Export.UnsupportedOutputObject");
      Logging.logger().warning(message);
      throw new IllegalArgumentException(message);
    }

    xmlWriter.writeStartElement("Style");

    // Line style
    xmlWriter.writeStartElement("LineStyle");

    final Color lineColor = this.getOutlineMaterial().getDiffuse();
    if (lineColor != null) {
      xmlWriter.writeStartElement("color");
      xmlWriter.writeCharacters(KMLExportUtil.stripHexPrefix(WWUtil.encodeColorABGR(lineColor)));
      xmlWriter.writeEndElement();

      xmlWriter.writeStartElement("colorMode");
      xmlWriter.writeCharacters("normal");
      xmlWriter.writeEndElement();
    }

    final Double lineWidth = this.getOutlineWidth();
    if (lineWidth != null) {
      xmlWriter.writeStartElement("width");
      xmlWriter.writeCharacters(Double.toString(lineWidth));
      xmlWriter.writeEndElement();
    }

    xmlWriter.writeEndElement(); // LineStyle

    // Poly style
    xmlWriter.writeStartElement("PolyStyle");

    final Color fillColor = this.getInteriorMaterial().getDiffuse();
    if (fillColor != null) {
      xmlWriter.writeStartElement("color");
      xmlWriter.writeCharacters(KMLExportUtil.stripHexPrefix(WWUtil.encodeColorABGR(fillColor)));
      xmlWriter.writeEndElement();

      xmlWriter.writeStartElement("colorMode");
      xmlWriter.writeCharacters("normal");
      xmlWriter.writeEndElement();
    }

    xmlWriter.writeStartElement("fill");
    xmlWriter.writeCharacters(kmlBoolean(isDrawInterior()));
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("outline");
    xmlWriter.writeCharacters(kmlBoolean(isDrawOutline()));
    xmlWriter.writeEndElement();

    xmlWriter.writeEndElement(); // PolyStyle
    xmlWriter.writeEndElement(); // Style

    xmlWriter.flush();
    if (closeWriterWhenFinished) xmlWriter.close();
  }