Search in sources :

Example 1 with Document

use of org.jdom.Document in project cas by apereo.

the class GoogleAccountsServiceFactory method createService.

@Override
public GoogleAccountsService createService(final HttpServletRequest request) {
    final String relayState = request.getParameter(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE);
    final String xmlRequest = this.googleSaml20ObjectBuilder.decodeSamlAuthnRequest(request.getParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST));
    if (StringUtils.isBlank(xmlRequest)) {
        LOGGER.trace("SAML AuthN request not found in the request");
        return null;
    }
    final Document document = this.googleSaml20ObjectBuilder.constructDocumentFromXml(xmlRequest);
    if (document == null) {
        return null;
    }
    final Element root = document.getRootElement();
    final String assertionConsumerServiceUrl = root.getAttributeValue("AssertionConsumerServiceURL");
    final String requestId = root.getAttributeValue("ID");
    final GoogleAccountsService s = new GoogleAccountsService(assertionConsumerServiceUrl, relayState, requestId);
    s.setLoggedOutAlready(true);
    return s;
}
Also used : Element(org.jdom.Element) Document(org.jdom.Document)

Example 2 with Document

use of org.jdom.Document in project nhin-d by DirectProject.

the class HumanReadableTextAssembler method assembleHtmlBody.

/**
   * This method will assemble html bounce message
   * 
   * @return bounce html message
   * @throws IOException
   */
protected String assembleHtmlBody(List<Address> rejectedRecipients, String errorMessage) throws IOException {
    List<UnescapedText> lstToUnescape = new ArrayList<UnescapedText>();
    Element html = new Element("html");
    Element body = new Element("body");
    html.addContent(body);
    {
        Element p = new Element("p");
        body.addContent(p);
        UnescapedText text = new UnescapedText(bounceHeader);
        lstToUnescape.add(text);
        p.addContent(text);
    }
    {
        Element p = new Element("p");
        body.addContent(p);
        p.setText(this.recipientsTitle);
        Element ul = new Element("ul");
        p.addContent(ul);
        for (Address address : rejectedRecipients) {
            Element li = new Element("li");
            ul.addContent(li);
            li.addContent(address.toString());
        }
    }
    {
        Element p = new Element("p");
        body.addContent(p);
        p.setText(this.errorMessageTitle);
        Element br = new Element("br");
        p.addContent(br);
        if ((errorMessage != null) && errorMessage.length() > 0) {
            p.addContent(errorMessage);
        } else {
            UnescapedText text = new UnescapedText(this.errorMessageDefault);
            lstToUnescape.add(text);
            p.addContent(text);
        }
    }
    {
        Element p = new Element("p");
        body.addContent(p);
        UnescapedText text = new UnescapedText(bounceFooter);
        lstToUnescape.add(text);
        p.addContent(text);
    }
    Document document = new Document(html);
    String randomStr;
    {
        // Determine which string indicator can be used to indicate that a
        // string should not be escaped.
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        XMLOutputter outputter = new NoEscapeXMLOutputter(Format.getPrettyFormat());
        outputter.output(document, byteArrayOutputStream);
        String htmlString = new String(byteArrayOutputStream.toByteArray());
        randomStr = getUniqueString();
        while (htmlString.indexOf(randomStr) > -1) {
            randomStr = getUniqueString();
        }
    }
    String htmlString;
    {
        for (UnescapedText unescapedText : lstToUnescape) {
            unescapedText.setUnescapedIndicator(randomStr);
        }
        XMLOutputter outputter = new UnescapedAwareXMLOutputter(Format.getPrettyFormat(), randomStr);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        outputter.output(document, byteArrayOutputStream);
        htmlString = new String(byteArrayOutputStream.toByteArray());
    }
    return htmlString;
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Address(javax.mail.Address) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.jdom.Document)

Example 3 with Document

use of org.jdom.Document in project symmetric-ds by JumpMind.

the class AbstractXmlPublisherExtensionPoint method finalizeXmlAndPublish.

protected void finalizeXmlAndPublish(Context context) {
    Map<String, Element> contextCache = getXmlCache(context);
    Collection<Element> buffers = contextCache.values();
    for (Iterator<Element> iterator = buffers.iterator(); iterator.hasNext(); ) {
        String xml = new XMLOutputter(xmlFormat).outputString(new Document(iterator.next()));
        log.debug("Sending XML to IPublisher: {}", xml);
        iterator.remove();
        long ts = System.currentTimeMillis();
        publisher.publish(context, xml.toString());
        amountOfTimeToPublishMessagesSinceLastPrintTime += (System.currentTimeMillis() - ts);
        numberOfMessagesPublishedSinceLastPrintTime++;
    }
    if ((System.currentTimeMillis() - lastStatisticsPrintTime) > timeBetweenStatisticsPrintTime) {
        synchronized (this) {
            if ((System.currentTimeMillis() - lastStatisticsPrintTime) > timeBetweenStatisticsPrintTime) {
                log.info(name + " published " + numberOfMessagesPublishedSinceLastPrintTime + " messages in the last " + (System.currentTimeMillis() - lastStatisticsPrintTime) / 1000 + " seconds.  Spent " + (amountOfTimeToPublishMessagesSinceLastPrintTime / numberOfMessagesPublishedSinceLastPrintTime) + "ms of publishing time per message");
                lastStatisticsPrintTime = System.currentTimeMillis();
                numberOfMessagesPublishedSinceLastPrintTime = 0;
                amountOfTimeToPublishMessagesSinceLastPrintTime = 0;
            }
        }
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element) Document(org.jdom.Document)

Example 4 with Document

use of org.jdom.Document in project libresonic by Libresonic.

the class JAXBWriter method getRESTProtocolVersion.

private String getRESTProtocolVersion() throws Exception {
    InputStream in = null;
    try {
        in = StringUtil.class.getResourceAsStream("/libresonic-rest-api.xsd");
        Document document = new SAXBuilder().build(in);
        Attribute version = document.getRootElement().getAttribute("version");
        return version.getValue();
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Attribute(org.jdom.Attribute) InputStream(java.io.InputStream) StringUtil(org.libresonic.player.util.StringUtil) Document(org.jdom.Document)

Example 5 with Document

use of org.jdom.Document in project libresonic by Libresonic.

the class LyricsService method parseSearchResult.

private LyricsInfo parseSearchResult(String xml) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(new StringReader(xml));
    Element root = document.getRootElement();
    Namespace ns = root.getNamespace();
    String lyric = StringUtils.trimToNull(root.getChildText("Lyric", ns));
    String song = root.getChildText("LyricSong", ns);
    String artist = root.getChildText("LyricArtist", ns);
    return new LyricsInfo(lyric, artist, song);
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) StringReader(java.io.StringReader) Document(org.jdom.Document) Namespace(org.jdom.Namespace)

Aggregations

Document (org.jdom.Document)90 Element (org.jdom.Element)67 IOException (java.io.IOException)40 SAXBuilder (org.jdom.input.SAXBuilder)40 JDOMException (org.jdom.JDOMException)24 File (java.io.File)16 XMLOutputter (org.jdom.output.XMLOutputter)16 ArrayList (java.util.ArrayList)13 List (java.util.List)12 StringReader (java.io.StringReader)10 XPath (org.jdom.xpath.XPath)10 Format (org.jdom.output.Format)9 StringWriter (java.io.StringWriter)8 InputStream (java.io.InputStream)7 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)7 Writer (java.io.Writer)5 URL (java.net.URL)5 JDOMUtil.loadDocument (com.intellij.openapi.util.JDOMUtil.loadDocument)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4