public void printInfo(boolean printCoordinates) { System.out.printf( "%d, %s: %d parts, %d points", this.getRecordNumber(), this.getShapeType(), this.getNumberOfParts(), this.getNumberOfPoints()); for (Map.Entry<String, Object> a : this.getAttributes().getEntries()) { if (a.getKey() != null) System.out.printf(", %s", a.getKey()); if (a.getValue() != null) System.out.printf(", %s", a.getValue()); } System.out.println(); System.out.print("\tAttributes: "); for (Map.Entry<String, Object> entry : this.getAttributes().getEntries()) { System.out.printf("%s = %s, ", entry.getKey(), entry.getValue()); } System.out.println(); if (!printCoordinates) return; VecBuffer vb = this.getPointBuffer(0); for (LatLon ll : vb.getLocations()) { System.out.printf("\t%f, %f\n", ll.getLatitude().degrees, ll.getLongitude().degrees); } }
/** * Helper function that takes a Map of String, String where key contains the value of an evaluated * SynapsePath expression and value contains the type of SynapsePath in use. * * <p>It returns the type of conversion required (XML | JSON | String) based on the actual * returned value and the path type. * * @param entry * @return */ private String inferReplacementType(Map.Entry<String, String> entry) { if (entry.getValue().equals(SynapsePath.X_PATH) && isWellFormedXML(entry.getKey())) { return XML_TYPE; } else if (entry.getValue().equals(SynapsePath.X_PATH) && !isWellFormedXML(entry.getKey())) { return STRING_TYPE; } else if (entry.getValue().equals(SynapsePath.JSON_PATH) && isJson(entry.getKey())) { return JSON_TYPE; } else if (entry.getValue().equals(SynapsePath.JSON_PATH) && !isJson((entry.getKey()))) { return STRING_TYPE; } else { return STRING_TYPE; } }
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 }