Example usage for javax.xml.stream XMLStreamWriter setPrefix

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

Introduction

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

Prototype

public void setPrefix(String prefix, String uri) throws XMLStreamException;

Source Link

Document

Sets the prefix the uri is bound to.

Usage

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);
    }/*w w  w . j  av  a2s.  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;
}

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

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

    if (!FTPconnection.isConnected()) {
        throw new Exception(ErrorMessages.err_FTC002);
    }//  w  w  w .  java2 s.com

    List<Object> FTPconnectionObject = _checkResourcePath(FTPconnection, remoteResourcePath,
            "get-resource-metadata", checkIsDirectory(remoteResourcePath));

    FTPFile[] resources = (FTPFile[]) FTPconnectionObject.get(1);

    StringWriter writer = new StringWriter();
    XMLStreamWriter xmlWriter = null;

    try {
        xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
        xmlWriter.setPrefix(modulePrefix, moduleNsUri);
        xmlWriter.writeStartDocument();
        for (FTPFile resource : resources) {
            _generateResourceElement(xmlWriter, resource, null, remoteResourcePath);
        }
        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 metadata for resource '" + remoteResourcePath + "' in "
            + (new Date().getTime() - startTime) + " ms.");

    return resultAsStreamResult;
}