Java Code Examples for org.apache.commons.lang.StringEscapeUtils.escapeXml()

The following are Jave code examples for showing how to use escapeXml() of the org.apache.commons.lang.StringEscapeUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: doctemplate   File: XmlBasedFieldMergeElement.java   View Source Code Vote up 6 votes
/**
 * @see ch.dvbern.lib.doctemplate.common.BasicMergeElement#getContent(ch.dvbern.lib.doctemplate.common.MergeContext,
 *      ch.dvbern.lib.doctemplate.common.MergeSource, java.io.OutputStream)
 */
@Override
public void getContent(MergeContext ctx, MergeSource mergeSource, OutputStream output) throws DocTemplateException {

	// Format-Suffix aus key extrahieren
	String keyWithoutFormatSuffix = this.key, formatSuffix = null;
	int i = this.key.indexOf(FORMAT_SUFFIX);
	if (i > 0) {
		formatSuffix = this.key.substring(i + FORMAT_SUFFIX.length());
		keyWithoutFormatSuffix = this.key.substring(0, i);
	}

	Object data = mergeSource.getData(ctx, keyWithoutFormatSuffix);
	if (data instanceof Image) {
		addImage((T) data, formatSuffix, output);
	} else if (data != null) {
		String dataAsString = FormatHelper.getDataAsString(data, StringUtils.isEmpty(formatSuffix) ? getDefaultFormatter(data) : formatSuffix);
		dataAsString = StringEscapeUtils.escapeXml(dataAsString);
		writeText(output, dataAsString);
	} else {
		log.warn(this.name + ": no template source with key " + this.key);
	}
}
 
Example 2
Project: rapidminer   File: Tools.java   View Source Code Vote up 5 votes
/** Replaces angle brackets by html entities. */
public static String escapeXML(String string) {
	if (string == null) {
		return "null";
	}
	return StringEscapeUtils.escapeXml(string);
}
 
Example 3
Project: convertigo-engine   File: XMLUtils.java   View Source Code Vote up 4 votes
public static String getCDataXml(String s) {
	return StringEscapeUtils.escapeXml(getCDataText(s));
}
 
Example 4
Project: convertigo-engine   File: TransactionWithVariables.java   View Source Code Vote up 4 votes
@Override
public String generateXsdRequestData() throws Exception {
	String prefix = getXsdTypePrefix();
   	
   	String xsdRequestData = null;
   	RequestableVariable variable = null;
   	xsdRequestData = 	"  <xsd:complexType name=\""+ prefix + getName() + "RequestData\">\n";
	//xsdRequestData += 	"    <xsd:annotation>\n";
	//xsdRequestData += 	"      <xsd:documentation>"+ XMLUtils.getCDataXml(getComment()) +"</xsd:documentation>\n";
	//xsdRequestData += 	"    </xsd:annotation>\n";
   	xsdRequestData +=	"    <xsd:sequence>\n";
	for (int i=0; i<numberOfVariables(); i++) {
		variable = (RequestableVariable)getVariable(i);
		if (variable.isWsdl()) {
			if (variable.isMultiValued()) {
				xsdRequestData += "      <xsd:element minOccurs=\"1\" maxOccurs=\"1\" name=\""+variable.getName()+"\" >\n";
				xsdRequestData += "        <xsd:annotation>\n";
				xsdRequestData += "          <xsd:documentation>"+ XMLUtils.getCDataXml(variable.getComment()) +"</xsd:documentation>\n";
				xsdRequestData += "          <xsd:appinfo>"+ StringEscapeUtils.escapeXml(variable.getDescription()) +"</xsd:appinfo>\n";
				xsdRequestData += "        </xsd:annotation>\n";
				xsdRequestData += "        <xsd:complexType>\n";
				xsdRequestData += "          <xsd:sequence>\n";
				xsdRequestData += "            <xsd:element minOccurs=\"0\" maxOccurs=\"unbounded\" name=\"item\" type=\""+variable.getSchemaType()+"\" />\n";
				xsdRequestData += "          </xsd:sequence>\n";
				xsdRequestData += "        </xsd:complexType>\n";
				xsdRequestData += "      </xsd:element>\n";
			}
			else {
				xsdRequestData += "      <xsd:element minOccurs=\"1\" maxOccurs=\"1\" name=\""+variable.getName()+"\" type=\""+variable.getSchemaType()+"\">\n";
				xsdRequestData += "        <xsd:annotation>\n";
				xsdRequestData += "          <xsd:documentation>"+ XMLUtils.getCDataXml(variable.getComment()) +"</xsd:documentation>\n";
				xsdRequestData += "          <xsd:appinfo>"+ StringEscapeUtils.escapeXml(variable.getDescription()) +"</xsd:appinfo>\n";
				xsdRequestData += "        </xsd:annotation>\n";
				xsdRequestData += "      </xsd:element>\n";
			}
		}
	}
	xsdRequestData +=	"    </xsd:sequence>\n";
	xsdRequestData +=	"  </xsd:complexType>\n";
   	return xsdRequestData;
   }
 
Example 5
Project: lams   File: NotificationServlet.java   View Source Code Vote up 4 votes
private void getNotifications(Integer userId, HttpServletRequest request, HttpServletResponse response)
    throws IOException {
Document doc = NotificationServlet.docBuilder.newDocument();
Element notificationsElement = doc.createElement("Notifications");
doc.appendChild(notificationsElement);

Long lessonId = WebUtil.readLongParam(request, CentralConstants.PARAM_LESSON_ID, true);
Integer limit = WebUtil.readIntParam(request, "limit", true);
Integer offset = WebUtil.readIntParam(request, "offset", true);
Boolean pendingOnly = WebUtil.readBooleanParam(request, "pendingOnly", true);

List<Subscription> subscriptions = NotificationServlet.eventNotificationService
	.getNotificationSubscriptions(lessonId, userId, pendingOnly, limit, offset);
for (Subscription subscription : subscriptions) {
    Element notificationElement = doc.createElement("Notification");

    notificationElement.setAttribute("id", subscription.getUid().toString());

    Boolean pending = !DeliveryMethodNotification.LAST_OPERATION_SEEN
	    .equals(subscription.getLastOperationMessage());
    notificationElement.setAttribute("pending", pending.toString());

    Long notificationLessonId = subscription.getEvent().getEventSessionId();
    if (notificationLessonId != null) {
	notificationElement.setAttribute("lessonId", notificationLessonId.toString());
    }

    String message = subscription.getEvent().getMessage();
    Matcher matcher = NotificationServlet.anchorPattern.matcher(message);
    if (matcher.find()) {
	String href = StringEscapeUtils.escapeXml(matcher.group(2));
	notificationElement.setAttribute("href", href);
	message = matcher.group(3);
    }
    notificationElement.appendChild(doc.createCDATASection(message));

    notificationsElement.appendChild(notificationElement);
}

response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");

DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
LSOutput lsOutput = domImplementation.createLSOutput();
lsOutput.setEncoding("UTF-8");
lsOutput.setByteStream(response.getOutputStream());
lsSerializer.write(doc, lsOutput);
   }
 
Example 6
Project: Ins_fb_pictureSpider_WEB   File: EncodeUtils.java   View Source Code Vote up 4 votes
/**
 * Xml 转码.
 */
public static String xmlEscape(String xml) {
    return StringEscapeUtils.escapeXml(xml);
}
 
Example 7
Project: DWSurvey   File: EncodeUtils.java   View Source Code Vote up 4 votes
/**
 * Xml 转码.
 */
public static String xmlEscape(String xml) {
	return StringEscapeUtils.escapeXml(xml);
}
 
Example 8
Project: uflo   File: SequenceFlowParser.java   View Source Code Vote up 4 votes
protected String unescape(String str){
	if(StringUtils.isEmpty(str))return str;
	str=StringEscapeUtils.escapeXml(str);
	return StringEscapeUtils.unescapeXml(str);
}
 
Example 9
Project: joai-project   File: XMLUtils.java   View Source Code Vote up 2 votes
/**
 *  Escapes the characters in a String using XML entities.
 *
 * @param  xml  The String to escape, may be null
 * @return      A new escaped String, null if null string input
 */
public final static String escapeXml(String xml) {
	return StringEscapeUtils.escapeXml(xml);
}