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:org.ballerinalang.bre.bvm.CPU.java
private static void execXMLOpcodes(WorkerExecutionContext ctx, WorkerData sf, int opcode, int[] operands) { int i;//w w w . j a v a 2s .co m int j; int k; int localNameIndex; int uriIndex; int prefixIndex; BXML<?> xmlVal; BXMLQName xmlQName; switch (opcode) { case InstructionCodes.XMLATTRSTORE: i = operands[0]; j = operands[1]; k = operands[2]; xmlVal = (BXML) sf.refRegs[i]; if (xmlVal == null) { handleNullRefError(ctx); break; } xmlQName = (BXMLQName) sf.refRegs[j]; if (xmlQName == null) { handleNullRefError(ctx); break; } xmlVal.setAttribute(xmlQName.getLocalName(), xmlQName.getUri(), xmlQName.getPrefix(), sf.stringRegs[k]); break; case InstructionCodes.XMLATTRLOAD: i = operands[0]; j = operands[1]; k = operands[2]; xmlVal = (BXML) sf.refRegs[i]; if (xmlVal == null) { handleNullRefError(ctx); break; } xmlQName = (BXMLQName) sf.refRegs[j]; if (xmlQName == null) { handleNullRefError(ctx); break; } sf.stringRegs[k] = xmlVal.getAttribute(xmlQName.getLocalName(), xmlQName.getUri(), xmlQName.getPrefix()); break; case InstructionCodes.XML2XMLATTRS: i = operands[0]; j = operands[1]; xmlVal = (BXML) sf.refRegs[i]; if (xmlVal == null) { sf.refRegs[j] = null; break; } sf.refRegs[j] = new BXMLAttributes(xmlVal); break; case InstructionCodes.S2QNAME: i = operands[0]; j = operands[1]; k = operands[2]; String qNameStr = sf.stringRegs[i]; int parenEndIndex = qNameStr.indexOf('}'); if (qNameStr.startsWith("{") && parenEndIndex > 0) { sf.stringRegs[j] = qNameStr.substring(parenEndIndex + 1, qNameStr.length()); sf.stringRegs[k] = qNameStr.substring(1, parenEndIndex); } else { sf.stringRegs[j] = qNameStr; sf.stringRegs[k] = STRING_NULL_VALUE; } break; case InstructionCodes.NEWQNAME: localNameIndex = operands[0]; uriIndex = operands[1]; prefixIndex = operands[2]; i = operands[3]; String localname = sf.stringRegs[localNameIndex]; localname = StringEscapeUtils.escapeXml11(localname); String prefix = sf.stringRegs[prefixIndex]; prefix = StringEscapeUtils.escapeXml11(prefix); sf.refRegs[i] = new BXMLQName(localname, sf.stringRegs[uriIndex], prefix); break; case InstructionCodes.XMLSEQLOAD: i = operands[0]; j = operands[1]; k = operands[2]; xmlVal = (BXML) sf.refRegs[i]; if (xmlVal == null) { handleNullRefError(ctx); break; } long index = sf.longRegs[j]; sf.refRegs[k] = xmlVal.getItem(index); break; case InstructionCodes.XMLLOAD: i = operands[0]; j = operands[1]; k = operands[2]; xmlVal = (BXML<?>) sf.refRegs[i]; if (xmlVal == null) { handleNullRefError(ctx); break; } String qname = sf.stringRegs[j]; sf.refRegs[k] = xmlVal.children(qname); break; case InstructionCodes.XMLLOADALL: i = operands[0]; j = operands[1]; xmlVal = (BXML<?>) sf.refRegs[i]; if (xmlVal == null) { handleNullRefError(ctx); break; } sf.refRegs[j] = xmlVal.children(); break; case InstructionCodes.NEWXMLELEMENT: case InstructionCodes.NEWXMLCOMMENT: case InstructionCodes.NEWXMLTEXT: case InstructionCodes.NEWXMLPI: case InstructionCodes.XMLSEQSTORE: case InstructionCodes.NEWXMLSEQ: execXMLCreationOpcodes(ctx, sf, opcode, operands); break; default: throw new UnsupportedOperationException(); } }
From source file:org.ballerinalang.model.values.BXMLItem.java
private String getTextValue(OMNode node) { switch (node.getType()) { case OMNode.ELEMENT_NODE: StringBuilder sb = new StringBuilder(); Iterator<OMNode> children = ((OMElement) node).getChildren(); while (children.hasNext()) { sb.append(getTextValue(children.next())); }/*w w w. j av a 2 s . co m*/ return sb.toString(); case OMNode.TEXT_NODE: String text = ((OMText) node).getText(); return StringEscapeUtils.escapeXml11(text); case OMNode.COMMENT_NODE: return STRING_NULL_VALUE; case OMNode.PI_NODE: return STRING_NULL_VALUE; default: return STRING_NULL_VALUE; } }
From source file:org.bonitasoft.platform.setup.command.configure.BundleConfigurator.java
static String escapeXmlCharacters(String url) { return StringEscapeUtils.escapeXml11(url); }
From source file:org.dice_research.topicmodeling.io.xml.AbstractDocumentXmlWriter.java
protected void writeDocumentProperty(Writer writer, ParseableDocumentProperty property) throws IOException { String tagName = CorpusXmlTagHelper.getTagNameOfParseableDocumentProperty(property.getClass()); if (tagName != null) { writer.write("<" + tagName + ">"); if (property instanceof StringContainingDocumentProperty) { writer.write(StringEscapeUtils .escapeXml11(((StringContainingDocumentProperty) property).getStringValue())); } else {/*from w w w . jav a 2 s .c om*/ writer.write(StringEscapeUtils.escapeXml11(property.getValue().toString())); } writer.write("</" + tagName + ">\n"); } else { LOGGER.error("There is no XML tag name defined for the ParseableDocumentProperty class " + property.getClass().getCanonicalName() + ". Discarding this property."); } }
From source file:org.dice_research.topicmodeling.io.xml.AbstractDocumentXmlWriter.java
protected String prepareText(DocumentText text, NamedEntitiesInText nes) { List<String> textParts = new ArrayList<String>(); List<NamedEntityInText> entities = nes.getNamedEntities(); Collections.sort(entities);// w w w. ja v a2 s .com String originalText = text.getText(); // start with the last label and add the parts of the new text beginning // with its end to the array // Note that we are expecting that the labels are sorted descending by // there position in the text! boolean isSignedNamedEntity; int startFormerLabel = originalText.length(); for (NamedEntityInText currentNE : entities) { // proof if this label undercuts the last one. if (startFormerLabel >= currentNE.getEndPos()) { isSignedNamedEntity = currentNE instanceof SignedNamedEntityInText; // append the text between this label and the former one textParts.add(">"); textParts.add(CorpusXmlTagHelper.TEXT_PART_TAG_NAME); textParts.add("</"); try { textParts.add(StringEscapeUtils .escapeXml11(originalText.substring(currentNE.getEndPos(), startFormerLabel))); } catch (StringIndexOutOfBoundsException e) { LOGGER.error("Got a wrong named entity (" + currentNE.toString() + ")", e); textParts.add("<AN_ERROR_OCCURED/>"); } textParts.add(">"); textParts.add(CorpusXmlTagHelper.TEXT_PART_TAG_NAME); textParts.add("<"); // append the markedup label textParts.add(">"); textParts.add(isSignedNamedEntity ? CorpusXmlTagHelper.SIGNED_NAMED_ENTITY_IN_TEXT_TAG_NAME : CorpusXmlTagHelper.NAMED_ENTITY_IN_TEXT_TAG_NAME); textParts.add("</"); try { textParts.add(StringEscapeUtils .escapeXml11(originalText.substring(currentNE.getStartPos(), currentNE.getEndPos()))); } catch (StringIndexOutOfBoundsException e) { LOGGER.error("Got a wrong named entity (" + currentNE.toString() + ")", e); textParts.add("<AN_ERROR_OCCURED/>"); } textParts.add("\">"); // textParts.add(Integer.toString(currentNE.getLength())); // textParts.add("\" length=\""); // textParts.add(Integer.toString(currentNE.getStartPos())); // textParts.add("\" start=\""); if (isSignedNamedEntity) { textParts.add(((SignedNamedEntityInText) currentNE).getSource()); textParts.add("\" source=\""); } textParts.add(currentNE.getNamedEntityUri()); textParts.add(" uri=\""); textParts.add(isSignedNamedEntity ? CorpusXmlTagHelper.SIGNED_NAMED_ENTITY_IN_TEXT_TAG_NAME : CorpusXmlTagHelper.NAMED_ENTITY_IN_TEXT_TAG_NAME); textParts.add("<"); // remember the start position of this label startFormerLabel = currentNE.getStartPos(); } } if (startFormerLabel > 0) { textParts.add("</SimpleTextPart>"); textParts.add(StringEscapeUtils.escapeXml11(originalText.substring(0, startFormerLabel))); textParts.add("<SimpleTextPart>"); } // Form the new text beginning with its end StringBuilder textWithMarkups = new StringBuilder(); for (int i = textParts.size() - 1; i >= 0; --i) { textWithMarkups.append(textParts.get(i)); } return textWithMarkups.toString(); }
From source file:org.dswarm.xmlenhancer.XMLEnhancer.java
private static void enhanceAttributes(final Attributes attributes) { attributes.forEach(attribute -> { final String value = attribute.getValue(); String escapedValue = StringEscapeUtils.escapeXml11(value); attribute.setValue(escapedValue); });/*from ww w . j a v a 2 s . com*/ }
From source file:org.luwrain.extensions.mssapi.SSML.java
/** convert text to ssml xml with upper pitch control for each upper case char * @param pitch pitch increase in % */ public static String upperCasePitchControl(String text, int pitch) { String xml = StringEscapeUtils.escapeXml11(text); StringBuilder sb = new StringBuilder(xml.length()); sb.append(/* w ww. java 2s. co m*/ "<?xml version='1.0' encoding='utf-8'?><speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='ru-RU'><prosody pitch='+0%'>"); StringBuilder sbul = new StringBuilder(xml.length()); Boolean lasupper = null; for (char c : xml.toCharArray()) { if (lasupper == null) lasupper = Character.isUpperCase(c); if (lasupper != Character.isUpperCase(c)) { if (lasupper) { sb.append("<prosody pitch='"); sb.append(String.format("%+d", pitch)); sb.append("%'>"); sb.append(sbul); sb.append("</prosody>"); } else { sb.append(sbul); } sbul.delete(0, sbul.length()); } lasupper = Character.isUpperCase(c); sbul.append(c); } if (lasupper) { sb.append("<prosody pitch='"); sb.append(String.format("%+d", pitch)); sb.append("%'>"); sb.append(sbul); sb.append("</prosody>"); } else { sb.append(sbul); } sb.append("</prosody></speak>"); return sb.toString(); }
From source file:org.silverpeas.core.util.WebEncodeHelper.java
public static String escapeXml(String javastring) { if (isDefined(javastring)) { return StringEscapeUtils.escapeXml11(javastring); } else {// ww w . j a v a 2 s. c o m return ""; } }
From source file:org.wso2.carbon.messageconsole.ui.serializers.ResponseArbitraryFieldsSerializer.java
@Override public JsonElement serialize(ResponseArbitraryField responseArbitraryField, Type type, JsonSerializationContext jsonSerializationContext) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(RESULT, responseArbitraryField.getResult()); jsonObject.addProperty(MESSAGE, responseArbitraryField.getMessage()); JsonArray records = new JsonArray(); if (responseArbitraryField.getColumns() != null) { for (Column column : responseArbitraryField.getColumns()) { JsonObject jsonRecord = new JsonObject(); jsonRecord.addProperty(NAME, column.getKey()); jsonRecord.addProperty(VALUE, StringEscapeUtils.escapeXml11(column.getValue())); jsonRecord.addProperty(TYPE, column.getType()); records.add(jsonRecord);// w w w . jav a 2 s . com } } jsonObject.add(RECORDS, records); return jsonObject; }
From source file:org.wso2.carbon.messageconsole.ui.serializers.ResponseResultSerializer.java
@Override public JsonElement serialize(ResponseResult responseResult, Type type, JsonSerializationContext jsonSerializationContext) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(RESULT, responseResult.getResult()); jsonObject.addProperty(MESSAGE, responseResult.getMessage()); jsonObject.addProperty(TOTAL_RECORD_COUNT, responseResult.getTotalRecordCount()); jsonObject.addProperty(ACTUAL_RECORD_COUNT, responseResult.getActualRecordCount()); jsonObject.addProperty(SEARCH_TIME, responseResult.getSearchTime()); JsonArray records = new JsonArray(); if (responseResult.getRecords() != null) { for (Record record : responseResult.getRecords()) { JsonObject jsonRecord = new JsonObject(); if (record != null) { for (Column column : record.getColumns()) { jsonRecord.addProperty(column.getKey(), StringEscapeUtils.escapeXml11(column.getValue())); }/*from w ww .j a v a 2s . com*/ } records.add(jsonRecord); } } jsonObject.add(RECORDS, records); return jsonObject; }