List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeHtml4
public static final String escapeHtml4(final String input)
Escapes the characters in a String using HTML entities.
For example:
"bread" & "butter"
"bread" & "butter"
.
From source file:com.aurel.track.exchange.docx.exporter.CustomXML.java
public static Document convertToDOM(TWorkItemBean documentItem, Integer personID, Locale locale) { Document dom = null;// w ww . j a v a 2 s.c o m try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); dom = builder.newDocument(); } catch (FactoryConfigurationError e) { LOGGER.error("Creating the DOM document failed with FactoryConfigurationError:" + e.getMessage()); return null; } catch (ParserConfigurationException e) { LOGGER.error("Creating the DOM document failed with ParserConfigurationException: " + e.getMessage()); return null; } Element root = dom.createElement(CUSTOM_XML_ELEMENTS.MAIN_ELEMENT); if (documentItem != null) { Integer itemID = documentItem.getObjectID(); List<TWorkItemBean> itemList = new LinkedList<TWorkItemBean>(); itemList.add(documentItem); List<ReportBean> reportBeansList = LoadItemIDListItems.getReportBeansByWorkItems(itemList, personID, locale, true, false, false, false, false, false, false, false, false); ReportBean showableWorkItem = reportBeansList.get(0); Map<Integer, String> showValuesMap = showableWorkItem.getShowValuesMap(); if (showValuesMap != null) { List<TFieldBean> fieldBeansList = FieldBL.loadAll(); for (TFieldBean fieldBean : fieldBeansList) { Integer fieldID = fieldBean.getObjectID(); String fieldName = fieldBean.getName(); String showValue = showValuesMap.get(fieldID); if (showValue != null && !"".equals(showValue)) { IFieldTypeRT fieldTypeRT = FieldTypeManager.getFieldTypeRT(fieldID); if (fieldTypeRT != null) { if (fieldTypeRT.isLong()) { showValue = StringEscapeUtils.escapeHtml4(showValue); } } appendChild(root, fieldName, showValue, dom); appendChild(root, fieldName + CUSTOM_XML_ELEMENTS.PRESENT_SUFFIX, Boolean.TRUE.toString(), dom); } else { appendChild(root, fieldName + CUSTOM_XML_ELEMENTS.PRESENT_SUFFIX, Boolean.FALSE.toString(), dom); appendChild(root, fieldName, "", dom); } } List<TPersonBean> consultedPersonBeans = PersonBL.getDirectConsultants(itemID); addWatcherNodes(consultedPersonBeans, root, dom, CUSTOM_XML_ELEMENTS.CONSULTED_LIST, CUSTOM_XML_ELEMENTS.CONSULTED_PERSON); List<TPersonBean> informedPersonBeans = PersonBL.getDirectInformants(itemID); addWatcherNodes(informedPersonBeans, root, dom, CUSTOM_XML_ELEMENTS.INFORMED_LIST, CUSTOM_XML_ELEMENTS.INFORMED_PERSON); List<HistoryValues> comments = HistoryLoaderBL.getRestrictedWorkItemComments(personID, itemID, locale, false, /*LONG_TEXT_TYPE.ISPLAIN*/ LONG_TEXT_TYPE.ISFULLHTML); addCommentNodes(comments, root, dom, locale); } } dom.appendChild(root); return dom; }
From source file:at.gv.egiz.pdfas.web.servlets.ProvidePDFServlet.java
protected void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*w w w .j a v a 2 s . c om*/ String invokeURL = PdfAsHelper.getInvokeURL(request, response); if (invokeURL == null || !WebConfiguration.isProvidePdfURLinWhitelist(invokeURL)) { if (invokeURL != null) { logger.warn(invokeURL + " is not allowed by whitelist"); } String template = PdfAsHelper.getProvideTemplate(); template = template.replace(PDF_DATA_URL, PdfAsHelper.generatePdfURL(request, response)); // Deliver to Browser directly! response.setContentType("text/html"); response.getWriter().write(template); response.getWriter().close(); } else { // Redirect Browser String template = PdfAsHelper.getInvokeRedirectTemplateSL(); URL url = new URL(invokeURL); int p = url.getPort(); //no port, but http or https --> use default port if ((url.getProtocol().equalsIgnoreCase("https") || url.getProtocol().equalsIgnoreCase("http")) && p == -1) { p = url.getDefaultPort(); } String invokeUrlProcessed = url.getProtocol() + "://" + // "http" + ":// url.getHost() + // "myhost" ":" + // ":" p + // "8080" url.getPath(); template = template.replace("##INVOKE_URL##", invokeUrlProcessed); String extraParams = UrlParameterExtractor.buildParameterFormString(url); template = template.replace("##ADD_PARAMS##", extraParams); byte[] signedData = PdfAsHelper.getSignedPdf(request, response); if (signedData != null) { template = template.replace("##PDFLENGTH##", String.valueOf(signedData.length)); } else { throw new PdfAsException("No Signature data available"); } String target = PdfAsHelper.getInvokeTarget(request, response); if (target == null) { target = "_self"; } template = template.replace("##TARGET##", StringEscapeUtils.escapeHtml4(target)); template = template.replace("##PDFURL##", URLEncoder.encode(PdfAsHelper.generatePdfURL(request, response), "UTF-8")); response.setContentType("text/html"); response.getWriter().write(template); response.getWriter().close(); } } catch (Exception e) { PdfAsHelper.setSessionException(request, response, e.getMessage(), e); PdfAsHelper.gotoError(getServletContext(), request, response); } }
From source file:at.gv.egiz.pdfas.web.servlets.ErrorPage.java
protected void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (PdfAsHelper.getFromDataUrl(request)) { // redirect to here! response.sendRedirect(PdfAsHelper.generateErrorURL(request, response)); return;//ww w. java2s.c om } else { String errorURL = PdfAsHelper.getErrorURL(request, response); Throwable e = PdfAsHelper.getSessionException(request, response); StatisticEvent statisticEvent = PdfAsHelper.getStatisticEvent(request, response); if (statisticEvent != null) { if (!statisticEvent.isLogged()) { statisticEvent.setStatus(Status.ERROR); statisticEvent.setException(e); if (e instanceof PDFASError) { statisticEvent.setErrorCode(((PDFASError) e).getCode()); } statisticEvent.setEndNow(); statisticEvent.setTimestampNow(); StatisticFrontend.getInstance().storeEvent(statisticEvent); statisticEvent.setLogged(true); } } String message = PdfAsHelper.getSessionErrMessage(request, response); if (errorURL != null && WebConfiguration.isProvidePdfURLinWhitelist(errorURL)) { String template = PdfAsHelper.getErrorRedirectTemplateSL(); URL url = new URL(errorURL); String errorURLProcessed = url.getProtocol() + "://" + // "http" + ":// url.getHost() + // "myhost" ":" + // ":" url.getPort() + // "8080" url.getPath(); template = template.replace("##ERROR_URL##", errorURLProcessed); String extraParams = UrlParameterExtractor.buildParameterFormString(url); template = template.replace("##ADD_PARAMS##", extraParams); String target = PdfAsHelper.getInvokeTarget(request, response); if (target == null) { target = "_self"; } template = template.replace("##TARGET##", StringEscapeUtils.escapeHtml4(target)); if (e != null && WebConfiguration.isShowErrorDetails()) { template = template.replace("##CAUSE##", URLEncoder.encode(e.getMessage(), "UTF-8")); } else { template = template.replace("##CAUSE##", ""); } if (message != null) { template = template.replace("##ERROR##", URLEncoder.encode(message, "UTF-8")); } else { template = template.replace("##ERROR##", "Unbekannter Fehler"); } response.setContentType("text/html"); response.getWriter().write(template); response.getWriter().close(); } else { if (errorURL != null) { logger.warn(errorURL + " is not allowed by whitelist"); } String template = PdfAsHelper.getErrorTemplate(); if (message != null) { template = template.replace(ERROR_MESSAGE, message); } else { template = template.replace(ERROR_MESSAGE, "Unbekannter Fehler"); } if (e != null && WebConfiguration.isShowErrorDetails()) { template = template.replace(ERROR_STACK, HTMLFormater.formatStackTrace(e.getStackTrace())); } else { template = template.replace(ERROR_STACK, ""); } response.setContentType("text/html"); response.getWriter().write(template); response.getWriter().close(); } } }
From source file:com.netsteadfast.greenstep.util.TemplateUtils.java
public static String escapeHtml4TemplateHtmlContent(String strContent) throws Exception { if (StringUtils.isBlank(strContent)) { return ""; }/*from w w w . ja va 2s.c om*/ return StringEscapeUtils.escapeHtml4(strContent).replaceAll("\n", Constants.HTML_BR); }
From source file:com.searchcode.app.service.route.CodeRouteService.java
public Map<String, Object> getCode(Request request, Response response) { Map<String, Object> map = new HashMap<>(); Repo repo = Singleton.getRepo();//from w w w . ja va 2 s . c om Data data = Singleton.getData(); SearchcodeLib scl = Singleton.getSearchcodeLib(data); OWASPClassifier owaspClassifier = new OWASPClassifier(); Cocomo2 coco = new Cocomo2(); String codeId = request.params(":codeid"); CodeResult codeResult = this.codeSearcher.getByCodeId(codeId); if (codeResult == null) { response.redirect("/404/"); halt(); } List<String> codeLines = codeResult.code; StringBuilder code = new StringBuilder(); StringBuilder lineNos = new StringBuilder(); String padStr = ""; for (int total = codeLines.size() / 10; total > 0; total = total / 10) { padStr += " "; } for (int i = 1, d = 10, len = codeLines.size(); i <= len; i++) { if (i / d > 0) { d *= 10; padStr = padStr.substring(0, padStr.length() - 1); // Del last char } code.append("<span id=\"").append(i).append("\"></span>") .append(StringEscapeUtils.escapeHtml4(codeLines.get(i - 1))).append("\n"); lineNos.append(padStr).append("<a href=\"#").append(i).append("\">").append(i).append("</a>") .append("\n"); } List<OWASPMatchingResult> owaspResults = new ArrayList<OWASPMatchingResult>(); if (CommonRouteService.owaspAdvisoriesEnabled()) { if (!codeResult.languageName.equals("Text") && !codeResult.languageName.equals("Unknown")) { owaspResults = owaspClassifier.classifyCode(codeLines, codeResult.languageName); } } int limit = Integer.parseInt(Properties.getProperties().getProperty(Values.HIGHLIGHT_LINE_LIMIT, Values.DEFAULT_HIGHLIGHT_LINE_LIMIT)); boolean highlight = Singleton.getHelpers().tryParseInt(codeResult.codeLines, "0") <= limit; RepoResult repoResult = repo.getRepoByName(codeResult.repoName); if (repoResult != null) { map.put("source", repoResult.getSource()); } map.put("fileName", codeResult.fileName); // TODO fix this properly code path includes the repo name and should be removed String codePath = codeResult.codePath; if (codeResult.codePath.contains("/")) { codePath = codeResult.codePath.substring(codeResult.codePath.indexOf('/'), codeResult.codePath.length()); } if (!codePath.startsWith("/")) { codePath = "/" + codePath; } map.put("codePath", codePath); map.put("codeLength", codeResult.codeLines); map.put("linenos", lineNos.toString()); map.put("languageName", codeResult.languageName); map.put("md5Hash", codeResult.md5hash); map.put("repoName", codeResult.repoName); map.put("highlight", highlight); map.put("repoLocation", codeResult.getRepoLocation()); map.put("codeValue", code.toString()); map.put("highligher", CommonRouteService.getSyntaxHighlighter()); map.put("codeOwner", codeResult.getCodeOwner()); map.put("owaspResults", owaspResults); double estimatedEffort = coco.estimateEffort(scl.countFilteredLines(codeResult.getCode())); int estimatedCost = (int) coco.estimateCost(estimatedEffort, CommonRouteService.getAverageSalary()); if (estimatedCost != 0 && !scl.languageCostIgnore(codeResult.getLanguageName())) { map.put("estimatedCost", estimatedCost); } map.put("logoImage", CommonRouteService.getLogo()); map.put("isCommunity", App.ISCOMMUNITY); map.put(Values.EMBED, Singleton.getData().getDataByName(Values.EMBED, Values.EMPTYSTRING)); return map; }
From source file:com.silverpeas.util.EncodeHelper.java
public static String convertHTMLEntities(String text) { SilverTrace.debug("util", "Encode.convertHTMLEntities()", "root.MSG_GEN_PARAM_VALUE", " text recu " + text); String result = StringEscapeUtils.escapeHtml4(text); SilverTrace.debug("util", "Encode.convertHTMLEntities()", "root.MSG_GEN_PARAM_VALUE", "text sortant = " + result); return result; }/* w ww. j a v a2 s.c o m*/
From source file:de.decoit.visa.topology.VLAN.java
@Override public JSONObject toJSON() throws JSONException { JSONObject rv = new JSONObject(); rv.put("identifier", getIdentifier()); rv.put("name", StringEscapeUtils.escapeHtml4(name)); rv.put("color", color); return rv;//from ww w. j ava 2 s. c o m }
From source file:com.primeleaf.krystal.web.view.console.SearchView.java
@SuppressWarnings("unchecked") private void printDocuments() { ArrayList<DocumentClass> documentClasses = (ArrayList<DocumentClass>) request .getAttribute("DOCUMENTCLASSLIST"); for (DocumentClass documentClass : documentClasses) { ArrayList<Hit> hits = (ArrayList<Hit>) request.getAttribute(documentClass.getClassId() + "_HITS"); if (hits.size() > 0) { out.println("<div class=\"panel panel-default\">"); out.println("<div class=\"panel-heading\">"); out.println("<div class=\"row\">"); out.println("<div class=\"col-xs-8\">"); out.println("<h4><i class=\"fa fa-file fa-lg\"></i> " + StringEscapeUtils.escapeHtml4(documentClass.getClassName()) + ""); out.println(" - " + StringEscapeUtils.escapeHtml4(documentClass.getClassDescription()) + "</h4>"); out.println("</div>"); out.println("<div class=\"col-xs-4 text-right\">"); out.println("<h4>" + hits.size() + " Documents</h4>"); out.println("</div>"); out.println("</div>");//row out.println("</div>");//panel-heading out.println("<div class=\"table-responsive\">"); out.println("<table class=\"table table-striped\">"); out.println("<thead>"); out.println("<tr>"); out.println("<th class=\"text-center\">Document ID</th>"); if (documentClass.isRevisionControlEnabled()) { out.println("<th class=\"text-center\">Revision ID</th>"); }//from w w w .j a v a 2 s . co m for (IndexDefinition indexDefinition : documentClass.getIndexDefinitions()) { String indexDescription = indexDefinition.getIndexDisplayName(); out.println("<th>" + StringEscapeUtils.escapeHtml4(indexDescription) + "</th>"); } out.println("<th class=\"text-right\"> </th>"); out.println("</tr>"); out.println("</thead>"); out.println("<tbody>"); for (Hit hit : hits) { out.println("<tr>"); out.println("<td class=\"text-center\">" + hit.documentId + "</td>"); if (documentClass.isRevisionControlEnabled()) { out.println("<td class=\"text-center\">" + hit.revisionId + "</td>"); } for (String value : hit.indexValues) { out.println("<td>" + StringEscapeUtils.escapeHtml4(value) + "</td>"); } out.println("<td class=\"text-right\">"); out.println("<a href=\"" + HTTPConstants.BASEURL + "/console/viewdocument?documentid=" + hit.documentId + "&revisionid=" + hit.revisionId + "\" title=\"View Document\">View Document</a>"); out.println("</tr>"); } out.println("</tbody>"); out.println("</table>"); out.println("</div>");//table-responsive out.println("</div>");//panel } } }
From source file:com.navercorp.pinpoint.web.controller.BusinessTransactionController.java
@RequestMapping(value = "/bind", method = RequestMethod.POST) @ResponseBody/*from w ww . j a v a2 s .c om*/ public String metaDataBind(@RequestParam("type") String type, @RequestParam("metaData") String metaData, @RequestParam("bind") String bind) { if (logger.isDebugEnabled()) { logger.debug("POST /bind params {metaData={}, bind={}}", metaData, bind); } if (metaData == null) { return ""; } List<String> bindValues; String combinedResult = ""; if (type.equals("sql")) { bindValues = parameterParser.parseOutputParameter(bind); combinedResult = sqlParser.combineBindValues(metaData, bindValues); } else if (type.equals("mongoJson")) { bindValues = parameterJsonParser.parseOutputParameter(bind); combinedResult = mongoJsonParser.combineBindValues(metaData, bindValues); } if (logger.isDebugEnabled()) { logger.debug("Combined result={}", combinedResult); } if (type.equals("mongoJson")) { return StringEscapeUtils.unescapeHtml4(combinedResult); } return StringEscapeUtils.escapeHtml4(combinedResult); }
From source file:com.opendesign.vo.DesignWorkVO.java
public String getContents() { return StringEscapeUtils.escapeHtml4(contents); }