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

The following examples show how to use org.apache.commons.lang.StringEscapeUtils#escapeXml() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WmlTVPEncoderv20XmlStreamWriter.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
/**
 * Get the {@link String} representation of {@link Value}
 *
 * @param value {@link Value} to get {@link String} representation from
 *
 * @return {@link String} representation of {@link Value}
 */
private String getValue(Value<?> value) {
    if (value != null && value.isSetValue()) {
        if (value instanceof QuantityValue) {
            QuantityValue quantityValue = (QuantityValue) value;
            return Double.toString(quantityValue.getValue().doubleValue());
        } else if (value instanceof ProfileValue) {
            ProfileValue gwglcValue = (ProfileValue) value;
            if (gwglcValue.isSetValue()) {
                return getValue(gwglcValue.getValue().iterator().next().getSimpleValue());
            }
        } else if (value instanceof CountValue) {
            CountValue countValue = (CountValue) value;
            return Integer.toString(countValue.getValue());
        } else if (value instanceof TextValue) {
            TextValue textValue = (TextValue) value;
            String nonXmlEscapedText = textValue.getValue();
            return StringEscapeUtils.escapeXml(nonXmlEscapedText);
        }
    }
    return null;
}
 
Example 2
Source File: DataSourceDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private String escapeXML(String prov, boolean escape) {
	String statement = null;
	int cutStartIndex = prov.indexOf("<STMT>");
	cutStartIndex = cutStartIndex + 6;
	int cutEndIndex = prov.indexOf("</STMT>");
	statement = prov.substring(cutStartIndex, cutEndIndex);

	if (escape) {
		statement = StringEscapeUtils.escapeXml(statement);
	} else {
		statement = StringEscapeUtils.unescapeXml(statement);
	}

	int cutStart = prov.indexOf("<STMT>");
	cutStart = cutStart + 6;
	int cutEnd = prov.indexOf("</STMT>");
	String firstPart = prov.substring(0, cutStart);
	String secondPart = prov.substring(cutEnd, prov.length());
	prov = firstPart + statement + secondPart;
	return prov;
}
 
Example 3
Source File: Const.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Mask XML content. i.e. replace characters with &values;
 *
 * @param content content
 * @return masked content
 */
public static String escapeXml( String content ) {
  if ( Utils.isEmpty( content ) ) {
    return content;
  }
  return StringEscapeUtils.escapeXml( content );
}
 
Example 4
Source File: TestCaseRun.java    From mdw with Apache License 2.0 5 votes vote down vote up
List<ProcessInstance> loadProcess(TestCaseProcess[] processes, Asset expectedResults) throws TestException {
    processInstances = null;
    if (isLoadTest())
        throw new TestException("Not supported for load tests");
    try {
        List<Process> processVos = new ArrayList<>();
        if (isVerbose())
            log.println("loading runtime data for processes:");
        for (TestCaseProcess process : processes) {
            if (isVerbose())
                log.println("  - " + process.getLabel());
            processVos.add(process.getProcess());
        }
        processInstances = loadResults(processVos, expectedResults, processes[0]);
        return processInstances;
    }
    catch (Exception ex) {
        String msg = ex.getMessage() == null ? "" : ex.getMessage().trim();
        if (msg.startsWith("<")) {
            // xml message
            try {
                MDWStatusMessageDocument statusMsgDoc = MDWStatusMessageDocument.Factory.parse(msg);
                msg = statusMsgDoc.getMDWStatusMessage().getStatusMessage();
            }
            catch (XmlException xmlEx) {
                // not an MDW status message -- just escape XML
                msg = StringEscapeUtils.escapeXml(msg);
            }
        }
        throw new TestException(msg, ex);
    }
}
 
Example 5
Source File: MonthlyEmployeeReport.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * XML-escaped or null if not exists.
 */
public String getKost2Description()
{
  if (kost2 == null) {
    return null;
  }
  return StringEscapeUtils.escapeXml(kost2.getDescription());
}
 
Example 6
Source File: ReportGenerator.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
/** Encode entity for HTML or XML output. */
public static String entityEncode(String text) {
    String result = text;

    if (result == null) {
        return result;
    }

    // The escapeXml function doesnt cope with some 'special' chrs

    return StringEscapeUtils.escapeXml(XMLStringUtil.escapeControlChrs(result));
}
 
Example 7
Source File: Mapping.java    From AML-Project with Apache License 2.0 5 votes vote down vote up
public String toRDF()
{
	URIMap uris = AML.getInstance().getURIMap();
	String sourceURI = uris.getURI(sourceId);
	String targetURI = uris.getURI(targetId);
	String out = "\t<map>\n" +
		"\t\t<Cell>\n" +
		"\t\t\t<entity1 rdf:resource=\""+ sourceURI +"\"/>\n" +
		"\t\t\t<entity2 rdf:resource=\""+ targetURI +"\"/>\n" +
		"\t\t\t<measure rdf:datatype=\"http://www.w3.org/2001/XMLSchema#float\">"+ similarity +"</measure>\n" +
		"\t\t\t<relation>" + StringEscapeUtils.escapeXml(rel.toString()) + "</relation>\n";
	out += "\t\t</Cell>\n" +
		"\t</map>\n";
	return out;
}
 
Example 8
Source File: MonthlyEmployeeReport.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * XML-escaped or null if not exists.
 */
public String getKost2ArtName()
{
  if (kost2 == null || kost2.getKost2Art() == null) {
    return null;
  }
  return StringEscapeUtils.escapeXml(kost2.getKost2Art().getName());
}
 
Example 9
Source File: PublishEventMessageRest.java    From mdw with Apache License 2.0 5 votes vote down vote up
@Override
protected String getRequestData() throws ActivityException {
    String eventName = getEventName();

    if (eventName == null)
        throw new ActivityException("Event Name attribute is missing");

    String request = beginMsg + eventName + middleMsg + StringEscapeUtils.escapeXml(getEventMessage()) + endMsg;
    return request;
}
 
Example 10
Source File: FastSimpleGenericEdifactDirectXMLParser.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public String sanitizeText( String txt ) {

    // resolve all RELEASE characters
    if ( txt.indexOf( "?" ) >= 0 ) {
      txt = txt.replace( "?+", "+" );
      txt = txt.replace( "?:", ":" );
      txt = txt.replace( "?'", "'" );
      txt = txt.replace( "??", "?" );
    }

    // enocde XML entities
    return StringEscapeUtils.escapeXml( txt );
  }
 
Example 11
Source File: TermLikelihood.java    From topic-detection with Apache License 2.0 4 votes vote down vote up
public String toString() { 
        return StringEscapeUtils.escapeXml(term.name);       
//        return StringEscapeUtils.escapeHtml(term.name);       
    }
 
Example 12
Source File: StringHelper.java    From olat with Apache License 2.0 4 votes vote down vote up
public static final String escapeXml(String str) {
    return StringEscapeUtils.escapeXml(str);
}
 
Example 13
Source File: EscapeHelper.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public String xml(final String value) {
  return StringEscapeUtils.escapeXml(value);
}
 
Example 14
Source File: AndroidEditor.java    From DroidUIBuilder with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void generateWidget(Widget w, PrintWriter pw)
{
	pw.print("<" + w.getTagName());
	Vector<Property> props = (Vector<Property>) w.getProperties().clone();
	if (w != rootLayout)
		w.getParent().addOutputProperties(w, props);
	for (Property prop : props)
	{
		if (prop.getValue() != null
				&& prop.getValue().toString().length() > 0
				&& !prop.isDefault())
		{
			// Work around an android bug... *sigh*
			if (w instanceof CheckBox
					&& prop.getAtttributeName().equals("android:padding"))
				continue;
			String value;
			if (prop instanceof StringProperty)
			{
				value = StringEscapeUtils.escapeXml(((StringProperty) prop)
						.getRawStringValue());
			}
			else
			{
				value = prop.getValue().toString();
			}
			pw.println();
			pw
					.print("\t" + prop.getAtttributeName() + "=\"" + value
							+ "\"");
		}
	}
	if (w instanceof Layout)
	{
		pw.println(">");
		for (Widget wt : ((Layout) w).getWidgets())
		{
			generateWidget(wt, pw);
		}
		pw.println("</" + w.getTagName() + ">");
	}
	else
	{
		pw.println(" />");
	}
}
 
Example 15
Source File: NotificationServlet.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
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 = 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 16
Source File: AbstractSTSService.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private SAMLNameIdentifier generateNameIdentifier(X509Certificate authnCertificate) throws TechnicalConnectorException {
   Validate.notNull(authnCertificate, "Parameter authnCertificate is not nullable.");
   String cn = authnCertificate.getSubjectX500Principal().getName("RFC1779");
   String ca = authnCertificate.getIssuerX500Principal().getName("RFC1779");
   return new SAMLNameIdentifier(StringEscapeUtils.escapeXml(cn), "urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName", StringEscapeUtils.escapeXml(ca), StringEscapeUtils.escapeXml(cn));
}
 
Example 17
Source File: AbstractSTSService.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private SAMLNameIdentifier generateNameIdentifier(X509Certificate authnCertificate) throws TechnicalConnectorException {
   Validate.notNull(authnCertificate, "Parameter authnCertificate is not nullable.");
   String cn = authnCertificate.getSubjectX500Principal().getName("RFC1779");
   String ca = authnCertificate.getIssuerX500Principal().getName("RFC1779");
   return new SAMLNameIdentifier(StringEscapeUtils.escapeXml(cn), "urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName", StringEscapeUtils.escapeXml(ca), StringEscapeUtils.escapeXml(cn));
}
 
Example 18
Source File: AbstractSTSService.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private SAMLNameIdentifier generateNameIdentifier(X509Certificate authnCertificate) throws TechnicalConnectorException {
   Validate.notNull(authnCertificate, "Parameter authnCertificate is not nullable.");
   String cn = authnCertificate.getSubjectX500Principal().getName("RFC1779");
   String ca = authnCertificate.getIssuerX500Principal().getName("RFC1779");
   return new SAMLNameIdentifier(StringEscapeUtils.escapeXml(cn), "urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName", StringEscapeUtils.escapeXml(ca), StringEscapeUtils.escapeXml(cn));
}
 
Example 19
Source File: JavaExtensions.java    From restcommander with Apache License 2.0 4 votes vote down vote up
public static String escapeXml(String str) {
    return StringEscapeUtils.escapeXml(str);
}
 
Example 20
Source File: TextUtils.java    From webarchive-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Escapes a string so that it can be placed inside XML/HTML attribute.
 * Replaces ampersand, less-than, greater-than, single-quote, and 
 * double-quote with escaped versions.
 * @param s The string to escape
 * @return The same string escaped.
 */
public static String escapeForMarkupAttribute(String s) {
    return StringEscapeUtils.escapeXml(s);
}