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:eu.elf.license.LicenseQueryHandler.java
/** * Creates OrderProductQuery from LicenseModel that is used for Concluding the License * * @param lm - License Model to be concluded with selected values for configrurationParameters * @param userId - userid/*from ww w .jav a 2s .c o m*/ * @return OrderProduct query string for the WPOS Service * @throws Exception */ private String createOrderProductQueryFromLicenseModel(LicenseModel lm, String userId) throws Exception { List<LicenseParam> lpList = lm.getParams(); // create query string String wposQuery = "<?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:OrderProduct brief=\"true\">" + "<wpos:Customer>" + "<xcpf:UserIdentifier>" + userId + "</xcpf:UserIdentifier>" + "</wpos:Customer>" + "<wpos:Product id=\"" + lm.getId() + "\">" + "<wpos:ConfigParams>"; for (int i = 0; i < lpList.size(); i++) { if (lpList.get(i).getParameterClass().equals("configurationParameter")) { if (lpList.get(i).getName().equals("LICENSE_USER_GROUP")) { wposQuery += "<wpos:Parameter name=\"" + StringEscapeUtils.escapeXml10(lpList.get(i).getName()) + "\">" + "<wpos:Value>Users</wpos:Value>" + "</wpos:Parameter>"; } else if (lpList.get(i).getName().equals("LICENSE_USER_ID")) { wposQuery += "<wpos:Parameter name=\"" + StringEscapeUtils.escapeXml10(lpList.get(i).getName()) + "\">" + "<wpos:Value selected=\"true\">" + userId + "</wpos:Value>" + "</wpos:Parameter>"; } else if (lpList.get(i).getName().equals("LICENSE_USER_TYPE")) { wposQuery += "<wpos:parameter name=\"" + StringEscapeUtils.escapeXml10(lpList.get(i).getName()) + "\" type=\"string\" multi=\"false\">" + "<wpos:value title=\"Individual\" selected=\"true\">SubjectId</wpos:value>" + "</wpos:parameter>"; } else if (lpList.get(i).getName().equals("LICENSE_DURATION")) { wposQuery += "<wpos:Parameter name=\"" + StringEscapeUtils.escapeXml10(lpList.get(i).getName()) + "\">"; LicenseParamEnum duration = (LicenseParamEnum) lpList.get(i); wposQuery += "<wpos:Value selected=\"true\">" + StringEscapeUtils.escapeXml10(duration.getSelections().get(0)) + "</wpos:Value>" + "</wpos:Parameter>"; } else { if (lpList.get(i) instanceof LicenseParamText) { LicenseParamText lpt = (LicenseParamText) lpList.get(i); wposQuery += "<wpos:Parameter name=\"" + StringEscapeUtils.escapeXml10(lpt.getName()) + "\" type=\"string\">" + "<wpos:Value>" + lpt.getValues().get(0) + "</wpos:Value>" + "</wpos:Parameter>"; } if (lpList.get(i) instanceof LicenseParamInt) { LicenseParamInt lpi = (LicenseParamInt) lpList.get(i); wposQuery += "<wpos:Parameter name=\"" + StringEscapeUtils.escapeXml10(lpi.getName()) + "\" type=\"real\">" + "<wpos:Value>" + lpi.getValue() + "</wpos:Value>" + "</wpos:Parameter>"; } if (lpList.get(i) instanceof LicenseParamBln) { LicenseParamBln lpbln = (LicenseParamBln) lpList.get(i); wposQuery += "<wpos:Parameter name=\"" + StringEscapeUtils.escapeXml10(lpbln.getName()) + "\" type=\"boolean\">" + "<wpos:Value>" + lpbln.getValue() + "</wpos:Value>" + "</wpos:Parameter>"; } if (lpList.get(i) instanceof LicenseParamEnum) { LicenseParamEnum lpenum = (LicenseParamEnum) lpList.get(i); if (lpenum.isMulti() && lpenum.getSelections().size() > 0) { wposQuery += "<wpos:Parameter name=\"" + StringEscapeUtils.escapeXml10(lpenum.getName()) + "\" type=\"string\" multi=\"true\" optional=\"true\">"; String selectionsString = ""; for (int j = 0; j < lpenum.getSelections().size(); j++) { if (j == 0) { selectionsString = lpenum.getSelections().get(j); } else { selectionsString += ", " + lpenum.getSelections().get(j); } } wposQuery += "<wpos:Value selected=\"true\">" + StringEscapeUtils.escapeXml10(selectionsString) + "</wpos:Value>"; wposQuery += "</wpos:Parameter>"; } else if (!lpenum.isMulti()) { wposQuery += "<wpos:Parameter name=\"" + StringEscapeUtils.escapeXml10(lpenum.getName()) + "\" type=\"string\" multi=\"false\">"; for (int k = 0; k < lpenum.getOptions().size(); k++) { if (CheckIfListOfStringContainsValue(lpenum.getSelections(), lpenum.getOptions().get(k)) == true) { wposQuery += "<wpos:Value selected=\"true\">" + StringEscapeUtils.escapeXml10(lpenum.getOptions().get(k)) + "</wpos:Value>"; } //else { // wposQuery += "<wpos:value>" + StringEscapeUtils.escapeXml10(lpenum.getOptions().get(k)) + "</wpos:value>"; //} } wposQuery += "</wpos:Parameter>"; } } } } } wposQuery += "</wpos:ConfigParams>" + "</wpos:Product>" + "</wpos:OrderProduct>" + "</wpos:WPOSRequest>"; return wposQuery; }
From source file:eu.elf.license.LicenseQueryHandler.java
/** * Deactivate license/*from ww w . j a v a 2 s . c o m*/ * * @param bcs * @param licenseId * @throws ClientProtocolException * @throws IOException */ public Boolean deactivateLicense(BasicCookieStore bcs, String licenseId) throws ClientProtocolException, IOException { String SOAPAction = "http://security.conterra.de/LicenseManager/DeactivateLicense"; String deactivateLicenseQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Envelope xmlns=\"http://www.w3.org/2003/05/soap-envelope\">" + "<Body>" + "<licmanp:DeactivateLicense ID=\"B1202458930484\" Version=\"2.0\" IssueInstant=\"2001-12-17T09:30:47.0Z\" " + " xmlns:licmanp=\"http://www.52north.org/licensemanagerprotocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">" + "<saml:AssertionIDRef>" + StringEscapeUtils.escapeXml10(licenseId) + "</saml:AssertionIDRef>" + "</licmanp:DeactivateLicense>" + "</Body>" + "</Envelope>"; Boolean success = sendSOAP(bcs, deactivateLicenseQuery, SOAPAction); return success; }
From source file:eu.elf.license.LicenseQueryHandler.java
/** * Activate license/*from www . jav a 2 s . c om*/ * * @param bcs * @param licenseId * @throws ClientProtocolException * @throws IOException */ public Boolean activateLicense(BasicCookieStore bcs, String licenseId) throws ClientProtocolException, IOException { String SOAPAction = "http://security.conterra.de/LicenseManager/ActivateLicense"; String activateLicenseQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Envelope xmlns=\"http://www.w3.org/2003/05/soap-envelope\">" + "<Body>" + "<licmanp:ActivateLicense ID=\"B1202458930484\" Version=\"2.0\" IssueInstant=\"2001-12-17T09:30:47.0Z\" " + " xmlns:licmanp=\"http://www.52north.org/licensemanagerprotocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">" + "<saml:AssertionIDRef>" + StringEscapeUtils.escapeXml10(licenseId) + "</saml:AssertionIDRef>" + "</licmanp:ActivateLicense>" + "</Body>" + "</Envelope>"; Boolean success = sendSOAP(bcs, activateLicenseQuery, SOAPAction); return success; }
From source file:eu.elf.license.LicenseQueryHandler.java
/** * Deactivate license//from www. j av a2s.com * * @param bcs * @param licenseId * @throws ClientProtocolException * @throws IOException */ public Boolean deleteLicense(BasicCookieStore bcs, String licenseId) throws ClientProtocolException, IOException { String SOAPAction = "http://security.conterra.de/LicenseManager/DeleteLicense"; String deleteLicenseQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Envelope xmlns=\"http://www.w3.org/2003/05/soap-envelope\">" + "<Body>" + "<licmanp:DeleteLicense ID=\"B1202458930484\" Version=\"2.0\" IssueInstant=\"2001-12-17T09:30:47.0Z\" " + " xmlns:licmanp=\"http://www.52north.org/licensemanagerprotocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">" + "<saml:AssertionIDRef>" + StringEscapeUtils.escapeXml10(licenseId) + "</saml:AssertionIDRef>" + "</licmanp:DeleteLicense>" + "</Body>" + "</Envelope>"; Boolean success = sendSOAP(bcs, deleteLicenseQuery, SOAPAction); return success; }
From source file:org.ambraproject.rhino.service.taxonomy.impl.TaxonomyClassificationServiceImpl.java
/** * @inheritDoc//from ww w . j ava 2 s . c o m */ @Override public List<String> getRawTerms(Document articleXml, Article article, boolean isTextRequired) { RuntimeConfiguration.TaxonomyConfiguration configuration = getTaxonomyConfiguration(); String toCategorize = getCategorizationContent(articleXml); ArticleIngestion latest = articleCrudService.readLatestRevision(article).getIngestion(); String header = String.format(MESSAGE_HEADER, new SimpleDateFormat("yyyy-MM-dd").format(latest.getPublicationDate()), latest.getJournal().getTitle(), latest.getArticleType(), article.getDoi()); String aiMessage = String.format(MESSAGE_BEGIN, configuration.getThesaurus()) + StringEscapeUtils.escapeXml10(String.format(MESSAGE_DOC_ELEMENT, header, toCategorize)) + MESSAGE_END; HttpPost post = new HttpPost(configuration.getServer().toString()); post.setEntity(new StringEntity(aiMessage, APPLICATION_XML_UTF_8)); DocumentBuilder documentBuilder = newDocumentBuilder(); Document response; try (CloseableHttpResponse httpResponse = httpClient.execute(post); InputStream stream = httpResponse.getEntity().getContent()) { response = documentBuilder.parse(stream); } catch (IOException e) { throw new TaxonomyRemoteServiceNotAvailableException(e); } catch (SAXException e) { throw new TaxonomyRemoteServiceInvalidBehaviorException( "Invalid XML returned from " + configuration.getServer(), e); } //parse result NodeList vectorElements = response.getElementsByTagName("VectorElement"); List<String> results = new ArrayList<>(vectorElements.getLength()); // Add the text that is sent to taxonomy server if isTextRequired is true if (isTextRequired) { toCategorize = StringEscapeUtils.unescapeXml(toCategorize); results.add(toCategorize); } //The first and last elements of the vector response are just MAITERMS for (int i = 1; i < vectorElements.getLength() - 1; i++) { results.add(vectorElements.item(i).getTextContent()); } if ((isTextRequired && results.size() == 1) || results.isEmpty()) { log.error("Taxonomy server returned 0 terms. " + article.getDoi()); } return results; }
From source file:org.ambraproject.rhino.service.taxonomy.impl.TaxonomyClassificationServiceImpl.java
/** * Returns a string containing only the parts of the article that should be examined by the taxonomy server. For * research articles, this is presently the title, the abstract, the Materials and Methods section, and the Results * section. (If any of these sections are not present, they are not sent, but this is not a fatal error.) If none of * these sections (abstract, materials/methods, or results) are present, then this method will return the entire body * text. This is usually the case for non-research-articles, such as corrections, opinion pieces, etc. * Please not that the "getSuggestedTermsFullPathsPlos" requires the data within the "content" tag to be * XML-escaped twice. Hence, we XML escape it once in this method and once when we escape the "doc" tag in * {@link getRawTerms} method./*from w w w .j av a 2 s. com*/ * * @param dom DOM tree of an article * @return raw text content, XML-escaped, of the relevant article sections */ @VisibleForTesting static String getCategorizationContent(Document dom) { StringBuilder sb = new StringBuilder(); appendElementIfExists(sb, dom, "article-title"); appendAllElementsIfExists(sb, dom, "abstract"); appendElementIfExists(sb, dom, "body"); return StringEscapeUtils.escapeXml10(sb.toString().trim()); }
From source file:org.apache.chemistry.opencmis.server.impl.webservices.CmisWebServicesServlet.java
protected void printError(HttpServletRequest request, HttpServletResponse response, String message) throws IOException { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setContentType("text/xml"); response.setCharacterEncoding(IOUtils.UTF8); PrintWriter pw = response.getWriter(); String messageEscaped = StringEscapeUtils.escapeXml10(message); pw.println("<?xml version='1.0' encoding='UTF-8'?>"); pw.println("<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">"); pw.println("<S:Body>"); pw.println("<S:Fault>"); pw.println("<faultcode>S:Client</faultcode>"); pw.println("<faultstring>" + messageEscaped + "</faultstring>"); pw.println("<detail>"); pw.println("<cmisFault xmlns=\"http://docs.oasis-open.org/ns/cmis/messaging/200908/\">"); pw.println("<type>runtime</type>"); pw.println("<code>0</code>"); pw.println("<message>" + messageEscaped + "</message>"); pw.println("</cmisFault>"); pw.println("</detail>"); pw.println("</S:Fault>"); pw.println("</S:Body>"); pw.println("</S:Envelope>"); pw.flush();//w ww .ja va 2s . com }
From source file:org.apache.jmeter.protocol.ldap.sampler.LDAPExtSampler.java
@Override public SampleResult sample(Entry e) { XMLBuffer xmlBuffer = new XMLBuffer(); xmlBuffer.openTag("ldapanswer"); // $NON-NLS-1$ SampleResult res = new SampleResult(); res.setResponseData("successfull", null); res.setResponseMessage("Success"); // $NON-NLS-1$ res.setResponseCode("0"); // $NON-NLS-1$ res.setContentType("text/xml");// $NON-NLS-1$ boolean isSuccessful = true; res.setSampleLabel(getName());//from w w w . ja v a 2s . co m DirContext dirContext = ldapContexts.get(getThreadName()); try { xmlBuffer.openTag("operation"); // $NON-NLS-1$ final String testType = getTest(); xmlBuffer.tag("opertype", testType); // $NON-NLS-1$ log.debug("performing test: " + testType); if (testType.equals(UNBIND)) { res.setSamplerData("Unbind"); xmlBuffer.tag("baseobj", getRootdn()); // $NON-NLS-1$ xmlBuffer.tag("binddn", getUserDN()); // $NON-NLS-1$ unbindOp(dirContext, res); } else if (testType.equals(BIND)) { res.setSamplerData("Bind as " + getUserDN()); xmlBuffer.tag("baseobj", getRootdn()); // $NON-NLS-1$ xmlBuffer.tag("binddn", getUserDN()); // $NON-NLS-1$ xmlBuffer.tag("connectionTO", getConnTimeOut()); // $NON-NLS-1$ bindOp(res); } else if (testType.equals(SBIND)) { res.setSamplerData("SingleBind as " + getUserDN()); xmlBuffer.tag("baseobj", getRootdn()); // $NON-NLS-1$ xmlBuffer.tag("binddn", getUserDN()); // $NON-NLS-1$ xmlBuffer.tag("connectionTO", getConnTimeOut()); // $NON-NLS-1$ singleBindOp(res); } else if (testType.equals(COMPARE)) { res.setSamplerData( "Compare " + getPropertyAsString(COMPAREFILT) + " " + getPropertyAsString(COMPAREDN)); xmlBuffer.tag("comparedn", getPropertyAsString(COMPAREDN)); // $NON-NLS-1$ xmlBuffer.tag("comparefilter", getPropertyAsString(COMPAREFILT)); // $NON-NLS-1$ NamingEnumeration<SearchResult> cmp = null; try { res.sampleStart(); cmp = LdapExtClient.compare(dirContext, getPropertyAsString(COMPAREFILT), getPropertyAsString(COMPAREDN)); if (!cmp.hasMore()) { res.setResponseCode("5"); // $NON-NLS-1$ res.setResponseMessage("compareFalse"); isSuccessful = false; } } finally { res.sampleEnd(); if (cmp != null) { cmp.close(); } } } else if (testType.equals(ADD)) { res.setSamplerData("Add object " + getBaseEntryDN()); xmlBuffer.tag("attributes", getArguments().toString()); // $NON-NLS-1$ xmlBuffer.tag("dn", getBaseEntryDN()); // $NON-NLS-1$ addTest(dirContext, res); } else if (testType.equals(DELETE)) { res.setSamplerData("Delete object " + getBaseEntryDN()); xmlBuffer.tag("dn", getBaseEntryDN()); // $NON-NLS-1$ deleteTest(dirContext, res); } else if (testType.equals(MODIFY)) { res.setSamplerData("Modify object " + getBaseEntryDN()); xmlBuffer.tag("dn", getBaseEntryDN()); // $NON-NLS-1$ xmlBuffer.tag("attributes", getLDAPArguments().toString()); // $NON-NLS-1$ modifyTest(dirContext, res); } else if (testType.equals(RENAME)) { res.setSamplerData( "ModDN object " + getPropertyAsString(MODDDN) + " to " + getPropertyAsString(NEWDN)); xmlBuffer.tag("dn", getPropertyAsString(MODDDN)); // $NON-NLS-1$ xmlBuffer.tag("newdn", getPropertyAsString(NEWDN)); // $NON-NLS-1$ renameTest(dirContext, res); } else if (testType.equals(SEARCH)) { final String scopeStr = getScope(); final int scope = getScopeAsInt(); final String searchFilter = getPropertyAsString(SEARCHFILTER); final String searchBase = getPropertyAsString(SEARCHBASE); final String timeLimit = getTimelim(); final String countLimit = getCountlim(); res.setSamplerData("Search with filter " + searchFilter); xmlBuffer.tag("searchfilter", StringEscapeUtils.escapeXml10(searchFilter)); // $NON-NLS-1$ xmlBuffer.tag("baseobj", getRootdn()); // $NON-NLS-1$ xmlBuffer.tag("searchbase", searchBase);// $NON-NLS-1$ xmlBuffer.tag("scope", scopeStr); // $NON-NLS-1$ xmlBuffer.tag("countlimit", countLimit); // $NON-NLS-1$ xmlBuffer.tag("timelimit", timeLimit); // $NON-NLS-1$ NamingEnumeration<SearchResult> srch = null; try { res.sampleStart(); srch = LdapExtClient.searchTest(dirContext, searchBase, searchFilter, scope, getCountlimAsLong(), getTimelimAsInt(), getRequestAttributes(getAttrs()), isRetobj(), isDeref()); if (isParseFlag()) { try { xmlBuffer.openTag("searchresults"); // $NON-NLS-1$ writeSearchResults(xmlBuffer, srch); } finally { xmlBuffer.closeTag("searchresults"); // $NON-NLS-1$ } } else { xmlBuffer.tag("searchresults", // $NON-NLS-1$ "hasElements=" + srch.hasMoreElements()); // $NON-NLS-1$ } } finally { if (srch != null) { srch.close(); } res.sampleEnd(); } } } catch (NamingException ex) { // TODO: tidy this up String returnData = ex.toString(); final int indexOfLDAPErrCode = returnData.indexOf("LDAP: error code"); if (indexOfLDAPErrCode >= 0) { res.setResponseMessage(returnData.substring(indexOfLDAPErrCode + 21, returnData.indexOf(']'))); // $NON-NLS-1$ res.setResponseCode(returnData.substring(indexOfLDAPErrCode + 17, indexOfLDAPErrCode + 19)); } else { res.setResponseMessage(returnData); res.setResponseCode("800"); // $NON-NLS-1$ } isSuccessful = false; } finally { xmlBuffer.closeTag("operation"); // $NON-NLS-1$ xmlBuffer.tag("responsecode", res.getResponseCode()); // $NON-NLS-1$ xmlBuffer.tag("responsemessage", res.getResponseMessage()); // $NON-NLS-1$ res.setResponseData(xmlBuffer.toString(), null); res.setDataType(SampleResult.TEXT); res.setSuccessful(isSuccessful); } return res; }
From source file:org.apache.jmeter.protocol.ldap.sampler.LDAPExtSampler.java
private String getWriteValue(final Object value) { if (value instanceof String) { // assume it's senstive data return StringEscapeUtils.escapeXml10((String) value); }/* w w w . j a va 2 s. co m*/ if (value instanceof byte[]) { try { return StringEscapeUtils.escapeXml10(new String((byte[]) value, "UTF-8")); //$NON-NLS-1$ } catch (UnsupportedEncodingException e) { log.error("this can't happen: UTF-8 character encoding not supported", e); } } return StringEscapeUtils.escapeXml10(value.toString()); }
From source file:org.apache.openmeetings.cli.ConnectionPropertiesPatcher.java
protected static void patchProp(String[] tokens, int idx, String name, String value) { String prop = tokens[idx].trim(); if (prop.startsWith(name)) { prop = name + "=" + StringEscapeUtils.escapeXml10(value); tokens[idx] = prop;//from ww w .j a v a2 s . com } }