Example usage for org.apache.commons.lang3 StringEscapeUtils escapeXml

List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeXml

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeXml.

Prototype

@Deprecated
public static final String escapeXml(final String input) 

Source Link

Document

Escapes the characters in a String using XML entities.

For example: "bread" & "butter" => "bread" & "butter" .

Usage

From source file:org.mfcrawler.model.export.gexf.ExportSitesGexf.java

/**
 * Writes a gexf node from a site//from   www  .  j a v  a2  s. c om
 * @param fileWriter the file write
 * @param site the site (the node)
 * @exception
 */
private static void writeGexfNode(FileWriter fileWriter, Site site) throws IOException {
    String domainName = StringEscapeUtils.escapeXml(site.getDomain().getName());
    fileWriter.write("<node id=\"");
    fileWriter.write(domainName);
    fileWriter.write("\" label=\"");
    fileWriter.write(domainName);
    fileWriter.write("\" start=\"");
    fileWriter.write(ConversionUtils.toFormattedDate(site.getCrawlTime(), DATETIME_FORMAT));

    fileWriter.write("\"> <attvalues> <attvalue for=\"totalScore\" value=\"");
    fileWriter.write(ConversionUtils.toString(site.getTotalScore()));
    fileWriter.write("\"/> <attvalue for=\"averageScore\" value=\"");
    fileWriter.write(ConversionUtils.toString(site.getTotalScore() / site.getCrawledPagesNumber()));
    fileWriter.write("\"/> <attvalue for=\"crawledPagesNumber\" value=\"");
    fileWriter.write(ConversionUtils.toString(site.getCrawledPagesNumber()));
    fileWriter.write("\"/> </attvalues> </node> \n");
}

From source file:org.mfcrawler.model.export.gexf.ExportSitesGexf.java

/**
 * Writes a gexf edge from a domain's page and a domain's link
 * @param fileWriter the file write// ww  w.j a v  a 2s  . c  o  m
 * @param edgeId the edge id
 * @param page the page, the source of the edge
 * @param externLink the externLink, the target of the edge
 * @exception
 */
private static void writeGexfEdge(FileWriter fileWriter, int edgeId, Page page, Link externLink)
        throws IOException {
    fileWriter.write("<edge id=\"");
    fileWriter.write(ConversionUtils.toString(edgeId));
    fileWriter.write("\" source=\"");
    fileWriter.write(StringEscapeUtils.escapeXml(page.getLink().getDomain().getName()));
    fileWriter.write("\" target=\"");
    fileWriter.write(StringEscapeUtils.escapeXml(externLink.getDomain().getName()));
    fileWriter.write("\" type=\"directed\" /> \n");
}

From source file:org.miradi.utils.XmlUtilities2.java

public static String getXmlEncoded(String value) {
    if (isEmptyValue(value))
        return value;

    return StringEscapeUtils.escapeXml(value);
}

From source file:org.moe.natjgen.CEnumConstant.java

@Override
public String toString() {
    StringBuilder b = new StringBuilder();
    b.append("<constant name=\"");
    b.append(StringEscapeUtils.escapeXml(getName()));
    b.append("\"");

    b.append(" value=\"");
    b.append(Long.toHexString(value.getValue()));
    b.append("\"");

    if (value.hasDifferent32BitValue()) {
        b.append(" value32=\"");
        b.append(Long.toHexString(value.getValue32()));
        b.append("\"");
    }//from   www .  j a  v a 2  s  .c  o m

    b.append(" />");

    return b.toString();
}

From source file:org.moe.natjgen.CEnumManager.java

@Override
public String toString() {
    StringBuilder b = new StringBuilder();
    b.append("<enum name=\"" + StringEscapeUtils.escapeXml(getFullyQualifiedName()) + "\">");
    for (CEnumConstant constant : constants) {
        if (!constant.getDontGenerate()) {
            b.append(constant);/*from   w w w . ja  v a2s. c o  m*/
        }
    }
    b.append("</enum>");
    return b.toString();
}

From source file:org.n52.sos.encoder.OGCProcedureEncoder.java

/**
 * Helper method to encode a Procedure as a SensorML 1.0.1 Component.
 *//*from  w ww  .  j  a  v a  2 s.com*/
private String encodeSingleProcedure(Procedure procedure) {
    StringBuilder componentString = new StringBuilder(componentTemplate101);

    replace(componentString, COMPONENT_PROCEDURE_ID, procedure.getId());
    replace(componentString, COMPONENT_PROCEDURE_RESOURCE, procedure.getResource());

    List<String> featureIDs = procedure.getFeaturesOfInterest();
    String featuresString = "";
    if (featureIDs != null) {
        int count = 1;
        for (String featureID : featureIDs) {
            featuresString += "<swe:field name=\"FeatureOfInterest-" + count++ + "\">\n";
            featuresString += "   <swe:Text definition=\"FeatureOfInterestID\">\n";
            featuresString += "      <swe:value>" + featureID + "</swe:value>\n";
            featuresString += "   </swe:Text>\n";
            featuresString += "</swe:field>";
        }
    }
    replace(componentString, COMPONENT_PROCEDURE_FEATURES, featuresString);

    List<String> aggregationTypes = procedure.getAggregationTypeIDs();
    String aggrTypeString = "";
    if (aggregationTypes != null) {
        int count2 = 1;
        for (String aggrTypeID : aggregationTypes) {
            aggrTypeString += "<swe:field name=\"AggregationType-" + count2++ + "\">\n";
            aggrTypeString += "   <swe:Text definition=\"http://dd.eionet.europa.eu/vocabularies/aq/averagingperiod\">\n";
            aggrTypeString += "      <swe:value>" + aggrTypeID + "</swe:value>\n";
            aggrTypeString += "   </swe:Text>\n";
            aggrTypeString += "</swe:field>";
        }
    }
    replace(componentString, COMPONENT_PROCEDURE_AGGREGATIONTYPES, aggrTypeString);

    List<Output> outputs = procedure.getOutputs();
    String outputsString = "";
    for (Output output : outputs) {

        String propertyLabel = StringEscapeUtils.escapeXml(output.getObservedPropertyLabel());

        outputsString += "<output name=\"" + propertyLabel + "\">\n";
        outputsString += "   <swe:Quantity definition=\"" + output.getObservedPropertyID() + "\">\n";

        if (output.getUnit() != null) {
            outputsString += "      <swe:uom code=\"" + output.getUnit() + "\"/>\n";
        }

        outputsString += "   </swe:Quantity>\n";
        outputsString += "</output>";
    }
    replace(componentString, COMPONENT_PROCEDURE_OUTPUTS, outputsString);

    return componentString.toString();
}

From source file:org.nerve.utils.encode.EncodeUtils.java

public static String xmlEscape(String xml) {
    return StringEscapeUtils.escapeXml(xml);
}

From source file:org.onesun.sdi.spi.socialmedia.AbstractSocialMediaProvider.java

@Override
public boolean save(String pathToExports) {
    try {/* w w w . j a  va  2  s  .  com*/
        String dirPath = pathToExports + getIdentity() + "/";
        File dir = new File(dirPath);
        if (dir.exists() == false) {
            logger.info("Export: " + dir.getAbsolutePath());
            dir.mkdirs();
        }

        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = null;
        Element root = null;

        OutputFormat format = null;
        String path = null;
        File file = null;

        // apiClass can't be null ... Provider must be initialized (lazy loading)
        if (apiClass == null) {
            init();
        }

        // Write properties
        path = dirPath + "properties.xml";
        file = new File(path);
        if (file.exists() == false) {
            document = documentBuilder.newDocument();
            root = document.createElement("root");
            root.setAttribute("oauthVersion", oauthVersion.name());
            root.setAttribute("developerUrl", developerUrl);
            root.setAttribute("apiClass", apiClass.getCanonicalName());
            root.setAttribute("category", getCategory());
            root.setAttribute("identity", getIdentity());
            root.setAttribute("authentication", getAuthentication());
            document.appendChild(root);

            format = new OutputFormat(document);
            format.setIndenting(true);

            XMLSerializer serializer = new XMLSerializer(new FileOutputStream(file), format);
            logger.info("Serializing completed for: " + file.getAbsolutePath());
            serializer.serialize(document);
        }

        // Write Scope
        path = dirPath + "scopes.xml";
        file = new File(path);
        if (file.exists() == false && apiScopeList != null && apiScopeList.size() > 0) {
            document = documentBuilder.newDocument();
            root = document.createElement("root");

            for (String apiScope : apiScopeList) {
                Element scope = document.createElement("scope");
                scope.setTextContent(apiScope);

                root.appendChild(scope);
            }

            document.appendChild(root);

            format = new OutputFormat(document);
            format.setIndenting(true);

            XMLSerializer serializer = new XMLSerializer(new FileOutputStream(file), format);
            logger.info("Serializing completed for: " + file.getAbsolutePath());
            serializer.serialize(document);
        }

        // Write Resources
        path = dirPath + "resources.xml";
        file = new File(path);
        if (file.exists() == false && resources != null && resources.size() > 0) {
            document = documentBuilder.newDocument();
            root = document.createElement("root");

            for (RESTResource resource : resources) {
                Element e = null;
                Element r = document.createElement("resource");

                e = document.createElement("resourceName");
                e.setTextContent(resource.getResourceName());
                r.appendChild(e);

                String text = null;

                e = document.createElement("url");
                text = StringEscapeUtils.escapeXml(resource.getUrl());
                e.setTextContent(text);
                r.appendChild(e);

                e = document.createElement("verb");
                e.setTextContent(resource.getVerb().name());
                r.appendChild(e);

                text = resource.getTextFormat().name();
                if (text != null && text.trim().compareToIgnoreCase("UNKNOWN") != 0) {
                    e = document.createElement("textFormat");
                    e.setTextContent(text);
                    r.appendChild(e);
                }

                text = resource.getPayload();
                if (text != null && text.trim().length() > 0) {
                    e = document.createElement("payload");
                    e.setTextContent(text);
                    r.appendChild(e);
                }

                text = resource.getParameters();
                if (text != null && text.trim().length() > 0) {
                    e = document.createElement("parameters");
                    e.setTextContent(text);
                    r.appendChild(e);
                }

                boolean flag = resource.isAccessTokenRequired();
                e = document.createElement("isAccessTokenRequired");
                e.setTextContent(Boolean.toString(flag));
                r.appendChild(e);

                // Write Headers
                Map<String, String> headers = resource.getHeaders();
                if (headers != null && headers.size() > 0) {
                    e = document.createElement("headers");

                    for (String key : headers.keySet()) {
                        Element he = document.createElement("header");
                        he.setAttribute(key, headers.get(key));

                        e.appendChild(he);
                    }

                    r.appendChild(e);
                }

                // Write to parent
                root.appendChild(r);
            }

            document.appendChild(root);

            format = new OutputFormat(document);
            format.setIndenting(true);

            XMLSerializer serializer = new XMLSerializer(new FileOutputStream(file), format);
            logger.info("Serializing completed for: " + file.getAbsolutePath());
            serializer.serialize(document);

            return true;
        }

    } catch (ParserConfigurationException e) {
        logger.error("ParserConfigurationException while creating new document instance: " + e.getMessage());
    } catch (FileNotFoundException e) {
        logger.error("FileNotFoundException while creating new document instance: " + e.getMessage());
    } catch (IOException e) {
        logger.error("IOException while creating new document instance: " + e.getMessage());
    } finally {
    }

    return false;
}

From source file:org.openbmap.soapclient.GpxExporter.java

/**
 * Iterates on way points and write them.
 * @param bw Writer to the target file./*from   ww w.jav  a 2s.  c o  m*/
 * @param c Cursor to way points.
 * @throws IOException
 */
private void writeWifis(final BufferedWriter bw) throws IOException {
    Log.i(TAG, "Writing wifi waypoints");

    Cursor c = mDbHelper.getReadableDatabase().rawQuery(WIFI_POINTS_SQL_QUERY,
            new String[] { String.valueOf(mSession), String.valueOf(0) });
    //Log.i(TAG, WIFI_POINTS_SQL_QUERY);
    final int colLatitude = c.getColumnIndex(Schema.COL_LATITUDE);
    final int colLongitude = c.getColumnIndex(Schema.COL_LONGITUDE);
    final int colAltitude = c.getColumnIndex(Schema.COL_ALTITUDE);
    final int colTimestamp = c.getColumnIndex(Schema.COL_TIMESTAMP);
    final int colSsid = c.getColumnIndex(Schema.COL_SSID);

    long outer = 0;
    while (!c.isAfterLast()) {
        c.moveToFirst();
        //StringBuffer out = new StringBuffer();
        while (!c.isAfterLast()) {
            bw.write("\t<wpt lat=\"");
            bw.write(String.valueOf(c.getDouble(colLatitude)));
            bw.write("\" ");
            bw.write("lon=\"");
            bw.write(String.valueOf(c.getDouble(colLongitude)));
            bw.write("\">\n");
            bw.write("\t\t<ele>");
            bw.write(String.valueOf(c.getDouble(colAltitude)));
            bw.write("</ele>\n");
            bw.write("\t\t<time>");
            // time stamp conversion to ISO 8601
            bw.write(getGpxDate(c.getLong(colTimestamp)));
            bw.write("</time>\n");
            bw.write("\t\t<name>");
            bw.write(StringEscapeUtils.escapeXml(c.getString(colSsid)));
            bw.write("</name>\n");
            bw.write("\t</wpt>\n");

            c.moveToNext();
        }
        //bw.write(out.toString());
        //out = null;
        // fetch next CURSOR_SIZE records
        outer += CURSOR_SIZE;
        c.close();
        c = mDbHelper.getReadableDatabase().rawQuery(WIFI_POINTS_SQL_QUERY,
                new String[] { String.valueOf(mSession), String.valueOf(outer) });
    }
    c.close();
    System.gc();
}

From source file:org.openbmap.soapclient.GpxExporter.java

/**
 * Iterates on way points and write them.
 * @param bw Writer to the target file.//from   w  w w . j  a  va2s .  c  o m
 * @param c Cursor to way points.
 * @throws IOException
 */
private void writeCells(final BufferedWriter bw) throws IOException {
    Log.i(TAG, "Writing cell waypoints");
    Cursor c = mDbHelper.getReadableDatabase().rawQuery(CELL_POINTS_SQL_QUERY,
            new String[] { String.valueOf(mSession), String.valueOf(0) });

    final int colLatitude = c.getColumnIndex(Schema.COL_LATITUDE);
    final int colLongitude = c.getColumnIndex(Schema.COL_LONGITUDE);
    final int colAltitude = c.getColumnIndex(Schema.COL_ALTITUDE);
    final int colTimestamp = c.getColumnIndex(Schema.COL_TIMESTAMP);
    final int colName = c.getColumnIndex("name");

    long outer = 0;
    while (!c.isAfterLast()) {
        c.moveToFirst();
        //StringBuffer out = new StringBuffer();
        while (!c.isAfterLast()) {
            bw.write("\t<wpt lat=\"");
            bw.write(String.valueOf(c.getDouble(colLatitude)));
            bw.write("\" ");
            bw.write("lon=\"");
            bw.write(String.valueOf(c.getDouble(colLongitude)));
            bw.write("\">\n");
            bw.write("\t\t<ele>");
            bw.write(String.valueOf(c.getDouble(colAltitude)));
            bw.write("</ele>\n");
            bw.write("\t\t<time>");
            // time stamp conversion to ISO 8601
            bw.write(getGpxDate(c.getLong(colTimestamp)));
            bw.write("</time>\n");
            bw.write("\t\t<name>");
            bw.write(StringEscapeUtils.escapeXml(c.getString(colName)));
            bw.write("</name>\n");
            bw.write("\t</wpt>\n");

            c.moveToNext();
        }

        //bw.write(out.toString());
        //out = null;
        // fetch next CURSOR_SIZE records
        outer += CURSOR_SIZE;
        c.close();
        c = mDbHelper.getReadableDatabase().rawQuery(CELL_POINTS_SQL_QUERY,
                new String[] { String.valueOf(mSession), String.valueOf(outer) });
    }
    c.close();
    System.gc();
}