Example usage for org.xml.sax ContentHandler characters

List of usage examples for org.xml.sax ContentHandler characters

Introduction

In this page you can find the example usage for org.xml.sax ContentHandler characters.

Prototype

public void characters(char ch[], int start, int length) throws SAXException;

Source Link

Document

Receive notification of character data.

Usage

From source file:org.apache.syncope.core.logic.report.RoleReportlet.java

private void doExtractAttributes(final ContentHandler handler, final AbstractAttributableTO attributableTO,
        final Collection<String> attrs, final Collection<String> derAttrs, final Collection<String> virAttrs)
        throws SAXException {

    AttributesImpl atts = new AttributesImpl();
    if (!attrs.isEmpty()) {
        Map<String, AttrTO> attrMap = attributableTO.getPlainAttrMap();

        handler.startElement("", "", "attributes", null);
        for (String attrName : attrs) {
            atts.clear();//from w  w w  .ja va2s  . com

            atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, attrName);
            handler.startElement("", "", "attribute", atts);

            if (attrMap.containsKey(attrName)) {
                for (String value : attrMap.get(attrName).getValues()) {
                    handler.startElement("", "", "value", null);
                    handler.characters(value.toCharArray(), 0, value.length());
                    handler.endElement("", "", "value");
                }
            } else {
                LOG.debug("{} not found for {}[{}]", attrName, attributableTO.getClass().getSimpleName(),
                        attributableTO.getKey());
            }

            handler.endElement("", "", "attribute");
        }
        handler.endElement("", "", "attributes");
    }

    if (!derAttrs.isEmpty()) {
        Map<String, AttrTO> derAttrMap = attributableTO.getDerAttrMap();

        handler.startElement("", "", "derivedAttributes", null);
        for (String attrName : derAttrs) {
            atts.clear();

            atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, attrName);
            handler.startElement("", "", "derivedAttribute", atts);

            if (derAttrMap.containsKey(attrName)) {
                for (String value : derAttrMap.get(attrName).getValues()) {
                    handler.startElement("", "", "value", null);
                    handler.characters(value.toCharArray(), 0, value.length());
                    handler.endElement("", "", "value");
                }
            } else {
                LOG.debug("{} not found for {}[{}]", attrName, attributableTO.getClass().getSimpleName(),
                        attributableTO.getKey());
            }

            handler.endElement("", "", "derivedAttribute");
        }
        handler.endElement("", "", "derivedAttributes");
    }

    if (!virAttrs.isEmpty()) {
        Map<String, AttrTO> virAttrMap = attributableTO.getVirAttrMap();

        handler.startElement("", "", "virtualAttributes", null);
        for (String attrName : virAttrs) {
            atts.clear();

            atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, attrName);
            handler.startElement("", "", "virtualAttribute", atts);

            if (virAttrMap.containsKey(attrName)) {
                for (String value : virAttrMap.get(attrName).getValues()) {
                    handler.startElement("", "", "value", null);
                    handler.characters(value.toCharArray(), 0, value.length());
                    handler.endElement("", "", "value");
                }
            } else {
                LOG.debug("{} not found for {}[{}]", attrName, attributableTO.getClass().getSimpleName(),
                        attributableTO.getKey());
            }

            handler.endElement("", "", "virtualAttribute");
        }
        handler.endElement("", "", "virtualAttributes");
    }
}

From source file:org.apache.syncope.core.logic.report.RoleReportlet.java

private void doExtractConf(final ContentHandler handler) throws SAXException {
    if (conf == null) {
        LOG.debug("Report configuration is not present");
    }//from  w  w  w.  ja va 2 s  .  co  m

    AttributesImpl atts = new AttributesImpl();
    handler.startElement("", "", "configurations", null);
    handler.startElement("", "", "roleAttributes", atts);

    for (Feature feature : conf.getFeatures()) {
        atts.clear();
        handler.startElement("", "", "feature", atts);
        handler.characters(feature.name().toCharArray(), 0, feature.name().length());
        handler.endElement("", "", "feature");
    }

    for (String attr : conf.getPlainAttrs()) {
        atts.clear();
        handler.startElement("", "", "attribute", atts);
        handler.characters(attr.toCharArray(), 0, attr.length());
        handler.endElement("", "", "attribute");
    }

    for (String derAttr : conf.getDerAttrs()) {
        atts.clear();
        handler.startElement("", "", "derAttribute", atts);
        handler.characters(derAttr.toCharArray(), 0, derAttr.length());
        handler.endElement("", "", "derAttribute");
    }

    for (String virAttr : conf.getVirAttrs()) {
        atts.clear();
        handler.startElement("", "", "virAttribute", atts);
        handler.characters(virAttr.toCharArray(), 0, virAttr.length());
        handler.endElement("", "", "virAttribute");
    }

    handler.endElement("", "", "roleAttributes");
    handler.endElement("", "", "configurations");
}

From source file:org.apache.syncope.core.logic.report.UserReportlet.java

private void doExtractConf(final ContentHandler handler) throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    handler.startElement("", "", "configurations", null);
    handler.startElement("", "", "userAttributes", atts);

    for (Feature feature : conf.getFeatures()) {
        atts.clear();/*w ww.  j  a  va2s.  c o  m*/
        handler.startElement("", "", "feature", atts);
        handler.characters(feature.name().toCharArray(), 0, feature.name().length());
        handler.endElement("", "", "feature");
    }

    for (String attr : conf.getPlainAttrs()) {
        atts.clear();
        handler.startElement("", "", "attribute", atts);
        handler.characters(attr.toCharArray(), 0, attr.length());
        handler.endElement("", "", "attribute");
    }

    for (String derAttr : conf.getDerAttrs()) {
        atts.clear();
        handler.startElement("", "", "derAttribute", atts);
        handler.characters(derAttr.toCharArray(), 0, derAttr.length());
        handler.endElement("", "", "derAttribute");
    }

    for (String virAttr : conf.getVirAttrs()) {
        atts.clear();
        handler.startElement("", "", "virAttribute", atts);
        handler.characters(virAttr.toCharArray(), 0, virAttr.length());
        handler.endElement("", "", "virAttribute");
    }

    handler.endElement("", "", "userAttributes");
    handler.endElement("", "", "configurations");
}

From source file:org.apache.syncope.core.provisioning.java.job.report.AuditReportlet.java

private void doExtractConf(final ContentHandler handler) throws SAXException {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
    jdbcTemplate.setMaxRows(conf.getSize());
    List<Map<String, Object>> rows = jdbcTemplate
            .queryForList("SELECT * FROM SYNCOPEAUDIT ORDER BY EVENT_DATE DESC");

    handler.startElement("", "", "events", null);
    AttributesImpl atts = new AttributesImpl();
    for (Map<String, Object> row : rows) {
        AuditEntry auditEntry = POJOHelper.deserialize(row.get("MESSAGE").toString(), AuditEntry.class);

        atts.clear();//from  w ww . j  av a  2s  . c o m
        if (StringUtils.isNotBlank(auditEntry.getWho())) {
            atts.addAttribute("", "", "who", ReportXMLConst.XSD_STRING, auditEntry.getWho());
        }
        handler.startElement("", "", "event", atts);

        atts.clear();
        if (StringUtils.isNotBlank(auditEntry.getLogger().getCategory())) {
            atts.addAttribute("", "", "category", ReportXMLConst.XSD_STRING,
                    auditEntry.getLogger().getCategory());
        }
        if (StringUtils.isNotBlank(auditEntry.getLogger().getSubcategory())) {
            atts.addAttribute("", "", "subcategory", ReportXMLConst.XSD_STRING,
                    auditEntry.getLogger().getSubcategory());
        }
        if (StringUtils.isNotBlank(auditEntry.getLogger().getEvent())) {
            atts.addAttribute("", "", "event", ReportXMLConst.XSD_STRING, auditEntry.getLogger().getEvent());
        }
        if (auditEntry.getLogger().getResult() != null) {
            atts.addAttribute("", "", "result", ReportXMLConst.XSD_STRING,
                    auditEntry.getLogger().getResult().name());
        }
        handler.startElement("", "", "logger", atts);
        handler.endElement("", "", "logger");

        if (auditEntry.getBefore() != null) {
            char[] before = ToStringBuilder.reflectionToString(auditEntry.getBefore(), ToStringStyle.JSON_STYLE)
                    .toCharArray();
            handler.startElement("", "", "before", null);
            handler.characters(before, 0, before.length);
            handler.endElement("", "", "before");
        }

        if (auditEntry.getInput() != null) {
            handler.startElement("", "", "inputs", null);
            for (Object inputObj : auditEntry.getInput()) {
                char[] input = ToStringBuilder.reflectionToString(inputObj, ToStringStyle.JSON_STYLE)
                        .toCharArray();
                handler.startElement("", "", "input", null);
                handler.characters(input, 0, input.length);
                handler.endElement("", "", "input");
            }
            handler.endElement("", "", "inputs");
        }

        if (auditEntry.getOutput() != null) {
            char[] output = ToStringBuilder.reflectionToString(auditEntry.getOutput(), ToStringStyle.JSON_STYLE)
                    .toCharArray();
            handler.startElement("", "", "output", null);
            handler.characters(output, 0, output.length);
            handler.endElement("", "", "output");
        }

        handler.startElement("", "", "throwable", null);
        char[] throwable = row.get("THROWABLE").toString().toCharArray();
        handler.characters(throwable, 0, throwable.length);
        handler.endElement("", "", "throwable");

        handler.endElement("", "", "event");
    }
    handler.endElement("", "", "events");
}

From source file:org.apache.syncope.core.provisioning.java.job.report.GroupReportlet.java

private void doExtractAttributes(final ContentHandler handler, final AnyTO anyTO,
        final Collection<String> attrs, final Collection<String> derAttrs, final Collection<String> virAttrs)
        throws SAXException {

    AttributesImpl atts = new AttributesImpl();
    if (!attrs.isEmpty()) {
        Map<String, AttrTO> attrMap = EntityTOUtils.buildAttrMap(anyTO.getPlainAttrs());

        handler.startElement("", "", "attributes", null);
        for (String attrName : attrs) {
            atts.clear();/*from w  w  w .  j a v a2 s  . c  o m*/

            atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, attrName);
            handler.startElement("", "", "attribute", atts);

            if (attrMap.containsKey(attrName)) {
                for (String value : attrMap.get(attrName).getValues()) {
                    handler.startElement("", "", "value", null);
                    handler.characters(value.toCharArray(), 0, value.length());
                    handler.endElement("", "", "value");
                }
            } else {
                LOG.debug("{} not found for {}[{}]", attrName, anyTO.getClass().getSimpleName(),
                        anyTO.getKey());
            }

            handler.endElement("", "", "attribute");
        }
        handler.endElement("", "", "attributes");
    }

    if (!derAttrs.isEmpty()) {
        Map<String, AttrTO> derAttrMap = EntityTOUtils.buildAttrMap(anyTO.getDerAttrs());

        handler.startElement("", "", "derivedAttributes", null);
        for (String attrName : derAttrs) {
            atts.clear();

            atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, attrName);
            handler.startElement("", "", "derivedAttribute", atts);

            if (derAttrMap.containsKey(attrName)) {
                for (String value : derAttrMap.get(attrName).getValues()) {
                    handler.startElement("", "", "value", null);
                    handler.characters(value.toCharArray(), 0, value.length());
                    handler.endElement("", "", "value");
                }
            } else {
                LOG.debug("{} not found for {}[{}]", attrName, anyTO.getClass().getSimpleName(),
                        anyTO.getKey());
            }

            handler.endElement("", "", "derivedAttribute");
        }
        handler.endElement("", "", "derivedAttributes");
    }

    if (!virAttrs.isEmpty()) {
        Map<String, AttrTO> virAttrMap = EntityTOUtils.buildAttrMap(anyTO.getVirAttrs());

        handler.startElement("", "", "virtualAttributes", null);
        for (String attrName : virAttrs) {
            atts.clear();

            atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, attrName);
            handler.startElement("", "", "virtualAttribute", atts);

            if (virAttrMap.containsKey(attrName)) {
                for (String value : virAttrMap.get(attrName).getValues()) {
                    handler.startElement("", "", "value", null);
                    handler.characters(value.toCharArray(), 0, value.length());
                    handler.endElement("", "", "value");
                }
            } else {
                LOG.debug("{} not found for {}[{}]", attrName, anyTO.getClass().getSimpleName(),
                        anyTO.getKey());
            }

            handler.endElement("", "", "virtualAttribute");
        }
        handler.endElement("", "", "virtualAttributes");
    }
}

From source file:org.apache.syncope.core.provisioning.java.job.report.GroupReportlet.java

private void doExtractConf(final ContentHandler handler) throws SAXException {
    if (conf == null) {
        LOG.debug("Report configuration is not present");
    }//from   w  w w  . j a va2s.co  m

    AttributesImpl atts = new AttributesImpl();
    handler.startElement("", "", "configurations", null);
    handler.startElement("", "", "groupAttributes", atts);

    if (conf != null) {
        for (Feature feature : conf.getFeatures()) {
            atts.clear();
            handler.startElement("", "", "feature", atts);
            handler.characters(feature.name().toCharArray(), 0, feature.name().length());
            handler.endElement("", "", "feature");
        }

        for (String attr : conf.getPlainAttrs()) {
            atts.clear();
            handler.startElement("", "", "attribute", atts);
            handler.characters(attr.toCharArray(), 0, attr.length());
            handler.endElement("", "", "attribute");
        }

        for (String derAttr : conf.getDerAttrs()) {
            atts.clear();
            handler.startElement("", "", "derAttribute", atts);
            handler.characters(derAttr.toCharArray(), 0, derAttr.length());
            handler.endElement("", "", "derAttribute");
        }

        for (String virAttr : conf.getVirAttrs()) {
            atts.clear();
            handler.startElement("", "", "virAttribute", atts);
            handler.characters(virAttr.toCharArray(), 0, virAttr.length());
            handler.endElement("", "", "virAttribute");
        }
    }

    handler.endElement("", "", "groupAttributes");
    handler.endElement("", "", "configurations");
}

From source file:org.apache.tika.parser.jdbc.JDBCTableReader.java

protected void addAllCharacters(String s, ContentHandler handler) throws SAXException {
    if (s == null) {
        return;/*from w  ww. jav  a  2s  .  c  o m*/
    }
    char[] chars = s.toCharArray();
    handler.characters(chars, 0, chars.length);
}

From source file:org.exist.cocoon.XMLDBSource.java

private void queryToSAX(ContentHandler handler, Collection collection, String resource)
        throws SAXException, XMLDBException {

    AttributesImpl attributes = new AttributesImpl();

    XPathQueryService service = (XPathQueryService) collection.getService("XPathQueryService", "1.0");
    ResourceSet resultSet = (resource == null) ? service.query(query) : service.queryResource(resource, query);

    attributes.addAttribute("", QUERY_ATTR, QUERY_ATTR, "CDATA", query);
    attributes.addAttribute("", RESULTS_COUNT_ATTR, RESULTS_COUNT_ATTR, "CDATA",
            Long.toString(resultSet.getSize()));

    handler.startDocument();/*w w  w.  j  av a2s  . co m*/
    handler.startPrefixMapping(PREFIX, URI);
    handler.startElement(URI, RESULTSET, QRESULTSET, attributes);

    IncludeXMLConsumer includeHandler = new IncludeXMLConsumer(handler);

    // Print search results
    ResourceIterator results = resultSet.getIterator();
    while (results.hasMoreResources()) {
        XMLResource result = (XMLResource) results.nextResource();

        final String id = result.getId();
        final String documentId = result.getDocumentId();

        attributes.clear();
        if (id != null) {
            attributes.addAttribute("", RESULT_ID_ATTR, RESULT_ID_ATTR, CDATA, id);
        }
        if (documentId != null) {
            attributes.addAttribute("", RESULT_DOCID_ATTR, RESULT_DOCID_ATTR, CDATA, documentId);
        }

        handler.startElement(URI, RESULT, QRESULT, attributes);
        try {
            result.getContentAsSAX(includeHandler);
        } catch (XMLDBException xde) {
            // That may be a text-only result
            Object content = result.getContent();
            if (content instanceof String) {
                String text = (String) content;
                handler.characters(text.toCharArray(), 0, text.length());
            } else {
                // Cannot do better
                throw xde;
            }
        }
        handler.endElement(URI, RESULT, QRESULT);
    }

    handler.endElement(URI, RESULTSET, QRESULTSET);
    handler.endPrefixMapping(PREFIX);
    handler.endDocument();
}

From source file:org.geoserver.wps.BinaryEncoderDelegate.java

public void encode(ContentHandler output) throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ppio.encode(object, bos);/*from ww  w.j  a va  2s  . c  o  m*/

    char[] chars = new String(Base64.encodeBase64(bos.toByteArray())).toCharArray();
    output.characters(chars, 0, chars.length);
}

From source file:org.geoserver.wps.RawDataEncoderDelegate.java

public void encode(ContentHandler output) throws Exception {
    InputStream is = null;// w w w.j a va  2s. c  o m
    try {
        is = rawData.getInputStream();
        byte[] buffer = new byte[4096];
        int read = 0;
        while ((read = is.read(buffer)) > 0) {
            char[] chars;
            if (read == 4096) {
                chars = new String(Base64.encodeBase64(buffer)).toCharArray();
            } else {
                byte[] reducedBuffer = new byte[read];
                System.arraycopy(buffer, 0, reducedBuffer, 0, read);
                chars = new String(Base64.encodeBase64(reducedBuffer)).toCharArray();
            }

            output.characters(chars, 0, chars.length);
        }
    } finally {
        IOUtils.closeQuietly(is);
    }
}