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:de.mpg.mpdl.inge.cone.util.TreeFragment.java
/** * {@inheritDoc}/*from www . j a v a 2 s . co m*/ */ public String toRdf(Model model) { if (size() == 0) { try { return StringEscapeUtils .escapeXml10(PropertyReader.getProperty("escidoc.cone.service.url") + subject); } catch (Exception e) { throw new RuntimeException(e); } } else { StringWriter result = new StringWriter(); Map<String, String> namespaces = new HashMap<String, String>(); ModelList modelList; try { modelList = ModelList.getInstance(); } catch (Exception e) { throw new RuntimeException(e); } int counter = 0; result.append("<" + (model.getRdfAboutTag().getPrefix() != null ? model.getRdfAboutTag().getPrefix() + ":" : "") + model.getRdfAboutTag().getLocalPart()); if (!subject.startsWith("genid:")) { try { result.append(" rdf:about=\""); result.append(PropertyReader.getProperty("escidoc.cone.service.url") + subject); result.append("\""); } catch (Exception e) { throw new RuntimeException(e); } } if (language != null && !"".equals(language)) { result.append(" xml:lang=\""); result.append(language); result.append("\""); } for (String predicate : keySet()) { Matcher matcher = NAMESPACE_PATTERN.matcher(predicate); if (matcher.find()) { String namespace = matcher.group(1) + (matcher.group(3) == null ? "" : matcher.group(3)); if (!namespaces.containsKey(namespace)) { String prefix; if (modelList.getDefaultNamepaces().containsKey(namespace)) { prefix = modelList.getDefaultNamepaces().get(namespace); } else { counter++; prefix = "ns" + counter; } namespaces.put(namespace, prefix); result.append(" xmlns:" + prefix + "=\"" + namespace + "\""); } } } result.append(">\n"); for (String predicate : keySet()) { Matcher matcher = NAMESPACE_PATTERN.matcher(predicate); String namespace = null; String tagName = null; String prefix = null; if (matcher.find()) { namespace = matcher.group(1) + (matcher.group(3) == null ? "" : matcher.group(3)); prefix = namespaces.get(namespace); tagName = matcher.group(4); } else { int lastColon = predicate.lastIndexOf(":"); tagName = predicate.substring(lastColon + 1); } List<LocalizedTripleObject> values = get(predicate); for (LocalizedTripleObject value : values) { result.append("<"); if (namespace != null) { result.append(prefix); result.append(":"); } result.append(tagName); if (value.getLanguage() != null && !"".equals(value.getLanguage())) { result.append(" xml:lang=\""); result.append(value.getLanguage()); result.append("\""); } Predicate p = model.getPredicate(predicate); // display links to other resources as rdf:resource attribute, if includeResource is false if (p != null && p.getResourceModel() != null && !p.isIncludeResource()) { String url = value.toString(); if (!(url.startsWith("http://") || url.startsWith("https://") || url.startsWith("ftp:"))) { try { if (value.toString().startsWith("/")) { url = PropertyReader.getProperty("escidoc.cone.service.url") + url.substring(0, url.length() - 1); } else { url = PropertyReader.getProperty("escidoc.cone.service.url") + url; } } catch (Exception e) { throw new RuntimeException(e); } } result.append(" rdf:resource=\"" + url + "\"/>"); } else { result.append(">"); result.append(value.toRdf(model)); result.append("</"); if (namespace != null) { result.append(prefix); result.append(":"); } result.append(tagName); result.append(">\n"); } } } result.append("</" + (model.getRdfAboutTag().getPrefix() != null ? model.getRdfAboutTag().getPrefix() + ":" : "") + model.getRdfAboutTag().getLocalPart() + ">\n"); return result.toString(); } }
From source file:de.mpg.escidoc.services.cone.util.TreeFragment.java
/** * {@inheritDoc}//from ww w .j av a2 s .c o m */ public String toRdf(Model model) { if (size() == 0) { try { return StringEscapeUtils .escapeXml10(PropertyReader.getProperty("escidoc.cone.service.url") + subject); } catch (Exception e) { throw new RuntimeException(e); } } else { StringWriter result = new StringWriter(); Map<String, String> namespaces = new HashMap<String, String>(); ModelList modelList; try { modelList = ModelList.getInstance(); } catch (Exception e) { throw new RuntimeException(e); } int counter = 0; result.append("<" + (model.getRdfAboutTag().getPrefix() != null ? model.getRdfAboutTag().getPrefix() + ":" : "") + model.getRdfAboutTag().getLocalPart()); if (!subject.startsWith("genid:")) { try { result.append(" rdf:about=\""); result.append(PropertyReader.getProperty("escidoc.cone.service.url") + subject); result.append("\""); } catch (Exception e) { throw new RuntimeException(e); } } if (language != null && !"".equals(language)) { result.append(" xml:lang=\""); result.append(language); result.append("\""); } for (String predicate : keySet()) { Matcher matcher = NAMESPACE_PATTERN.matcher(predicate); if (matcher.find()) { String namespace = matcher.group(1) + (matcher.group(3) == null ? "" : matcher.group(3)); if (!namespaces.containsKey(namespace)) { String prefix; if (modelList.getDefaultNamepaces().containsKey(namespace)) { prefix = modelList.getDefaultNamepaces().get(namespace); } else { counter++; prefix = "ns" + counter; } namespaces.put(namespace, prefix); result.append(" xmlns:" + prefix + "=\"" + namespace + "\""); } } } result.append(">\n"); for (String predicate : keySet()) { Matcher matcher = NAMESPACE_PATTERN.matcher(predicate); String namespace = null; String tagName = null; String prefix = null; if (matcher.find()) { namespace = matcher.group(1) + (matcher.group(3) == null ? "" : matcher.group(3)); prefix = namespaces.get(namespace); tagName = matcher.group(4); } else { int lastColon = predicate.lastIndexOf(":"); tagName = predicate.substring(lastColon + 1); } List<LocalizedTripleObject> values = get(predicate); for (LocalizedTripleObject value : values) { result.append("<"); if (namespace != null) { result.append(prefix); result.append(":"); } result.append(tagName); if (value.getLanguage() != null && !"".equals(value.getLanguage())) { result.append(" xml:lang=\""); result.append(value.getLanguage()); result.append("\""); } Predicate p = model.getPredicate(predicate); //display links to other resources as rdf:resource attribute, if includeResource is false if (p != null && p.getResourceModel() != null && !p.isIncludeResource()) { String url = value.toString(); if (!(url.startsWith("http://") || url.startsWith("https://") || url.startsWith("ftp:"))) { try { if (value.toString().startsWith("/")) { url = PropertyReader.getProperty("escidoc.cone.service.url") + url.substring(0, url.length() - 1); } else { url = PropertyReader.getProperty("escidoc.cone.service.url") + url; } } catch (Exception e) { throw new RuntimeException(e); } } result.append(" rdf:resource=\"" + url + "\"/>"); } else { result.append(">"); result.append(value.toRdf(model)); result.append("</"); if (namespace != null) { result.append(prefix); result.append(":"); } result.append(tagName); result.append(">\n"); } } } result.append("</" + (model.getRdfAboutTag().getPrefix() != null ? model.getRdfAboutTag().getPrefix() + ":" : "") + model.getRdfAboutTag().getLocalPart() + ">\n"); return result.toString(); } }
From source file:com.itude.mobile.mobbl.core.model.MBElement.java
public StringBuffer asXmlWithLevel(StringBuffer appendToMe, int level, boolean escapeContent) { String bodyText = getBodyText(); boolean hasBodyText = (bodyText != null && bodyText.length() > 0); StringUtil.appendIndentString(appendToMe, level).append("<").append(_definition.getName()); for (MBAttributeDefinition def : _definition.getAttributes()) { String attrName = def.getName(); String attrValue = _values.get(attrName); if (!attrName.equals(TEXT_ATTRIBUTE)) { appendToMe.append(attributeAsXml(attrName, attrValue)); }/*from ww w . j a v a 2 s .c o m*/ } if (_definition.getChildren().isEmpty() && !hasBodyText) { appendToMe.append("/>\n"); } else { appendToMe.append(">"); if (hasBodyText) { appendToMe.append(StringEscapeUtils.escapeXml10(getBodyText().trim())); } else { appendToMe.append("\n"); } for (MBElementDefinition elemDef : _definition.getChildren()) { List<MBElement> lst = getElements().get(elemDef.getName()); if (lst != null) { for (MBElement elem : lst) { elem.asXmlWithLevel(appendToMe, level + 2, escapeContent); } } } int closingLevel = 0; if (!hasBodyText) { closingLevel = level; } StringUtil.appendIndentString(appendToMe, closingLevel).append("</").append(_definition.getName()) .append(">\n"); } return appendToMe; }
From source file:eu.elf.license.LicenseQueryHandler.java
/** * Gets the list of licenses that the user has concluded from the WPOS Service * * @param user - user name/* w ww . ja v a 2 s . com*/ * @return WPOS service response * @throws IOException */ public String getUserLicensesAsXMLString(String user) throws Exception { String getUserLicensesQuery = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wpos:WPOSRequest xmlns:wpos=\"http://www.conterra.de/wpos/1.1\" xmlns:xcpf=\"http://www.conterra.de/xcpf/1.1\" version=\"1.1.0\">" + "<wpos:GetOrderList brief=\"false\">" + "<wpos:Filter>" + "<wpos:CustomerId>" + StringEscapeUtils.escapeXml10(user) + "</wpos:CustomerId>" + "</wpos:Filter>" + "</wpos:GetOrderList>" + "</wpos:WPOSRequest>"; try { return doHTTPQuery(this.wposURL, "post", getUserLicensesQuery, false).toString(); } catch (Exception e) { throw e; } }
From source file:com.melani.utils.ProjectHelpers.java
public static String parsearCaracteresEspecialesXML1(String xmlaParsear) { String xml = "No paso Nada"; StringBuilder sb = null;/* w w w . j av a 2 s .co m*/ try { sb = new StringBuilder(xmlaParsear); if (xmlaParsear.indexOf("<item>") != -1) { xml = StringEscapeUtils.escapeXml10( xmlaParsear.substring(xmlaParsear.indexOf("nes>") + 4, xmlaParsear.indexOf("</obse"))); sb.replace(sb.indexOf("nes>") + 4, sb.indexOf("</obse"), xml); } if (xmlaParsear.indexOf("<Domicilio>") != -1) { xml = StringEscapeUtils.escapeXml10( xmlaParsear.substring(xmlaParsear.indexOf("mes>") + 4, xmlaParsear.indexOf("</det1"))); sb.replace(sb.indexOf("mes>") + 4, sb.indexOf("</det1"), xml); } xml = sb.toString(); } catch (Exception e) { xml = "Error"; logger.error("Error en metodo parsearCaracteresEspecialesXML1 " + e.getLocalizedMessage()); } finally { return xml; } }
From source file:eu.elf.license.LicenseQueryHandler.java
/** * Gets the list of licenses that the user has concluded from the WPOS Service * * @param user - user name//from w w w.j av a2 s .c o m * @return WPOS service response * @throws IOException */ //public List<LicenseModelGroup> getUserLicensesAsLicenseModelGroupList(String user) throws Exception { public UserLicenses getUserLicensesAsLicenseUserLicensesObject(BasicCookieStore bcs, String user) throws Exception { ArrayList<String> activeLicenses = new ArrayList<String>(); String getUserLicensesQuery = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wpos:WPOSRequest xmlns:wpos=\"http://www.conterra.de/wpos/1.1\" xmlns:xcpf=\"http://www.conterra.de/xcpf/1.1\" version=\"1.1.0\">" + "<wpos:GetOrderList brief=\"false\">" + "<wpos:Filter>" + "<wpos:CustomerId>" + StringEscapeUtils.escapeXml10(user) + "</wpos:CustomerId>" + "</wpos:Filter>" + "</wpos:GetOrderList>" + "</wpos:WPOSRequest>"; final String response = doHTTPQuery(this.wposURL, "post", getUserLicensesQuery, false).toString(); UserLicenses userLicenses = LicenseParser.parseUserLicensesAsLicenseModelGroupList(response, user); if (userLicenses.getUserLicenses() != null && userLicenses.getUserLicenses().size() > 0) { log.debug("User licenses found: ", userLicenses.getUserLicenses().size()); // fetch list of active user licenses activeLicenses = getActiveLicensesForUser(bcs, user); // update isActive = true status for active UserLicense objects for (int i = 0; i < userLicenses.getUserLicenses().size(); i++) { for (int j = 0; j < activeLicenses.size(); j++) { if (activeLicenses.get(j).equals(userLicenses.getUserLicenses().get(i).getLicenseId())) { userLicenses.getUserLicenses().get(i).setIsActive(true); } } } } else { log.debug("User has no licenses"); } return userLicenses; }
From source file:edu.emory.cci.aiw.i2b2etl.dest.metadata.PropositionConceptTreeBuilder.java
private Concept addNode(PropositionDefinition propDef) throws InvalidConceptCodeException, KnowledgeSourceReadException, OntologyBuildException { ConceptId conceptId = PropDefConceptId.getInstance(propDef.getId(), null, null, this.metadata); Concept newChild = new Concept(conceptId, this.conceptCode, this.metadata); newChild.setDownloaded(propDef.getDownloaded()); Date updated = propDef.getUpdated(); newChild.setUpdated(updated != null ? propDef.getUpdated() : propDef.getCreated()); String[] children = propDef.getChildren(); String[] inverseIsAs = propDef.getInverseIsA(); newChild.setInDataSource(children.length == 0 //is a leaf || inverseIsAs.length == 0 /* is abstracted */); newChild.setDerived(children.length > inverseIsAs.length); newChild.setDisplayName(propDef.getDisplayName()); newChild.setSourceSystemCode(//from ww w .j ava 2s .c o m MetadataUtil.toSourceSystemCode(propDef.getSourceId().getStringRepresentation())); newChild.setValueTypeCode(this.valueTypeCode); newChild.setComment(propDef.getDescription()); newChild.setAlreadyLoaded(this.alreadyLoaded); Attribute attribute = propDef.attribute(Util.C_FULLNAME_ATTRIBUTE_NAME); if (attribute != null) { Value value = attribute.getValue(); if (value != null) { newChild.setFullName(value.getFormatted()); } } if (this.valueTypeCode == ValueTypeCode.LABORATORY_TESTS) { ValueType valueType = ((ParameterDefinition) propDef).getValueType(); newChild.setDataType(DataType.dataTypeFor(valueType)); if (children.length < 1) { newChild.setMetadataXml( "<?xml version=\"1.0\"?><ValueMetadata><Version>3.02</Version><CreationDateTime>" + this.createDate + "</CreationDateTime><TestID>" + StringEscapeUtils.escapeXml10(newChild.getConceptCode()) + "</TestID><TestName>" + StringEscapeUtils.escapeXml10(newChild.getDisplayName()) + "</TestName><DataType>" + (newChild.getDataType() == DataType.NUMERIC ? "Float" : "String") + "</DataType><Flagstouse></Flagstouse><Oktousevalues>Y</Oktousevalues><UnitValues><NormalUnits> </NormalUnits></UnitValues></ValueMetadata>"); } } else { newChild.setDataType(DataType.TEXT); } if (this.metadata.getFromIdCache(conceptId) == null) { this.metadata.addToIdCache(newChild); } else { newChild.setSynonymCode(SynonymCode.SYNONYM); } return newChild; }
From source file:com.microsoft.aad.adal4j.WSTrustRequest.java
private static StringBuilder buildSecurityHeader(StringBuilder securityHeaderBuilder, String username, String password, WSTrustVersion version) { StringBuilder messageCredentialsBuilder = new StringBuilder(MAX_EXPECTED_MESSAGE_SIZE); String guid = UUID.randomUUID().toString(); username = StringEscapeUtils.escapeXml10(username); password = StringEscapeUtils.escapeXml10(password); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = new Date(); String currentTimeString = dateFormat.format(date); // Expiry is 10 minutes after creation int toAdd = 60 * 1000 * 10; date = new Date(date.getTime() + toAdd); String expiryTimeString = dateFormat.format(date); messageCredentialsBuilder.append(String.format("<o:UsernameToken u:Id='uuid-" + "%s'>" + // guid "<o:Username>%s</o:Username>" + // username "<o:Password>%s</o:Password>" + // password "</o:UsernameToken>", guid, username, password)); securityHeaderBuilder.append(//from w w w . j av a 2 s . co m "<o:Security s:mustUnderstand='1' xmlns:o='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>"); securityHeaderBuilder.append(String.format("<u:Timestamp u:Id='_0'>" + "<u:Created>%s</u:Created>" + // created "<u:Expires>%s</u:Expires>" + // Expires "</u:Timestamp>", currentTimeString, expiryTimeString)); securityHeaderBuilder.append(messageCredentialsBuilder.toString()); securityHeaderBuilder.append("</o:Security>"); return securityHeaderBuilder; }
From source file:com.streamsets.pipeline.lib.el.StringEL.java
@ElFunction(prefix = "str", name = "escapeXML10", description = "Returns a string safe to embed in an XML 1.0 or 1.1 document.") public static String escapeXml10(@ElParam("string") String string) { return StringEscapeUtils.escapeXml10(string); }
From source file:com.evolveum.polygon.connector.hcm.DocumentProcessing.java
public Map<String, Object> parseXMLData(HcmConnectorConfiguration conf, ResultsHandler handler, Map<String, Object> schemaAttributeMap, Filter query) { XMLInputFactory factory = XMLInputFactory.newInstance(); try {//from ww w. j a va 2s . c o m String uidAttributeName = conf.getUidAttribute(); String primariId = conf.getPrimaryId(); String startName = ""; String value = null; StringBuilder assignmentXMLBuilder = null; List<String> builderList = new ArrayList<String>(); Integer nOfIterations = 0; Boolean isSubjectToQuery = false; Boolean isAssigment = false; Boolean evaluateAttr = true; Boolean specificAttributeQuery = false; XMLEventReader eventReader = factory.createXMLEventReader(new FileReader(conf.getFilePath())); List<String> dictionary = populateDictionary(FIRSTFLAG); if (!attrsToGet.isEmpty()) { attrsToGet.add(uidAttributeName); attrsToGet.add(primariId); specificAttributeQuery = true; evaluateAttr = false; LOGGER.ok("The uid and primary id were added to the queried attribute list"); schemaAttributeMap = modifySchemaAttributeMap(schemaAttributeMap); } while (eventReader.hasNext()) { XMLEvent event = eventReader.nextEvent(); Integer code = event.getEventType(); if (code == XMLStreamConstants.START_ELEMENT) { StartElement startElement = event.asStartElement(); startName = startElement.getName().getLocalPart(); if (!evaluateAttr && attrsToGet.contains(startName)) { evaluateAttr = true; } if (!elementIsEmployeeData) { if (startName.equals(EMPLOYEES)) { if (dictionary.contains(nOfIterations.toString())) { LOGGER.ok("The defined number of iterations has been hit: {0}", nOfIterations.toString()); break; } else { startName = ""; elementIsEmployeeData = true; nOfIterations++; } } } else if (evaluateAttr) { if (!isAssigment) { if (!ASSIGNMENTTAG.equals(startName)) { } else { assignmentXMLBuilder = new StringBuilder(); isAssigment = true; } } else { builderList = processAssignment(startName, null, START, builderList); } if (multiValuedAttributesList.contains(startName)) { elementIsMultiValued = true; } } } else if (elementIsEmployeeData) { if (code == XMLStreamConstants.CHARACTERS && evaluateAttr) { Characters characters = event.asCharacters(); if (!characters.isWhiteSpace()) { StringBuilder valueBuilder; if (value != null) { valueBuilder = new StringBuilder(value).append("") .append(characters.getData().toString()); } else { valueBuilder = new StringBuilder(characters.getData().toString()); } value = valueBuilder.toString(); // value = StringEscapeUtils.escapeXml10(value); // LOGGER.info("The attribute value for: {0} is // {1}", startName, value); } } else if (code == XMLStreamConstants.END_ELEMENT) { EndElement endElement = event.asEndElement(); String endName = endElement.getName().getLocalPart(); isSubjectToQuery = checkFilter(endName, value, query, uidAttributeName); if (!isSubjectToQuery) { attributeMap.clear(); elementIsEmployeeData = false; value = null; endName = EMPLOYEES; } if (endName.equals(EMPLOYEES)) { attributeMap = handleEmployeeData(attributeMap, schemaAttributeMap, handler, uidAttributeName, primariId); elementIsEmployeeData = false; } else if (evaluateAttr) { if (endName.equals(startName)) { if (value != null) { if (!isAssigment) { if (!elementIsMultiValued) { attributeMap.put(startName, value); } else { multiValuedAttributeBuffer.put(startName, value); } } else { value = StringEscapeUtils.escapeXml10(value); builderList = processAssignment(endName, value, VALUE, builderList); builderList = processAssignment(endName, null, END, builderList); } // LOGGER.info("Attribute name: {0} and the // Attribute value: {1}", endName, value); value = null; } } else { if (endName.equals(ASSIGNMENTTAG)) { builderList = processAssignment(endName, null, CLOSE, builderList); // if (assigmentIsActive) { for (String records : builderList) { assignmentXMLBuilder.append(records); } attributeMap.put(ASSIGNMENTTAG, assignmentXMLBuilder.toString()); // } else { // } builderList = new ArrayList<String>(); // assigmentIsActive = false; isAssigment = false; } else if (multiValuedAttributesList.contains(endName)) { processMultiValuedAttributes(multiValuedAttributeBuffer); } } } if (specificAttributeQuery && evaluateAttr) { evaluateAttr = false; } } } else if (code == XMLStreamConstants.END_DOCUMENT) { handleBufferedData(uidAttributeName, primariId, handler); } } } catch (FileNotFoundException e) { StringBuilder errorBuilder = new StringBuilder("File not found at the specified path.") .append(e.getLocalizedMessage()); LOGGER.error("File not found at the specified path: {0}", e); throw new ConnectorIOException(errorBuilder.toString()); } catch (XMLStreamException e) { LOGGER.error("Unexpected processing error while parsing the .xml document : {0}", e); StringBuilder errorBuilder = new StringBuilder( "Unexpected processing error while parsing the .xml document. ") .append(e.getLocalizedMessage()); throw new ConnectorIOException(errorBuilder.toString()); } return attributeMap; }