public static void writePlacemarksFile(Writer writer, List<Placemark> placemarks) throws IOException { XmlWriter xmlWriter = new XmlWriter(writer, true); final String[] tags = XmlWriter.createTags(0, "Placemarks"); xmlWriter.println(tags[0]); for (Placemark placemark : placemarks) { if (placemark != null) { writeXML(placemark, xmlWriter, 1); } } xmlWriter.println(tags[1]); xmlWriter.close(); }
public void printLine(int indent, String tagName, String text) { final String[] tags = createTags(indent, tagName); printLine(tags, text); }
public void printLine(String[] tags, String text) { if (text != null && text.trim().length() > 0) { _pWriter.print(tags[0]); _pWriter.print(encode(text)); _pWriter.println(tags[1].trim()); } else { _pWriter.println(tags[0].substring(0, tags[0].length() - 1).concat(" />")); } }
public static void writeColor(final String tagName, final int indent, final Color color, final XmlWriter writer) { final String[] colorTags = XmlWriter.createTags(indent, tagName); writer.println(colorTags[0]); DimapProductHelpers.printColorTag(indent + 1, color, writer); writer.println(colorTags[1]); } }
public void testPrintLineText_parentheses() { StringWriter stringWriter = new StringWriter(); XmlWriter xmlWriter = new XmlWriter(stringWriter, false); xmlWriter.printLine(XmlWriter.createTags(1, "tag"), "test < test > test"); String current = stringWriter.toString(); String expected = " <tag>test < test > test</tag>"; stringWriter = new StringWriter(); new PrintWriter(stringWriter).println(); expected = expected + stringWriter.toString(); assertEquals(expected, current); }
public static void writeXML(Placemark placemark, XmlWriter writer, int indent) { Guardian.assertNotNull("writer", writer); Guardian.assertGreaterThan("indent", indent, -1); final String[][] attributes = {new String[]{DimapProductConstants.ATTRIB_NAME, placemark.getName()}}; final String[] pinTags = XmlWriter.createTags(indent, DimapProductConstants.TAG_PLACEMARK, attributes); writer.println(pinTags[0]); indent++; writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_LABEL, placemark.getLabel()); writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_DESCRIPTION, placemark.getDescription()); final GeoPos geoPos = placemark.getGeoPos(); if (geoPos != null) { writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_LATITUDE, geoPos.lat); writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_LONGITUDE, geoPos.lon); } final PixelPos pixelPos = placemark.getPixelPos(); if (pixelPos != null && pixelPos.isValid()) { writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_PIXEL_X, pixelPos.x); writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_PIXEL_Y, pixelPos.y); } final String styleCss = placemark.getStyleCss(); if (styleCss != null && !styleCss.isEmpty()) { writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_STYLE_CSS, styleCss); } writer.println(pinTags[1]); }
public void printLine(int indent, String tagName, float f) { printLine(indent, tagName, String.valueOf(f)); }
protected void writeMaskUsages(XmlWriter pw, int indent, RasterDataNode[] rasterDataNodes) { Guardian.assertNotNull("pw", pw); Guardian.assertNotNull("rasterDataNodes", rasterDataNodes); for (int i = 0; i < rasterDataNodes.length; i++) { final RasterDataNode rasterDataNode = rasterDataNodes[i]; ProductNodeGroup<Mask> overlayMaskGroup = rasterDataNode.getOverlayMaskGroup(); if (overlayMaskGroup.getNodeCount() > 0) { final String[] boTags = createTags(indent, DimapProductConstants.TAG_MASK_USAGE); pw.println(boTags[0]); if (rasterDataNode instanceof Band) { pw.printLine(indent + 1, DimapProductConstants.TAG_BAND_INDEX, i); } else { pw.printLine(indent + 1, DimapProductConstants.TAG_TIE_POINT_GRID_INDEX, i); } final String[][] attributes = new String[1][]; if (overlayMaskGroup.getNodeCount() > 0) { attributes[0] = new String[]{ DimapProductConstants.ATTRIB_NAMES, StringUtils.arrayToCsv(overlayMaskGroup.getNodeNames()) }; pw.printLine(indent + 1, DimapProductConstants.TAG_OVERLAY, attributes, null); } pw.println(boTags[1]); } } }
public void testCreateTags() { String[] tags = XmlWriter.createTags(0, "name"); assertEquals(2, tags.length); assertEquals("<name>", tags[0]); assertEquals("</name>", tags[1]); }
protected void writeImageDisplayElements(int indent) { final StringWriter stringWriter = new StringWriter(); final XmlWriter sXmlW = new XmlWriter(stringWriter, false); final Band[] bands = product.getBands(); final String[] idTags = createTags(indent, DimapProductConstants.TAG_IMAGE_DISPLAY); writeBandStatistics(sXmlW, indent, bands); writeMaskUsages(sXmlW, indent + 1, bands); writeMaskUsages(sXmlW, indent + 1, product.getTiePointGrids()); sXmlW.close(); final String childTags = stringWriter.toString(); if (childTags != null && childTags.length() > 0) { println(idTags[0]); print(childTags); println(idTags[1]); } }
public void testWriteXML_IndentIsSmallerThanZero() { Placemark placemark = Placemark.createPointPlacemark(PinDescriptor.getInstance(), "pinName", "pinLabel", "", null, new GeoPos(), product.getGeoCoding()); try { int indent = -1; PlacemarkIO.writeXML(placemark, new XmlWriter(new StringWriter(), false), indent); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // expected IllegalArgumentException } catch (Exception e) { fail("IllegalArgumentException expected"); } }
public static String[] createTags(int indent, String name, String[][] attributes) { Debug.assertNotNullOrEmpty(name); Debug.assertNotNull(attributes); final StringBuffer tag = new StringBuffer(); final String indentWs = getIndentWhiteSpace(indent); tag.append(indentWs); tag.append("<"); tag.append(name); for (int i = 0; i < attributes.length; i++) { final String[] att_val = attributes[i]; if (att_val.length > 1) { final String attribute = att_val[0]; final String value = att_val[1]; if (attribute != null && attribute.length() > 0) { tag.append(" " + attribute + "=\""); if (value != null) { tag.append(encode(value)); } tag.append("\""); } } } tag.append(">"); final String[] tags = new String[2]; tags[0] = tag.toString(); tags[1] = indentWs + "</" + name + ">"; return tags; }
public static String[] createTags(int indent, String name) { final String[] tags = new String[2]; final String ws = getIndentWhiteSpace(indent); tags[0] = ws + "<" + name + ">"; tags[1] = ws + "</" + name + ">"; return tags; }
public XmlWriter(Writer writer, boolean initHeadline) { Guardian.assertNotNull("writer", writer); if (writer instanceof PrintWriter) { _pWriter = (PrintWriter) writer; } else { _pWriter = new PrintWriter(writer); } _xmlOutputter = new XMLOutputter(); final Format format = _xmlOutputter.getFormat(); format.setIndent(" "); // four spaces _xmlOutputter.setFormat(format); if (initHeadline) { init(); } }
public void testPrintLineWidthText() { StringWriter stringWriter = new StringWriter(); XmlWriter xmlWriter = new XmlWriter(stringWriter, false); xmlWriter.printLine(XmlWriter.createTags(1, "tag"), "name"); String current = stringWriter.toString(); String expected = " <tag>name</tag>"; stringWriter = new StringWriter(); new PrintWriter(stringWriter).println(); expected = expected + stringWriter.toString(); assertEquals(expected, current); }
public void writeXML(XmlWriter writer, int indent) { Guardian.assertNotNull("writer", writer); Guardian.assertGreaterThan("indent", indent, -1); String[][] attributes = new String[1][]; attributes[0] = new String[]{DimapProductConstants.ATTRIB_NAME, getName()}; String[] bdTags = XmlWriter.createTags(indent, DimapProductConstants.TAG_BITMASK_DEFINITION, attributes); writer.println(bdTags[0]); String description = getDescription(); if (description == null) { description = ""; } attributes[0] = new String[]{DimapProductConstants.ATTRIB_VALUE, description}; writer.printLine(indent + 1, DimapProductConstants.TAG_BITMASK_DESCRIPTION, attributes, null); String expr = getExpr(); if (expr == null) { expr = ""; } attributes[0] = new String[]{DimapProductConstants.ATTRIB_VALUE, expr}; writer.printLine(indent + 1, DimapProductConstants.TAG_BITMASK_EXPRESSION, attributes, null); DimapProductHelpers.printColorTag(indent + 1, getColor(), writer); attributes[0] = new String[]{DimapProductConstants.ATTRIB_VALUE, String.valueOf(getTransparency())}; writer.printLine(indent + 1, DimapProductConstants.TAG_BITMASK_TRANSPARENCY, attributes, null); writer.println(bdTags[1]); }
public void printLine(int indent, String tagName, double d) { printLine(indent, tagName, String.valueOf(d)); }
if (band.getImageInfo() != null) { final String[] bsTags = createTags(indent + 1, DimapProductConstants.TAG_BAND_STATISTICS); sXmlW.println(bsTags[0]); sXmlW.printLine(indent + 2, DimapProductConstants.TAG_BAND_INDEX, i); sXmlW.printLine(indent + 2, DimapProductConstants.TAG_STX_MIN, band.getStx().getMinimum()); sXmlW.printLine(indent + 2, DimapProductConstants.TAG_STX_MAX, band.getStx().getMaximum()); sXmlW.printLine(indent + 2, DimapProductConstants.TAG_STX_MEAN, band.getStx().getMean()); sXmlW.printLine(indent + 2, DimapProductConstants.TAG_STX_STDDEV, band.getStx().getStandardDeviation()); sXmlW.printLine(indent + 2, DimapProductConstants.TAG_STX_LEVEL, band.getStx().getResolutionLevel()); final int[] bins = band.getStx().getHistogramBins(); if (bins != null && bins.length > 0) { sXmlW.printLine(indent + 2, DimapProductConstants.TAG_HISTOGRAM, StringUtils.arrayToCsv(bins)); sXmlW.printLine(indent + 2, DimapProductConstants.TAG_NUM_COLORS, paletteDefinition.getNumColors()); final Iterator iterator = paletteDefinition.getIterator(); while (iterator.hasNext()) { final ColorPaletteDef.Point point = (ColorPaletteDef.Point) iterator.next(); final String[] cppTags = createTags(indent + 2, DimapProductConstants.TAG_COLOR_PALETTE_POINT); sXmlW.println(cppTags[0]); sXmlW.printLine(indent + 3, DimapProductConstants.TAG_SAMPLE, point.getSample()); if (StringUtils.isNotNullAndNotEmpty(point.getLabel())) { sXmlW.printLine(indent + 3, DimapProductConstants.TAG_LABEL, point.getLabel()); sXmlW.println(cppTags[1]); sXmlW.printLine(indent + 2, DimapProductConstants.TAG_HISTOGRAM_MATCHING, band.getImageInfo().getHistogramMatching().toString());
public void testCreateTagsWithAtribs() { String[] tags = XmlWriter.createTags(2, "name", new String[][]{{"a", "b"}, {"c", "d"}}); assertEquals(2, tags.length); assertEquals(" <name a=\"b\" c=\"d\">", tags[0]); assertEquals(" </name>", tags[1]); }
public void testWriteXML_DifferentValidIndent() { Placemark placemark = Placemark.createPointPlacemark(PinDescriptor.getInstance(), "pinName", "pinLabel", "", null, new GeoPos(4f, 87f), product.getGeoCoding()); placemark.setDescription("pinDescription"); StringWriter stringWriter = new StringWriter(); PlacemarkIO.writeXML(placemark, new XmlWriter(stringWriter, false), 0); String expected = "" + "<Placemark name=\"pinName\">" + _ls + " <LABEL>pinLabel</LABEL>" + _ls + " <DESCRIPTION>pinDescription</DESCRIPTION>" + _ls + " <LATITUDE>4.0</LATITUDE>" + _ls + " <LONGITUDE>87.0</LONGITUDE>" + _ls + "</Placemark>" + _ls; assertEquals(expected, stringWriter.toString()); stringWriter = new StringWriter(); PlacemarkIO.writeXML(placemark, new XmlWriter(stringWriter, false), 3); expected = "" + " <Placemark name=\"pinName\">" + _ls + " <LABEL>pinLabel</LABEL>" + _ls + " <DESCRIPTION>pinDescription</DESCRIPTION>" + _ls + " <LATITUDE>4.0</LATITUDE>" + _ls + " <LONGITUDE>87.0</LONGITUDE>" + _ls + " </Placemark>" + _ls; assertEquals(expected, stringWriter.toString()); }