Example usage for org.jdom2.output XMLOutputter XMLOutputter

List of usage examples for org.jdom2.output XMLOutputter XMLOutputter

Introduction

In this page you can find the example usage for org.jdom2.output XMLOutputter XMLOutputter.

Prototype

public XMLOutputter() 

Source Link

Document

This will create an XMLOutputter with a default Format and XMLOutputProcessor .

Usage

From source file:com.marklogic.client.example.handle.JDOMHandle.java

License:Apache License

protected XMLOutputter makeOutputter() {
    return new XMLOutputter();
}

From source file:com.novell.ldapchai.cr.ChaiResponseSet.java

License:Open Source License

static String rsToChaiXML(final ChaiResponseSet rs) throws ChaiValidationException, ChaiOperationException {
    final Element rootElement = new Element(XML_NODE_ROOT);
    rootElement.setAttribute(XML_ATTRIBUTE_MIN_RANDOM_REQUIRED,
            String.valueOf(rs.getChallengeSet().getMinRandomRequired()));
    rootElement.setAttribute(XML_ATTRIBUTE_LOCALE, rs.getChallengeSet().getLocale().toString());
    rootElement.setAttribute(XML_ATTRIBUTE_VERSION, VALUE_VERSION);
    rootElement.setAttribute(XML_ATTRIBUTE_CHAI_VERSION, ChaiConstant.CHAI_API_VERSION);

    if (rs.caseInsensitive) {
        rootElement.setAttribute(XML_ATTRIBUTE_CASE_INSENSITIVE, "true");
    }//from ww  w.j a  v  a2s . c  o  m

    if (rs.csIdentifier != null) {
        rootElement.setAttribute(XML_ATTRIBUTE_CHALLENGE_SET_IDENTIFER, rs.csIdentifier);
    }

    if (rs.timestamp != null) {
        rootElement.setAttribute(XML_ATTRIBUTE_TIMESTAMP, DATE_FORMATTER.format(rs.timestamp));
    }

    if (rs.crMap != null) {
        for (final Challenge loopChallenge : rs.crMap.keySet()) {
            final Answer answer = rs.crMap.get(loopChallenge);
            final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_RESPONSE);
            rootElement.addContent(responseElement);
        }
    }

    if (rs.helpdeskCrMap != null) {
        for (final Challenge loopChallenge : rs.helpdeskCrMap.keySet()) {
            final Answer answer = rs.helpdeskCrMap.get(loopChallenge);
            final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_HELPDESK_RESPONSE);
            rootElement.addContent(responseElement);
        }
    }

    final Document doc = new Document(rootElement);
    final XMLOutputter outputter = new XMLOutputter();
    final Format format = Format.getRawFormat();
    format.setTextMode(Format.TextMode.PRESERVE);
    format.setLineSeparator("");
    outputter.setFormat(format);
    return outputter.outputString(doc);
}

From source file:com.novell.ldapchai.impl.edir.NmasResponseSet.java

License:Open Source License

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 {/*  ww w. jav a2  s  .  co  m*/
        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);
}

From source file:com.rhythm.louie.server.LouieProperties.java

License:Apache License

private static Document loadDocument(URL configs, boolean validate) {
    Document properties;/*  www.  j  a  v a  2s .co  m*/
    SAXBuilder docBuilder;
    if (validate) {
        docBuilder = new SAXBuilder(XMLReaders.XSDVALIDATING);
    } else {
        docBuilder = new SAXBuilder(XMLReaders.NONVALIDATING);
    }
    try {
        properties = docBuilder.build(configs);
    } catch (NullPointerException ex) {
        LoggerFactory.getLogger(LouieProperties.class)
                .error("Failed to load properties file. Defaults will be used.\n{}", ex.toString());
        System.out.println(ex.getMessage());
        List<Server> empty = Collections.emptyList();
        Server.processServers(empty);
        return null;
    } catch (IOException | JDOMException ex) {
        Matcher match = missingElem.matcher(ex.getMessage());
        if (match.matches()) {
            LoggerFactory.getLogger(LouieProperties.class).info("No schema located: no validation performed.");
            return loadDocument(configs, false);
        } else {
            String error = "Properties file error! All services shutdown";
            ServiceManager.recordError(error, ex);
            LoggerFactory.getLogger(LouieProperties.class).error("{}\n{}", error, ex.toString());
            List<Server> empty = Collections.emptyList();
            ServiceProperties.globalDisable(); //brute disable
            Server.processServers(empty);
            return null;
        }
    }
    document = new XMLOutputter().outputString(properties);
    return properties;
}

From source file:com.rometools.modules.content.io.ContentModuleParser.java

License:Open Source License

protected String getXmlInnerText(final Element e) {
    final StringBuffer sb = new StringBuffer();
    final XMLOutputter xo = new XMLOutputter();
    final List<Content> children = e.getContent();
    sb.append(xo.outputString(children));

    return sb.toString();
}

From source file:com.rometools.modules.itunes.io.ITunesParser.java

License:Open Source License

protected String getXmlInnerText(final Element e) {
    final StringBuffer sb = new StringBuffer();
    final XMLOutputter xo = new XMLOutputter();
    final List<Content> children = e.getContent();
    sb.append(xo.outputString(children));
    return sb.toString();
}

From source file:com.rometools.propono.atom.server.AtomServlet.java

License:Apache License

/**
 * Handles an Atom GET by calling handler and writing results to response.
 */// ww  w .j  a v a  2  s  .  c o m
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse res)
        throws ServletException, IOException {
    LOG.debug("Entering");
    final AtomHandler handler = createAtomRequestHandler(req, res);
    final String userName = handler.getAuthenticatedUsername();
    if (userName != null) {
        final AtomRequest areq = new AtomRequestImpl(req);
        try {
            if (handler.isAtomServiceURI(areq)) {
                // return an Atom Service document
                final AtomService service = handler.getAtomService(areq);
                final Document doc = service.serviceToDocument();
                res.setContentType("application/atomsvc+xml; charset=utf-8");
                final Writer writer = res.getWriter();
                final XMLOutputter outputter = new XMLOutputter();
                outputter.setFormat(Format.getPrettyFormat());
                outputter.output(doc, writer);
                writer.close();
                res.setStatus(HttpServletResponse.SC_OK);
            } else if (handler.isCategoriesURI(areq)) {
                final Categories cats = handler.getCategories(areq);
                res.setContentType("application/xml");
                final Writer writer = res.getWriter();
                final Document catsDoc = new Document();
                catsDoc.setRootElement(cats.categoriesToElement());
                final XMLOutputter outputter = new XMLOutputter();
                outputter.output(catsDoc, writer);
                writer.close();
                res.setStatus(HttpServletResponse.SC_OK);
            } else if (handler.isCollectionURI(areq)) {
                // return a collection
                final Feed col = handler.getCollection(areq);
                col.setFeedType(FEED_TYPE);
                final WireFeedOutput wireFeedOutput = new WireFeedOutput();
                final Document feedDoc = wireFeedOutput.outputJDom(col);
                res.setContentType("application/atom+xml; charset=utf-8");
                final Writer writer = res.getWriter();
                final XMLOutputter outputter = new XMLOutputter();
                outputter.setFormat(Format.getPrettyFormat());
                outputter.output(feedDoc, writer);
                writer.close();
                res.setStatus(HttpServletResponse.SC_OK);
            } else if (handler.isEntryURI(areq)) {
                // return an entry
                final Entry entry = handler.getEntry(areq);
                if (entry != null) {
                    res.setContentType("application/atom+xml; type=entry; charset=utf-8");
                    final Writer writer = res.getWriter();
                    Atom10Generator.serializeEntry(entry, writer);
                    writer.close();
                } else {
                    res.setStatus(HttpServletResponse.SC_NOT_FOUND);
                }
            } else if (handler.isMediaEditURI(areq)) {
                final AtomMediaResource entry = handler.getMediaResource(areq);
                res.setContentType(entry.getContentType());
                res.setContentLength((int) entry.getContentLength());
                Utilities.copyInputToOutput(entry.getInputStream(), res.getOutputStream());
                res.getOutputStream().flush();
                res.getOutputStream().close();
            } else {
                res.setStatus(HttpServletResponse.SC_NOT_FOUND);
            }
        } catch (final AtomException ae) {
            res.sendError(ae.getStatus(), ae.getMessage());
            LOG.debug("An error occured while processing GET", ae);
        } catch (final Exception e) {
            res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
            LOG.debug("An error occured while processing GET", e);
        }
    } else {
        res.setHeader("WWW-Authenticate", "BASIC realm=\"AtomPub\"");
        res.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    }
    LOG.debug("Exiting");
}

From source file:com.rometools.propono.atom.server.impl.FileBasedCollection.java

License:Open Source License

private void updateFeedDocument(final Feed f) throws AtomException {
    try {//from ww w. j  av a 2 s. c om
        synchronized (FileStore.getFileStore()) {
            final WireFeedOutput wireFeedOutput = new WireFeedOutput();
            final Document feedDoc = wireFeedOutput.outputJDom(f);
            final XMLOutputter outputter = new XMLOutputter();
            // outputter.setFormat(Format.getPrettyFormat());
            final OutputStream fos = FileStore.getFileStore().getFileOutputStream(getFeedPath());
            outputter.output(feedDoc, new OutputStreamWriter(fos, "UTF-8"));
        }
    } catch (final FeedException fex) {
        throw new AtomException(fex);
    } catch (final IOException ex) {
        throw new AtomException(ex);
    }
}

From source file:com.rometools.propono.atom.server.impl.FileBasedCollection.java

License:Open Source License

private InputStream createDefaultFeedDocument(final String uri) throws AtomException {

    final Feed f = new Feed();
    f.setTitle("Feed");
    f.setId(uri);//from   ww w  . j  a v  a2 s  .  co m
    f.setFeedType(FEED_TYPE);

    final Link selfLink = new Link();
    selfLink.setRel("self");
    selfLink.setHref(uri);
    f.getOtherLinks().add(selfLink);

    try {
        final WireFeedOutput wireFeedOutput = new WireFeedOutput();
        final Document feedDoc = wireFeedOutput.outputJDom(f);
        final XMLOutputter outputter = new XMLOutputter();
        // outputter.setFormat(Format.getCompactFormat());
        final OutputStream fos = FileStore.getFileStore().getFileOutputStream(getFeedPath());
        outputter.output(feedDoc, new OutputStreamWriter(fos, "UTF-8"));

    } catch (final FeedException ex) {
        throw new AtomException(ex);
    } catch (final IOException ex) {
        throw new AtomException(ex);
    } catch (final Exception e) {

        e.printStackTrace();
    }
    return FileStore.getFileStore().getFileInputStream(getFeedPath());
}

From source file:com.rometools.rome.io.impl.Atom03Parser.java

License:Open Source License

private Content parseContent(final Element e) {

    String value = null;//from  w  w  w.  java 2s.  c  om

    String type = getAttributeValue(e, "type");
    if (type == null) {
        type = "text/plain";
    }

    String mode = getAttributeValue(e, "mode");
    if (mode == null) {
        mode = Content.XML; // default to xml content
    }

    if (mode.equals(Content.ESCAPED)) {

        // do nothing XML Parser took care of this
        value = e.getText();

    } else if (mode.equals(Content.BASE64)) {

        value = Base64.decode(e.getText());

    } else if (mode.equals(Content.XML)) {

        final XMLOutputter outputter = new XMLOutputter();
        final List<org.jdom2.Content> contents = e.getContent();
        for (final org.jdom2.Content content : contents) {
            if (content instanceof Element) {
                final Element element = (Element) content;
                if (element.getNamespace().equals(getAtomNamespace())) {
                    element.setNamespace(Namespace.NO_NAMESPACE);
                }
            }

        }
        value = outputter.outputString(contents);

    }

    final Content content = new Content();
    content.setType(type);
    content.setMode(mode);
    content.setValue(value);
    return content;
}