List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeXml
@Deprecated public static final String escapeXml(final String input)
Escapes the characters in a String using XML entities.
For example: "bread" & "butter" => "bread" & "butter" .
From source file:org.opendatakit.tables.utils.CollectUtil.java
/** * Build a default form. This form will allow being swiped through, one field * at a time./* w w w. j ava 2 s .c o m*/ * * @param file * the file to write the form to * @param columns * the columnProperties of the table. * @param title * the title of the form * @param formId * the id of the form * @return true if the file was successfully written */ private static boolean buildBlankForm(Context context, String appName, String tableId, ArrayList<ColumnDefinition> orderedDefns, File file, String formId) { OutputStreamWriter writer = null; try { List<ColumnDefinition> geopointList = GeoColumnUtil.get().getGeopointColumnDefinitions(orderedDefns); List<ColumnDefinition> uriList = RowPathColumnUtil.get().getUriColumnDefinitions(orderedDefns); ArrayList<ColumnDefinition> orderedElements = orderedDefns; String localizedDisplayName; SQLiteDatabase db = null; try { db = DatabaseFactory.get().getDatabase(context, appName); localizedDisplayName = TableUtil.get().getLocalizedDisplayName(db, tableId); } finally { if (db != null) { db.close(); } } FileOutputStream out = new FileOutputStream(file); writer = new OutputStreamWriter(out, CharEncoding.UTF_8); writer.write( "<h:html xmlns=\"http://www.w3.org/2002/xforms\" " + "xmlns:h=\"http://www.w3.org/1999/xhtml\" " + "xmlns:ev=\"http://www.w3.org/2001/xml-events\" " + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " + "xmlns:jr=\"http://openrosa.org/javarosa\">"); writer.write("<h:head>"); writer.write("<h:title>"); writer.write(StringEscapeUtils.escapeXml(localizedDisplayName)); writer.write("</h:title>"); writer.write("<model>"); writer.write("<instance>"); writer.write("<"); writer.write(DEFAULT_ROOT_ELEMENT); writer.write(" "); writer.write("id=\""); writer.write(StringEscapeUtils.escapeXml(formId)); writer.write("\">"); for (ColumnDefinition cd : orderedElements) { ColumnDefinition cdContainingElement = cd.getParent(); if (cdContainingElement != null) { if (geopointList.contains(cdContainingElement) || uriList.contains(cdContainingElement)) { // processed by the containing type continue; } // and if this is not a unit of retention, a containing element is // handling it. if (!cd.isUnitOfRetention()) { continue; } } // ok. we are directly processing this... and possibly sucking values // out of sub-elements... writer.write("<"); writer.write(cd.getElementKey()); writer.write("/>"); } writer.write("<meta><instanceID/></meta>"); writer.write("</"); writer.write(DEFAULT_ROOT_ELEMENT); writer.write(">"); writer.write("</instance>"); ElementTypeManipulator m = ElementTypeManipulatorFactory.getInstance(appName); for (ColumnDefinition cd : orderedElements) { ColumnDefinition cdContainingElement = cd.getParent(); if (cdContainingElement != null) { if (geopointList.contains(cdContainingElement) || uriList.contains(cdContainingElement)) { // processed by the containing type continue; } // and if this is not a unit of retention, a containing element is // handling it. if (!cd.isUnitOfRetention()) { continue; } } // ok. we are directly processing this... and possibly sucking values // out of sub-elements... ElementType type = cd.getType(); String collectType = m.getDefaultRenderer(cd.getType()).getCollectType(); if (collectType == null) { collectType = "string"; } writer.write("<bind nodeset=\"/"); writer.write(DEFAULT_ROOT_ELEMENT); writer.write("/"); writer.write(cd.getElementKey()); writer.write("\" type=\""); writer.write(collectType); writer.write("\"/>"); } writer.write("<bind nodeset=\"/"); writer.write(DEFAULT_ROOT_ELEMENT); writer.write("/meta/instanceID\" type=\"string\" required=\"true()\"/>"); writer.write("<itext>"); writer.write("<translation lang=\"eng\">"); for (ColumnDefinition cd : orderedElements) { ColumnDefinition cdContainingElement = cd.getParent(); if (cdContainingElement != null) { if (geopointList.contains(cdContainingElement) || uriList.contains(cdContainingElement)) { // processed by the containing type continue; } // and if this is not a unit of retention, a containing element is // handling it. if (!cd.isUnitOfRetention()) { continue; } } db = null; try { db = DatabaseFactory.get().getDatabase(context, appName); localizedDisplayName = ColumnUtil.get().getLocalizedDisplayName(db, tableId, cd.getElementKey()); } finally { if (db != null) { db.close(); } } // ok. we are directly processing this... and possibly sucking values // out of sub-elements... writer.write("<text id=\"/"); writer.write(DEFAULT_ROOT_ELEMENT); writer.write("/"); writer.write(cd.getElementKey()); writer.write(":label\">"); writer.write("<value>"); writer.write(localizedDisplayName); writer.write("</value>"); writer.write("</text>"); } writer.write("</translation>"); writer.write("</itext>"); writer.write("</model>"); writer.write("</h:head>"); writer.write("<h:body>"); for (ColumnDefinition cd : orderedElements) { ColumnDefinition cdContainingElement = cd.getParent(); if (cdContainingElement != null) { if (geopointList.contains(cdContainingElement) || uriList.contains(cdContainingElement)) { // processed by the containing type continue; } // and if this is not a unit of retention, a containing element is // handling it. if (!cd.isUnitOfRetention()) { continue; } } // ok. we are directly processing this... and possibly sucking values // out of sub-elements... String action = "input"; String additionalAttributes = ""; if (uriList.contains(cd)) { action = "upload"; String basetype = cd.getElementName().substring(0, cd.getElementName().length() - 3); if (basetype.equals("mime")) { basetype = "*"; // not supported by ODK Collect... launch OI File // Manager? } additionalAttributes = " mediatype=\"" + basetype + "/*\""; } writer.write("<" + action + additionalAttributes + " ref=\"/" + DEFAULT_ROOT_ELEMENT + "/" + cd.getElementKey() + "\">"); writer.write("<label ref=\"jr:itext('/" + DEFAULT_ROOT_ELEMENT + "/" + cd.getElementKey() + ":label')\"/>"); writer.write("</" + action + ">"); } writer.write("</h:body>"); writer.write("</h:html>"); writer.flush(); writer.close(); return true; } catch (IOException e) { // TODO Auto-generated catch block WebLogger.getLogger(appName).printStackTrace(e); return false; } finally { try { writer.close(); } catch (IOException e) { } } }
From source file:org.opendatakit.tables.utils.CollectUtil.java
/** * Write the row for a table out to a file to later be inserted into an * existing Collect form. This existing form must match the fields specified * in params.//www . jav a 2 s .c o m * <p> * The file generated is at the location and name specified in * {@link DATA_FILE_PATH_AND_NAME}. * * TODO: add support for select-multiple * * The mechanics of this are modeled on the getIntentForOdkCollectEditRow * method in Controller that handles the case for editing every column in a * screen by screen fashion, generating the entire form on the fly. * * @param context * @param appName * @param tableId * @param orderedDefns * @param values * @param params * the form parameters * @param rowId * @return true if the write succeeded */ private static boolean writeRowDataToBeEdited(Context context, String appName, String tableId, ArrayList<ColumnDefinition> orderedDefns, Map<String, String> values, CollectFormParameters params, String rowId) { /* * This is currently implemented thinking that all you need to have is: * * <?xml version='1.0' ?><data id="tablesaddrowformid"> * * followed by a series of: * * <columnName1>firstFieldData</columnName1> ... * <lastColumn>lastField</lastField> * * We will just go ahead and write all the fields/columns, knowing that the * form will simply ignore those for which it does not have matching entry * fields. */ List<ColumnDefinition> geopointList = GeoColumnUtil.get().getGeopointColumnDefinitions(orderedDefns); List<ColumnDefinition> uriList = RowPathColumnUtil.get().getUriColumnDefinitions(orderedDefns); OutputStreamWriter writer = null; try { FileOutputStream out = new FileOutputStream(getEditRowFormFile(appName, tableId, rowId)); writer = new OutputStreamWriter(out, CharEncoding.UTF_8); writer.write("<?xml version='1.0' ?><"); writer.write(params.getRootElement()); writer.write(" id=\""); writer.write(StringEscapeUtils.escapeXml(params.getFormId())); writer.write("\">"); for (ColumnDefinition cd : orderedDefns) { ColumnDefinition cdContainingElement = cd.getParent(); if (cdContainingElement != null) { if (geopointList.contains(cdContainingElement) || uriList.contains(cdContainingElement)) { // processed by the containing type continue; } // and if this is not a unit of retention, a containing element is // handling it. if (!cd.isUnitOfRetention()) { continue; } } // ok. we are directly processing this... and possibly sucking values // out of sub-elements... ElementType type = cd.getType(); if (geopointList.contains(cd)) { // find its children... List<ColumnDefinition> children = cd.getChildren(); ColumnDefinition[] cparray = new ColumnDefinition[4]; if (!children.isEmpty()) { cparray[0] = children.get(0); } if (children.size() > 1) { cparray[1] = children.get(1); } if (children.size() > 2) { cparray[2] = children.get(2); } if (children.size() > 3) { cparray[3] = children.get(3); } ColumnDefinition cplat = null, cplng = null, cpalt = null, cpacc = null; for (ColumnDefinition scp : cparray) { if (scp.getElementName().equals("latitude")) { cplat = scp; } else if (scp.getElementName().equals("longitude")) { cplng = scp; } else if (scp.getElementName().equals("altitude")) { cpalt = scp; } else if (scp.getElementName().equals("accuracy")) { cpacc = scp; } } boolean nonNull = false; StringBuilder b = new StringBuilder(); if (cplat != null) { String value = (values == null) ? null : values.get(cplat.getElementKey()); if (value == null) { b.append("-999999"); } else { nonNull = true; b.append(value); } } b.append(" "); if (cplng != null) { String value = (values == null) ? null : values.get(cplng.getElementKey()); if (value == null) { b.append("-999999"); } else { nonNull = true; b.append(value); } } b.append(" "); if (cpalt != null) { String value = (values == null) ? null : values.get(cpalt.getElementKey()); if (value == null) { b.append("-999999"); } else { nonNull = true; b.append(value); } } b.append(" "); if (cpacc != null) { String value = (values == null) ? null : values.get(cpacc.getElementKey()); if (value == null) { b.append("-999999"); } else { nonNull = true; b.append(value); } } if (nonNull) { writer.write("<"); writer.write(cd.getElementKey()); writer.write(">"); writer.write(StringEscapeUtils.escapeXml(b.toString())); writer.write("</"); writer.write(cd.getElementKey()); writer.write(">"); } else { writer.write("<"); writer.write(cd.getElementKey()); writer.write("/>"); } } else if (uriList.contains(cd)) { // find its children... List<ColumnDefinition> children = cd.getChildren(); ColumnDefinition[] cparray = new ColumnDefinition[children.size()]; for (int i = 0; i < children.size(); ++i) { cparray[i] = children.get(i); } // find the uriFragment ColumnDefinition cpfrag = null; for (ColumnDefinition scp : cparray) { if (scp.getElementName().equals("uriFragment")) { cpfrag = scp; } } String value = null; if (cpfrag != null) { value = (values == null) ? null : values.get(cpfrag.getElementKey()); } if (value != null) { File f = ODKFileUtils.getAsFile(appName, value); value = f.getName(); } if (value != null) { writer.write("<"); writer.write(cd.getElementKey()); writer.write(">"); writer.write(StringEscapeUtils.escapeXml(value)); writer.write("</"); writer.write(cd.getElementKey()); writer.write(">"); } else { writer.write("<"); writer.write(cd.getElementKey()); writer.write("/>"); } } else if (cd.isUnitOfRetention()) { String value = (values == null) ? null : values.get(cd.getElementKey()); if (value != null) { writer.write("<"); writer.write(cd.getElementKey()); writer.write(">"); if (type.getElementType().equals(ElementType.DATE)) { // TODO: get this in the correct format... writer.write(StringEscapeUtils.escapeXml(value)); } else if (type.getElementType().equals(ElementType.DATETIME)) { // TODO: get this in the correct format... writer.write(StringEscapeUtils.escapeXml(value)); } else if (type.getElementType().equals(ElementType.TIME)) { // TODO: get this in the correct format... writer.write(StringEscapeUtils.escapeXml(value)); } else { writer.write(StringEscapeUtils.escapeXml(value)); } writer.write("</"); writer.write(cd.getElementKey()); writer.write(">"); } else { writer.write("<"); writer.write(cd.getElementKey()); writer.write("/>"); } } } writer.write("<meta>"); writer.write("<instanceID>"); writer.write(StringEscapeUtils.escapeXml(rowId)); writer.write("</instanceID>"); writer.write("</meta>"); writer.write("</"); writer.write(params.getRootElement()); writer.write(">"); writer.flush(); writer.close(); return true; } catch (IOException e) { WebLogger.getLogger(appName).e(TAG, "IOException while writing data file"); WebLogger.getLogger(appName).printStackTrace(e); return false; } finally { try { writer.close(); } catch (IOException e) { } } }
From source file:org.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.escapeXml(value); tokens[idx] = prop;//from w w w .j ava2 s .com } }
From source file:org.pgptool.gui.ui.tools.UiUtils.java
public static String plainToBoldHtmlString(String text) { return "<html><body><b>" + StringEscapeUtils.escapeXml(text) + "</b></body></html>"; }
From source file:org.pgptool.gui.ui.tools.UiUtils.java
public static String envelopeStringIntoHtml(String text) { return "<html><body>" + StringEscapeUtils.escapeXml(text) + "</body></html>"; }
From source file:org.rythmengine.utils.S.java
/** * Return a {@link org.rythmengine.utils.RawData} type wrapper of * an object with XML escaping/*w ww. ja v a2s .co m*/ * <p/> * <p>Object is {@link #toString(Object) converted to String} before escaping</p> * <p/> * <p>After the object get escaped, the output string is safe to put inside a XML * attribute * @param o * @return XML escaped data */ @Transformer public static RawData escapeXML(Object o) { if (null == o) return RawData.NULL; if (o instanceof RawData) return (RawData) o; return new RawData(StringEscapeUtils.escapeXml(o.toString())); }
From source file:org.rythmengine.utils.S.java
/** * Alias of {@link #escapeXML(Object)}/*from www.j av a2 s . co m*/ * * @param o * @return XML escaped data */ public static RawData escapeXml(Object o) { if (null == o) return RawData.NULL; if (o instanceof RawData) return (RawData) o; return new RawData(StringEscapeUtils.escapeXml(o.toString())); }
From source file:org.slc.sli.sandbox.idp.saml.SamlResponseComposer.java
private void addAttribute(StringBuilder buf, String key, String value) { buf.append(ATTRIBUTE_NAME_BEGIN_TEMPLATE.replace("__NAME__", key)); buf.append(ATTRIBUTE_VALUE_TEMPLATE.replace("__VALUE__", StringEscapeUtils.escapeXml(value))); buf.append(ATTRIBUTE_NAME_END_TEMPLATE); }
From source file:org.slc.sli.validation.schema.NeutralSchemaXMLStringWriter.java
private String escape(String input) { return StringEscapeUtils.escapeXml(input); }
From source file:org.spdx.licenseTemplate.SpdxLicenseTemplateHelper.java
/** * Escapes and formats text/* w w w . j av a 2 s . com*/ * @param text unformatted text * @param inParagraph true if inside a paragraph tag * @return */ public static String formatEscapeHTML(String text, boolean inParagraph) { String retval = StringEscapeUtils.escapeXml(text); return addHtmlFormatting(retval, inParagraph); }