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;
}
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;
}
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;
}
}
}
}
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);
}
}
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);
}
Aggregations