List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeXml11
public static String escapeXml11(final String input)
Escapes the characters in a String using XML entities.
For example: "bread" & "butter" => "bread" & "butter" .
From source file:lv.coref.io.MmaxReaderWriter.java
private void writeWords(String filename, Text text) { StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); sb.append("<!DOCTYPE words SYSTEM \"words.dtd\">\n"); sb.append("<words>"); int iToken = 1; for (Sentence sentence : text.getSentences()) { for (Token t : sentence) { sb.append("<word id=\"word_").append(iToken++).append("\">"); sb.append(StringEscapeUtils.escapeXml11(t.getWord())); sb.append("</word>\n"); }// ww w .j a v a2 s. c o m } sb.append("</words>"); StringUtils.printToFile(filename, sb.toString()); }
From source file:net.longfalcon.newsj.Nzb.java
private void _doWriteNZBforRelease(Release release, Directory nzbBaseDir) throws IOException, JAXBException { long releaseId = release.getId(); String releaseGuid = release.getGuid(); String releaseName = release.getName(); long startTime = System.currentTimeMillis(); Category category = release.getCategory(); String categoryName = null;/* ww w .j av a 2s .co m*/ if (category != null) { categoryName = category.getTitle(); } net.longfalcon.newsj.xml.Nzb nzbRoot = new net.longfalcon.newsj.xml.Nzb(); nzbRoot.setXmlns(_XMLNS); Head head = new Head(); List<Meta> metaElements = head.getMeta(); Meta categoryMeta = new Meta(); categoryMeta.setType("category"); categoryMeta.setvalue(StringEscapeUtils.escapeXml11(categoryName)); Meta nameMeta = new Meta(); nameMeta.setType("name"); nameMeta.setvalue(StringEscapeUtils.escapeXml11(releaseName)); metaElements.add(categoryMeta); metaElements.add(nameMeta); nzbRoot.setHead(head); List<File> files = nzbRoot.getFile(); List<Binary> binaries = binaryDAO.findBinariesByReleaseId(releaseId); for (Binary binary : binaries) { File fileElement = new File(); fileElement.setPoster(StringEscapeUtils.escapeXml11(binary.getFromName())); fileElement.setDate(String.valueOf(binary.getDate().getTime())); String subjectString = String.format("%s (1/%s)", StringEscapeUtils.escapeXml11(binary.getName()), binary.getTotalParts()); fileElement.setSubject(subjectString); Groups groupsElement = new Groups(); List<Group> groups = groupsElement.getGroup(); net.longfalcon.newsj.model.Group group = groupDAO.findGroupByGroupId(binary.getGroupId()); Group groupElement = new Group(); groupElement.setvalue(group.getName()); groups.add(groupElement); // TODO: add XRef groups fileElement.setGroups(groupsElement); Segments segmentsElement = new Segments(); List<Segment> segments = segmentsElement.getSegment(); List<Object[]> messageIdSizePartNos = partDAO .findDistinctMessageIdSizeAndPartNumberByBinaryId(binary.getId()); for (Object[] messageIdSizePartNo : messageIdSizePartNos) { // messageIdSizePartNo is {String,Long,Integer} Segment segment = new Segment(); segment.setBytes(String.valueOf(messageIdSizePartNo[1])); segment.setNumber(String.valueOf(messageIdSizePartNo[2])); segment.setvalue(String.valueOf(messageIdSizePartNo[0])); segments.add(segment); } fileElement.setSegments(segmentsElement); files.add(fileElement); } long startFileWriteTime = System.currentTimeMillis(); FsFile fileHandle = getNzbFileHandle(release, nzbBaseDir); Writer writer = new OutputStreamWriter(fileHandle.getOutputStream(), Charset.forName("UTF-8")); getMarshaller().marshal(nzbRoot, writer); writer.write(String.format("<!-- generated by NewsJ %s -->", config.getReleaseVersion())); writer.flush(); writer.close(); Period totalTimePeriod = new Period(startTime, System.currentTimeMillis()); Period buildTimePeriod = new Period(startTime, startFileWriteTime); Period writeTimePeriod = new Period(startFileWriteTime, System.currentTimeMillis()); _log.info(String.format("Wrote NZB for %s in %s;\n build time: %s write time: %s", releaseName, _periodFormatter.print(totalTimePeriod), _periodFormatter.print(buildTimePeriod), _periodFormatter.print(writeTimePeriod))); }
From source file:ee.ria.xroad.opmonitordaemon.HealthDataMetricsUtil.java
private static String escapeString(String string) { return StringEscapeUtils.escapeXml11(string) // For Zabbix: escape the dots that are part of the service // ID so Zabbix won't split the value when processing the // key of the item such as: // jmx[com.example:Type=Hello,all.fruits.apple.weight] .replaceAll("\\.", ".") // For Zabbix: escape the backslash, the space and the comma: .replaceAll("\\\\", "\").replaceAll(" ", " ").replaceAll(",", ",") // For Zabbix: escape the square brackets that are used as // the containers of the JMX parameter name and attribute // such as: // jmx[<parameter name [with square brackets], attribute>]. .replaceAll("\\[", "[").replaceAll("]", "]") // Replace forward slashes to be able to convert the identifier // string back into a service identifier object .replaceAll("/", "/"); }
From source file:com.boazlev.waze.web.WazeServlet.java
private String toXmlData(String tag, String data) { StringBuilder sb = new StringBuilder(); sb.append("<").append(tag).append(">"); if (data != null) { sb.append(StringEscapeUtils.escapeXml11(data)); }/*from w ww. j ava 2s . c o m*/ sb.append("</").append(tag).append(">"); return sb.toString(); }
From source file:io.stallion.utils.Sanitize.java
public static String escapeXml(String s) { return StringEscapeUtils.escapeXml11(s); }
From source file:com.esri.geoportal.commons.csw.client.impl.Profile.java
/** * Creates to internal xml request.//from w w w. j av a 2 s . c om * * @return string representing internal xml request */ private String createInternalXmlRequest(ICriteria criteria) { String request = "<?xml version='1.0' encoding='UTF-8' ?>"; request += "<GetRecords>" + "<StartPosition>" + criteria.getStartPosition() + "</StartPosition>"; request += "<MaxRecords>" + criteria.getMaxRecords() + "</MaxRecords>"; request += "<KeyWord>" + StringEscapeUtils.escapeXml11(criteria.getSearchText()) + "</KeyWord>"; request += ("<LiveDataMap>" + criteria.isLiveDataAndMapsOnly() + "</LiveDataMap>"); if (criteria.getEnvelope() != null) { request += ("<Envelope>"); request += "<MinX>" + criteria.getEnvelope().getXMin() + "</MinX>"; request += "<MinY>" + criteria.getEnvelope().getYMin() + "</MinY>"; request += "<MaxX>" + criteria.getEnvelope().getXMax() + "</MaxX>"; request += "<MaxY>" + criteria.getEnvelope().getYMax() + "</MaxY>"; request += "</Envelope>"; request += "<RecordsFullyWithinEnvelope>" + criteria.getOperation() == Contains + "</RecordsFullyWithinEnvelope>"; request += "<RecordsIntersectWithEnvelope>" + criteria.getOperation() == Intersects + "</RecordsIntersectWithEnvelope>"; } request += "</GetRecords>"; return request; }
From source file:com.igormaznitsa.jhexed.swing.editor.ui.exporters.XmlExporter.java
@Override public void export(final File file) throws IOException { final StringBuilder buffer = new StringBuilder(256000); buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); buffer.append("<jhexed>\n"); buffer.append("\t<docOptions>\n"); buffer.append("\t\t<columns>").append(this.docOptions.getColumns()).append("</columns>\n"); buffer.append("\t\t<rows>").append(this.docOptions.getRows()).append("</rows>\n"); buffer.append("\t\t<commentary>").append(StringEscapeUtils.escapeXml10(this.docOptions.getCommentary())) .append("</commentary>\n"); buffer.append("\t\t<hexBorderWidth>").append(this.docOptions.getLineWidth()).append("</hexBorderWidth>\n"); buffer.append("\t\t<hexBorderColor>").append(Utils.color2html(this.docOptions.getColor(), false)) .append("</hexBorderColor>\n"); buffer.append("\t\t<hexOrientation>").append( this.docOptions.getHexOrientation() == HexEngine.ORIENTATION_VERTICAL ? "vertical" : "horizontal") .append("</hexOrientation>\n"); buffer.append("\t</docOptions>\n"); if (exportData.isBackgroundImageExport() && this.docOptions.getImage() != null) { buffer.append("\t<backImage>") .append(Utils.byteArray2String(this.docOptions.getImage().getImageData(), true, true)) .append("</backImage>\n"); }/*from www . java 2s . c o m*/ buffer.append("\t<layers>\n"); for (final LayerExportRecord f : exportData.getLayers()) { if (Thread.currentThread().isInterrupted()) { return; } if (f.isAllowed()) { buffer.append("\t\t<layer name=\"") .append(StringEscapeUtils.escapeXml10(f.getLayer().getLayerName())) .append("\" commentary=\"") .append(StringEscapeUtils.escapeXml10(f.getLayer().getComments())).append("\">\n"); buffer.append("\t\t\t<values>\n"); for (int i = 1; i < f.getLayer().getHexValuesNumber(); i++) { final HexFieldValue vl = f.getLayer().getHexValueForIndex(i); buffer.append("\t\t\t\t<value index=\"").append(i).append("\" name=\"") .append(StringEscapeUtils.escapeXml10(vl.getName())).append("\" commentary=\"") .append(StringEscapeUtils.escapeXml10(vl.getComment())).append("\">\n"); if (vl instanceof HexColorValue) { final Color clr = ((HexColorValue) vl).getColor(); buffer.append("\t\t\t\t\t<color color=\"").append(Utils.color2html(clr, true)) .append("\"/>\n"); } else if (vl instanceof HexSVGImageValue) { buffer.append("\t\t\t\t\t<svg>").append(Utils .byteArray2String(((HexSVGImageValue) vl).getImage().getImageData(), true, true)) .append("</svg>\n"); } buffer.append("\t\t\t\t</value>\n"); } buffer.append("\t\t\t</values>\n"); buffer.append("\t\t\t<array>").append(Utils.byteArray2String(f.getLayer().getArray(), true, true)) .append("</array>\n"); buffer.append("\t\t</layer>\n"); } } buffer.append("\t</layers>\n"); if (this.exportData.isCellCommentariesExport()) { buffer.append("\t<cellComments>\n"); final Iterator<Entry<HexPosition, String>> cellComment = this.cellComments.iterator(); while (cellComment.hasNext()) { if (Thread.currentThread().isInterrupted()) { return; } final Entry<HexPosition, String> entry = cellComment.next(); final HexPosition hexPos = entry.getKey(); final String escapedComment = StringEscapeUtils.escapeXml11(entry.getValue()); buffer.append("\t\t<cellComment col=\"").append(hexPos.getColumn()).append("\" row=\"") .append(hexPos.getRow()).append("\" text=\"").append(escapedComment).append("\"/>\n"); } buffer.append("\t</cellComments>\n"); } buffer.append("</jhexed>\n"); if (!Thread.currentThread().isInterrupted()) { FileUtils.write(file, buffer.toString()); } }
From source file:com.quest.keycloak.protocol.wsfed.builders.RequestSecurityTokenResponseBuilder.java
public RequestSecurityTokenResponse build() throws ConfigurationException, ProcessingException { RequestSecurityTokenResponse response = new RequestSecurityTokenResponse(); response.setContext(StringEscapeUtils.escapeXml11(context)); XMLGregorianCalendar issueInstance = XMLTimeUtil.getIssueInstant(); response.setLifetime(new Lifetime(issueInstance.toGregorianCalendar(), XMLTimeUtil.add(issueInstance, tokenExpiration * 1000).toGregorianCalendar())); response.setAppliesTo(new AppliesTo()); EndpointReferenceType ert = new EndpointReferenceType(); ert.setAddress(new AttributedURIType()); ert.getAddress().setValue(requestIssuer); response.getAppliesTo().addAny(ert); response.setRequestedSecurityToken(new RequestedSecurityTokenType()); response.setRequestType(URI.create("http://schemas.xmlsoap.org/ws/2005/02/trust/Issue")); if (samlToken != null) { //Sign token Document doc = AssertionUtil.asDocument(samlToken); doc = signAssertion(doc);/*from www.j av a 2s.c o m*/ response.getRequestedSecurityToken().add(doc.getDocumentElement()); response.setRequestedUnattachedReference(new RequestedReferenceType()); response.getRequestedUnattachedReference().setSecurityTokenReference(new SecurityTokenReferenceType()); KeyIdentifierType ki = new KeyIdentifierType(); ki.setValue(IDGenerator.create("ID_")); ki.setValueType("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLID"); response.getRequestedUnattachedReference().getSecurityTokenReference().addAny(ki); response.setTokenType( URI.create("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0")); } else if (jwt != null) { BinarySecurityTokenType bstt = new BinarySecurityTokenType(); bstt.setValue(Base64.encodeBytes(jwt.getBytes())); bstt.setId(IDGenerator.create("ID_")); bstt.setValueType("urn:ietf:params:oauth:token-type:jwt"); bstt.setEncodingType( "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"); response.getRequestedSecurityToken().add(bstt); response.setTokenType(URI.create("urn:ietf:params:oauth:token-type:jwt")); } else { throw new ConfigurationException("SAML or JWT must be set."); } return response; }
From source file:lv.coref.io.MmaxReaderWriter.java
private void writeCoreferences(String filename, Text text) { StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); sb.append("<!DOCTYPE markables SYSTEM \"markables.dtd\">\n"); sb.append("<markables xmlns=\"www.eml.org/NameSpaces/coref\">\n"); int iMent = 1; for (Mention m : text.getMentions()) { String corefClass = m.getMentionChain().size() > 1 ? "set_" + m.getMentionChain().getID() : "empty"; String span = createSpanString("word_", m.getFirstToken().getTextPosition(), m.getLastToken().getTextPosition()); String headString = StringUtils.join(m.getHeads(), " "); headString = StringEscapeUtils.escapeXml11(headString); sb.append("<markable"); sb.append(" id=\"markable_").append(iMent++).append("\""); sb.append(" span=\"").append(span).append("\""); sb.append(" coref_class=\"").append(corefClass).append("\""); sb.append(" category=\"").append(m.getCategory().name()).append("\""); sb.append(" mmax_level=\"").append("coref").append("\""); sb.append(" rule=\"").append("unknown").append("\""); sb.append(" type=\"").append(m.getType().name()).append("\""); sb.append(" heads=\"").append(headString).append("\""); sb.append(" />\n"); }/* w w w . ja v a 2 s . com*/ sb.append("</markables>"); StringUtils.printToFile(filename, sb.toString()); }
From source file:com.vns.pdf.impl.PdfDocument.java
private void createTextAreaFile() { String pageXmlFileName = textAreaFilePath.toAbsolutePath().toString(); try {/*from ww w.jav a 2 s. co m*/ JAXBContext context = JAXBContext.newInstance(Doc.class); Marshaller ms = context.createMarshaller(); ms.setProperty(JAXB_FORMATTED_OUTPUT, true); ms.setProperty(CharacterEscapeHandler.class.getName(), (CharacterEscapeHandler) (ch, start, length, isAttVal, out) -> { String escape = StringEscapeUtils.escapeXml11(new String(ch)); if (!escape.contains("&#")) out.write(escape.toCharArray(), 0, escape.toCharArray().length); }); ms.marshal(doc, new File(pageXmlFileName)); } catch (JAXBException ex) { LOGGER.error(ex.getMessage(), ex); } }