Java Code Examples for org.jdom2.output.XMLOutputter#setFormat()

The following examples show how to use org.jdom2.output.XMLOutputter#setFormat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UscTteCollectionReader.java    From bluima with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(UimaContext context)
        throws ResourceInitializationException {
    inputDir = CORPORA_BASE + "USC_TTE_corpus";
    // inputDir = CORPORA_HOME + "src/test/resources/corpus/USC_TTE_corpus";
    docCnt = 1;
    super.initialize(context);
    try {
        File corpusDir = new File(inputDir);
        checkArgument(corpusDir.exists());
        // duplicating code from AbstractFileReader to add "xml" filtering
        fileIterator = DirectoryIterator.get(directoryIterator, corpusDir,
                "xml", false);
        builder = new SAXBuilder();
        xo = new XMLOutputter();
        xo.setFormat(Format.getRawFormat());
        sentenceXPath = XPathFactory.instance().compile("//S");
    } catch (Exception e) {
        throw new ResourceInitializationException(
                ResourceInitializationException.NO_RESOURCE_FOR_PARAMETERS,
                new Object[] { inputDir });
    }
}
 
Example 2
Source File: Database.java    From CardinalPGM with MIT License 6 votes vote down vote up
public boolean save(File file) {
    XMLOutputter out = new XMLOutputter();
    out.setFormat(Format.getPrettyFormat());
    try {
        if (file.createNewFile()) {
            Cardinal.getInstance().getLogger().info("Database file not found, creating...");
            out.output(document, new FileWriter(file));
            return true;
        } else {
            out.output(document, new FileWriter(file));
            return true;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}
 
Example 3
Source File: DomainConfigTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testDomainConfig() throws Exception {

    URL resurl = DomainConfigTest.class.getResource("/domain.xml");
    SAXBuilder jdom = new SAXBuilder();
    Document doc = jdom.build(resurl);

    ConfigContext context = ConfigSupport.createContext(null, Paths.get(resurl.toURI()), doc);
    ConfigPlugin plugin = new WildFlyCamelConfigPlugin();
    plugin.applyDomainConfigChange(context, true);

    Element element = ConfigSupport.findChildElement(doc.getRootElement(), "server-groups", NS_DOMAINS);
    Assert.assertNotNull("server-groups not null", element);
    element = ConfigSupport.findElementWithAttributeValue(element, "server-group", "name", "camel-server-group", NS_DOMAINS);
    Assert.assertNotNull("camel-server-group not null", element);

    XMLOutputter output = new XMLOutputter();
    output.setFormat(Format.getRawFormat());
    //System.out.println(output.outputString(doc));
}
 
Example 4
Source File: MetadataPersister.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends N2oMetadata> void persist(T n2o, String directory) {
    boolean isCreate = metadataRegister.contains(n2o.getId(), n2o.getClass());
    checkLock();
    Element element = persisterFactory.produce(n2o).persist(n2o, n2o.getNamespace());
    Document doc = new Document();
    doc.addContent(element);
    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(XmlUtil.N2O_FORMAT);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        xmlOutput.output(doc, outputStream);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    InfoConstructor info = findOrCreateXmlInfo(n2o, directory);
    String path = PathUtil.convertUrlToAbsolutePath(info.getURI());
    if (path == null)
        throw new IllegalStateException();
    watchDir.skipOn(path);
    try {
        saveContentToFile(new ByteArrayInputStream(outputStream.toByteArray()), new File(path));
        metadataRegister.update(info);//if exists
        metadataRegister.add(info);
        eventBus.publish(new ConfigPersistEvent(this, info, isCreate));
    } finally {
        watchDir.takeOn(path);
    }
}
 
Example 5
Source File: PersistOperation.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
private ByteArrayOutputStream writeDocument(S source) {
    Element element = persisterFactory.produce(source).persist(source, source.getNamespace());
    Document doc = new Document();
    doc.addContent(element);
    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(format);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        xmlOutput.output(doc, outputStream);
    } catch (IOException e) {
        throw new N2oException("Error during reading metadata " + source.getId(), e);
    }
    return outputStream;
}
 
Example 6
Source File: XmlCustomModifier.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void close() throws Exception {
    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    try (FileWriter fileWriter = new FileWriter(xmlFile)) {
        xmlOutput.output(document, fileWriter);
    }
}
 
Example 7
Source File: JDomUtils.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public static void saveDocument(Document pDoc, String filename) {
    try {
        XMLOutputter xmlOutput = new XMLOutputter();
        
        // display nice nice
        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(pDoc, new FileWriter(filename));
    } catch (Exception e) {
        logger.warn("Unable to save document", e);
    }
}
 
Example 8
Source File: JDomUtils.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
public static String toShortString(Document pDoc) {
    XMLOutputter xmlOutput = new XMLOutputter();

    // display nice nice
    xmlOutput.setFormat(Format.getCompactFormat());
    return xmlOutput.outputString(pDoc);
}
 
Example 9
Source File: ConvertJsonToXmlService.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
public String convertToXmlString(final ConvertJsonToXmlInputs inputs) {
    if (isBlank(inputs.getJson())) {
        return EMPTY;
    }
    final XMLOutputter xmlWriter = new XMLOutputter();
    xmlWriter.setFormat(getFormat(inputs.getPrettyPrint(), inputs.getShowXmlDeclaration()));
    if (inputs.getShowXmlDeclaration()) {
        return xmlWriter.outputString(convertJsonStringToXmlDocument(inputs.getJson(), inputs.getRootTagName()));
    }
    return getXmlFromElements(convertJsonStringToXmlElements(inputs.getJson(), inputs.getRootTagName()), xmlWriter);
}
 
Example 10
Source File: IbisXmlLayout.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
	Document document = new Document(element.detach());
	XMLOutputter xmlOutputter = new XMLOutputter();
	xmlOutputter.setFormat(Format.getPrettyFormat().setOmitDeclaration(true));
	return xmlOutputter.outputString(document);
}
 
Example 11
Source File: XmlBuilder.java    From iaf with Apache License 2.0 5 votes vote down vote up
public String toXML(boolean xmlHeader) {
	Document document = new Document(element.detach());
	XMLOutputter xmlOutputter = new XMLOutputter();
	xmlOutputter.setFormat(
			Format.getPrettyFormat().setOmitDeclaration(!xmlHeader));
	return xmlOutputter.outputString(document);
}
 
Example 12
Source File: NmasResponseSet.java    From ldapchai with GNU Lesser General Public License v2.1 4 votes vote down vote up
static String csToNmasXML( final ChallengeSet cs, final String guidValue )
{
    final Element rootElement = new Element( NMAS_XML_ROOTNODE );
    rootElement.setAttribute( NMAS_XML_ATTR_RANDOM_COUNT, String.valueOf( cs.getMinRandomRequired() ) );
    if ( guidValue != null )
    {
        rootElement.setAttribute( "GUID", guidValue );
    }
    else
    {
        rootElement.setAttribute( "GUID", "0" );
    }

    for ( final Challenge challenge : cs.getChallenges() )
    {
        final Element loopElement = new Element( NMAS_XML_NODE_CHALLENGE );
        if ( challenge.getChallengeText() != null )
        {
            loopElement.setText( challenge.getChallengeText() );
        }

        if ( challenge.isAdminDefined() )
        {
            loopElement.setAttribute( NMAS_XML_ATTR_DEFINE, "Admin" );
        }
        else
        {
            loopElement.setAttribute( NMAS_XML_ATTR_DEFINE, "User" );
        }

        if ( challenge.isRequired() )
        {
            loopElement.setAttribute( NMAS_XML_ATTR_TYPE, "Required" );
        }
        else
        {
            loopElement.setAttribute( NMAS_XML_ATTR_TYPE, "Random" );
        }

        loopElement.setAttribute( NMAS_XML_ATTR_MIN_LENGTH, String.valueOf( challenge.getMinLength() ) );
        loopElement.setAttribute( NMAS_XML_ATTR_MAX_LENGTH, String.valueOf( challenge.getMaxLength() ) );

        rootElement.addContent( loopElement );
    }

    final XMLOutputter outputter = new XMLOutputter();
    final Format format = Format.getRawFormat();
    format.setTextMode( Format.TextMode.PRESERVE );
    format.setLineSeparator( "" );
    outputter.setFormat( format );
    return outputter.outputString( rootElement );
}
 
Example 13
Source File: ConfigTestSupport.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
public void outputDocumentContent(Document document, OutputStream stream) throws IOException {
    XMLOutputter output = new XMLOutputter();
    output.setFormat(Format.getRawFormat());
    output.output(document, stream);
}
 
Example 14
Source File: XMLUtils.java    From wildfly-camel with Apache License 2.0 3 votes vote down vote up
public static String compactXML(InputStream input) throws Exception {

        Document doc = new SAXBuilder().build(input);

        XMLOutputter xo = new XMLOutputter();
        xo.setFormat(Format.getCompactFormat().setOmitDeclaration(true));

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        xo.output(doc, baos);

        return new String(baos.toByteArray()).trim();
    }