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:rifServices.fileFormats.XMLUtility.java

/**
 * Write field./*from  w ww  . j  a  va  2 s .  co  m*/
 *
 * @param recordName the record name
 * @param fieldName the field name
 * @param value the value
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void writeField(final String recordName, final String fieldName, final String value) throws IOException {

    if (StringUtils.isEmpty(value) == true) {
        return;
    }

    writeFieldStartTag(recordName, fieldName);
    printStream.print(StringEscapeUtils.escapeXml(value));

    writeFieldEndTag(fieldName);
}

From source file:rifServices.fileFormats.XMLUtility.java

/**
 * Write value.//from  ww w.  j  a  v a 2  s.c o m
 *
 * @param value the value
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void writeValue(final String value) throws IOException {

    printStream.print(StringEscapeUtils.escapeXml(value));
    printStream.flush();
}

From source file:sk.opendata.odn.harvester.datanest.OrganizationsDatanestHarvester.java

@Override
public OrganizationRecord scrapOneRecord(String[] row) throws ParseException {
    OrganizationRecord record = new OrganizationRecord();

    record.setId("org_" + row[ATTR_INDEX_ID]);
    record.setDatanestId(row[ATTR_INDEX_ID]);
    record.setSource(row[ATTR_INDEX_SOURCE]);
    record.setName(StringEscapeUtils.escapeXml(row[ATTR_INDEX_NAME]));
    record.setLegalForm(row[ATTR_INDEX_LEGAL_FORM]);
    record.setSeat(row[ATTR_INDEX_SEAT]);
    record.setIco(row[ATTR_INDEX_ICO]);//from ww  w  .  j  ava2  s .c  o m

    Date dateFrom = sdf.parse(row[ATTR_INDEX_DATE_FROM]);
    record.setDateFrom(dateFrom);

    if (!row[ATTR_INDEX_DATE_TO].isEmpty()) {
        Date dateTo = sdf.parse(row[ATTR_INDEX_DATE_TO]);
        record.setDateTo(dateTo);
    }

    logger.debug("scrapped record of: " + record.getName());

    return record;
}

From source file:uk.ac.liverpool.spreadsheet.ToXML.java

private void printSheetContent(Sheet sheet) {
    ensureColumnBounds(sheet);/*from w ww. j  av  a 2  s  .c  o m*/
    printColumnHeads();

    cellsToFormula = new HashMap<String, List<String>>();
    cellToFormulaConverted = new HashMap<String, String>();
    crToParent = new HashMap<String, List<String>>();
    FormulaParsingWorkbook fpwb;
    FormulaRenderingWorkbook frwb;
    if (xswb != null) {
        XSSFEvaluationWorkbook w = XSSFEvaluationWorkbook.create(xswb);
        frwb = w;
        fpwb = w;
    } else if (hswb != null) {
        HSSFEvaluationWorkbook w = HSSFEvaluationWorkbook.create(hswb);
        frwb = w;
        fpwb = w;
    }

    else
        return;
    // first we need to determine all the dependencies ofr each formula
    Iterator<Row> rows = sheet.rowIterator();
    while (rows.hasNext()) {
        Row row = rows.next();
        for (int i = firstColumn; i < endColumn; i++) {
            if (i >= row.getFirstCellNum() && i < row.getLastCellNum()) {
                Cell cell = row.getCell(i);
                if (cell != null) {
                    if (cell.getCellType() == Cell.CELL_TYPE_FORMULA)
                        try {
                            parseFormula(cell, fpwb, frwb);

                        } catch (Exception x) {

                        }
                }
            }
        }
    }
    rows = sheet.rowIterator();

    while (rows.hasNext()) {
        Row row = rows.next();
        int rowNumber = row.getRowNum() + 1;
        out.format("  <TableRow>%n");
        out.format("    <RowHeader>%d</RowHeader>%n", rowNumber);
        out.format("  <TableCells>%n");
        for (int i = firstColumn; i < endColumn; i++) {
            String content = "0";
            String attrs = "";
            CellStyle style = null;
            String valueType = "float";
            Cell cell = row.getCell(i);
            CellReference c = new CellReference(rowNumber - 1, i);
            attrs += " cellID=\"." + c.formatAsString() + "\"";

            String cr = c.formatAsString();
            // if (i >= row.getFirstCellNum() && i < row.getLastCellNum()) {

            if (cell != null && cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
                attrs += " readOnly=\"readOnly\"";
                try {
                    attrs += " cellFormula=\"" + StringEscapeUtils.escapeXml(cell.getCellFormula()) + "\"";
                } catch (Exception x) {
                    attrs += " cellFormula=\"FORMULA ERROR\"";
                }
            } else {
                List<String> cfrl = cellsToFormula.get(cr);
                StringBuffer formula = new StringBuffer("");

                if (cfrl != null) {
                    List<String> refs = new LinkedList<String>();
                    visit(cfrl, refs);
                    System.out.println(refs);
                    cleanup(refs);
                    for (String s : refs) {
                        formula.append(StringEscapeUtils.escapeXml(cellToFormulaConverted.get(s)));
                        formula.append(" || ");
                    }
                }
                if (formula.length() > 0)
                    attrs += " formula=\"" + formula.substring(0, formula.length() - 4) + "\"";
            }
            if (cell != null) {
                style = cell.getCellStyle();
                // Set the value that is rendered for the cell
                // also applies the format

                try {
                    CellFormat cf = CellFormat.getInstance(style.getDataFormatString());
                    CellFormatResult result = cf.apply(cell);
                    content = result.text;
                } catch (Exception x) {
                    content = "DATA FORMULA ERROR ";
                }

            }
            // }
            attrs += " value_type=\"" + valueType + "\"";
            attrs += " value=\"" + StringEscapeUtils.escapeXml(content) + "\"";
            out.format("    <TableCell  %s>%s</TableCell>%n", // class=%s
                    // styleName(style),
                    attrs, StringEscapeUtils.escapeXml(content));
        }
        out.format(" </TableCells> </TableRow>%n%n");
    }
}

From source file:us.conxio.XMLUtilities.AttributeMap.java

/**
 * Return the entire attribute map as a string.
 * @return A String representation of the entire attribute map, suitable for
 * inclusion in an XML element./* w  w  w  .  ja va  2  s .  c o  m*/
 */
@Override
public String toString() {
    if (attributeMap.isEmpty())
        return "";

    StringBuilder buildBuffer = new StringBuilder();
    Iterator attributeIterator = attributeMap.entrySet().iterator();
    while (attributeIterator.hasNext()) {
        Map.Entry attributeEntry = (Map.Entry) attributeIterator.next();
        String attributeKey = (String) attributeEntry.getKey();
        String attributeValue = (String) attributeEntry.getValue();
        if (attributeKey != null && !attributeKey.isEmpty()) {
            buildBuffer.append(" ").append(attributeKey).append("=\"");
            if (escape && attributeValue != null) {
                String unescaped = StringEscapeUtils.unescapeHtml4(attributeValue);
                attributeValue = StringEscapeUtils.escapeXml(unescaped);
            } // if

            if (attributeValue != null)
                buildBuffer.append(attributeValue);
            buildBuffer.append("\"");
        } // if
    } // while

    return buildBuffer.toString();
}