List of usage examples for org.apache.commons.lang StringEscapeUtils escapeHtml
public static String escapeHtml(String input)
From source file:edu.isi.karma.controller.command.publish.PublishRDFCellCommand.java
@Override public UpdateContainer doIt(Workspace workspace) throws CommandException { if (isDeprecated()) { return new UpdateContainer(new ErrorUpdate("PublishRDFCellCommand is currently not supported")); }/*ww w . ja v a2 s . co m*/ //Worksheet worksheet = workspace.getWorksheet(worksheetId); // Get the alignment for this worksheet Alignment alignment = AlignmentManager.Instance() .getAlignment(AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId)); if (alignment == null || alignment.isEmpty()) { logger.info("Alignment is NULL for " + worksheetId); return new UpdateContainer(new ErrorUpdate("Worksheet not modeled!")); } try { // Generate the KR2RML data structures for the RDF generation /*final ErrorReport errorReport = new ErrorReport(); KR2RMLMappingGenerator mappingGen = new KR2RMLMappingGenerator( workspace, worksheet, alignment, worksheet.getSemanticTypes(), rdfSourcePrefix, rdfSourceNamespace, false, errorReport); KR2RMLMapping mapping = mappingGen.getKR2RMLMapping(); KR2RMLWorksheetRDFGenerator rdfGen = new KR2RMLWorksheetRDFGenerator(worksheet, workspace.getFactory(), workspace.getOntologyManager(), pw, mapping, errorReport, false); // Create empty data structures Set<String> existingTopRowTriples = new HashSet<String>(); Set<String> predicatesCovered = new HashSet<String>(); Map<String, ReportMessage> predicatesFailed = new HashMap<String, ReportMessage>(); Set<String> predicatesSuccessful = new HashSet<String>(); Node node = workspace.getFactory().getNode(nodeId); rdfGen.generateTriplesForCell(node, existingTopRowTriples, node.getHNodeId(), predicatesCovered, predicatesFailed, predicatesSuccessful);*/ return new UpdateContainer(new AbstractUpdate() { @Override public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) { JSONObject outputObject = new JSONObject(); try { outputObject.put(JsonKeys.updateType.name(), "PublishCellRDFUpdate"); String rdfCellEscapeString = StringEscapeUtils.escapeHtml(outRdf.toString()); outputObject.put(JsonKeys.cellRdf.name(), rdfCellEscapeString.replaceAll("\\n", "<br />")); outputObject.put(JsonKeys.worksheetId.name(), worksheetId); pw.println(outputObject.toString(4)); } catch (JSONException e) { logger.error("Error occured while generating JSON!"); } } }); } catch (Exception e) { return new UpdateContainer(new ErrorUpdate(e.getMessage())); } }
From source file:edu.lafayette.metadb.web.metadata.PrintMetadata.java
private String getMetadataDisplay(Metadata m) { String attribute = m.getElement() + "." + m.getLabel(); return "<p><span style='font-weight: bold; padding-left:25px'>" + attribute + "</span>:</p>" + "<p style='padding-left:50px; margin-top:-3px'>" + StringEscapeUtils.escapeHtml(m.getData()) + "</p>"; }
From source file:com.rapidminer.operator.preprocessing.filter.attributes.NumericValueAttributeFilter.java
@Override public void init(ParameterHandler parameterHandler) throws UserError, ConditionCreationException { String conditionString = parameterHandler.getParameterAsString(PARAMETER_NUMERIC_CONDITION); Operator operator = null;/*from w w w . java2 s . c o m*/ if (parameterHandler instanceof Operator) { operator = (Operator) parameterHandler; } if (conditionString == null || conditionString.length() == 0) { throw new UserError(operator, "cannot_parse_expression", StringEscapeUtils.escapeHtml(conditionString), I18N.getErrorMessage("numeric_value_filter.no_parameter_string")); } // testing if not allowed combination of and and or if (conditionString.contains("||") && conditionString.contains("&&")) { throw new UserError(operator, "cannot_parse_expression", StringEscapeUtils.escapeHtml(conditionString), I18N.getErrorMessage("numeric_value_filter.and_combined_with_or")); } this.conjunctiveMode = conditionString.contains("&&"); conditions = new ArrayList<>(); boolean conditionFound; for (String conditionSubString : conditionString.split("[|&]{2}")) { conditionFound = false; for (String conditionOperator : CONDITION_OPERATORS) { if (conditionSubString.trim().startsWith(conditionOperator)) { conditionFound = true; // Quotation needed, to prevent conditionOperator to be interpreted as a regex String number = conditionSubString.replaceFirst("\\Q" + conditionOperator + "\\E", "").trim(); // check if number is valid try { Double.parseDouble(number); conditions.add(new Condition(conditionOperator, number)); break; } catch (NullPointerException | NumberFormatException e) { throw new UserError(operator, "cannot_parse_expression", StringEscapeUtils.escapeHtml(conditionString), I18N.getErrorMessage("numeric_value_filter.invalid_syntax", new Object())); } } } if (!conditionFound) { throw new UserError(operator, "cannot_parse_expression", StringEscapeUtils.escapeHtml(conditionString), I18N.getErrorMessage("numeric_value_filter.missing_relational_operator")); } } }
From source file:com.redhat.rhn.frontend.action.configuration.files.CompareDeployedSubmitAction.java
private void makeMessage(Action action, HttpServletRequest request) { if (action != null) { //get how many servers this action was created for. int successes = action.getServerActions().size(); String number = LocalizationService.getInstance().formatNumber(new Integer(successes)); //build the url for the action we have created. String url = "/rhn/schedule/ActionDetails.do?aid=" + action.getId(); //create the success message ActionMessages msg = new ActionMessages(); String key;//from ww w . j av a 2s. c o m if (successes == 1) { key = "configdiff.schedule.success.singular"; } else { key = "configdiff.schedule.success"; } Object[] args = new Object[2]; args[0] = StringEscapeUtils.escapeHtml(url); args[1] = StringEscapeUtils.escapeHtml(number); //add in the success message msg.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(key, args)); getStrutsDelegate().saveMessages(request, msg); } else { //Something went wrong, tell user! ActionErrors errors = new ActionErrors(); getStrutsDelegate().addError("configdiff.schedule.error", errors); getStrutsDelegate().saveMessages(request, errors); } }
From source file:com.controlj.green.bulktrend.trendserver.SearchServlet.java
private void writeStringCell(ServletOutputStream out, String cssClass, String content) throws IOException { writeRawCell(out, cssClass, StringEscapeUtils.escapeHtml(content)); }
From source file:com.p5solutions.core.json.JsonSerializer.java
/** * Escaping new lines and quotes for json. * // ww w. j a v a 2 s. c o m * @param value * @return */ protected String escape(String value) { if (value == null) { return null; } //value = HtmlUtils.htmlEscape(value); //value = JavaScriptUtils.javaScriptEscape(value) ; value = StringEscapeUtils.escapeHtml(value); value = StringEscapeUtils.escapeJavaScript(value); value = value.replace("\\'", "'"); // value = value.replace("\\", "\\\\"); // value = value.replace("\t", "\\t"); // value = value.replace("\n", "\\n"); // value = value.replace("\r", "\\r"); // value = value.replace("\"", "\\\""); return value; }
From source file:com.admc.jcreole.Indexer.java
/** * This is a highly-modified fork of Tomcat's method * DefaultServlet.renderHtml()./*from ww w . java2s.c om*/ * * @param directory Will throw an IllegalArgumentException if this is not * a real directory. * @param listUp Generate an entry for "..". * @return HTML fragment that is a HTML table element. */ public StringBuilder generateTable(File directory, String displayName, boolean listUp, FileComparator.SortBy sortBy, boolean ascendSort) { /* * TODO: Use an EnumMap or something to cache FileComparators instead * of instantiating one for every method call. */ Matcher matcher = null; if (!directory.isDirectory()) throw new IllegalArgumentException("Not a directory: " + directory.getAbsolutePath()); if ((namePattern == null && nameFormatString != null) || (namePattern != null && nameFormatString == null)) throw new IllegalStateException( "'namePattern' and 'nameFormatString' must either both be " + "set or both be null"); StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb); String name = displayName; sb.append("<table class=\"jcreole_dirindex\" width=\"100%\" " + "cellspacing=\"0\" cellpadding=\"5\" align=\"center\">\r\n"); // Render the column headings sb.append("<tr>\r\n"); sb.append("<td align=\"left\"><font size=\"+1\"><strong>"); sb.append("<a href=\"?sort="); try { sb.append(URLEncoder.encode((sortBy == FileComparator.SortBy.NAME && ascendSort) ? "-" : "+", "UTF-8")); sb.append("NAME\">Nodename</a>"); if (sortBy == FileComparator.SortBy.NAME) sb.append("<sup>").append(ascendSort ? '+' : '-').append("</sup>"); sb.append("</strong></font></td>\r\n"); sb.append("<td align=\"center\"><font size=\"+1\"><strong>"); sb.append("<a href=\"?sort="); sb.append(URLEncoder.encode((sortBy == FileComparator.SortBy.SIZE && ascendSort) ? "-" : "+", "UTF-8")); sb.append("SIZE\">Size</a>"); if (sortBy == FileComparator.SortBy.SIZE) sb.append("<sup>").append(ascendSort ? '+' : '-').append("</sup>"); sb.append("</strong></font></td>\r\n"); sb.append("<td align=\"right\"><font size=\"+1\"><strong>"); sb.append("<a href=\"?sort="); sb.append(URLEncoder.encode((sortBy == FileComparator.SortBy.MODIFIED && ascendSort) ? "-" : "+", "UTF-8")); } catch (UnsupportedEncodingException uee) { throw new RuntimeException("Unable to encode to UTF-8"); } sb.append("MODIFIED\">Last Modified</a>"); if (sortBy == FileComparator.SortBy.MODIFIED) sb.append("<sup>").append(ascendSort ? '+' : '-').append("</sup>"); sb.append("</strong></font></td>\r\n"); sb.append("</tr>"); boolean shade = true; // DIR ENTRY: if (listUp) { sb.append("<tr"); sb.append(" bgcolor=\"#eeeeee\""); sb.append(">\r\n"); sb.append("<td align=\"left\"> \r\n"); sb.append("<a href=\"../\"><tt><strong>..</strong> ("); sb.append(StringEscapeUtils.escapeHtml(tailStripperPattern.matcher(displayName).replaceFirst(""))); sb.append(")</tt></a></td>\r\n"); sb.append("<td align=\"right\"><tt>"); sb.append(" "); sb.append("</tt></td>\r\n"); sb.append("<td align=\"right\"><tt>"); sb.append(StringEscapeUtils .escapeHtml(isoDateTimeFormatter.format(directory.getParentFile().lastModified()))); sb.append("</tt></td>\r\n"); sb.append("</tr>\r\n"); } // END DIR ENTRY List<File> fileList = Arrays.asList(directory.listFiles(filter)); Collections.sort(fileList, new FileComparator(sortBy, ascendSort)); // Render the directory entries within this directory for (File file : fileList) { String nodeName = file.getName(); if (namePattern != null) { if (file.isFile()) { matcher = namePattern.matcher(nodeName); if (!matcher.matches()) continue; } else { matcher = null; } } shade = !shade; sb.append("<tr"); if (shade) sb.append(" bgcolor=\"#eeeeee\""); sb.append(">\r\n"); sb.append("<td align=\"left\"> \r\n"); sb.append("<a href=\""); if (matcher == null) { sb.append(nodeName); } else { // Terrible hack dur to terrible Java varargs limitation: switch (matcher.groupCount()) { case 1: formatter.format(nameFormatString, matcher.group(1)); break; case 2: formatter.format(nameFormatString, matcher.group(1), matcher.group(2)); break; case 3: formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3)); break; case 4: formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4)); break; case 5: formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4), matcher.group(5)); break; case 6: formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4), matcher.group(5), matcher.group(6)); break; case 7: formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4), matcher.group(5), matcher.group(6), matcher.group(7)); break; case 8: formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4), matcher.group(5), matcher.group(6), matcher.group(7), matcher.group(8)); break; case 9: formatter.format(nameFormatString, matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4), matcher.group(5), matcher.group(6), matcher.group(7), matcher.group(8), matcher.group(9)); break; default: throw new IllegalArgumentException( "Pattern captured too many (" + matcher.groupCount() + ") groups: " + namePattern); } } if (file.isDirectory()) sb.append('/'); sb.append("\"><tt>"); sb.append(StringEscapeUtils.escapeHtml(nodeName)); if (file.isDirectory()) sb.append('/'); sb.append("</tt></a></td>\r\n"); sb.append("<td align=\"right\"><tt>"); if (file.isDirectory()) sb.append(" "); else if (file.isFile()) sb.append(file.length()); sb.append("</tt></td>\r\n"); sb.append("<td align=\"right\"><tt>"); sb.append(StringEscapeUtils.escapeHtml(isoDateTimeFormatter.format(file.lastModified()))); sb.append("</tt></td>\r\n"); sb.append("</tr>\r\n"); } // Render the page footer sb.append("</table>\r\n"); return sb; }
From source file:eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation.java
/** * Format an entity for inclusion in an explanation. * //from w w w . jav a2 s.c o m * @param entityDef the entity definition, may be <code>null</code> * @param html if the format should be HMTL, otherwise the format is just * text * @param indexInFront whether index conditions should be in front of the * property name or behind in brackets * @param locale the locale for the explanation, to be matched if content is * available * @return the formatted entity name or <code>null</code> in case of * <code>null</code> input */ protected String formatEntity(EntityDefinition entityDef, boolean html, boolean indexInFront, Locale locale) { if (entityDef == null) return null; // get name and standard text String name = entityDef.getDefinition().getDisplayName(); String text = quoteName(name, html); // modify text with filter List<ChildContext> path = entityDef.getPropertyPath(); // different output than AlignmentUtil in case of property with index // condition if (path != null && !path.isEmpty() && path.get(path.size() - 1).getIndex() != null) { if (indexInFront) { text = MessageFormat.format(getBaseMessage("index_pre", locale), formatNumber(path.get(path.size() - 1).getIndex() + 1, locale), text); } else { text += " " + MessageFormat.format(getBaseMessage("index_post", locale), formatNumber(path.get(path.size() - 1).getIndex() + 1, locale)); } } else { String filterString = AlignmentUtil.getContextText(entityDef); if (html) { filterString = StringEscapeUtils.escapeHtml(filterString); } if (filterString != null) text += " " + MessageFormat.format(getBaseMessage("filter", locale), quoteText(filterString, html)); } return text; }
From source file:com.jaspersoft.jasperserver.war.action.tree.TreeAction.java
/** * Gets the data, builds tree model and returns serialized tree data. *//*from w w w .j a v a 2 s . co m*/ public Event getNode(RequestContext context) { String providerId = context.getRequestParameters().get(PROVIDER); String uri = context.getRequestParameters().get(URI); String depth = context.getRequestParameters().get(DEPTH); String prefetchNodesList = context.getRequestParameters().get(PREFETCH); String forceHtmlEscape = context.getRequestParameters().get(FORCE_HTML_ESCAPE); int d = 0; if (depth != null && depth.length() > 0) { try { d = Integer.parseInt(depth); if (d < 0) { d = 0; } } catch (Exception e) { log.error("Invalid parameter : depth : " + depth, e); } } List<String> prefetchList = null; if (prefetchNodesList != null && prefetchNodesList.length() > 0) { prefetchList = Arrays.asList(prefetchNodesList.split(",")); } TreeDataProvider treeDataProvider = findProvider(context, providerId); TreeNode treeNode; if (prefetchList == null) { try { treeNode = treeDataProvider.getNode(exContext(context), uri, d); } catch (AccessDeniedException e) { treeNode = treeDataProvider.getNode(exContext(context), configurationBean.getPublicFolderUri(), d); } } else { try { treeNode = TreeHelper.getSubtree(exContext(context), treeDataProvider, uri, prefetchList, d); } catch (AccessDeniedException e) { treeNode = TreeHelper.getSubtree(exContext(context), treeDataProvider, configurationBean.getPublicFolderUri(), prefetchList, d); } } String model = ""; if (treeNode != null) { StringBuffer sb = new StringBuffer(); sb.append("<div id='treeNodeText'>"); String response = treeNode.toJSONString(); if (forceHtmlEscape != null && forceHtmlEscape.equals("true")) { sb.append(StringEscapeUtils.escapeHtml(response)); } else { sb.append(response); } sb.append("</div>"); model = sb.toString(); } context.getRequestScope().put(AJAX_REPORT_MODEL, model); return success(); }
From source file:edu.lafayette.metadb.web.dataman.ViewMetadata.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) *//*from ww w . j a va 2 s .com*/ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF8"), true); String projname = (String) request.getSession(false).getAttribute(Global.SESSION_PROJECT); String username = (String) request.getSession(false).getAttribute(Global.SESSION_USERNAME); JSONObject output = new JSONObject(); JSONArray headers = new JSONArray(); JSONArray items = new JSONArray(); if (projname == null || projname.equals("")) return; int itemCount = ItemsDAO.nextItemNumber(projname) - 1; try { JSONObject itemNumberHeader = new JSONObject(); itemNumberHeader.put("name", "Filename"); itemNumberHeader.put("editable", false); headers.put(itemNumberHeader); for (int i = 0; i < itemCount; i++) { items.put(new JSONArray()); int itemNumber = i + 1; String[] filePath = ItemsDAO.getMasterPath(projname, itemNumber).split("/"); //String[] itemFilename = filePath[filePath.length - 1].split("-"); String itemName = filePath[filePath.length - 1]; items.getJSONArray(i).put(itemName); } String[] techList = request.getParameterValues(Global.MD_TYPE_TECH); if (techList != null) for (String attr : techList) { String element = attr.split("-")[0]; String[] labelArray = attr.split("-"); String label = labelArray.length > 1 ? labelArray[1] : ""; JSONObject techHeader = new JSONObject(); techHeader.put("name", element + (label.equals("") ? "" : "." + label)); techHeader.put("editable", false); headers.put(techHeader); List<String> techData = TechnicalDataDAO.getMultipleTechnicalData(projname, element, label); for (int i = 0; i < itemCount; i++) { String data = ""; if (i < techData.size()) data = techData.get(i); items.getJSONArray(i).put(data); } } Permission metadataPermission = PermissionManDAO.getUserPermission(username, projname); boolean editAdmin = metadataPermission.getAdmin_md().equals("read_write"); boolean editDesc = metadataPermission.getDesc_md().equals("read_write"); String[] adminList = request.getParameterValues(Global.MD_TYPE_ADMIN); if (adminList != null) for (String attr : adminList) { String[] labelArray = attr.split("-"); String element = labelArray[0]; String label = labelArray.length > 1 ? labelArray[1] : ""; List<String> adminDescData = AdminDescDataDAO.getMultipleAdminDescData(projname, element, label, Global.MD_TYPE_ADMIN); //MetaDbHelper.note("Select size "+adminDescData.size()); JSONObject adminHeader = new JSONObject(); adminHeader.put("name", element + (label.equals("") ? "" : "." + label)); adminHeader.put("editable", editAdmin); headers.put(adminHeader); for (int i = 0; i < itemCount; i++) { String data = ""; if (i < adminDescData.size()) data = StringEscapeUtils.escapeHtml(adminDescData.get(i)); items.getJSONArray(i).put(data); } } String[] descList = request.getParameterValues(Global.MD_TYPE_DESC); if (descList != null) for (String attr : descList) { String[] labelArray = attr.split("-"); String element = labelArray[0]; String label = labelArray.length > 1 ? labelArray[1] : ""; List<String> adminDescData = AdminDescDataDAO.getMultipleAdminDescData(projname, element, label, Global.MD_TYPE_DESC); //MetaDbHelper.note("Select size "+adminDescData.size()); JSONObject descHeader = new JSONObject(); descHeader.put("name", element + (label.equals("") ? "" : "." + label)); descHeader.put("editable", editDesc); headers.put(descHeader); for (int i = 0; i < itemCount; i++) { String data = ""; if (i < adminDescData.size()) if (AdminDescAttributesDAO.getAttributeByName(projname, element, label).isSorted()) data = StringEscapeUtils.escapeHtml(MetaDbHelper.sortVocab(adminDescData.get(i))); else data = StringEscapeUtils.escapeHtml(adminDescData.get(i)); items.getJSONArray(i).put(data); } } output.put("headers", headers); output.put("items", items); } catch (Exception e) { MetaDbHelper.logEvent(e); } out.print(output); out.flush(); }