EclipseXmlFormatterStepImpl { public String format(String raw, String baseLocation) throws Exception { IStructuredDocument document = new BasicStructuredDocument(new XMLSourceParser()); document.setPreferredLineDelimiter(LINE_DELIMITER); IDocumentPartitioner partitioner = new StructuredTextPartitionerForXML(); document.setDocumentPartitioner(new StructuredTextPartitionerForXML()); partitioner.connect(document); document.set(raw); DOMModelImpl xmlDOM = new DOMModelImpl(); xmlDOM.setBaseLocation(baseLocation); xmlDOM.getFactoryRegistry().addFactory(xmlAdapterFactory); xmlDOM.setStructuredDocument(document); ModelQuery modelQuery = ModelQueryUtil.getModelQuery(xmlDOM); modelQuery.getCMDocumentManager().setPropertyEnabled(CMDocumentManager.PROPERTY_USE_CACHED_RESOLVED_URI, true); TextEdit formatterChanges = formatter.format(xmlDOM, 0, document.getLength(), preferences); formatterChanges.apply(document); return document.get(); } EclipseXmlFormatterStepImpl(Properties properties); String format(String raw, String baseLocation);  }
@Test public void simpleDefaultFormat() throws Throwable { String[] input = testData.input("xml_space.test"); String output = formatter.format(input[0], input[1]); assertEquals("Unexpected formatting with default preferences.", testData.expected("xml_space.test"), output); }
@Test public void invalidXmlFormat() throws Throwable { String[] input = testData.input("xml_space.test"); input[0] += INCOMPLETE; String output = formatter.format(input[0], input[1]); String expected = testData.expected("xml_space.test") + LINE_DELIMITER + INCOMPLETE; assertEquals("Incomplete XML not formatted on best effort basis.", expected, output); }
@Test public void illegalXmlCharater() throws Throwable { String[] input = testData.input("xml_space.test"); input[0] = ILLEGAL_CHAR + input[0]; String output = formatter.format(input[0], input[1]); String expected = LINE_DELIMITER + LINE_DELIMITER + testData.expected("xml_space.test"); assertEquals("Illegal character not replaced by line delimiter.", expected, output); }
@Test public void dtdRelativePath() throws Throwable { String[] input = testData.input("dtd_relative.test"); String output = formatter.format(input[0], input[1]); assertEquals("Relative DTD not resolved. Restrictions are not applied by formatter.", testData.expected("dtd_relative.test"), output); }
@Test public void dtdExternalPath() throws Throwable { String[] input = testData.input("dtd_external.test"); String output = formatter.format(input[0], input[1]); assertNotEquals("External DTD resolved by default. Restrictions are applied by formatter.", testData.expected("dtd_external.test"), output); }
@Test public void xsdRelativePath() throws Throwable { String[] input = testData.input("xsd_relative.test"); String output = formatter.format(input[0], input[1]); assertEquals("Relative XSD not resolved. Restrictions are not applied by formatter.", testData.expected("xsd_relative.test"), output); }
@Test public void xsdExternalPath() throws Throwable { String[] input = testData.input("xsd_external.test"); String output = formatter.format(input[0], input[1]); assertNotEquals("External XSD resolved per default. Restrictions are applied by formatter.", testData.expected("xsd_external.test"), output); }
@Test public void xsdNotFound() throws Throwable { String[] input = testData.input("xsd_not_found.test"); String output = formatter.format(input[0], input[1]); assertEquals("Unresolved XSD/DTD not silently ignored.", testData.expected("xsd_not_found.test"), output); }