List of usage examples for org.apache.commons.lang3 StringEscapeUtils ESCAPE_HTML4
CharSequenceTranslator ESCAPE_HTML4
To view the source code for org.apache.commons.lang3 StringEscapeUtils ESCAPE_HTML4.
Click Source Link
From source file:net.officefloor.plugin.web.http.template.PropertyHttpTemplateWriter.java
@Override public void write(ServerWriter writer, boolean isDefaultCharset, Object bean, HttpApplicationLocation location) throws IOException { // If no bean, then no value to output if (bean == null) { return;//from ww w. j a v a2s .c om } // Obtain the property text value String propertyTextValue; try { // Obtain the property value from bean Object value = this.valueRetriever.retrieveValue(bean, this.propertyName); // Obtain the text value to write as content propertyTextValue = (value == null ? "" : value.toString()); } catch (InvocationTargetException ex) { // Propagate cause of method failure throw new IOException(ex.getCause()); } catch (Exception ex) { // Propagate failure throw new IOException(ex); } // Write out the value if (this.isEscaped) { // Write the escaped value StringEscapeUtils.ESCAPE_HTML4.translate(propertyTextValue, writer); } else { // Write the raw value writer.write(propertyTextValue); } }
From source file:org.apache.chemistry.opencmis.server.impl.atompub.CmisAtomPubServlet.java
/** * Prints the error HTML page./* w ww. ja v a 2s .c om*/ */ protected void printError(Exception ex, HttpServletRequest request, HttpServletResponse response) { int statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; String exceptionName = "runtime"; if (ex instanceof CmisRuntimeException) { LOG.error(createLogMessage(ex, request), ex); statusCode = getErrorCode((CmisRuntimeException) ex); } else if (ex instanceof CmisStorageException) { LOG.error(createLogMessage(ex, request), ex); statusCode = getErrorCode((CmisStorageException) ex); exceptionName = ((CmisStorageException) ex).getExceptionName(); } else if (ex instanceof CmisBaseException) { statusCode = getErrorCode((CmisBaseException) ex); exceptionName = ((CmisBaseException) ex).getExceptionName(); if (statusCode == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) { LOG.error(createLogMessage(ex, request), ex); } } else if (ex instanceof IOException) { LOG.warn(createLogMessage(ex, request), ex); } else { LOG.error(createLogMessage(ex, request), ex); } if (response.isCommitted()) { LOG.warn("Failed to send error message to client. Response is already committed.", ex); return; } String message = ex.getMessage(); if (!(ex instanceof CmisBaseException)) { message = "An error occurred!"; } try { response.resetBuffer(); response.setStatus(statusCode); response.setContentType("text/html"); response.setCharacterEncoding(IOUtils.UTF8); PrintWriter pw = response.getWriter(); pw.print("<html><head><title>Apache Chemistry OpenCMIS - " + exceptionName + " error</title>" + "<style><!--H1 {font-size:24px;line-height:normal;font-weight:bold;background-color:#f0f0f0;color:#003366;border-bottom:1px solid #3c78b5;padding:2px;} " + "BODY {font-family:Verdana,arial,sans-serif;color:black;font-size:14px;} " + "HR {color:#3c78b5;height:1px;}--></style></head><body>"); pw.print("<h1>HTTP Status " + statusCode + " - <!--exception-->" + exceptionName + "<!--/exception--></h1>"); pw.print("<p><!--message-->"); StringEscapeUtils.ESCAPE_HTML4.translate(message, pw); pw.print("<!--/message--></p>"); String st = ExceptionHelper.getStacktraceAsString(ex); if (st != null) { pw.print("<hr noshade='noshade'/><!--stacktrace--><pre>\n<!--key-->stacktrace<!--/key><!--value-->" + st + "<!--/value-->\n</pre><!--/stacktrace--><hr noshade='noshade'/>"); } if (ex instanceof CmisBaseException) { Map<String, String> additionalData = ((CmisBaseException) ex).getAdditionalData(); if (additionalData != null && !additionalData.isEmpty()) { pw.print("<hr noshade='noshade'/>Additional data:<br><br>"); for (Map.Entry<String, String> e : additionalData.entrySet()) { pw.print("<!--key-->"); StringEscapeUtils.ESCAPE_HTML4.translate(e.getKey(), pw); pw.print("<!--/key--> = <!--value-->"); StringEscapeUtils.ESCAPE_HTML4.translate(e.getValue(), pw); pw.print("<!--/value--><br>"); } } } pw.print("</body></html>"); } catch (Exception e) { LOG.error(createLogMessage(ex, request), e); try { response.sendError(statusCode, message); } catch (Exception en) { // there is nothing else we can do } } }
From source file:org.apache.nifi.attribute.expression.language.evaluation.functions.CharSequenceTranslatorEvaluator.java
public static StringEvaluator html4EscapeEvaluator(final Evaluator<String> subject) { return new CharSequenceTranslatorEvaluator(subject, StringEscapeUtils.ESCAPE_HTML4); }
From source file:org.jboss.dashboard.ui.components.HandlerMarkupGenerator.java
protected String getHiddenMarkup(String name, String value) { name = StringEscapeUtils.ESCAPE_HTML4.translate(name); value = StringEscapeUtils.ESCAPE_HTML4.translate(value); return "<input type=\"hidden\" name=\"" + name + "\" value=\"" + value + "\">"; }
From source file:org.jboss.dashboard.ui.components.table.DataSetTableFormatter.java
protected String formatCellValue(Table table, int row, int column) { DataSetTable dataSetTable = (DataSetTable) table; DataProperty property = dataSetTable.getDataProperty(column); if (property == null) return ""; DataPropertyFormatter formatter = DataFormatterRegistry.lookup() .getPropertyFormatter(property.getPropertyId()); return StringEscapeUtils.ESCAPE_HTML4.translate( formatter.formatValue(property, table.getValueAt(row, column), LocaleManager.currentLocale())); }
From source file:org.jboss.dashboard.ui.components.table.TableFormatter.java
protected void setTableAttributes(TableHandler tableHandler) { Table table = tableHandler.getTable(); setAttribute("currentpage", table.getCurrentPage()); setAttribute("rowcount", table.getRowCount()); setAttribute("maxrowspage", table.getMaxRowsPerPage()); setAttribute("headerposition", table.getHeaderPosition()); setAttribute("htmlstyleedit", StringUtils.defaultString(StringEscapeUtils.ESCAPE_HTML4.translate(table.getHtmlStyle()))); setAttribute("rowevenstyleedit", StringUtils.defaultString(StringEscapeUtils.ESCAPE_HTML4.translate(table.getRowEvenStyle()))); setAttribute("rowoddstyleedit", StringUtils.defaultString(StringEscapeUtils.ESCAPE_HTML4.translate(table.getRowOddStyle()))); setAttribute("rowhoverstyleedit", StringUtils.defaultString(StringEscapeUtils.ESCAPE_HTML4.translate(table.getRowHoverStyle()))); setAttribute("htmlclass", StringUtils.defaultString(StringEscapeUtils.ESCAPE_HTML4.translate(table.getHtmlClass()))); setAttribute("rowevenclass", StringUtils.defaultString(StringEscapeUtils.ESCAPE_HTML4.translate(table.getRowEventClass()))); setAttribute("rowoddclass", StringUtils.defaultString(StringEscapeUtils.ESCAPE_HTML4.translate(table.getRowOddClass()))); setAttribute("rowhoverclass", StringUtils.defaultString(StringEscapeUtils.ESCAPE_HTML4.translate(table.getRowHoverClass()))); setAttribute("htmlstyleview", table.getHtmlStyle()); }
From source file:org.jboss.dashboard.ui.components.table.TableFormatter.java
protected void setColumnAttributes(TableColumn column, int columnIndex) { Locale locale = LocaleManager.currentLocale(); setAttribute("column", column); setAttribute("columnindex", columnIndex); setAttribute("columnmodel", column.getPropertyId()); setAttribute("columnname", column.getName(locale)); setAttribute("columnhint", column.getHint(locale)); setAttribute("columnselectable", column.isSelectable()); setAttribute("columnsortable", isColumnSortable(column)); String icon = getSortIcon(column, columnIndex); setAttribute("iconId", icon); setAttribute("iconTextId", getSortKeyText(icon)); String headerHTML = column.getHeaderHtmlStyle(); String cellsHTML = column.getCellHtmlStyle(); if (headerHTML == null) headerHTML = cellsHTML;/*from w w w . j a va 2 s . c om*/ if (headerHTML != null) { setAttribute("columnheaderhtmlstyle", StringUtils.defaultString(headerHTML)); setAttribute("columnheaderstyleedit", StringUtils.defaultString(StringEscapeUtils.ESCAPE_HTML4.translate(headerHTML))); } if (cellsHTML != null) { setAttribute("columncellhtmlstyle", StringUtils.defaultString(cellsHTML)); setAttribute("columncellstyleedit", StringUtils.defaultString(StringEscapeUtils.ESCAPE_HTML4.translate(cellsHTML))); } String htmlValue = column.getHtmlValue(); if (htmlValue != null) { setAttribute("columnhtmlvalue", StringUtils.defaultString(htmlValue)); setAttribute("columnhtmlvalueedit", StringUtils.defaultString(StringEscapeUtils.ESCAPE_HTML4.translate(htmlValue))); } }
From source file:org.jboss.dashboard.ui.components.table.TableFormatter.java
protected String formatCellValue(Table table, int row, int column) { Object value = table.getValueAt(row, column); if (value == null) return ""; return StringEscapeUtils.ESCAPE_HTML4.translate(value.toString()); }
From source file:org.jboss.dashboard.ui.config.components.homePages.HomePagesFormatter.java
protected void renderPageSelect(WorkspaceImpl workspace, Long selectedOption, Role role) { Section[] sections = workspace.getAllSections(); //Sorted setAttribute("inputName", "defaultPageFor_" + role.getName()); setAttribute("roleName", role.getName()); setAttribute("roleDescription", role.getDescription(getLocale())); renderFragment("outputSelectStart"); renderFragment("outputPageSelectOption");//Empty option for (int i = 0; i < sections.length; i++) { Section section = sections[i];//from ww w . j a v a 2 s .c om setAttribute("selected", section.getId().equals(selectedOption)); setAttribute("sectionId", section.getId()); setAttribute("sectionName", StringEscapeUtils.ESCAPE_HTML4.translate(getLocalizedValue(section.getTitle()))); renderFragment("outputPageSelectOption"); } renderFragment("outputSelectEnd"); }
From source file:org.jboss.dashboard.ui.config.components.panelInstance.PanelInstancesPropertiesFormatter.java
public void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws FormatterException { renderFragment("outputStart"); renderFragment("outputStartRow"); renderFragment("outputHeaderDelete"); setAttribute("value", "ui.title"); renderFragment("outputHeaders"); setAttribute("value", "ui.admin.configuration.panelInstances.panelsCount"); renderFragment("outputHeaders"); renderFragment("outputEndRow"); PanelInstance[] instances = null;//from w w w .ja va 2 s .c o m try { WorkspaceImpl workspace = ((WorkspaceImpl) getWorkspacesManager() .getWorkspace(handler.getWorkspaceId())); instances = workspace.getPanelInstances(); if (instances == null || instances.length == 0) { renderFragment("outputStartRow"); renderFragment("empty"); renderFragment("outputEndRow"); return; } final Map<Long, String> instancesTitles = calculateInstancesTitles(workspace, getLang()); Arrays.sort(instances, new Comparator<PanelInstance>() { public int compare(PanelInstance p1, PanelInstance p2) { return (instancesTitles.get(p1.getInstanceId())) .compareToIgnoreCase(instancesTitles.get(p2.getInstanceId())); } }); Map<Long, Integer> panelStatistics = calculatePanelsStatistics(workspace); for (int i = 0; i < instances.length; i++) { renderFragment("outputStartRow"); PanelInstance instance = instances[i]; String estilo = (i % 2) == 1 ? "skn-even_row" : "skn-odd_row"; setAttribute("estilo", estilo); setAttribute("value", instance.getId()); renderFragment("outputDelete"); setAttribute("estilo", estilo); String title = instancesTitles.get(instance.getInstanceId()); setAttribute("value", StringEscapeUtils.ESCAPE_HTML4.translate(title)); renderFragment("outputTitle"); setAttribute("estilo", estilo); Integer panelCount = panelStatistics.get(instance.getInstanceId()); setAttribute("value", panelCount != null ? panelCount : new Integer(0)); renderFragment("outputPanelsNumber"); renderFragment("outputEndRow"); } renderFragment("outputEnd"); } catch (Exception e) { log.error("Error getting workspace instances:", e); } }