Example usage for javax.xml.stream XMLStreamWriter writeStartElement

List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter writeStartElement.

Prototype

public void writeStartElement(String localName) throws XMLStreamException;

Source Link

Document

Writes a start tag to the output.

Usage

From source file:org.apache.nifi.authorization.StandardManagedAuthorizer.java

@Override
public String getFingerprint() throws AuthorizationAccessException {
    XMLStreamWriter writer = null;
    final StringWriter out = new StringWriter();
    try {/* w  w  w  .j a  v  a2 s  .  co m*/
        writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out);
        writer.writeStartDocument();
        writer.writeStartElement("managedAuthorizations");

        writer.writeStartElement(ACCESS_POLICY_PROVIDER_ELEMENT);
        if (accessPolicyProvider instanceof ConfigurableAccessPolicyProvider) {
            writer.writeCharacters(((ConfigurableAccessPolicyProvider) accessPolicyProvider).getFingerprint());
        }
        writer.writeEndElement();

        writer.writeStartElement(USER_GROUP_PROVIDER_ELEMENT);
        if (userGroupProvider instanceof ConfigurableUserGroupProvider) {
            writer.writeCharacters(((ConfigurableUserGroupProvider) userGroupProvider).getFingerprint());
        }
        writer.writeEndElement();

        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
    } catch (XMLStreamException e) {
        throw new AuthorizationAccessException("Unable to generate fingerprint", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (XMLStreamException e) {
                // nothing to do here
            }
        }
    }

    return out.toString();
}

From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java

private void startDocument(final XMLStreamWriter writer, final String rootElement) throws XMLStreamException {
    writer.writeStartDocument();//  w  w w. j  a  va  2  s.  c o  m
    writer.setDefaultNamespace(Constants.NS_ATOM);
    writer.writeStartElement(rootElement);

    namespaces(writer);
}

From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java

private void writeLink(final XMLStreamWriter writer, final Link link, final ExtraContent content)
        throws XMLStreamException, EdmPrimitiveTypeException {
    writer.writeStartElement(Constants.ATOM_ELEM_LINK);

    if (StringUtils.isNotBlank(link.getRel())) {
        writer.writeAttribute(Constants.ATTR_REL, link.getRel());
    }//w  w  w. ja v a 2 s . c  o  m
    if (StringUtils.isNotBlank(link.getTitle())) {
        writer.writeAttribute(Constants.ATTR_TITLE, link.getTitle());
    }
    if (StringUtils.isNotBlank(link.getHref())) {
        writer.writeAttribute(Constants.ATTR_HREF, link.getHref());
    }
    if (StringUtils.isNotBlank(link.getType())) {
        writer.writeAttribute(Constants.ATTR_TYPE, link.getType());
    }

    content.write(writer, link);

    for (Annotation annotation : link.getAnnotations()) {
        annotation(writer, annotation, null);
    }
    writer.writeEndElement();
}

From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java

private void common(final XMLStreamWriter writer, final AbstractODataObject object) throws XMLStreamException {
    if (StringUtils.isNotBlank(object.getTitle())) {
        writer.writeStartElement(Constants.ATOM_ELEM_TITLE);
        writer.writeAttribute(Constants.ATTR_TYPE, TYPE_TEXT);
        writer.writeCharacters(object.getTitle());
        writer.writeEndElement();//w  w w  .j a va  2 s.c o  m
    }
}

From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java

private void entity(final XMLStreamWriter writer, final Entity entity)
        throws XMLStreamException, EdmPrimitiveTypeException {
    if (entity.getBaseURI() != null) {
        writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE,
                entity.getBaseURI().toASCIIString());
    }/*from w  ww  .  j  a  v  a  2s .c o  m*/

    if (serverMode && StringUtils.isNotBlank(entity.getETag())) {
        writer.writeAttribute(namespaceMetadata, Constants.ATOM_ATTR_ETAG, entity.getETag());
    }

    if (entity.getId() != null) {
        writer.writeStartElement(Constants.ATOM_ELEM_ID);
        writer.writeCharacters(entity.getId().toASCIIString());
        writer.writeEndElement();
    }

    writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY);
    writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, Constants.NS_SCHEME);
    if (StringUtils.isNotBlank(entity.getType())) {
        writer.writeAttribute(Constants.ATOM_ATTR_TERM,
                new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external());
    }
    writer.writeEndElement();

    common(writer, entity);

    if (serverMode) {
        if (entity.getEditLink() != null) {
            links(writer, Collections.singletonList(entity.getEditLink()));
        }

        if (entity.getSelfLink() != null) {
            links(writer, Collections.singletonList(entity.getSelfLink()));
        }
    }

    links(writer, entity.getAssociationLinks());
    if (serverMode) {
        links(writer, entity.getNavigationLinks());
    } else {
        writeNavigationLinks(writer, entity.getNavigationLinks());
        writeNavigationLinks(writer, entity.getNavigationBindings());
    }
    links(writer, entity.getMediaEditLinks());

    if (serverMode) {
        for (Operation operation : entity.getOperations()) {
            writer.writeStartElement(namespaceMetadata, Constants.ATOM_ELEM_ACTION);
            writer.writeAttribute(Constants.ATTR_METADATA, operation.getMetadataAnchor());
            writer.writeAttribute(Constants.ATTR_TITLE, operation.getTitle());
            writer.writeAttribute(Constants.ATTR_TARGET, operation.getTarget().toASCIIString());
            writer.writeEndElement();
        }
    }

    writer.writeStartElement(Constants.ATOM_ELEM_CONTENT);
    if (entity.isMediaEntity()) {
        if (StringUtils.isNotBlank(entity.getMediaContentType())) {
            writer.writeAttribute(Constants.ATTR_TYPE, entity.getMediaContentType());
        }
        if (entity.getMediaContentSource() != null) {
            writer.writeAttribute(Constants.ATOM_ATTR_SRC, entity.getMediaContentSource().toASCIIString());
        }
        writer.writeEndElement();

        writer.writeStartElement(namespaceMetadata, Constants.PROPERTIES);
        properties(writer, entity.getProperties());
    } else {
        writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML.toContentTypeString());
        writer.writeStartElement(namespaceMetadata, Constants.PROPERTIES);
        properties(writer, entity.getProperties());
        writer.writeEndElement();
    }
    writer.writeEndElement();

    for (Annotation annotation : entity.getAnnotations()) {
        annotation(writer, annotation, null);
    }
}

From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java

private void entityRef(final XMLStreamWriter writer, final Entity entity) throws XMLStreamException {
    writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF);
    writer.writeDefaultNamespace(namespaceMetadata);
    writer.writeAttribute(Constants.ATOM_ATTR_ID, entity.getId().toASCIIString());
    writer.writeEndElement();// w w  w. j  av a2  s. c o  m
}

From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java

private void entityRef(final XMLStreamWriter writer, final ResWrap<Entity> container)
        throws XMLStreamException {
    writer.writeStartElement(Constants.ATOM_ELEM_ENTRY_REF);
    writer.writeDefaultNamespace(namespaceMetadata);
    addContextInfo(writer, container);/*  w w w.  j  ava  2 s.  c  om*/
    writer.writeAttribute(Constants.ATOM_ATTR_ID, container.getPayload().getId().toASCIIString());
}

From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java

private void link(final Writer outWriter, final Link link) throws XMLStreamException {
    final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);

    writer.writeStartDocument();//from  ww w.  j av a  2s.c o m

    writer.writeStartElement(Constants.ELEM_LINKS);
    writer.writeDefaultNamespace(namespaceData);

    writer.writeStartElement(Constants.ELEM_URI);
    writer.writeCharacters(link.getHref());
    writer.writeEndElement();

    writer.writeEndElement();

    writer.writeEndDocument();
    writer.flush();
}

From source file:org.apache.olingo.commons.core.data.AtomSerializer.java

private void startDocument(final XMLStreamWriter writer, final String rootElement) throws XMLStreamException {
    writer.writeStartDocument();//from w  w w .j a  va  2 s.  c o m
    writer.setDefaultNamespace(Constants.NS_ATOM);

    writer.writeStartElement(rootElement);

    namespaces(writer);
}

From source file:org.apache.olingo.commons.core.data.AtomSerializer.java

private void links(final XMLStreamWriter writer, final List<Link> links) throws XMLStreamException {
    for (Link link : links) {
        writer.writeStartElement(Constants.ATOM_ELEM_LINK);

        if (StringUtils.isNotBlank(link.getRel())) {
            writer.writeAttribute(Constants.ATTR_REL, link.getRel());
        }//from   www . ja  v  a 2  s  .c  o  m
        if (StringUtils.isNotBlank(link.getTitle())) {
            writer.writeAttribute(Constants.ATTR_TITLE, link.getTitle());
        }
        if (StringUtils.isNotBlank(link.getHref())) {
            writer.writeAttribute(Constants.ATTR_HREF, link.getHref());
        }
        if (StringUtils.isNotBlank(link.getType())) {
            writer.writeAttribute(Constants.ATTR_TYPE, link.getType());
        }

        if (link.getInlineEntry() != null || link.getInlineFeed() != null) {
            writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ATOM_ELEM_INLINE,
                    version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA));

            if (link.getInlineEntry() != null) {
                writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
                entry(writer, link.getInlineEntry());
                writer.writeEndElement();
            }
            if (link.getInlineFeed() != null) {
                writer.writeStartElement(Constants.ATOM_ELEM_FEED);
                feed(writer, link.getInlineFeed());
                writer.writeEndElement();
            }

            writer.writeEndElement();
        }

        writer.writeEndElement();
    }
}