Example usage for javax.xml.stream XMLStreamWriter writeNamespace

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

Introduction

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

Prototype

public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException;

Source Link

Document

Writes a namespace to the output stream If the prefix argument to this method is the empty string, "xmlns", or null this method will delegate to writeDefaultNamespace

Usage

From source file:org.simbasecurity.core.saml.SAMLServiceImpl.java

@Override
public String createLogoutRequest(String logoutRequestId, Date issueInstant, String nameId, String sessionIndex)
        throws XMLStreamException, IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = factory.createXMLStreamWriter(baos);

    writer.writeStartElement("samlp", "LogoutRequest", NS_SAMLP);
    writer.writeNamespace("samlp", NS_SAMLP);

    writer.writeAttribute("ID", "_" + logoutRequestId);
    writer.writeAttribute("Version", "2.0");
    writer.writeAttribute("IssueInstant", SAML_DATE_FORMAT.format(issueInstant));

    writer.writeStartElement("saml", "Issuer", NS_SAML);
    writer.writeNamespace("saml", NS_SAML);
    writer.writeCharacters("https://iamapps.belgium.be/");
    writer.writeEndElement();// w  ww  .  j av  a 2s  . co m

    writer.writeStartElement("saml", "NameID", NS_SAML);
    writer.writeNamespace("saml", NS_SAML);
    writer.writeAttribute("NameQualifier",
            configurationService.getValue(SimbaConfigurationParameter.SAML_IDP_SLO_TARGET_URL));
    writer.writeAttribute("SPNameQualifier", "https://iamapps.belgium.be/");
    writer.writeAttribute("Format", NAMEID_TRANSIENT);
    writer.writeCharacters(nameId);
    writer.writeEndElement();

    writer.writeStartElement("samlp", "SessionIndex", NS_SAMLP);
    writer.writeNamespace("saml", NS_SAMLP);
    writer.writeCharacters(sessionIndex);
    writer.writeEndElement();

    writer.writeEndElement();
    writer.flush();

    return encodeSAMLRequest(baos.toByteArray());
}

From source file:org.slc.sli.modeling.tools.xsdgen.Uml2XsdWriter.java

/**
 * Writes the UML model to the XML stream in XSD format.
 *
 * @param model/*from w  w  w  .j  a v a  2  s.  co  m*/
 *            The UML model.
 * @param xsw
 *            The XML stream.
 * @throws XMLStreamException
 *             if anything bad happens.
 */
private static final void writeSchema(final List<PsmDocument<Type>> elements, final ModelIndex lookup,
        final Uml2XsdPlugin plugin, final XMLStreamWriter xsw) throws XMLStreamException {
    writeStartElement(XsdElementName.SCHEMA, xsw);
    try {
        xsw.writeNamespace(PREFIX_XS, NAMESPACE_XS);
        final Map<String, String> prefixMappings = plugin.declarePrefixMappings();
        for (final Map.Entry<String, String> entry : prefixMappings.entrySet()) {
            final String namespace = entry.getValue();
            if (namespace == null) {
                throw new IllegalArgumentException("namespace declared by plugin is null.");
            }
            if (namespace.trim().length() == 0) {
                throw new IllegalArgumentException("namespace declared by plugin is the empty string.");
            }
            xsw.writeNamespace(entry.getKey(), namespace);
        }

        final String targetNamespace = plugin.getTargetNamespace();
        if (targetNamespace == null) {
            throw new IllegalArgumentException("targetNamespace declared by plugin is null.");
        }
        if (targetNamespace.trim().length() > 0) {
            xsw.writeAttribute("targetNamespace", targetNamespace);
            writeFormDefaultForElements(plugin.isElementFormDefaultQualified(), xsw);
            writeFormDefaultForAttributes(plugin.isAttributeFormDefaultQualified(), xsw);
        }

        for (final PsmDocument<Type> element : elements) {
            writeTopLevelElement(element, lookup, plugin, xsw);
        }
        for (final SimpleType simpleType : sort(combine(lookup.getDataTypes().values(), lookup.getEnumTypes()),
                TypeComparator.SINGLETON)) {
            writeSimpleType(simpleType, lookup, plugin, xsw);
        }
        for (final ClassType enumType : sort(lookup.getClassTypes().values(), TypeComparator.SINGLETON)) {
            // DE2424 exclude creating a ComplexType with no name
            if ("".equals(enumType.getName()) == false) {
                writeComplexType(enumType, lookup, plugin, xsw);
            }
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.wadl.writer.WadlWriter.java

private static final void writeApplication(final Application app, final Map<String, String> prefixMappings,
        final XMLStreamWriter xsw) throws XMLStreamException {
    xsw.writeStartElement(WADL_PREFIX, WadlElementName.APPLICATION.getLocalName(), WadlSyntax.NAMESPACE);
    try {// w  ww  .ja va 2s  . co m
        xsw.writeNamespace(WADL_PREFIX, WadlSyntax.NAMESPACE);
        xsw.writeNamespace("xsi", SCHEMA_INSTANCE_NS);
        xsw.writeAttribute("xsi", SCHEMA_INSTANCE_NS, "schemaLocation", SCHEMA_LOCATION_VALUE);
        xsw.writeNamespace("xs", SCHEMA_NS);
        for (final Map.Entry<String, String> prefix : prefixMappings.entrySet()) {
            xsw.writeNamespace(prefix.getKey(), prefix.getValue());
        }
        writeDocumentation(app, xsw);
        writeGrammars(app.getGrammars(), xsw);
        writeResources(app.getResources(), xsw);
        for (final ResourceType resourceType : app.getResourceTypes()) {
            writeResourceType(resourceType, xsw);
        }
        for (final Method method : app.getMethods()) {
            writeMethod(method, xsw);
        }
        for (final Representation representation : app.getRepresentations()) {
            writeRepresentation(representation, xsw);
        }
        for (final Representation representation : app.getFaults()) {
            writeFault(representation, xsw);
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.xmi.comp.XmiMappingWriter.java

private static final void writeMappingDocument(final XmiComparison documentElement, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeProcessingInstruction("xml-stylesheet", "type='text/xsl' href='xmi-mapping.xsl'");
    xsw.setPrefix("", XmiMappingConstants.NAMESPACE_URI);
    xsw.writeStartElement(XmiMappingConstants.DOCUMENT_ELEMENT.getLocalPart());
    xsw.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    xsw.writeAttribute("xsi", "http://www.w3.org/2001/XMLSchema-instance", "noNamespaceSchemaLocation",
            "xmi-mapping.xsd");
    try {//from   ww w  .j  a v a  2 s . c o m
        writeReference(documentElement.getLhsDef(), XmiMappingConstants.LHS_MODEL, xsw);
        writeReference(documentElement.getRhsDef(), XmiMappingConstants.RHS_MODEL, xsw);
        for (final XmiMapping mapping : documentElement.getMappings()) {
            writeMapping(mapping, xsw);
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java

/**
 * Writes the UML model to the XML stream in XMI format.
 *
 * @param model The UML model./* w  w  w  .ja va2s .com*/
 * @param xsw   The XML stream.
 * @throws XMLStreamException if anything bad happens.
 */
private static final void writeXMI(final Model model, final ModelIndex mapper, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeStartElement("XMI");
    try {
        xsw.writeNamespace("UML", NAMESPACE_UML);
        xsw.writeAttribute("xmi.version", "1.2");
        writeContent(model, mapper, xsw);
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.tolven.assembler.ear.EARAssembler.java

protected String getXSLT(PluginDescriptor pd, File localDestDir) throws XMLStreamException, IOException {
    StringWriter xslt = new StringWriter();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = null;
    try {//from  w  ww.  j  av  a 2s  .  c o  m
        writer = factory.createXMLStreamWriter(xslt);
        writer.writeStartDocument("UTF-8", "1.0");
        writer.writeCharacters("\n");
        writer.writeStartElement("xsl:stylesheet");
        writer.writeAttribute("version", "2.0");
        writer.writeNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
        writer.writeNamespace("tp", "http://java.sun.com/xml/ns/javaee");
        writer.writeCharacters("\n");
        writer.writeStartElement("xsl:output");
        writer.writeAttribute("method", "xml");
        writer.writeAttribute("indent", "yes");
        writer.writeAttribute("encoding", "UTF-8");
        writer.writeAttribute("omit-xml-declaration", "no");
        writer.writeEndElement();
        writer.writeCharacters("\n");
        addMainTemplate(writer);
        addRootTemplate(writer);
        addJavaLibraryTemplates(pd, localDestDir);
        addConnectorModuleTemplates(pd, localDestDir, writer);
        addEJBModuleTemplates(pd, localDestDir, writer);
        addWARModuleTemplates(pd, localDestDir, writer);
        addSecurityRoleTemplates(pd, writer);
        writer.writeEndDocument();
        writer.writeEndDocument();
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
    return xslt.toString();
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

protected String getEJBJARXSLT() throws XMLStreamException {
    StringWriter xslt = new StringWriter();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlStreamWriter = null;
    try {//from w w  w .j  a va2  s .c o m
        xmlStreamWriter = factory.createXMLStreamWriter(xslt);
        xmlStreamWriter.writeStartDocument("UTF-8", "1.0");
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:stylesheet");
        xmlStreamWriter.writeAttribute("version", "2.0");
        xmlStreamWriter.writeNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
        xmlStreamWriter.writeNamespace("tp", "http://java.sun.com/xml/ns/javaee");
        xmlStreamWriter.writeAttribute("exclude-result-prefixes", "tp");
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:output");
        xmlStreamWriter.writeAttribute("method", "xml");
        xmlStreamWriter.writeAttribute("indent", "yes");
        xmlStreamWriter.writeAttribute("encoding", "UTF-8");
        xmlStreamWriter.writeAttribute("omit-xml-declaration", "no");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
        addMainTemplate(xmlStreamWriter);
        addRootTemplate(xmlStreamWriter);
        addEnterpriseBeansChildren(xmlStreamWriter);
        addAssemblyDescriptorChildren(xmlStreamWriter);
        xmlStreamWriter.writeEndDocument();
    } finally {
        if (xmlStreamWriter != null) {
            xmlStreamWriter.close();
        }
    }
    return xslt.toString();
}

From source file:org.tolven.assembler.facesconfig.FacesConfigAssembler.java

protected String getXSLT(PluginDescriptor pluginDescriptor) throws XMLStreamException {
    StringWriter xslt = new StringWriter();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlStreamWriter = null;
    boolean added = false;
    try {//from w  w  w . j  a  v  a2s .  c  o  m
        xmlStreamWriter = factory.createXMLStreamWriter(xslt);
        xmlStreamWriter.writeStartDocument("UTF-8", "1.0");
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:stylesheet");
        xmlStreamWriter.writeAttribute("version", "2.0");
        xmlStreamWriter.writeNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
        xmlStreamWriter.writeNamespace("tp", "http://java.sun.com/xml/ns/javaee");
        xmlStreamWriter.writeAttribute("exclude-result-prefixes", "tp");
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:output");
        xmlStreamWriter.writeAttribute("method", "xml");
        xmlStreamWriter.writeAttribute("indent", "yes");
        xmlStreamWriter.writeAttribute("encoding", "UTF-8");
        xmlStreamWriter.writeAttribute("omit-xml-declaration", "no");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
        addMainTemplate(xmlStreamWriter);
        addRootTemplate(xmlStreamWriter);
        added = added | addApplicationChildren(pluginDescriptor, xmlStreamWriter);
        added = added | addGlobalValidatorTemplates(pluginDescriptor, xmlStreamWriter);
        added = added | addGlobalConverterTemplates(pluginDescriptor, xmlStreamWriter);
        added = added | addLifeCycleTemplates(pluginDescriptor, xmlStreamWriter);
        added = added | addNavigationRuleTemplates(pluginDescriptor, xmlStreamWriter);
        added = added | addManagedBeanTemplates(pluginDescriptor, xmlStreamWriter);
        xmlStreamWriter.writeEndDocument();
    } finally {
        if (xmlStreamWriter != null) {
            xmlStreamWriter.close();
        }
    }
    if (added) {
        return xslt.toString();
    } else {
        return null;
    }
}

From source file:org.tolven.assembler.tomcatserver.TomcatServerXMLAssembler.java

protected String getXSLT(ExtensionPoint connectorExtensionPoint) throws XMLStreamException, IOException {
    StringWriter xslt = new StringWriter();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlStreamWriter = null;
    try {/*from  w  w w. ja  v  a  2s.  co  m*/
        xmlStreamWriter = factory.createXMLStreamWriter(xslt);
        xmlStreamWriter.writeStartDocument("UTF-8", "1.0");
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:stylesheet");
        xmlStreamWriter.writeAttribute("version", "2.0");
        xmlStreamWriter.writeNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:output");
        xmlStreamWriter.writeAttribute("method", "xml");
        xmlStreamWriter.writeAttribute("indent", "yes");
        xmlStreamWriter.writeAttribute("encoding", "UTF-8");
        xmlStreamWriter.writeAttribute("omit-xml-declaration", "no");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
        addMainTemplate(xmlStreamWriter);
        addServiceTemplate(connectorExtensionPoint, xmlStreamWriter);
        xmlStreamWriter.writeEndDocument();
        xmlStreamWriter.writeEndDocument();
    } finally {
        if (xmlStreamWriter != null) {
            xmlStreamWriter.close();
        }
    }
    return xslt.toString();
}

From source file:org.tolven.assembler.webxml.WebXMLAssembler.java

protected String getXSLT(PluginDescriptor pd) throws XMLStreamException {
    StringWriter xslt = new StringWriter();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlStreamWriter = null;
    try {/*from   w w  w  .  j a va 2  s  . c o m*/
        xmlStreamWriter = factory.createXMLStreamWriter(xslt);
        xmlStreamWriter.writeStartDocument("UTF-8", "1.0");
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:stylesheet");
        xmlStreamWriter.writeAttribute("version", "2.0");
        xmlStreamWriter.writeNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
        xmlStreamWriter.writeNamespace("tp", "http://java.sun.com/xml/ns/javaee");
        xmlStreamWriter.writeAttribute("exclude-result-prefixes", "tp");
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:output");
        xmlStreamWriter.writeAttribute("method", "xml");
        xmlStreamWriter.writeAttribute("indent", "yes");
        xmlStreamWriter.writeAttribute("encoding", "UTF-8");
        xmlStreamWriter.writeAttribute("omit-xml-declaration", "no");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
        addMainTemplate(xmlStreamWriter);
        addRootTemplate(xmlStreamWriter);
        addContextParameterTemplate(xmlStreamWriter);
        addContextParameterCallTemplates(pd, xmlStreamWriter);
        addFilterTemplates(pd, xmlStreamWriter);
        addListenerTemplates(pd, xmlStreamWriter);
        addServletTemplates(pd, xmlStreamWriter);
        addEJBLocalRefTemplates(pd, xmlStreamWriter);
        addSessionConfigTemplates(pd, xmlStreamWriter);
        addWelcomeFileListTemplates(pd, xmlStreamWriter);
        addWebSecurityConstraintTemplates(pd, xmlStreamWriter);
        addLoginConfigTemplates(pd, xmlStreamWriter);
        addSecurityRoleTemplates(pd, xmlStreamWriter);
        addEnvEntryTemplates(pd, xmlStreamWriter);
        addErrorPageTemplates(pd, xmlStreamWriter);
        xmlStreamWriter.writeEndDocument();
    } finally {
        if (xmlStreamWriter != null) {
            xmlStreamWriter.close();
        }
    }
    return xslt.toString();
}