Example usage for org.xml.sax.helpers AttributesImpl clear

List of usage examples for org.xml.sax.helpers AttributesImpl clear

Introduction

In this page you can find the example usage for org.xml.sax.helpers AttributesImpl clear.

Prototype

public void clear() 

Source Link

Document

Clear the attribute list for reuse.

Usage

From source file:org.apache.cocoon.generation.HttpProxyGenerator.java

/**
 * Generate debugging output as XML data from the current configuration.
 *
 * @throws SAXException If an error occurred parsing or processing XML in the pipeline.
 * @throws IOException If an I/O error occurred accessing the HTTP server.
 *//*  ww  w  .  ja va 2 s.c  o m*/
private void generateDebugOutput() throws SAXException, IOException {
    super.xmlConsumer.startDocument();

    AttributesImpl attributes = new AttributesImpl();
    attributes.addAttribute("", "method", "method", "CDATA", this.method.getName());
    attributes.addAttribute("", "url", "url", "CDATA", this.method.getURI().toString());
    attributes.addAttribute("", "protocol", "protocol", "CDATA",
            (this.method.isHttp11() ? "HTTP/1.1" : "HTTP/1.0"));
    super.xmlConsumer.startElement("", "request", "request", attributes);

    if (this.method instanceof PostMethod) {
        String body = ((PostMethod) this.method).getRequestBodyAsString();

        attributes.clear();
        attributes.addAttribute("", "name", "name", "CDATA", "Content-Type");
        attributes.addAttribute("", "value", "value", "CDATA", "application/x-www-form-urlencoded");
        super.xmlConsumer.startElement("", "header", "header", attributes);
        super.xmlConsumer.endElement("", "header", "header");

        attributes.clear();
        attributes.addAttribute("", "name", "name", "CDATA", "Content-Length");
        attributes.addAttribute("", "value", "value", "CDATA", Integer.toString(body.length()));
        super.xmlConsumer.startElement("", "header", "header", attributes);
        super.xmlConsumer.endElement("", "header", "header");

        attributes.clear();
        super.xmlConsumer.startElement("", "body", "body", attributes);
        super.xmlConsumer.characters(body.toCharArray(), 0, body.length());
        super.xmlConsumer.endElement("", "body", "body");
    }

    super.xmlConsumer.endElement("", "request", "request");

    super.xmlConsumer.endDocument();
    return;
}

From source file:org.apache.cocoon.transformation.LDAPTransformer.java

protected void start(String name, AttributesImpl attr) throws SAXException {
    super.contentHandler.startElement("", name, name, attr);
    attr.clear();
}

From source file:org.apache.cocoon.transformation.SethTransformer.java

private void start(String name, AttributesImpl attr) throws SAXException {
    super.contentHandler.startElement("", name, name, attr);
    attr.clear();
}

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

private void startViewport(String transform, Dimension size, Rectangle clipRect) throws IFException {
    try {/*from   w ww.ja  v  a2s  . c  o  m*/
        establish(MODE_NORMAL);
        AttributesImpl atts = new AttributesImpl();
        if (transform != null && transform.length() > 0) {
            XMLUtil.addAttribute(atts, "transform", transform);
        }
        handler.startElement("g", atts);

        atts.clear();
        XMLUtil.addAttribute(atts, "width", SVGUtil.formatMptToPt(size.width));
        XMLUtil.addAttribute(atts, "height", SVGUtil.formatMptToPt(size.height));
        if (clipRect != null) {
            int[] v = new int[] { clipRect.y, -clipRect.x + size.width - clipRect.width,
                    -clipRect.y + size.height - clipRect.height, clipRect.x };
            int sum = 0;
            for (int i = 0; i < 4; i++) {
                sum += Math.abs(v[i]);
            }
            if (sum != 0) {
                StringBuffer sb = new StringBuffer("rect(");
                sb.append(SVGUtil.formatMptToPt(v[0])).append(',');
                sb.append(SVGUtil.formatMptToPt(v[1])).append(',');
                sb.append(SVGUtil.formatMptToPt(v[2])).append(',');
                sb.append(SVGUtil.formatMptToPt(v[3])).append(')');
                XMLUtil.addAttribute(atts, "clip", sb.toString());
            }
            XMLUtil.addAttribute(atts, "overflow", "hidden");
        } else {
            XMLUtil.addAttribute(atts, "overflow", "visible");
        }
        handler.startElement("svg", atts);
    } catch (SAXException e) {
        throw new IFException("SAX error in startBox()", e);
    }
}

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();
        if (StringUtils.isNotBlank(auditEntry.getWho())) {
            atts.addAttribute("", "", "who", ReportXMLConst.XSD_STRING, auditEntry.getWho());
        }//from   ww  w .j av a2s  .c  o  m
        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  .ja v  a 2  s .  c o m
        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");
    }
}

From source file:org.apache.syncope.core.logic.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 = anyTO.getPlainAttrMap();

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

            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");
                }//  www  .j  a  v a2  s  .c om
            } 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 = anyTO.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, anyTO.getClass().getSimpleName(),
                        anyTO.getKey());
            }

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

    if (!virAttrs.isEmpty()) {
        Map<String, AttrTO> virAttrMap = anyTO.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, anyTO.getClass().getSimpleName(),
                        anyTO.getKey());
            }

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

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

private void doExtract(final ContentHandler handler, final List<Group> groups) throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    for (Group group : groups) {
        atts.clear();

        for (Feature feature : conf.getFeatures()) {
            String type = null;//from  w  w w  . j  a  v a  2  s  . co  m
            String value = null;
            switch (feature) {
            case key:
                type = ReportXMLConst.XSD_STRING;
                value = group.getKey();
                break;

            case name:
                type = ReportXMLConst.XSD_STRING;
                value = String.valueOf(group.getName());
                break;

            case groupOwner:
                type = ReportXMLConst.XSD_STRING;
                value = group.getGroupOwner().getKey();
                break;

            case userOwner:
                type = ReportXMLConst.XSD_STRING;
                value = group.getUserOwner().getKey();
                break;

            default:
            }

            if (type != null && value != null) {
                atts.addAttribute("", "", feature.name(), type, value);
            }
        }

        handler.startElement("", "", "group", atts);

        // Using GroupTO for attribute values, since the conversion logic of
        // values to String is already encapsulated there
        GroupTO groupTO = groupDataBinder.getGroupTO(group, true);

        doExtractAttributes(handler, groupTO, conf.getPlainAttrs(), conf.getDerAttrs(), conf.getVirAttrs());

        // to get resources associated to a group
        if (conf.getFeatures().contains(Feature.resources)) {
            doExtractResources(handler, groupTO);
        }
        //to get users asscoiated to a group is preferred GroupDAO to GroupTO
        if (conf.getFeatures().contains(Feature.users)) {
            handler.startElement("", "", "users", null);

            for (UMembership memb : groupDAO.findUMemberships(group)) {
                atts.clear();

                atts.addAttribute("", "", "key", ReportXMLConst.XSD_STRING, memb.getLeftEnd().getKey());
                atts.addAttribute("", "", "username", ReportXMLConst.XSD_STRING,
                        String.valueOf(memb.getLeftEnd().getUsername()));

                handler.startElement("", "", "user", atts);
                handler.endElement("", "", "user");
            }

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

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

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

private void doExtractConf(final ContentHandler handler) throws SAXException {
    if (conf == null) {
        LOG.debug("Report configuration is not present");
    }/*w  w w .  j  av  a 2s. com*/

    AttributesImpl atts = new AttributesImpl();
    handler.startElement("", "", "configurations", null);
    handler.startElement("", "", "groupAttributes", 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("", "", "groupAttributes");
    handler.endElement("", "", "configurations");
}

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

private void doExtract(final ContentHandler handler, final Any<?> any, final Set<Missing> missing,
        final Set<Misaligned> misaligned) throws SAXException {

    AttributesImpl atts = new AttributesImpl();

    for (Feature feature : conf.getFeatures()) {
        String type = null;/*from www .  j  a  v a2s.  c o  m*/
        String value = null;
        switch (feature) {
        case key:
            type = ReportXMLConst.XSD_STRING;
            value = any.getKey();
            break;

        case username:
            if (any instanceof User) {
                type = ReportXMLConst.XSD_STRING;
                value = User.class.cast(any).getUsername();
            }
            break;

        case groupName:
            if (any instanceof Group) {
                type = ReportXMLConst.XSD_STRING;
                value = Group.class.cast(any).getName();
            }
            break;

        case workflowId:
            type = ReportXMLConst.XSD_STRING;
            value = any.getWorkflowId();
            break;

        case status:
            type = ReportXMLConst.XSD_STRING;
            value = any.getStatus();
            break;

        case creationDate:
            type = ReportXMLConst.XSD_DATETIME;
            value = any.getCreationDate() == null ? StringUtils.EMPTY
                    : FormatUtils.format(any.getCreationDate());
            break;

        case lastLoginDate:
            if (any instanceof User) {
                type = ReportXMLConst.XSD_DATETIME;
                value = User.class.cast(any).getLastLoginDate() == null ? StringUtils.EMPTY
                        : FormatUtils.format(User.class.cast(any).getLastLoginDate());
            }
            break;

        case changePwdDate:
            if (any instanceof User) {
                type = ReportXMLConst.XSD_DATETIME;
                value = User.class.cast(any).getChangePwdDate() == null ? StringUtils.EMPTY
                        : FormatUtils.format(User.class.cast(any).getChangePwdDate());
            }
            break;

        case passwordHistorySize:
            if (any instanceof User) {
                type = ReportXMLConst.XSD_INT;
                value = String.valueOf(User.class.cast(any).getPasswordHistory().size());
            }
            break;

        case failedLoginCount:
            if (any instanceof User) {
                type = ReportXMLConst.XSD_INT;
                value = String.valueOf(User.class.cast(any).getFailedLogins());
            }
            break;

        default:
        }

        if (type != null && value != null) {
            atts.addAttribute("", "", feature.name(), type, value);
        }
    }

    handler.startElement("", "", getAnyElementName(any.getType().getKind()), atts);

    for (Missing item : missing) {
        atts.clear();
        atts.addAttribute("", "", "resource", ReportXMLConst.XSD_STRING, item.getResource());
        atts.addAttribute("", "", "connObjectKeyValue", ReportXMLConst.XSD_STRING,
                item.getConnObjectKeyValue());

        handler.startElement("", "", "missing", atts);
        handler.endElement("", "", "missing");
    }
    for (Misaligned item : misaligned) {
        atts.clear();
        atts.addAttribute("", "", "resource", ReportXMLConst.XSD_STRING, item.getResource());
        atts.addAttribute("", "", "connObjectKeyValue", ReportXMLConst.XSD_STRING,
                item.getConnObjectKeyValue());
        atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, item.getName());

        handler.startElement("", "", "misaligned", atts);

        handler.startElement("", "", "onSyncope", null);
        if (item.getOnSyncope() != null) {
            for (Object value : item.getOnSyncope()) {
                char[] asChars = value.toString().toCharArray();

                handler.startElement("", "", "value", null);
                handler.characters(asChars, 0, asChars.length);
                handler.endElement("", "", "value");
            }
        }
        handler.endElement("", "", "onSyncope");

        handler.startElement("", "", "onResource", null);
        if (item.getOnResource() != null) {
            for (Object value : item.getOnResource()) {
                char[] asChars = value.toString().toCharArray();

                handler.startElement("", "", "value", null);
                handler.characters(asChars, 0, asChars.length);
                handler.endElement("", "", "value");
            }
        }
        handler.endElement("", "", "onResource");

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

    handler.endElement("", "", getAnyElementName(any.getType().getKind()));
}