Example usage for javax.xml.stream XMLStreamWriter writeStartDocument

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

Introduction

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

Prototype

public void writeStartDocument() throws XMLStreamException;

Source Link

Document

Write the XML Declaration.

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  ww .  ja  va2  s .c  o 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();
    writer.setDefaultNamespace(Constants.NS_ATOM);
    writer.writeStartElement(rootElement);

    namespaces(writer);//from  ww w . j a v  a2  s .  co  m
}

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

private void property(final Writer outWriter, final Property property)
        throws XMLStreamException, EdmPrimitiveTypeException {
    final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);

    writer.writeStartDocument();

    property(writer, property);/*from   ww w.j  a  v a2  s  .c om*/

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

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

private void entity(final Writer outWriter, final Entity entity)
        throws XMLStreamException, EdmPrimitiveTypeException {
    final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);

    if (entity.getType() == null && entity.getProperties().isEmpty()) {
        writer.writeStartDocument();
        writer.setDefaultNamespace(namespaceMetadata);
        entityRef(writer, entity);//from  w ww .  ja  v  a 2 s .co m
    } else {
        startDocument(writer, Constants.ATOM_ELEM_ENTRY);
        entity(writer, entity);
    }
    writer.writeEndDocument();
    writer.flush();
}

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

private void entity(final Writer outWriter, final ResWrap<Entity> container)
        throws XMLStreamException, EdmPrimitiveTypeException {
    final Entity entity = container.getPayload();

    final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);

    if (entity.getType() == null && entity.getProperties().isEmpty()) {
        writer.writeStartDocument();
        writer.setDefaultNamespace(namespaceMetadata);

        entityRef(writer, container);// w w w.ja v a2s.  co  m
    } else {
        startDocument(writer, Constants.ATOM_ELEM_ENTRY);

        addContextInfo(writer, container);

        entity(writer, entity);
    }

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

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();

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

    writer.writeStartElement(Constants.ELEM_URI);
    writer.writeCharacters(link.getHref());
    writer.writeEndElement();/*from   w w w .ja  v a  2s .c  o m*/

    writer.writeEndElement();

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

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

private void reference(final Writer outWriter, final ResWrap<URI> container) throws XMLStreamException {
    final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);

    writer.writeStartDocument();

    writer.writeStartElement(Constants.ATTR_METADATA, Constants.ATTR_REF, Constants.NS_METADATA);
    writer.writeNamespace(Constants.ATTR_METADATA, Constants.NS_METADATA);
    writer.writeAttribute(Constants.ATTR_METADATA, Constants.NS_METADATA, Constants.CONTEXT,
            container.getContextURL().toASCIIString());
    writer.writeAttribute(Constants.ATOM_ATTR_ID, container.getPayload().toASCIIString());
    writer.writeEndElement();/* w w  w.j a va  2 s  .  c  om*/

    writer.writeEndDocument();
}

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

private void startDocument(final XMLStreamWriter writer, final String rootElement) throws XMLStreamException {
    writer.writeStartDocument();
    writer.setDefaultNamespace(Constants.NS_ATOM);

    writer.writeStartElement(rootElement);

    namespaces(writer);/*from   w w w .jav  a  2 s  .c o m*/
}

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

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

    writer.writeStartDocument();

    propSerializer.property(writer, property);

    writer.writeEndDocument();/*w w w .  jav  a2 s . co  m*/
    writer.flush();
}

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

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

    writer.writeStartDocument();

    writer.writeStartElement(Constants.ELEM_LINKS);
    writer.writeDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));

    writer.writeStartElement(Constants.ELEM_URI);
    writer.writeCharacters(link.getHref());
    writer.writeEndElement();/*from  w  ww .  j a v  a 2  s  .c o m*/

    writer.writeEndElement();

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