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

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

Introduction

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

Prototype

public AttributesImpl() 

Source Link

Document

Construct a new, empty AttributesImpl object.

Usage

From source file:net.tirasa.hct.cocoon.sax.HippoItemXMLDumper.java

public void dumpImages(final List<HippoGalleryImageSet> images, final String elementName, final boolean wrap)
        throws SAXException, ObjectBeanManagerException {

    if (wrap) {//  ww w  . j av  a  2 s.c  om
        saxConsumer.startElement(NS_HCT, Element.IMAGES.getName(), PREFIX_HCT + ":" + Element.IMAGES.getName(),
                EMPTY_ATTRS);
    }

    for (HippoGalleryImageSet img : images) {
        final AttributesImpl attrs = new AttributesImpl();
        attrs.addAttribute(NS_EMPTY, Attribute.PATH.getName(), Attribute.PATH.getName(), XSD_STRING,
                img.getPath());
        attrs.addAttribute(NS_EMPTY, Attribute.NAME.getName(), Attribute.NAME.getName(), XSD_STRING,
                img.getName());
        if (StringUtils.isNotBlank(img.getDescription())) {
            attrs.addAttribute(NS_EMPTY, Attribute.DESC.getName(), Attribute.DESC.getName(), XSD_STRING,
                    img.getDescription());
        }
        attrs.addAttribute(NS_EMPTY, Attribute.HEIGHT.getName(), Attribute.HEIGHT.getName(), XSD_INT,
                String.valueOf(img.getOriginal().getHeight()));
        attrs.addAttribute(NS_EMPTY, Attribute.WIDTH.getName(), Attribute.WIDTH.getName(), XSD_INT,
                String.valueOf(img.getOriginal().getWidth()));

        saxConsumer.startElement(NS_HCT, elementName, PREFIX_HCT + ":" + elementName, attrs);
        saxConsumer.endElement(NS_HCT, elementName, PREFIX_HCT + ":" + elementName);
    }

    if (wrap) {
        saxConsumer.endElement(NS_HCT, Element.IMAGES.getName(), PREFIX_HCT + ":" + Element.IMAGES.getName());
    }
}

From source file:net.tirasa.hct.cocoon.sax.HippoItemXMLDumper.java

public void dumpRelatedDocs(final List<HippoDocument> relDocs, final String elementName, final boolean wrap)
        throws SAXException, ObjectBeanManagerException {

    if (wrap) {//from ww  w .j ava  2 s .c om
        saxConsumer.startElement(NS_HCT, Element.RELATED_DOCS.getName(),
                PREFIX_HCT + ":" + Element.RELATED_DOCS.getName(), EMPTY_ATTRS);
    }

    AttributesImpl attrs;
    for (HippoDocument relDoc : relDocs) {
        attrs = new AttributesImpl();
        attrs.addAttribute(NS_EMPTY, Attribute.NAME.getName(), Attribute.NAME.getName(), XSD_STRING,
                relDoc.getName());
        attrs.addAttribute(NS_EMPTY, Attribute.PATH.getName(), Attribute.PATH.getName(), XSD_STRING,
                relDoc.getPath());
        attrs.addAttribute(NS_EMPTY, Attribute.LOC_NAME.getName(), Attribute.LOC_NAME.getName(), XSD_STRING,
                relDoc.getLocalizedName());
        attrs.addAttribute(NS_EMPTY, Attribute.LOCALE.getName(), Attribute.LOCALE.getName(), XSD_STRING,
                relDoc.getLocalizedName());

        saxConsumer.startElement(NS_HCT, elementName, PREFIX_HCT + ":" + elementName, attrs);
        saxConsumer.endElement(NS_HCT, elementName, PREFIX_HCT + ":" + elementName);
    }

    if (wrap) {
        saxConsumer.endElement(NS_HCT, Element.RELATED_DOCS.getName(),
                PREFIX_HCT + ":" + Element.RELATED_DOCS.getName());
    }
}

From source file:net.tirasa.hct.cocoon.sax.HippoItemXMLDumper.java

public void dumpTags(final TagCollection tags) throws SAXException {
    saxConsumer.startElement(NS_HCT, Element.TAGS.getName(), PREFIX_HCT + ":" + Element.TAGS.getName(),
            EMPTY_ATTRS);/*from   w ww  .j av  a  2 s .co  m*/

    for (Tag tag : tags.values()) {
        final AttributesImpl attrs = new AttributesImpl();
        attrs.addAttribute(NS_EMPTY, Attribute.SCORE.getName(), Attribute.SCORE.getName(), XSD_DOUBLE,
                String.valueOf(tag.getScore()));

        saxConsumer.startElement(NS_HCT, Element.TAG.getName(), PREFIX_HCT + ":" + Element.TAG.getName(),
                attrs);
        saxConsumer.characters(tag.getName().toCharArray(), 0, tag.getName().length());
        saxConsumer.endElement(NS_HCT, Element.TAG.getName(), PREFIX_HCT + ":" + Element.TAG.getName());
    }

    saxConsumer.endElement(NS_HCT, Element.TAGS.getName(), PREFIX_HCT + ":" + Element.TAGS.getName());
}

From source file:net.tirasa.hct.cocoon.sax.HippoItemXMLDumper.java

public void startTaxonomy(final HCTTaxonomyCategoryBean taxonomy, final Locale locale) throws SAXException {
    final AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute(NS_EMPTY, Attribute.NAME.getName(), Attribute.NAME.getName(), XSD_STRING,
            taxonomy.getKey());//  w  ww  . j a  va 2  s  .co m
    attrs.addAttribute(NS_EMPTY, Attribute.LOC_NAME.getName(), Attribute.LOC_NAME.getName(), XSD_STRING,
            taxonomy.getLocalizedName(locale.getLanguage()));
    attrs.addAttribute(NS_EMPTY, Attribute.ORDER.getName(), Attribute.ORDER.getName(), XSD_STRING,
            taxonomy.getOrder(locale.getLanguage()));
    attrs.addAttribute(NS_EMPTY, Attribute.PATH.getName(), Attribute.PATH.getName(), XSD_STRING,
            taxonomy.getPath());

    saxConsumer.startElement(NS_HCT, Element.TAXONOMY.getName(), PREFIX_HCT + ":" + Element.TAXONOMY.getName(),
            attrs);
}

From source file:net.tirasa.hct.cocoon.sax.HippoItemXMLDumper.java

public void dumpField(final Entry<String, Object> entry, final String dateFormat, final Locale locale)
        throws SAXException {

    final AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute(NS_EMPTY, Attribute.NAME.getName(), Attribute.NAME.getName(), XSD_STRING,
            entry.getKey());/* w  w  w . jav  a  2s  . c  o  m*/
    saxConsumer.startElement(NS_HCT, Element.FIELD.getName(), PREFIX_HCT + ":" + Element.FIELD.getName(),
            attrs);

    if (entry.getValue() instanceof String) {
        saxConsumer.startElement(NS_HCT, Element.VALUE.getName(), PREFIX_HCT + ":" + Element.VALUE.getName(),
                EMPTY_ATTRS);
        saxConsumer.characters(((String) entry.getValue()).toCharArray(), 0,
                ((String) entry.getValue()).length());
        saxConsumer.endElement(NS_HCT, Element.VALUE.getName(), PREFIX_HCT + ":" + Element.VALUE.getName());
    } else if (entry.getValue() instanceof Boolean) {
        saxConsumer.startElement(NS_HCT, Element.VALUE.getName(), PREFIX_HCT + ":" + Element.VALUE.getName(),
                EMPTY_ATTRS);
        saxConsumer.characters(((Boolean) entry.getValue()).toString().toCharArray(), 0,
                ((Boolean) entry.getValue()).toString().length());
        saxConsumer.endElement(NS_HCT, Element.VALUE.getName(), PREFIX_HCT + ":" + Element.VALUE.getName());
    } else if (entry.getValue() instanceof GregorianCalendar) {
        final SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, locale);
        final String date = sdf.format(((GregorianCalendar) entry.getValue()).getTime());

        saxConsumer.startElement(NS_HCT, Element.VALUE.getName(), PREFIX_HCT + ":" + Element.VALUE.getName(),
                EMPTY_ATTRS);
        saxConsumer.characters(date.toCharArray(), 0, date.length());
        saxConsumer.endElement(NS_HCT, Element.VALUE.getName(), PREFIX_HCT + ":" + Element.VALUE.getName());
    } else if (entry.getValue() instanceof String[]) {
        for (int i = 0; i < ((String[]) entry.getValue()).length; i++) {
            saxConsumer.startElement(NS_HCT, Element.VALUE.getName(),
                    PREFIX_HCT + ":" + Element.VALUE.getName(), EMPTY_ATTRS);
            saxConsumer.characters(((String[]) entry.getValue())[i].toCharArray(), 0,
                    ((String[]) entry.getValue())[i].length());
            saxConsumer.endElement(NS_HCT, Element.VALUE.getName(), PREFIX_HCT + ":" + Element.VALUE.getName());
        }
    }

    saxConsumer.endElement(NS_HCT, Element.FIELD.getName(), PREFIX_HCT + ":" + Element.FIELD.getName());
}

From source file:net.tirasa.hct.cocoon.sax.HippoItemXMLDumper.java

public void dumpHtml(final HCTConnManager connManager, final HippoHtml rtf, final XMLReader xmlReader,
        final String dateFormat, final Locale locale)
        throws SAXException, IOException, ObjectBeanManagerException {

    final AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute(NS_EMPTY, Attribute.NAME.getName(), Attribute.NAME.getName(), XSD_STRING, rtf.getName());
    saxConsumer.startElement(NS_HCT, Element.FIELD.getName(), PREFIX_HCT + ":" + Element.FIELD.getName(),
            attrs);/*from   ww w . j  a va  2 s .c o m*/

    xmlReader.parse(new InputSource(new StringReader(rtf.getContent())));

    final List<HippoGalleryImageSet> images = new ArrayList<HippoGalleryImageSet>();
    final List<HippoAsset> assets = new ArrayList<HippoAsset>();
    final List<HippoDocument> docs = new ArrayList<HippoDocument>();
    for (HippoFacetSelect facetSelect : rtf.getChildBeans(HippoFacetSelect.class)) {
        final HippoItem subElement = ObjectUtils.getHippoItemByUuid(connManager,
                (String) facetSelect.getProperty(HippoNodeType.HIPPO_DOCBASE));
        if (subElement instanceof HippoGalleryImageSet) {
            images.add((HippoGalleryImageSet) subElement);
        }
        if (subElement instanceof HippoAsset) {
            assets.add((HippoAsset) subElement);
        } else if (subElement instanceof HippoDocument) {
            docs.add((HippoDocument) subElement);
        }
    }
    saxConsumer.startElement(NS_HCT, Element.LINKS.getName(), PREFIX_HCT + ":" + Element.LINKS.getName(),
            EMPTY_ATTRS);
    dumpImages(images, Element.LINK.getName(), false);
    dumpAssets(assets, Element.LINK.getName(), false, dateFormat, locale);
    dumpRelatedDocs(docs, Element.LINK.getName(), false);
    saxConsumer.endElement(NS_HCT, Element.LINKS.getName(), PREFIX_HCT + ":" + Element.LINKS.getName());

    saxConsumer.endElement(NS_HCT, Element.FIELD.getName(), PREFIX_HCT + ":" + Element.FIELD.getName());
}

From source file:nl.nn.adapterframework.align.ToXml.java

public void handleElement(XSElementDeclaration elementDeclaration, N node) throws SAXException {
    String name = elementDeclaration.getName();
    String elementNamespace = elementDeclaration.getNamespace();
    String qname = getQName(elementNamespace, name);
    if (DEBUG)//from   www .  j a  v  a2 s . c o  m
        log.debug("handleNode() name [" + name + "] elementNamespace [" + elementNamespace + "]");
    newLine();
    AttributesImpl attributes = new AttributesImpl();
    Map<String, String> nodeAttributes = getAttributes(elementDeclaration, node);
    if (DEBUG)
        log.debug("node [" + name + "] search for attributeDeclaration");
    XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
    XSObjectList attributeUses = getAttributeUses(typeDefinition);
    if (attributeUses == null || attributeUses.getLength() == 0) {
        if (nodeAttributes != null && nodeAttributes.size() > 0) {
            log.warn("node [" + name + "] found [" + nodeAttributes.size()
                    + "] attributes, but no declared AttributeUses");
        } else {
            if (DEBUG)
                log.debug("node [" + name + "] no attributeUses, no attributes");
        }
    } else {
        if (nodeAttributes == null || nodeAttributes.isEmpty()) {
            log.warn("node [" + name + "] declared [" + attributeUses.getLength()
                    + "] attributes, but no attributes found");
        } else {
            for (int i = 0; i < attributeUses.getLength(); i++) {
                XSAttributeUse attributeUse = (XSAttributeUse) attributeUses.item(i);
                //if (DEBUG) log.debug("startElement ["+localName+"] attributeUse ["+ToStringBuilder.reflectionToString(attributeUse)+"]");
                XSAttributeDeclaration attributeDeclaration = attributeUse.getAttrDeclaration();
                if (DEBUG)
                    log.debug("node [" + name + "] attributeDeclaration ["
                            + ToStringBuilder.reflectionToString(attributeDeclaration) + "]");
                XSSimpleTypeDefinition attTypeDefinition = attributeDeclaration.getTypeDefinition();
                if (DEBUG)
                    log.debug("node [" + name + "] attTypeDefinition ["
                            + ToStringBuilder.reflectionToString(attTypeDefinition) + "]");
                String attName = attributeDeclaration.getName();
                if (nodeAttributes.containsKey(attName)) {
                    String value = nodeAttributes.remove(attName);
                    String uri = attributeDeclaration.getNamespace();
                    String attqname = getQName(uri, attName);
                    String type = null;
                    if (DEBUG)
                        log.debug(
                                "node [" + name + "] adding attribute [" + attName + "] value [" + value + "]");
                    attributes.addAttribute(uri, attName, attqname, type, value);
                }
            }
        }
    }
    if (isNil(elementDeclaration, node)) {
        validatorHandler.startPrefixMapping(XSI_PREFIX_MAPPING, XML_SCHEMA_INSTANCE_NAMESPACE);
        attributes.addAttribute(XML_SCHEMA_INSTANCE_NAMESPACE, XML_SCHEMA_NIL_ATTRIBUTE,
                XSI_PREFIX_MAPPING + ":" + XML_SCHEMA_NIL_ATTRIBUTE, "xs:boolean", "true");
        validatorHandler.startElement(elementNamespace, name, qname, attributes);
        validatorHandler.endElement(elementNamespace, name, qname);
        validatorHandler.endPrefixMapping(XSI_PREFIX_MAPPING);
    } else {
        validatorHandler.startElement(elementNamespace, name, qname, attributes);
        handleElementContents(elementDeclaration, node);
        validatorHandler.endElement(elementNamespace, name, qname);
    }
    //      if (createdPrefix!=null) {
    //         validatorHandler.endPrefixMapping(createdPrefix);
    //      }
}

From source file:org.alfresco.repo.content.transform.EMLParser.java

/**
 * Adapted extract multipart is the recusrsive parser that splits the data and apend it to the
 * final xhtml file./*from   ww w .j  av a 2 s . c  o m*/
 *
 * @param xhtml
 *            the xhtml
 * @param part
 *            the part
 * @param parentPart
 *            the parent part
 * @param context
 *            the context
 * @throws MessagingException
 *             the messaging exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws SAXException
 *             the sAX exception
 * @throws TikaException
 *             the tika exception
 */
public void adaptedExtractMultipart(XHTMLContentHandler xhtml, Part part, Part parentPart, ParseContext context)
        throws MessagingException, IOException, SAXException, TikaException {

    String disposition = part.getDisposition();
    if ((disposition != null && disposition.contains(Part.ATTACHMENT))) {
        return;
    }

    if (part.isMimeType("text/plain")) {
        if (parentPart != null && parentPart.isMimeType(MULTIPART_ALTERNATIVE)) {
            return;
        } else {
            // add file
            String data = part.getContent().toString();
            writeContent(part, data, MimetypeMap.MIMETYPE_TEXT_PLAIN, "txt");
        }
    } else if (part.isMimeType("multipart/*")) {
        Multipart mp = (Multipart) part.getContent();
        Part parentPartLocal = part;
        if (parentPart != null && parentPart.isMimeType(MULTIPART_ALTERNATIVE)) {
            parentPartLocal = parentPart;
        }
        int count = mp.getCount();
        for (int i = 0; i < count; i++) {
            adaptedExtractMultipart(xhtml, mp.getBodyPart(i), parentPartLocal, context);
        }
    } else if (part.isMimeType("message/rfc822")) {
        adaptedExtractMultipart(xhtml, (Part) part.getContent(), part, context);
    } else if (part.isMimeType("text/html")) {

        if ((parentPart != null && parentPart.isMimeType(MULTIPART_ALTERNATIVE))
                || (part.getDisposition() == null || !part.getDisposition().contains(Part.ATTACHMENT))) {
            Object data = part.getContent();
            String htmlFileData = prepareString(new String(data.toString()));
            writeContent(part, htmlFileData, MimetypeMap.MIMETYPE_HTML, "html");
        }

    } else if (part.isMimeType("image/*")) {

        String[] encoded = part.getHeader("Content-Transfer-Encoding");
        if (isContained(encoded, "base64")) {
            if (part.getDisposition() != null && part.getDisposition().contains(Part.ATTACHMENT)) {
                InputStream stream = part.getInputStream();
                byte[] binaryData = new byte[part.getSize()];
                stream.read(binaryData, 0, part.getSize());
                String encodedData = new String(Base64.encodeBase64(binaryData));
                String[] split = part.getContentType().split(";");
                String src = "data:" + split[0].trim() + ";base64," + encodedData;
                AttributesImpl attributes = new AttributesImpl();
                attributes.addAttribute(null, "src", "src", "String", src);
                xhtml.startElement("img", attributes);
                xhtml.endElement("img");
            }
        }

    } else {
        Object content = part.getContent();
        if (content instanceof String) {
            xhtml.element("div", prepareString(part.getContent().toString()));
        } else if (content instanceof InputStream) {
            InputStream fileContent = part.getInputStream();

            Parser parser = new AutoDetectParser();
            Metadata attachmentMetadata = new Metadata();

            BodyContentHandler handlerAttachments = new BodyContentHandler();
            parser.parse(fileContent, handlerAttachments, attachmentMetadata, context);

            xhtml.element("div", handlerAttachments.toString());

        }
    }
}

From source file:org.alfresco.repo.exporter.ViewXMLExporter.java

public void startNode(NodeRef nodeRef) {
    try {/*from ww  w  . jav  a  2 s  . co  m*/
        AttributesImpl attrs = new AttributesImpl();

        Path path = nodeService.getPath(nodeRef);
        if (path.size() > 1) {
            // a child name does not exist for root
            Path.ChildAssocElement pathElement = (Path.ChildAssocElement) path.last();
            QName childQName = pathElement.getRef().getQName();
            attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, CHILDNAME_LOCALNAME,
                    CHILDNAME_QNAME.toPrefixString(), null, toPrefixString(childQName));
        }

        QName type = nodeService.getType(nodeRef);
        contentHandler.startElement(type.getNamespaceURI(), type.getLocalName(), toPrefixString(type), attrs);
    } catch (SAXException e) {
        throw new ExporterException("Failed to process start node event - node ref " + nodeRef.toString(), e);
    }
}

From source file:org.alfresco.repo.exporter.ViewXMLExporter.java

public void startACL(NodeRef nodeRef) {
    try {//from  w w  w  .  ja v a 2s.  c  om
        AttributesImpl attrs = new AttributesImpl();
        boolean inherit = permissionService.getInheritParentPermissions(nodeRef);
        if (!inherit) {
            attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, INHERITPERMISSIONS_LOCALNAME,
                    INHERITPERMISSIONS_QNAME.toPrefixString(), null, "false");
        }
        contentHandler.startElement(ACL_QNAME.getNamespaceURI(), ACL_QNAME.getLocalName(),
                toPrefixString(ACL_QNAME), attrs);
    } catch (SAXException e) {
        throw new ExporterException("Failed to process start ACL event - node ref " + nodeRef.toString());
    }
}