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.unitedinternet.cosmo.util.DomWriter.java

private static void writeElement(Element e, XMLStreamWriter writer) throws XMLStreamException {
    //if (log.isDebugEnabled())
    //log.debug("Writing element " + e.getNodeName());

    String local = e.getLocalName();
    if (local == null) {
        local = e.getNodeName();/*from  ww w  . j a  v a2  s.co  m*/
    }

    String ns = e.getNamespaceURI();
    if (ns != null) {
        String prefix = e.getPrefix();
        if (prefix != null) {
            writer.writeStartElement(prefix, local, ns);
            writer.writeNamespace(prefix, ns);
        } else {
            writer.setDefaultNamespace(ns);
            writer.writeStartElement(ns, local);
            writer.writeDefaultNamespace(ns);
        }
    } else {
        writer.writeStartElement(local);
    }

    NamedNodeMap attributes = e.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        writeAttribute((Attr) attributes.item(i), writer);
    }

    NodeList children = e.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        writeNode(children.item(i), writer);
    }

    writer.writeEndElement();
}

From source file:ro.kuberam.libs.java.ftclient.FTP.FTP.java

public StreamResult listResources(Object abstractConnection, String remoteResourcePath) throws Exception {
    long startTime = new Date().getTime();

    boolean isDirectory = checkIsDirectory(remoteResourcePath);

    if (!isDirectory) {
        throw new Exception(ErrorMessages.err_FTC008);
    }/*from  ww  w .  j  a va2 s.  c  o  m*/

    FTPClient connection = (FTPClient) abstractConnection;
    if (!connection.isConnected()) {
        throw new Exception(ErrorMessages.err_FTC002);
    }

    List<Object> connectionObject = _checkResourcePath(connection, remoteResourcePath, "list-resources",
            isDirectory);

    System.out.println("resources: " + connectionObject.size());

    FTPFile[] resources = (FTPFile[]) connectionObject.get(1);
    StringWriter writer = new StringWriter();
    XMLStreamWriter xmlWriter = null;

    try {
        xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
        xmlWriter.setPrefix(modulePrefix, moduleNsUri);
        xmlWriter.writeStartDocument();
        xmlWriter.writeStartElement(modulePrefix + ":resources-list");
        xmlWriter.writeNamespace(modulePrefix, moduleNsUri);
        xmlWriter.writeAttribute("absolute-path", remoteResourcePath);
        for (FTPFile resource : resources) {
            _generateResourceElement(xmlWriter, resource, null, remoteResourcePath + resource.getName());
        }
        xmlWriter.writeEndElement();
        xmlWriter.writeEndDocument();
        xmlWriter.close();
    } catch (Exception ex) {
        throw new Exception(ex.getMessage());
    }

    // FTPconnection.completePendingCommand();
    StreamResult resultAsStreamResult = new StreamResult(writer);
    log.info("The FTP sub-module retrieved the list of resources in " + (new Date().getTime() - startTime)
            + " ms.");

    return resultAsStreamResult;
}