List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeXml10
public static String escapeXml10(final String input)
Escapes the characters in a String using XML entities.
For example: "bread" & "butter" => "bread" & "butter" .
From source file:eu.elf.license.LicenseQueryHandler.java
/** * Fetch list of user's active licenses//from w w w. j a v a 2 s.co m * * @param userid * @return */ private ArrayList<String> getActiveLicensesForUser(BasicCookieStore bcs, String userid) throws Exception { try { String SOAPAction = "http://security.conterra.de/LicenseManager/GetLicenseReferences"; ArrayList<String> activeLicenses = new ArrayList<String>(); String SOAPqueryString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Envelope xmlns=\"http://www.w3.org/2003/05/soap-envelope\">" + "<Body>" + "<licmanp:GetLicenseReferences xmlns:licmanp=\"http://www.52north.org/licensemanagerprotocol\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\">" + "<samlp:AttributeQuery ID=\"ID_2\" Version=\"1.0\" IssueInstant=\"2001-12-17T09:30:47.0Z\">" + "<saml:Subject>" + "<saml:NameID Format=\"urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified\">" + StringEscapeUtils.escapeXml10(userid) + "</saml:NameID>" + "</saml:Subject>" + "<saml:Attribute Name=\"urn:opengeospatial:ows4:geodrm:Active\">" + "<saml:AttributeValue>true</saml:AttributeValue>" + "</saml:Attribute>" + "</samlp:AttributeQuery>" + "</licmanp:GetLicenseReferences>" + "</Body>" + "</Envelope>"; String responseString = sendSOAPGetResponse(bcs, SOAPqueryString, SOAPAction); //log.debug("SOAPResponse: "+responseString); activeLicenses = LicenseParser.parseActiveLicensesFromGetLicenseReferencesResponse(responseString); return activeLicenses; } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:com.igormaznitsa.jhexed.swing.editor.ui.exporters.SVGImageExporter.java
public byte[] generateImage() throws IOException { final StringBuilder buffer = new StringBuilder(128000); buffer.append(//from w ww.j av a 2 s. c om "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); buffer.append("<!--") .append(StringEscapeUtils .escapeXml10("Generated by the JHexed Swing Editor (https://code.google.com/p/jhexed/)")) .append("-->\n"); final HexEngine<SVGImageExporter> engine = new HexEngine<SVGImageExporter>(64, 64, this.docOptions.getHexOrientation()); engine.setModel(this); if (this.docOptions.getImage() != null) { final float imageWidth = this.docOptions.getImage().getSVGWidth(); final float imageHeight = this.docOptions.getImage().getSVGHeight(); engine.setScale(imageWidth / engine.getVisibleSize().getWidth(), imageHeight / engine.getVisibleSize().getHeight()); } addSvgElement(buffer, engine.getVisibleSize().getWidthAsInt(), engine.getVisibleSize().getHeightAsInt()); buffer.append("<defs>"); addHexMask(buffer, engine.getHexScaledPoints()); if (this.exportData.isExportHexBorders()) { defineGridCell(buffer, engine.getHexScaledPoints()); } defineLayerValues(buffer, engine); buffer.append("</defs>\n"); if (this.exportData.isBackgroundImageExport() && this.docOptions.getImage() != null) { buffer.append(svgToImageTag(BACKGROUND, this.docOptions.getImage(), exportingLayerCounter, exportingLayerCounter, false)).append('\n'); } engine.setRenderer(new HexEngineRender<SVGImageExporter>() { @Override public void renderHexCell(final HexEngine<SVGImageExporter> engine, final SVGImageExporter gfx, final float x, final float y, final int col, final int row) { drawCell(buffer, x, y, engine.getScaledCellWidth(), engine.getScaledCellHeight(), col, row); } @Override public void attachedToEngine(final HexEngine<?> engine) { } @Override public void detachedFromEngine(final HexEngine<?> engine) { } }); buffer.append("<g id=\"LAYERS\">\n"); currentMode = Mode.LAYERS; for (int i = exportData.getLayers().size() - 1; i >= 0; i--) { exportingLayerCounter = i; final LayerExportRecord rec = exportData.getLayers().get(i); if (rec.isAllowed()) { buffer.append("<g id=\"layer").append(exportingLayerCounter).append("\">\n"); engine.draw(this); buffer.append("</g>\n"); } } buffer.append("</g>\n"); if (exportData.isExportHexBorders()) { currentMode = Mode.BORDER; buffer.append("<g id=\"HEXES\">\n"); engine.draw(this); buffer.append("</g>\n"); } if (exportData.isCellCommentariesExport()) { currentMode = Mode.COMMENTS; buffer.append("<g id=\"COMMENTS\">\n"); engine.draw(this); buffer.append("</g>\n"); } addEndSvgElement(buffer); return buffer.toString().getBytes(UTF8); }
From source file:com.itude.mobile.mobbl.core.model.MBElement.java
public String attributeAsXml(String name, Object attrValue) { attrValue = StringEscapeUtils.escapeXml10((String) attrValue); if (attrValue == null) { return ""; }//w w w.j av a 2 s. co m return " " + name + "='" + attrValue + "'"; }
From source file:eu.elf.license.LicenseQueryHandler.java
/** * Gets the details of the specific license * * @param licenseId - License identifier * @return WPOS Service response// ww w .j ava 2 s .co m * @throws IOException */ public GetLicenseDetailsQueryPojo getLicenseDetails(String licenseId) throws IOException, Exception { StringBuffer buf = null; GetLicenseDetailsQueryPojo pojo = null; String wposQuery = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wpos:WPOSRequest xmlns:wpos=\"http://www.conterra.de/wpos/1.1\" version=\"1.1.0\">" + "<wpos:GetPriceModel collapse=\"false\">" + "<wpos:Product>" + "<wpos:id>" + StringEscapeUtils.escapeXml10(licenseId) + "</wpos:id>" + "</wpos:Product>" + "</wpos:GetPriceModel>" + "</wpos:WPOSRequest>"; try { buf = doHTTPQuery(this.wposURL, "post", wposQuery, false); pojo = new GetLicenseDetailsQueryPojo(buf.toString()); //System.out.println("out: "+pojo.getXMLRepresentation()); } catch (IOException ioe) { throw ioe; } catch (Exception e) { throw e; } return pojo; }
From source file:edu.emory.cci.aiw.i2b2etl.dest.metadata.PropositionConceptTreeBuilder.java
private void addModifierConcepts(PropositionDefinition propDef, Concept appliedConcept) throws KnowledgeSourceReadException, InvalidConceptCodeException { if (this.modifiers.length > 0) { ConceptId modParentId = ModifierParentConceptId.getInstance(propDef.getId(), this.metadata); Concept modParent = new Concept(modParentId, null, this.metadata); modParent.setAlreadyLoaded(this.alreadyLoaded); this.metadata.addModifierRoot(modParent); if (this.metadata.getFromIdCache(modParentId) == null) { this.metadata.addToIdCache(modParent); } else {//from www . j a v a 2 s . co m modParent.setSynonymCode(SynonymCode.SYNONYM); } for (ModifierSpec modifier : this.modifiers) { PropertyDefinition propertyDef = propDef.propertyDefinition(modifier.getProperty()); if (propertyDef != null && !propertyDef.isInherited()) { String valStr = modifier.getValue(); Value val = valStr != null ? propertyDef.getValueType().parse(valStr) : null; ConceptId modId = ModifierConceptId.getInstance(propDef.getId(), propertyDef.getId(), val, this.metadata); Concept mod = new Concept(modId, modifier.getCodePrefix(), this.metadata); mod.setDisplayName(modifier.getDisplayName()); Date updated = propDef.getUpdated(); mod.setUpdated(updated != null ? propDef.getUpdated() : propDef.getCreated()); mod.setDownloaded(propDef.getDownloaded()); mod.setSourceSystemCode( MetadataUtil.toSourceSystemCode(propDef.getSourceId().getStringRepresentation())); mod.setValueTypeCode(this.valueTypeCode); mod.setAppliedPath(appliedConcept.getFullName() + "%"); mod.setDataType(DataType.dataTypeFor(propertyDef.getValueType())); mod.setFactTableColumn("MODIFIER_CD"); mod.setTableName("MODIFIER_DIMENSION"); mod.setColumnName("MODIFIER_PATH"); mod.setAlreadyLoaded(this.alreadyLoaded); Attribute attribute = propertyDef.getAttribute(Util.C_FULLNAME_ATTRIBUTE_NAME); if (attribute != null) { Value value = attribute.getValue(); if (value != null) { mod.setFullName(value.getFormatted()); } } if (propertyDef.getValueType() != ValueType.BOOLEANVALUE) { StringBuilder mXml = new StringBuilder(); mXml.append( "<?xml version=\"1.0\"?><ValueMetadata><Version>3.02</Version><CreationDateTime>"); mXml.append(this.createDate); mXml.append("</CreationDateTime><TestID>"); mXml.append(StringEscapeUtils.escapeXml10(mod.getConceptCode())); mXml.append("</TestID><TestName>"); mXml.append(StringEscapeUtils.escapeXml10(mod.getDisplayName())); mXml.append("</TestName>"); String valueSetId = propertyDef.getValueSetId(); if (valueSetId != null) { mXml.append("<DataType>Enum</DataType><EnumValues>"); ValueSet valueSet = this.knowledgeSourceCache.getValueSet(valueSetId); if (valueSet != null) { for (ValueSetElement vse : valueSet.getValueSetElements()) { mXml.append("<Val description=\""); mXml.append(StringEscapeUtils.escapeXml10(vse.getDisplayName())); mXml.append("\">"); mXml.append(StringEscapeUtils.escapeXml10(vse.getValue().getFormatted())); mXml.append("</Val>"); } } mXml.append("</EnumValues>"); } else { mXml.append("<DataType>"); mXml.append(mod.getDataType() == DataType.NUMERIC ? "Float" : "String"); mXml.append("</DataType>"); } mXml.append( "<Flagstouse></Flagstouse><Oktousevalues>Y</Oktousevalues><UnitValues><NormalUnits> </NormalUnits></UnitValues></ValueMetadata>"); mod.setMetadataXml(mXml.toString()); } if (this.metadata.getFromIdCache(modId) == null) { this.metadata.addToIdCache(mod); } else { mod.setSynonymCode(SynonymCode.SYNONYM); } if (this.metadata.getFromIdCache(modId) == null) { this.metadata.addToIdCache(mod); } else { mod.setSynonymCode(SynonymCode.SYNONYM); } modParent.add(mod); } } } }
From source file:eu.elf.license.LicenseQueryHandler.java
/** * Gets the price of the License Model//from w ww.j av a 2 s. c o m * * @param lm - LicenseModel object * @param userId - UserId * @throws Exception * @return - ProductPriceSum as String */ public String getLicenseModelPrice(LicenseModel lm, String userId) throws Exception { StringBuffer buf = null; String productPriceSum = ""; List<LicenseParam> lpList = lm.getParams(); String productPriceQuery = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wpos:WPOSRequest xmlns:wpos=\"http://www.conterra.de/wpos/1.1\" version=\"1.1.0\">" + "<wpos:GetPrice collapse=\"true\">" + "<wpos:Product id=\"" + StringEscapeUtils.escapeXml10(lm.getId()) + "\">" + "<wpos:ConfigParams>"; for (int i = 0; i < lpList.size(); i++) { if (lpList.get(i).getParameterClass().equals("configurationParameter")) { LicenseParam lp = (LicenseParam) lpList.get(i); String priceQuery = "<wpos:Parameter name=\"" + StringEscapeUtils.escapeXml10(lp.getName()) + "\">"; if (lp instanceof LicenseParamInt) { LicenseParamInt lpi = (LicenseParamInt) lp; priceQuery += "<wpos:Value selected=\"true\">" + lpi.getValue() + "</wpos:Value>" + "</wpos:Parameter>"; } else if (lp instanceof LicenseParamBln) { LicenseParamBln lpBln = (LicenseParamBln) lp; priceQuery += "<wpos:Value selected=\"true\">" + lpBln.getValue() + "</wpos:Value>" + "</wpos:Parameter>"; } else if (lp instanceof LicenseParamDisplay) { LicenseParamDisplay lpd = (LicenseParamDisplay) lp; List<String> values = lpd.getValues(); if (lp.getName().equals("LICENSE_USER_GROUP")) { priceQuery += "<wpos:Value>Users</wpos:Value>"; } else if (lp.getName().equals("LICENSE_USER_ID")) { priceQuery += "<wpos:Value>" + userId + "</wpos:Value>"; } else { for (int l = 0; l < values.size(); l++) { priceQuery += "<wpos:Value selected=\"true\">" + StringEscapeUtils.escapeXml10(values.get(l)) + "</wpos:Value>"; } } priceQuery += "</wpos:Parameter>"; } else if (lp instanceof LicenseParamEnum) { LicenseParamEnum lpEnum = (LicenseParamEnum) lp; List<String> tempOptions = lpEnum.getOptions(); List<String> tempSelections = lpEnum.getSelections(); if (tempSelections.size() == 0) { priceQuery = ""; } else { String selectionsString = ""; for (int j = 0; j < tempSelections.size(); j++) { if (j == 0) { selectionsString = tempSelections.get(j); } else { selectionsString += ", " + tempSelections.get(j); } } priceQuery += "<wpos:Value selected=\"true\">" + StringEscapeUtils.escapeXml10(selectionsString) + "</wpos:Value>" + "</wpos:Parameter>"; } } else if (lp instanceof LicenseParamText) { LicenseParamText lpText = (LicenseParamText) lp; List<String> values = lpText.getValues(); for (int k = 0; k < values.size(); k++) { priceQuery += "<wpos:Value selected=\"true\">" + lpText.getValues() + "</wpos:Value>"; } priceQuery += "</wpos:Parameter>"; } productPriceQuery += priceQuery; } } productPriceQuery += "</wpos:ConfigParams>" + "</wpos:Product>" + "</wpos:GetPrice>" + "</wpos:WPOSRequest>"; //System.out.println("query: "+productPriceQuery.toString()); try { buf = doHTTPQuery(this.wposURL, "post", productPriceQuery, false); //System.out.println("response: "+buf.toString()); // Get productPriceInfo from the response Document xmlDoc = LicenseParser.createXMLDocumentFromString(buf.toString()); Element catalogElement = (Element) xmlDoc .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "catalog").item(0); NodeList productGroupElementList = catalogElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "productGroup"); for (int m = 0; m < productGroupElementList.getLength(); m++) { Element productGroupElement = (Element) productGroupElementList.item(m); Element calculationElement = (Element) productGroupElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "calculation").item(0); Element declarationListElement = (Element) calculationElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "declarationList").item(0); Element referencedParametersElement = (Element) declarationListElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "referencedParameters").item(0); NodeList referencedParametersParameterList = referencedParametersElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter"); for (int n = 0; n < referencedParametersParameterList.getLength(); n++) { Element referencedParametersParameterElement = (Element) referencedParametersParameterList .item(n); NamedNodeMap referencedParametersParameterAttributeMap = referencedParametersParameterElement .getAttributes(); for (int o = 0; o < referencedParametersParameterAttributeMap.getLength(); o++) { Attr attrs = (Attr) referencedParametersParameterAttributeMap.item(o); if (attrs.getNodeName().equals("name")) { if (attrs.getNodeValue().equals("productPriceSum")) { Element valueElement = (Element) referencedParametersParameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value").item(0); productPriceSum = valueElement.getTextContent(); } } } } } } catch (Exception e) { throw e; } return productPriceSum; }
From source file:com.denimgroup.threadfix.importer.impl.remoteprovider.QualysRemoteProvider.java
private DefaultRequestConfigurer getScanFilterRequestConfigurer(int numResults, String appName) { String contents = "<ServiceRequest>\n" + " <preferences>\n" + " <limitResults>" + numResults + "</limitResults>\n" + " </preferences>\n" + " <filters>\n" + " <Criteria field=\"webApp.name\" operator=\"CONTAINS\">" + StringEscapeUtils.escapeXml10(appName) + "</Criteria>\n" + " <Criteria field=\"status\" operator=\"EQUALS\">FINISHED</Criteria>\n" + " </filters>\n" + "</ServiceRequest>"; return new DefaultRequestConfigurer().withUsernamePassword(username, password).withRequestBody(contents, null);/* ww w . jav a 2s . co m*/ }
From source file:android.databinding.tool.util.XmlEditor.java
private static String defaultReplacement(XMLParser.AttributeContext attr) { String textWithQuotes = attr.attrValue.getText(); String escapedText = textWithQuotes.substring(1, textWithQuotes.length() - 1); if (!escapedText.startsWith("@{") || !escapedText.endsWith("}")) { return null; }//from w w w.j a va 2s .c o m String text = StringEscapeUtils.unescapeXml(escapedText.substring(2, escapedText.length() - 1)); ANTLRInputStream inputStream = new ANTLRInputStream(text); BindingExpressionLexer lexer = new BindingExpressionLexer(inputStream); CommonTokenStream tokenStream = new CommonTokenStream(lexer); BindingExpressionParser parser = new BindingExpressionParser(tokenStream); BindingExpressionParser.BindingSyntaxContext root = parser.bindingSyntax(); BindingExpressionParser.DefaultsContext defaults = root.defaults(); if (defaults != null) { BindingExpressionParser.ConstantValueContext constantValue = defaults.constantValue(); BindingExpressionParser.LiteralContext literal = constantValue.literal(); if (literal != null) { BindingExpressionParser.StringLiteralContext stringLiteral = literal.stringLiteral(); if (stringLiteral != null) { TerminalNode doubleQuote = stringLiteral.DoubleQuoteString(); if (doubleQuote != null) { String quotedStr = doubleQuote.getText(); String unquoted = quotedStr.substring(1, quotedStr.length() - 1); return StringEscapeUtils.escapeXml10(unquoted); } else { String quotedStr = stringLiteral.SingleQuoteString().getText(); String unquoted = quotedStr.substring(1, quotedStr.length() - 1); String unescaped = unquoted.replace("\"", "\\\"").replace("\\`", "`"); return StringEscapeUtils.escapeXml10(unescaped); } } } return constantValue.getText(); } return null; }
From source file:com.gargoylesoftware.htmlunit.html.HtmlTextArea.java
/** * Recursively write the XML data for the node tree starting at <code>node</code>. * * @param indent white space to indent child nodes * @param printWriter writer where child nodes are written *///from www . j a va2 s. c om @Override protected void printXml(final String indent, final PrintWriter printWriter) { printWriter.print(indent + "<"); printOpeningTagContentAsXml(printWriter); printWriter.print(">"); printWriter.print(StringEscapeUtils.escapeXml10(getText())); printWriter.print("</textarea>"); }
From source file:com.norconex.jef4.suite.JobSuite.java
private void writeJobId(Writer out, JobSuiteStatusSnapshot statusTree, IJobStatus status) throws IOException { out.write("<job name=\""); out.write(StringEscapeUtils.escapeXml10(status.getJobId())); out.write("\">"); for (IJobStatus child : statusTree.getChildren(status)) { writeJobId(out, statusTree, child); }/*from www. ja v a 2 s.com*/ out.write("</job>"); }