Example usage for org.xml.sax ContentHandler startElement

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

Introduction

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

Prototype

public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException;

Source Link

Document

Receive notification of the beginning of an element.

Usage

From source file:org.apache.fop.render.svg.SVGDataUrlImageHandler.java

/** {@inheritDoc} */
public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException {
    SVGRenderingContext svgContext = (SVGRenderingContext) context;
    ImageRawStream raw = (ImageRawStream) image;
    InputStream in = raw.createInputStream();
    try {/*from   ww w  . j a  v a2s  . c o m*/
        ContentHandler handler = svgContext.getContentHandler();
        String url = DataURLUtil.createDataURL(in, raw.getMimeType());
        AttributesImpl atts = new AttributesImpl();
        addAttribute(atts, IFConstants.XLINK_HREF, url);
        atts.addAttribute("", "x", "x", CDATA, Integer.toString(pos.x));
        atts.addAttribute("", "y", "y", CDATA, Integer.toString(pos.y));
        atts.addAttribute("", "width", "width", CDATA, Integer.toString(pos.width));
        atts.addAttribute("", "height", "height", CDATA, Integer.toString(pos.height));
        try {
            handler.startElement(NAMESPACE, "image", "image", atts);
            handler.endElement(NAMESPACE, "image", "image");
        } catch (SAXException e) {
            throw new IOException(e.getMessage());
        }
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.java

public void outputToXml(ContentHandler contentHandler) throws SAXException {
    contentHandler.startElement("", "", "RECORD", new AttributesImpl());
    XMLUtils.addSaxString(contentHandler, "OPCODE", opCode.toString());
    contentHandler.startElement("", "", "DATA", new AttributesImpl());
    XMLUtils.addSaxString(contentHandler, "TXID", "" + txid);
    toXml(contentHandler);/*from   ww  w . j  a v a 2 s .  c o  m*/
    contentHandler.endElement("", "", "DATA");
    contentHandler.endElement("", "", "RECORD");
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.java

public static void blockToXml(ContentHandler contentHandler, Block block) throws SAXException {
    contentHandler.startElement("", "", "BLOCK", new AttributesImpl());
    XMLUtils.addSaxString(contentHandler, "BLOCK_ID", Long.toString(block.getBlockId()));
    XMLUtils.addSaxString(contentHandler, "NUM_BYTES", Long.toString(block.getNumBytes()));
    XMLUtils.addSaxString(contentHandler, "GENSTAMP", Long.toString(block.getGenerationStamp()));
    contentHandler.endElement("", "", "BLOCK");
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.java

public static void delegationTokenToXml(ContentHandler contentHandler, DelegationTokenIdentifier token)
        throws SAXException {
    contentHandler.startElement("", "", "DELEGATION_TOKEN_IDENTIFIER", new AttributesImpl());
    XMLUtils.addSaxString(contentHandler, "KIND", token.getKind().toString());
    XMLUtils.addSaxString(contentHandler, "SEQUENCE_NUMBER", Integer.toString(token.getSequenceNumber()));
    XMLUtils.addSaxString(contentHandler, "OWNER", token.getOwner().toString());
    XMLUtils.addSaxString(contentHandler, "RENEWER", token.getRenewer().toString());
    XMLUtils.addSaxString(contentHandler, "REALUSER", token.getRealUser().toString());
    XMLUtils.addSaxString(contentHandler, "ISSUE_DATE", Long.toString(token.getIssueDate()));
    XMLUtils.addSaxString(contentHandler, "MAX_DATE", Long.toString(token.getMaxDate()));
    XMLUtils.addSaxString(contentHandler, "MASTER_KEY_ID", Integer.toString(token.getMasterKeyId()));
    contentHandler.endElement("", "", "DELEGATION_TOKEN_IDENTIFIER");
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.java

public static void delegationKeyToXml(ContentHandler contentHandler, DelegationKey key) throws SAXException {
    contentHandler.startElement("", "", "DELEGATION_KEY", new AttributesImpl());
    XMLUtils.addSaxString(contentHandler, "KEY_ID", Integer.toString(key.getKeyId()));
    XMLUtils.addSaxString(contentHandler, "EXPIRY_DATE", Long.toString(key.getExpiryDate()));
    if (key.getEncodedKey() != null) {
        XMLUtils.addSaxString(contentHandler, "KEY", Hex.encodeHexString(key.getEncodedKey()));
    }//w  w  w .  j a  v a 2 s  . com
    contentHandler.endElement("", "", "DELEGATION_KEY");
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.java

public static void permissionStatusToXml(ContentHandler contentHandler, PermissionStatus perm)
        throws SAXException {
    contentHandler.startElement("", "", "PERMISSION_STATUS", new AttributesImpl());
    XMLUtils.addSaxString(contentHandler, "USERNAME", perm.getUserName());
    XMLUtils.addSaxString(contentHandler, "GROUPNAME", perm.getGroupName());
    fsPermissionToXml(contentHandler, perm.getPermission());
    contentHandler.endElement("", "", "PERMISSION_STATUS");
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.java

private static void appendAclEntriesToXml(ContentHandler contentHandler, List<AclEntry> aclEntries)
        throws SAXException {
    for (AclEntry e : aclEntries) {
        contentHandler.startElement("", "", "ENTRY", new AttributesImpl());
        XMLUtils.addSaxString(contentHandler, "SCOPE", e.getScope().name());
        XMLUtils.addSaxString(contentHandler, "TYPE", e.getType().name());
        if (e.getName() != null) {
            XMLUtils.addSaxString(contentHandler, "NAME", e.getName());
        }// w ww .j  a va2  s .  c  om
        fsActionToXml(contentHandler, e.getPermission());
        contentHandler.endElement("", "", "ENTRY");
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.java

private static void appendXAttrsToXml(ContentHandler contentHandler, List<XAttr> xAttrs) throws SAXException {
    for (XAttr xAttr : xAttrs) {
        contentHandler.startElement("", "", "XATTR", new AttributesImpl());
        XMLUtils.addSaxString(contentHandler, "NAMESPACE", xAttr.getNameSpace().toString());
        XMLUtils.addSaxString(contentHandler, "NAME", xAttr.getName());
        if (xAttr.getValue() != null) {
            try {
                XMLUtils.addSaxString(contentHandler, "VALUE",
                        XAttrCodec.encodeValue(xAttr.getValue(), XAttrCodec.HEX));
            } catch (IOException e) {
                throw new SAXException(e);
            }//from  w  w  w  . ja  v  a2s  . c  o  m
        }
        contentHandler.endElement("", "", "XATTR");
    }
}

From source file:org.apache.syncope.core.logic.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();//  w ww.  j a v  a2 s.  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.MULTI_LINE_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.MULTI_LINE_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.MULTI_LINE_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.logic.report.GroupReportlet.java

private void doExtractResources(final ContentHandler handler, final AnyTO anyTO) throws SAXException {

    if (anyTO.getResources().isEmpty()) {
        LOG.debug("No resources found for {}[{}]", anyTO.getClass().getSimpleName(), anyTO.getKey());
    } else {//  w w w  . j  a v a  2s .  com
        AttributesImpl atts = new AttributesImpl();
        handler.startElement("", "", "resources", null);

        for (String resourceName : anyTO.getResources()) {
            atts.clear();

            atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, resourceName);
            handler.startElement("", "", "resource", atts);
            handler.endElement("", "", "resource");
        }

        handler.endElement("", "", "resources");
    }
}