private void processRegular(Bound bound) { String format = "%.5f"; beginOpenElement(); addAttribute(XmlConstants.ATTRIBUTE_NAME_MINLON, String.format(Locale.US, format, bound.getLeft())); addAttribute(XmlConstants.ATTRIBUTE_NAME_MINLAT, String.format(Locale.US, format, bound.getBottom())); addAttribute(XmlConstants.ATTRIBUTE_NAME_MAXLON, String.format(Locale.US, format, bound.getRight())); addAttribute(XmlConstants.ATTRIBUTE_NAME_MAXLAT, String.format(Locale.US, format, bound.getTop())); if (bound.getOrigin() != null) { addAttribute("origin", bound.getOrigin()); } endOpenElement(true); }
/** * Writes the bound. * * @param bound * The bound to be processed. */ public void process(Bound bound) { if (legacyBound) { processLegacy(bound); } else { processRegular(bound); } }
/** * Test non-writing of a Bound element with an empty origin string. */ @Test public final void testProcess2() { BoundWriter bw = new BoundWriter("bound", 2, true); bw.setWriter(testBufferedWriter); bw.process(new Bound(20.123456, -21.987654, 22.555555, -23.234567, "")); try { testBufferedWriter.flush(); } catch (IOException e) { e.printStackTrace(); fail("IOException"); } assertTrue(testWriter.toString().equals("")); // not written; empty string } }
/** * {@inheritDoc} */ public void process(BoundContainer bound) { if (boundWritten) { throw new OsmosisRuntimeException("Bound element already written and only one allowed."); } if (entitiesWritten) { throw new OsmosisRuntimeException("Can't write bound element after other entities."); } boundWriter.process(bound.getEntity()); boundWritten = true; } }
/** * Updates the underlying writer. * * @param writer * The writer to be used for all output xml. */ public void updateWriter(final Writer writer) { nodeWriter.setWriter(writer); wayWriter.setWriter(writer); relationWriter.setWriter(writer); boundWriter.setWriter(writer); // reset the flags indicating which data has been written boundWritten = false; entitiesWritten = false; }
/** * Creates a new instance. * * @param indentLevel * The indent level of the sub-elements. */ SubElementWriter(int indentLevel, boolean legacyBound) { nodeWriter = new NodeWriter("node", indentLevel); wayWriter = new WayWriter("way", indentLevel); relationWriter = new RelationWriter("relation", indentLevel); if (legacyBound) { boundWriter = new BoundWriter("bound", indentLevel, legacyBound); } else { boundWriter = new BoundWriter("bounds", indentLevel, legacyBound); } }
/** * Test writing out a normal Bound element. */ @Test public final void testProcess1() { BoundWriter bw = new BoundWriter("bound", 2, true); bw.setWriter(testBufferedWriter); bw.process(new Bound(20.123456, -21.987654, 22.555555, -23.234567, "originstring")); try { testBufferedWriter.flush(); } catch (IOException e) { e.printStackTrace(); fail("IOException"); } // If this test fails, it could be because the regex has broken. There are a number of // variations which are valid XML which this regex won't catch. It might need any number of // \\s* to account for variable whitespace. String regexMatch = "^\\s*<bound\\s*" + "box=['\"]-23.23457,-21.98765,22.55556,20.12346['\"]\\s*" + "origin=['\"]originstring['\"]/>\\s*$"; assertTrue(testWriter.toString().matches(regexMatch)); }
/** * {@inheritDoc} */ public void process(BoundContainer bound) { if (boundWritten) { throw new OsmosisRuntimeException("Bound element already written and only one allowed."); } if (entitiesWritten) { throw new OsmosisRuntimeException("Can't write bound element after other entities."); } boundWriter.process(bound.getEntity()); boundWritten = true; } }
/** * Updates the underlying writer. * * @param writer * The writer to be used for all output xml. */ public void updateWriter(final Writer writer) { nodeWriter.setWriter(writer); wayWriter.setWriter(writer); relationWriter.setWriter(writer); boundWriter.setWriter(writer); // reset the flags indicating which data has been written boundWritten = false; entitiesWritten = false; }
/** * Creates a new instance. * * @param indentLevel * The indent level of the sub-elements. */ SubElementWriter(int indentLevel, boolean legacyBound) { nodeWriter = new NodeWriter("node", indentLevel); wayWriter = new WayWriter("way", indentLevel); relationWriter = new RelationWriter("relation", indentLevel); if (legacyBound) { boundWriter = new BoundWriter("bound", indentLevel, legacyBound); } else { boundWriter = new BoundWriter("bounds", indentLevel, legacyBound); } }
private void processRegular(Bound bound) { String format = "%.5f"; beginOpenElement(); addAttribute(XmlConstants.ATTRIBUTE_NAME_MINLON, String.format(Locale.US, format, bound.getLeft())); addAttribute(XmlConstants.ATTRIBUTE_NAME_MINLAT, String.format(Locale.US, format, bound.getBottom())); addAttribute(XmlConstants.ATTRIBUTE_NAME_MAXLON, String.format(Locale.US, format, bound.getRight())); addAttribute(XmlConstants.ATTRIBUTE_NAME_MAXLAT, String.format(Locale.US, format, bound.getTop())); if (bound.getOrigin() != null) { addAttribute("origin", bound.getOrigin()); } endOpenElement(true); }
/** * Writes the bound. * * @param bound * The bound to be processed. */ public void process(Bound bound) { if (legacyBound) { processLegacy(bound); } else { processRegular(bound); } }
private void processLegacy(Bound bound) { // Only add the Bound if the origin string isn't empty if (!"".equals(bound.getOrigin())) { beginOpenElement(); // Write with the US locale (to force . instead of , as the decimal // separator) // Use only 5 decimal places (~1.2 meter resolution should be // sufficient for Bound) addAttribute("box", String.format( Locale.US, "%.5f,%.5f,%.5f,%.5f", bound.getBottom(), bound.getLeft(), bound.getTop(), bound.getRight())); addAttribute("origin", bound.getOrigin()); endOpenElement(true); } } }
private void processLegacy(Bound bound) { // Only add the Bound if the origin string isn't empty if (!"".equals(bound.getOrigin())) { beginOpenElement(); // Write with the US locale (to force . instead of , as the decimal // separator) // Use only 5 decimal places (~1.2 meter resolution should be // sufficient for Bound) addAttribute("box", String.format( Locale.US, "%.5f,%.5f,%.5f,%.5f", bound.getBottom(), bound.getLeft(), bound.getTop(), bound.getRight())); addAttribute("origin", bound.getOrigin()); endOpenElement(true); } } }