Java Code Examples for org.apache.commons.lang3.StringEscapeUtils#escapeXml11()

The following examples show how to use org.apache.commons.lang3.StringEscapeUtils#escapeXml11() . 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: FlowFilePackagerV1.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void writeAttributesEntry(final Map<String, String> attributes, final TarArchiveOutputStream tout) throws IOException {
    final StringBuilder sb = new StringBuilder();
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE properties\n  SYSTEM \"http://java.sun.com/dtd/properties.dtd\">\n");
    sb.append("<properties>");
    for (final Map.Entry<String, String> entry : attributes.entrySet()) {
        final String escapedKey = StringEscapeUtils.escapeXml11(entry.getKey());
        final String escapedValue = StringEscapeUtils.escapeXml11(entry.getValue());
        sb.append("\n  <entry key=\"").append(escapedKey).append("\">").append(escapedValue).append("</entry>");
    }
    sb.append("</properties>");

    final byte[] metaBytes = sb.toString().getBytes(StandardCharsets.UTF_8);
    final TarArchiveEntry attribEntry = new TarArchiveEntry(FILENAME_ATTRIBUTES);
    attribEntry.setMode(tarPermissions);
    attribEntry.setSize(metaBytes.length);
    tout.putArchiveEntry(attribEntry);
    tout.write(metaBytes);
    tout.closeArchiveEntry();
}
 
Example 2
Source File: PlayCardHandler.java    From PYX-Reloaded with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public JsonWrapper handleWithUserInGame(User user, Game game, Parameters params, HttpServerExchange exchange) throws BaseCahHandler.CahException {
    String cardIdStr = params.getStringNotNull(Consts.GeneralKeys.CARD_ID);
    if (cardIdStr.isEmpty()) throw new BaseCahHandler.CahException(Consts.ErrorCode.BAD_REQUEST);

    int cardId;
    try {
        cardId = Integer.parseInt(cardIdStr);
    } catch (NumberFormatException ex) {
        throw new BaseCahHandler.CahException(Consts.ErrorCode.INVALID_CARD, ex);
    }

    String text = params.getString(Consts.GeneralKeys.WRITE_IN_TEXT);
    if (text != null && text.contains("<")) text = StringEscapeUtils.escapeXml11(text);

    return game.playCard(user, cardId, text);
}
 
Example 3
Source File: Profile.java    From geoportal-server-harvester with Apache License 2.0 6 votes vote down vote up
/**
 * Creates to internal xml request.
 *
 * @return string representing internal xml request
 */
private String createInternalXmlRequest(ICriteria criteria) {
  String request = "<?xml version='1.0' encoding='UTF-8' ?>";
  request += "<GetRecords>" + "<StartPosition>" + criteria.getStartPosition()
          + "</StartPosition>";
  request += "<MaxRecords>" + criteria.getMaxRecords() + "</MaxRecords>";
  request += "<KeyWord>" + StringEscapeUtils.escapeXml11(criteria.getSearchText()) + "</KeyWord>";
  request += ("<LiveDataMap>" + criteria.isLiveDataAndMapsOnly() + "</LiveDataMap>");
  if (criteria.getEnvelope() != null) {
    request += ("<Envelope>");
    request += "<MinX>" + criteria.getEnvelope().getXMin() + "</MinX>";
    request += "<MinY>" + criteria.getEnvelope().getYMin() + "</MinY>";
    request += "<MaxX>" + criteria.getEnvelope().getXMax() + "</MaxX>";
    request += "<MaxY>" + criteria.getEnvelope().getYMax() + "</MaxY>";
    request += "</Envelope>";
    request += "<RecordsFullyWithinEnvelope>" + criteria.getOperation() == Contains + "</RecordsFullyWithinEnvelope>";
    request += "<RecordsIntersectWithEnvelope>" + criteria.getOperation() == Intersects + "</RecordsIntersectWithEnvelope>";

  }
  request += "</GetRecords>";

  return request;
}
 
Example 4
Source File: CustomEmojiMessage.java    From wechattool with MIT License 5 votes vote down vote up
private void init(MessageDO messageDO) throws SQLException {
    //TODO:* WTF TALKER
    xml= messageDO.getContent();
    if(!talker.getUsername().equals("me")) {
        if (chatroom.getUid().endsWith("@chatroom")) {
            int pos= xml.indexOf(":");
            if(pos==-1){
                pos=xml.indexOf("*#*");
            }
            talker = Talker.getInstance(xml.substring(0,pos));
            xml = StringEscapeUtils.escapeXml11(xml.substring(pos + 2));
        }
    }
}
 
Example 5
Source File: Client.java    From geoportal-server-harvester with Apache License 2.0 5 votes vote down vote up
/**
 * Creates to internal xml request.
 *
 * @return string representing internal xml request
 */
private String createInternalXmlRequest(ICriteria criteria) {
  String request = "<?xml version='1.0' encoding='UTF-8' ?>";
  request += "<GetRecords>" + "<StartPosition>" + criteria.getStartPosition()
          + "</StartPosition>";
  request += "<MaxRecords>" + criteria.getMaxRecords() + "</MaxRecords>";
  request += "<KeyWord>" + (criteria.getSearchText() != null ? StringEscapeUtils.escapeXml11(criteria.getSearchText()) : "") + "</KeyWord>";
  request += ("<LiveDataMap>" + criteria.isLiveDataAndMapsOnly() + "</LiveDataMap>");
  if (criteria.getEnvelope() != null) {
    request += ("<Envelope>");
    request += "<MinX>" + criteria.getEnvelope().getXMin() + "</MinX>";
    request += "<MinY>" + criteria.getEnvelope().getYMin() + "</MinY>";
    request += "<MaxX>" + criteria.getEnvelope().getXMax() + "</MaxX>";
    request += "<MaxY>" + criteria.getEnvelope().getYMax() + "</MaxY>";
    request += "</Envelope>";
    request += "<RecordsFullyWithinEnvelope>" + (criteria.getOperation() == Contains) + "</RecordsFullyWithinEnvelope>";
    request += "<RecordsIntersectWithEnvelope>" + (criteria.getOperation() == Intersects) + "</RecordsIntersectWithEnvelope>";
  }
  if (criteria.getFromDate()!=null) {
    request += "<FromDate>" + formatIsoDate(criteria.getFromDate()) + "</FromDate>";
  }
  if (criteria.getToDate()!=null) {
    request += "<ToDate>" + formatIsoDate(criteria.getToDate()) + "</ToDate>";
  }
  request += "</GetRecords>";

  return request;
}
 
Example 6
Source File: StringEL.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@ElFunction(
    prefix = "str",
    name = "escapeXML11",
    description = "Returns a string safe to embed in an XML 1.1 document."
)
public static String escapeXml11(@ElParam("string") String string) {
  return StringEscapeUtils.escapeXml11(string);
}
 
Example 7
Source File: TemplateMaker.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
public String make() {
  if (Strings.isNullOrEmpty(this.template)) {
    throw new IllegalArgumentException(I18n.get(IExceptionMessage.TEMPLATE_MAKER_2));
  }

  ST st = new ST(stGroup, template);

  Map<String, Object> _map = Maps.newHashMap();
  if (localContext != null && !localContext.isEmpty()) {
    _map.putAll(localContext);
  }
  if (context != null) {
    _map.putAll(context);
  }

  // Internal context
  _map.put("__user__", AuthUtils.getUser());
  _map.put("__date__", LocalDate.now());
  _map.put("__time__", LocalTime.now());
  _map.put("__datetime__", LocalDateTime.now());

  for (String key : _map.keySet()) {
    Object value = _map.get(key);
    if (value instanceof String) {
      value = StringEscapeUtils.escapeXml11(value.toString());
    }
    st.add(key, value);
  }

  return _make(st);
}
 
Example 8
Source File: StringUtils.java    From open-cloud with MIT License 4 votes vote down vote up
/**
 * Xml 转码.
 */
public static String escapeXml(String xml) {
    return StringEscapeUtils.escapeXml11(xml);
}
 
Example 9
Source File: LodController.java    From LodView with MIT License 4 votes vote down vote up
@ResponseBody
@RequestMapping(value = { "/linkedResource", "/lodview/linkedResource" }, produces = "application/xml;charset=UTF-8")
public String resource(HttpServletRequest req, HttpServletResponse res, Locale locale, @RequestParam(value = "IRI") String IRI) throws IOException, Exception {

	if (confLinked.getSkipDomains().contains(IRI.replaceAll("http[s]*://([^/]+)/.*", "$1"))) {
		// System.out.println("LodController.resource() - skip - " + IRI);
		return "<root error=\"true\" about=\"" + StringEscapeUtils.escapeXml11(IRI) + "\"><title>" + //
				StringEscapeUtils.escapeXml11(messageSource.getMessage("error.skipedDomain", null, "skiping this URI", locale)) + //
				"</title><msg><![CDATA[skiping this URI, probably offline]]></msg></root>";
	}
	try {
		System.out.println("				LodController.resource() - load - " + IRI);
		/* TODO: change this in UNION queries for better performance */
		ResultBean results = new ResourceBuilder(messageSource).buildHtmlResource(IRI, locale, confLinked, null, true);

		StringBuilder result = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root about=\"" + StringEscapeUtils.escapeXml11(IRI) + "\">");

		result.append("<title><![CDATA[" + StringEscapeUtils.escapeHtml4(results.getTitle()) + "]]></title>");

		String lang = locale.getLanguage().toLowerCase();
		String descr = "";
		List<TripleBean> descrProperties = results.getLiterals(IRI).get(results.getDescriptionProperty());
		if (descrProperties != null) {
			for (TripleBean tripleBean : descrProperties) {
				if (lang.equals(tripleBean.getLang())) {
					descr = tripleBean.getValue();
					lang = tripleBean.getLang();
					break;
				} else if (tripleBean.getLang().equals("en")) {
					lang = tripleBean.getLang();
					descr = tripleBean.getValue();
				} else if (descr.equals("")) {
					descr = tripleBean.getValue();
					lang = tripleBean.getLang();
				}
			}
		}
		/*
		 * List<TripleBean> descrProperties =
		 * results.getLiterals(IRI).get(results.getDescriptionProperty());
		 * if (descrProperties != null) { boolean betterDescrMatch = false;
		 * for (TripleBean tripleBean : descrProperties) { if
		 * (confLinked.getDescriptionProperties
		 * ().contains(tripleBean.getProperty().getNsProperty()) ||
		 * confLinked
		 * .getDescriptionProperties().contains(tripleBean.getProperty
		 * ().getProperty())) { if (!betterDescrMatch && (descr.equals("")
		 * || preferredLanguage.equals(tripleBean.getLang()) ||
		 * tripleBean.getLang().equals("en"))) { descr =
		 * tripleBean.getValue(); lang = tripleBean.getLang(); if
		 * (preferredLanguage.equals(tripleBean.getLang())) {
		 * betterDescrMatch = true; } } } }
		 * 
		 * }
		 */

		result.append("<description lang=\"" + lang + "\"><![CDATA[" + StringEscapeUtils.escapeHtml4(descr) + "]]></description>");

		for (String img : results.getImages()) {
			result.append("<img src=\"" + StringEscapeUtils.escapeXml11(img) + "\"/>");
		}
		for (String link : results.getLinking()) {
			result.append("<link href=\"" + StringEscapeUtils.escapeXml11(link) + "\"/>");
		}
		result.append("<links tot=\"" + results.getLinking().size() + "\"/>");
		result.append("<longitude><![CDATA[" + results.getLongitude() + "]]></longitude>");
		result.append("<latitude><![CDATA[" + results.getLatitude() + "]]></latitude>");

		result.append("</root>");
		return result.toString();

	} catch (Exception e) {
		// e.printStackTrace();
		System.out.println(IRI + " unable to retrieve data " + e.getMessage());
		return "<root error=\"true\" about=\"" + StringEscapeUtils.escapeXml11(IRI) + "\"><title>" + //
				messageSource.getMessage("error.linkedResourceUnavailable", null, "unable to retrieve data", locale) + //
				"</title><msg><![CDATA[" + e.getMessage() + "]]></msg></root>";
	}
}
 
Example 10
Source File: StringUtils.java    From lemon with Apache License 2.0 4 votes vote down vote up
public static String escapeXml(String text) {
    return StringEscapeUtils.escapeXml11(text);
}
 
Example 11
Source File: EscapeUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * Xml转码,将字符串转码为符合XML1.1格式的字符串.
 * 
 * 比如 "bread" & "butter" 转化为 &quot;bread&quot; &amp; &quot;butter&quot;
 */
public static String escapeXml(String xml) {
	return StringEscapeUtils.escapeXml11(xml);
}
 
Example 12
Source File: EscapeUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * Xml转码,将字符串转码为符合XML1.1格式的字符串.
 * 
 * 比如 "bread" & "butter" 转化为 &quot;bread&quot; &amp; &quot;butter&quot;
 */
public static String escapeXml(String xml) {
	return StringEscapeUtils.escapeXml11(xml);
}
 
Example 13
Source File: EscapeUtil.java    From j360-dubbo-app-all with Apache License 2.0 2 votes vote down vote up
/**
 * Xml转码,将字符串转码为符合XML1.1格式的字符串.
 * 
 * 比如 "bread" & "butter" 转化为 &quot;bread&quot; &amp; &quot;butter&quot;
 */
public static String escapeXml(String xml) {
	return StringEscapeUtils.escapeXml11(xml);
}