Example usage for org.dom4j.io XMLWriter write

List of usage examples for org.dom4j.io XMLWriter write

Introduction

In this page you can find the example usage for org.dom4j.io XMLWriter write.

Prototype

public void write(Object object) throws IOException 

Source Link

Document

Writes the given object which should be a String, a Node or a List of Nodes.

Usage

From source file:nl.ru.cmbi.vase.parse.VASEXMLParser.java

License:Apache License

public static void write(VASEDataObject data, OutputStream xmlOut) throws IOException {

    DocumentFactory df = DocumentFactory.getInstance();

    Document doc = df.createDocument();

    Element root = doc.addElement("xml");

    if (data.getTitle() != null) {

        Element title = root.addElement("title");
        title.setText(data.getTitle());//from   w w  w.  j av  a 2s  . co  m
    }

    Element fasta = root.addElement("fasta");
    ByteArrayOutputStream fastaStream = new ByteArrayOutputStream();
    FastaParser.toFasta(data.getAlignment().getMap(), fastaStream);

    fasta.add(df.createCDATA(new String(fastaStream.toByteArray(), StandardCharsets.UTF_8)));

    Element pdb = root.addElement("pdb");
    pdb.addAttribute("pdbid", data.getPdbID());

    table2xml(data.getTable(), root);

    if (data.getPlots().size() > 0) {
        Element plots = root.addElement("plots");
        for (PlotDescription pd : data.getPlots()) {

            Element plot = plots.addElement("plot");
            plot.addElement("x").setText(pd.getXAxisColumnID());
            plot.addElement("y").setText(pd.getYAxisColumnID());
            plot.addAttribute("title", pd.getPlotTitle());
        }
    }

    XMLWriter writer = new XMLWriter(xmlOut);
    writer.write(doc);
    writer.close();
}

From source file:nl.tue.gale.ae.processor.plugin.ExportPlugin.java

License:Open Source License

public void doGet(Resource resource) throws ProcessorException {
    GaleContext gale = GaleContext.of(resource);
    try {/*w ww.  jav  a  2 s .c om*/
        String root = gale.req().getParameter("root");
        if (root == null || "".equals(root))
            throw new IllegalArgumentException("no 'root' specified as parameter");
        URI[] conceptList = CountModule.getUriCache(URIs.of(root), gale);
        Set<Concept> concepts = new TreeSet<Concept>(new Concept.comparator());
        for (URI concept : conceptList) {
            Concept c = gale.dm().get(concept);
            concepts.add(c);
            concepts.addAll(c.getNamedOutConcepts("extends"));
        }
        Element result = GDOMFormat.toXML(ImmutableList.copyOf(concepts));

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        XMLWriter writer = new XMLWriter(out, new OutputFormat("  ", true));
        writer.write(result);
        resource.put("stream", new ByteArrayInputStream(out.toByteArray()));
        resource.put("mime", "application/gdom");
        gale.usedStream();
    } catch (Exception e) {
        throw new ProcessorException("unable to export domain model to .gdom file: " + e.getMessage(), e);
    }
}

From source file:nl.tue.gale.common.GaleUtil.java

License:Open Source License

public static String serializeXML(Element element) {
    StringWriter out = new StringWriter();
    OutputFormat of = new OutputFormat();
    of.setExpandEmptyElements(true);/* ww w .  j  a va 2 s .  co m*/
    XMLWriter writer = new XMLWriter(out, of) {
        @Override
        protected void writeEmptyElementClose(String qualifiedName) throws IOException {
            if (omitCloseSet.contains(qualifiedName.toUpperCase())) {
                writer.write(" />");
            } else {
                super.writeEmptyElementClose(qualifiedName);
            }
        }
    };
    try {
        writer.write(element);
        writer.flush();
    } catch (IOException e) {
        e.printStackTrace();
        throw new IllegalArgumentException("unable to serialize XML: " + e.getMessage());
    }
    return out.toString();
}

From source file:noThreads.Playlist.java

License:Open Source License

public void createPlaylist(String filePath)
        throws IOException, DocumentException, SAXException, ParserConfigurationException {
    String xmlObject, title = null;
    boolean flag = true;
    XspfPlaylist playlist = new XspfPlaylist();
    playlist.setTitle("My Playlist");
    playlist.setVersion("1");

    // create track list first
    XspfPlaylistTrackList tracks = new XspfPlaylistTrackList();

    for (int i = 0; i < eradioLinks.size(); i++) {
        if (flag == true) {
            flag = false;/*from w  ww  .j  a  v  a2  s  .c om*/
            title = org.apache.commons.lang3.StringEscapeUtils.escapeXml(eradioLinks.get(i));
        } else {
            flag = true;
            //escape the xml characters of the url
            xmlObject = org.apache.commons.lang3.StringEscapeUtils.escapeXml(eradioLinks.get(i));

            // now create track, set title and add to list
            XspfTrack track = new XspfTrack();
            track.setTitle(title);
            track.setLocation(xmlObject);
            tracks.addTrack(track);
        }
    }
    // add tracks to playlist
    playlist.setPlaylistTrackList(tracks);

    //or use Dom4j to output the playlist
    File file = new File(filePath);
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(new FileWriter(file), format);
    Document doc = DocumentHelper.parseText(playlist.makeTextDocument());
    writer.write(doc);
    writer.close();
}

From source file:org.alfresco.module.vti.web.fp.DeleteMethod.java

License:Open Source License

@Override
protected void executeImpl() throws WebDAVServerException, Exception {
    try {//from   w w  w  . ja  v a  2s  . c om
        super.executeImpl();
        m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    } catch (WebDAVServerException e) {
        if (e.getHttpStatusCode() == WebDAV.WEBDAV_SC_LOCKED) {
            // SharePoint requires a special response for the case of
            //  trying to delete a locked document
            m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS);
            m_response.setContentType(WebDAV.XML_CONTENT_TYPE);
            m_response.addHeader(HEADER_X_MSDAVEXT_ERROR, "589838"); // TODO Don't hard code this constant

            XMLWriter xml = createXMLWriter();

            xml.startDocument();

            String nsdec = generateNamespaceDeclarations(namespaceMap);
            xml.startElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS + nsdec, WebDAV.XML_NS_MULTI_STATUS + nsdec,
                    getDAVHelper().getNullAttributes());

            xml.startElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE,
                    getDAVHelper().getNullAttributes());

            xml.startElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF,
                    getDAVHelper().getNullAttributes());
            xml.write(m_request.getRequestURL().toString());
            xml.endElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF);

            xml.startElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS,
                    getDAVHelper().getNullAttributes());
            xml.write(WebDAV.HTTP1_1 + " " + WebDAV.WEBDAV_SC_LOCKED + " " + SC_LOCKED_DESC);
            xml.endElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS);

            xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE);

            // Close the outer XML element
            xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS);

            // Send remaining data
            flushXML(xml);
        } else {
            throw e;
        }
    }
}

From source file:org.alfresco.module.vti.web.fp.PropfindMethod.java

License:Open Source License

/**
 * <p>//from   w  ww.  ja v a  2 s  .c o m
 *  Handle PROPFIND method of the MS-WDVME protocol.
 *  <ul>
 *      <li>1. If MS-Doclib header with value '1' presents in request it check for library existing and return
 *             the MS-Doclib header in response with value of the valid URL that is point to the library that 
 *             resource belongs to.
 *      </li>
 *      <li>
 *          2. If Depth header in request has a value '0' returns properties for the requested resource.
 *      </li>
 *      <li>
 *          3. If Depth header in request has a value 'infinity' (requested resources should be collection) 
 *             returns properties for the requested resource and all resources that are stored in requested 
 *             collection. 
 *      </li>
 *  </ul>
 *  In case if requested resource was not found then HTTP 404 status is sent to the client.
 * </p>
 */
@Override
protected void executeImpl() throws WebDAVServerException, Exception {
    String msDoclib = m_request.getHeader(HEADER_MS_DOCLIB);

    if (msDoclib != null && msDoclib.equals("1")) {
        try {
            getDAVHelper().getParentNodeForPath(getRootNodeRef(), m_strPath);
        } catch (FileNotFoundException e) {
            m_response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        // TODO: this shouldn't assume the requested URL is the one exposed to the outside world
        // (may be behind proxy). Change to parse properly.
        String docLibHref = URLDecoder
                .decode(m_request.getRequestURL().substring(0, m_request.getRequestURL().lastIndexOf("/")));
        m_response.setHeader(HEADER_MS_DOCLIB, docLibHref);
        return;
    }

    m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS);

    if (logger.isDebugEnabled()) {
        logger.debug("processing PROPFIND request with uri: " + m_request.getRequestURI());
    }

    FileInfo pathNodeInfo = null;

    // Check that the path exists
    pathNodeInfo = pathHelper.resolvePathFileInfo(m_strPath);

    if (pathNodeInfo == null) {
        // The path is not valid - send a 404 error back to the client
        m_response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    // Note the null check, as root node may be null in cloud.
    if (pathNodeInfo.getNodeRef() != null && getFileFolderService().isHidden(pathNodeInfo.getNodeRef())) {
        // ALF-17662, the path is hidden - send a 404 error back to the client
        m_response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    // Set the response content type
    m_response.setContentType(WebDAV.XML_CONTENT_TYPE);

    // Create multistatus response
    XMLWriter xml = createXMLWriter();

    xml.startDocument();

    String nsdec = generateNamespaceDeclarations(namespaceMap);
    xml.startElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS + nsdec, WebDAV.XML_NS_MULTI_STATUS + nsdec,
            getDAVHelper().getNullAttributes());

    if (containsCollblob) {
        xml.startElement("http://schemas.microsoft.com/repl/", "repl", "Repl:repl",
                getDAVHelper().getNullAttributes());
        xml.startElement("http://schemas.microsoft.com/repl/", "collblob", "Repl:collblob",
                getDAVHelper().getNullAttributes());
        xml.write(VtiUtils.formatPropfindDate(new Date()));
        xml.endElement("http://schemas.microsoft.com/repl/", "collblob", "Repl:collblob");
        xml.endElement("http://schemas.microsoft.com/repl/", "repl", "Repl:repl");
    }

    xml.write("\n");

    // Create the path for the current location in the tree
    StringBuilder baseBuild = new StringBuilder(256);
    baseBuild.append("");
    if (baseBuild.length() == 0 || baseBuild.charAt(baseBuild.length() - 1) != WebDAVHelper.PathSeperatorChar) {
        baseBuild.append(WebDAVHelper.PathSeperatorChar);
    }
    String basePath = baseBuild.toString();

    // Output the response for the root node, depth zero
    try {
        generateResponseForNode(xml, pathNodeInfo, basePath);
    } catch (Exception e) {
        m_response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    // If additional levels are required and the root node is a folder then recurse to the required
    // level and output node details a level at a time
    if (depth != DEPTH_ZERO && pathNodeInfo.isFolder()) {
        // Create the initial list of nodes to report
        List<FileInfo> nodeInfos = new ArrayList<FileInfo>(10);
        nodeInfos.add(pathNodeInfo);

        int curDepth = WebDAV.DEPTH_1;

        // List of next level of nodes to report
        List<FileInfo> nextNodeInfos = null;
        if (depth > WebDAV.DEPTH_1) {
            nextNodeInfos = new ArrayList<FileInfo>(10);
        }

        // Loop reporting each level of nodes to the requested depth
        while (curDepth <= depth && nodeInfos != null) {
            // Clear out the next level of nodes, if required
            if (nextNodeInfos != null) {
                nextNodeInfos.clear();
            }

            // Output the current level of node(s), the node list should
            // only contain folder nodes

            for (FileInfo curNodeInfo : nodeInfos) {
                // Get the list of child nodes for the current node
                List<FileInfo> childNodeInfos = getDAVHelper().getChildren(curNodeInfo);

                // can skip the current node if it doesn't have children
                if (childNodeInfos.size() == 0) {
                    continue;
                }

                // Output the child node details
                // Generate the base path for the current parent node

                baseBuild.setLength(0);
                try {
                    String pathSnippet = null;
                    if ((pathNodeInfo.getNodeRef() == null) && (curNodeInfo.getNodeRef() == null)) {
                        pathSnippet = "/";
                    } else {
                        pathSnippet = getDAVHelper().getPathFromNode(pathNodeInfo.getNodeRef(),
                                curNodeInfo.getNodeRef());
                    }

                    baseBuild.append(pathSnippet);
                } catch (FileNotFoundException e) {
                    // move to the next node
                    continue;
                }

                int curBaseLen = baseBuild.length();

                // Output the child node details
                for (FileInfo curChildInfo : childNodeInfos) {
                    // ALF-17662, do not show link nodes and hidden documents
                    // Note the null check, as node may be null in cloud.
                    final boolean isHidden = curChildInfo.getNodeRef() != null
                            && getFileFolderService().isHidden(curChildInfo.getNodeRef());
                    if (curChildInfo.isLink() == false && !isHidden) {
                        // Build the path for the current child node
                        baseBuild.setLength(curBaseLen);

                        baseBuild.append(WebDAVHelper.PathSeperatorChar + curChildInfo.getName());

                        // Output the current child node details
                        try {
                            generateResponseForNode(xml, curChildInfo, baseBuild.toString());
                        } catch (Exception e) {
                            m_response.setStatus(HttpServletResponse.SC_NOT_FOUND);
                            return;
                        }

                        // If the child is a folder add it to the list of next level nodes
                        if (nextNodeInfos != null && curChildInfo.isFolder()) {
                            nextNodeInfos.add(curChildInfo);
                        }
                    }
                }
            }

            // Update the current tree depth
            curDepth++;

            // Move the next level of nodes to the current node list
            nodeInfos.clear();
            if (nextNodeInfos != null) {
                nodeInfos.addAll(nextNodeInfos);
            }
        }
    }

    // Close the outer XML element
    xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS);

    // Send remaining data
    flushXML(xml);
}

From source file:org.alfresco.module.vti.web.fp.PropfindMethod.java

License:Open Source License

/**
 * Generates the required response XML for the current node
 * //from w  w w.  j ava 2  s .c  o  m
 * @param xml XMLWriter
 * @param nodeInfo FileInfo
 * @param path String
 */
protected void generateResponseForNode(XMLWriter xml, FileInfo nodeInfo, String path) throws Exception {
    boolean isFolder = nodeInfo.isFolder();

    // Output the response block for the current node
    xml.startElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE,
            getDAVHelper().getNullAttributes());

    path = URLDecoder.decode(m_request.getRequestURI()).replaceFirst(alfrescoContext, "") + path;
    path = path.replaceAll("//", "/");

    // Build the href string for the current node
    String relativeUrl = getDAVHelper().getURLForPath(m_request, path, isFolder);
    String strHRef = urlHelper.getExternalURLHostOnly() + relativeUrl;

    if (nodeInfo.isFolder()) {
        strHRef = strHRef.substring(0, strHRef.length() - 1);
    }

    strHRef = strHRef.endsWith("/") ? strHRef.substring(0, strHRef.length() - 1) : strHRef;

    xml.startElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF, getDAVHelper().getNullAttributes());
    xml.write(strHRef);
    xml.endElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF);

    generateAllPropertiesResponse(xml, nodeInfo, isFolder);

    // Close off the response element
    xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE);
    xml.write("\n");
}

From source file:org.alfresco.module.vti.web.fp.PropfindMethod.java

License:Open Source License

/**
 * Generates the XML response for a PROPFIND request that asks for all known
 * properties/*from   w  w  w .  j  a v  a  2 s  .c o  m*/
 * 
 * @param xml XMLWriter
 * @param nodeInfo FileInfo
 * @param isDir boolean
 */
protected void generateAllPropertiesResponse(XMLWriter xml, FileInfo nodeInfo, boolean isDir) throws Exception {
    // Get the properties for the node

    NodeRef node = nodeInfo.getNodeRef();

    Map<QName, Serializable> props = nodeInfo.getProperties();
    TypeConverter typeConv = DefaultTypeConverter.INSTANCE;

    NodeRef workingCopy = null;
    if (node != null) {
        workingCopy = getDAVHelper().getServiceRegistry().getCheckOutCheckInService().getWorkingCopy(node);
    }

    Map<QName, Serializable> workingCopyProps = null;
    if (workingCopy != null) {
        String workingCopyOwner = getDAVHelper().getNodeService()
                .getProperty(workingCopy, ContentModel.PROP_WORKING_COPY_OWNER).toString();
        if (workingCopyOwner
                .equals(getDAVHelper().getServiceRegistry().getAuthenticationService().getCurrentUserName())) {
            workingCopyProps = getDAVHelper().getNodeService().getProperties(workingCopy);
        }
    }

    // Output the start of the properties element

    Attributes nullAttr = getDAVHelper().getNullAttributes();

    xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT, nullAttr);
    xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP, nullAttr);

    xml.startElement(WebDAV.DAV_NS, WebDAV.XML_RESOURCE_TYPE, WebDAV.XML_RESOURCE_TYPE, nullAttr);
    if (isDir) {
        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_COLLECTION, WebDAV.XML_COLLECTION, nullAttr);
        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_COLLECTION, WebDAV.XML_COLLECTION);
    }
    xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESOURCE_TYPE, WebDAV.XML_RESOURCE_TYPE);

    // Get the node name

    Object davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_DISPLAYNAME);

    // Output the node name

    xml.startElement(WebDAV.DAV_NS, WebDAV.XML_DISPLAYNAME, WebDAV.XML_NS_DISPLAYNAME, nullAttr);
    if (davValue != null) {
        String name = typeConv.convert(String.class, davValue);
        if (name == null || name.length() == 0) {
            logger.error("WebDAV name is null, value=" + davValue.getClass().getName() + ", node=" + node);
        }
        xml.write(name);
    }
    xml.endElement(WebDAV.DAV_NS, WebDAV.XML_DISPLAYNAME, WebDAV.XML_NS_DISPLAYNAME);

    // Generate a lock status report, if locked
    if (workingCopy != null
            && (VtiUtils.isMacClientRequest(m_request) || VtiUtils.isOffice2010ClientRequest(m_request))) {
        // Office 2008/2011 for Mac assumes that checkouted node is locked node
        generateFakeLockDiscoveryResponseForWorkingCopy(xml, workingCopy, isDir);
    } else {
        generateLockDiscoveryResponse(xml, nodeInfo, isDir);
    }

    // Output the supported lock types

    if (!isDir) {
        writeLockTypes(xml);
    }

    if (isDir) {
        xml.startElement(WebDAV.DAV_NS, "isFolder", WebDAV.DAV_NS + ":isFolder", nullAttr);
        xml.write("t");
        xml.endElement(WebDAV.DAV_NS, "isFolder", WebDAV.DAV_NS + ":isFolder");
        xml.startElement(WebDAV.DAV_NS, "iscollection", WebDAV.DAV_NS + ":iscollection", nullAttr);
        xml.write("1");
        xml.endElement(WebDAV.DAV_NS, "iscollection", WebDAV.DAV_NS + ":iscollection");
        xml.startElement(WebDAV.DAV_NS, "ishidden", WebDAV.DAV_NS + ":ishidden", nullAttr);
        xml.write("0");
        xml.endElement(WebDAV.DAV_NS, "ishidden", WebDAV.DAV_NS + ":ishidden");
        xml.startElement(WebDAV.DAV_NS, "getcontenttype", WebDAV.DAV_NS + ":getcontenttype", nullAttr);
        xml.write("application/octet-stream");
        xml.endElement(WebDAV.DAV_NS, "getcontenttype", WebDAV.DAV_NS + ":getcontenttype");
        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LENGTH, WebDAV.XML_NS_GET_CONTENT_LENGTH,
                nullAttr);
        xml.write("0");
        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LENGTH, WebDAV.XML_NS_GET_CONTENT_LENGTH);

        // If the node is a folder then return as a collection type

        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_RESOURCE_TYPE, WebDAV.XML_NS_RESOURCE_TYPE, nullAttr);
        if (isDir)
            xml.write(DocumentHelper.createElement(WebDAV.XML_NS_COLLECTION));
        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESOURCE_TYPE, WebDAV.XML_NS_RESOURCE_TYPE);

        xml.startElement("Repl", "authoritative-directory", "Repl:authoritative-directory", nullAttr);
        xml.write("t");
        xml.endElement("Repl", "authoritative-directory", "Repl:authoritative-directory");
    }

    // Output the source
    //
    // NOTE: source is always a no content element in our implementation

    //xml.write(DocumentHelper.createElement(WebDAV.XML_NS_SOURCE));        

    // Get the modifed date/time

    if (workingCopyProps != null) {
        davValue = WebDAV.getDAVPropertyValue(workingCopyProps, WebDAV.XML_GET_LAST_MODIFIED);
    } else {
        davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_GET_LAST_MODIFIED);
    }

    Date lastModified = (Date) davValue;

    // Output the last modified date of the node

    xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_LAST_MODIFIED, WebDAV.XML_NS_GET_LAST_MODIFIED, nullAttr);
    if (davValue != null)
        xml.write(VtiUtils.formatPropfindDate(typeConv.convert(Date.class, davValue)));
    xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_LAST_MODIFIED, WebDAV.XML_NS_GET_LAST_MODIFIED);

    // Get the creation date
    davValue = WebDAV.getDAVPropertyValue(props, WebDAV.XML_CREATION_DATE);

    // Output the creation date

    xml.startElement(WebDAV.DAV_NS, WebDAV.XML_CREATION_DATE, WebDAV.XML_NS_CREATION_DATE, nullAttr);
    if (davValue != null)
        xml.write(VtiUtils.formatPropfindDate(typeConv.convert(Date.class, davValue)));
    xml.endElement(WebDAV.DAV_NS, WebDAV.XML_CREATION_DATE, WebDAV.XML_NS_CREATION_DATE);

    // For a file node output the content language and content type

    if (isDir == false) {
        long len = 0;

        ContentData contentData = (ContentData) props.get(ContentModel.PROP_CONTENT);
        if (contentData != null)
            len = contentData.getSize();

        // Output the content length

        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LENGTH, WebDAV.XML_NS_GET_CONTENT_LENGTH,
                nullAttr);
        xml.write("" + len);
        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_CONTENT_LENGTH, WebDAV.XML_NS_GET_CONTENT_LENGTH);

    }

    // Print out all the custom properties
    String guid = "";
    if (node != null) {
        guid = node.getId().toUpperCase();
    }

    xml.startElement("Repl", "repl-uid", "Repl:repl-uid", nullAttr);
    if (StringUtils.hasText(guid)) {
        xml.write(VtiUtils.constructRid(guid));
    }
    xml.endElement("Repl", "repl-uid", "Repl:repl-uid");

    xml.startElement("Repl", "resourcetag", "Repl:resourcetag", nullAttr);
    if (lastModified != null) {
        xml.write(VtiUtils.constructResourceTag(guid, lastModified));
    }
    xml.endElement("Repl", "resourcetag", "Repl:resourcetag");

    // Output the etag        
    xml.startElement(WebDAV.DAV_NS, WebDAV.XML_GET_ETAG, WebDAV.XML_NS_GET_ETAG, nullAttr);
    if (lastModified != null) {
        xml.write(VtiUtils.constructETag(guid, lastModified));
    }
    xml.endElement(WebDAV.DAV_NS, WebDAV.XML_GET_ETAG, WebDAV.XML_NS_GET_ETAG);

    if (!isDir) {
        String modifiedBy = props.get(ContentModel.PROP_MODIFIER).toString();
        xml.startElement("Office", "modifiedby", "Office:modifiedby", nullAttr);
        xml.write(modifiedBy);
        xml.endElement("Office", "modifiedby", "Office:modifiedby");

        // Office 2011 for Mac special property
        xml.startElement(WebDAV.DAV_NS, "getmodifiedby", WebDAV.DAV_NS_PREFIX + "getmodifiedby", nullAttr);
        xml.write(modifiedBy);
        xml.endElement(WebDAV.DAV_NS, "getmodifiedby", WebDAV.DAV_NS_PREFIX + "getmodifiedby");

    }
    // Close off the response

    xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP);
    xml.write("\n");

    xml.startElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS, nullAttr);
    xml.write(WebDAV.HTTP1_1 + " " + HttpServletResponse.SC_OK + " " + WebDAV.SC_OK_DESC);
    xml.endElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS);
    xml.write("\n");

    xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROPSTAT, WebDAV.XML_NS_PROPSTAT);
    xml.write("\n");
}

From source file:org.alfresco.module.vti.web.fp.PropfindMethod.java

License:Open Source License

/**
 * Generates the XML response snippet showing the fake lock information for the given path
 * /*from   www .j  a  v a 2 s  .  c  o m*/
 * @param xml XMLWriter
 * @param node NodeRef
 * @param isDir boolean
 */
protected void generateFakeLockDiscoveryResponseForWorkingCopy(XMLWriter xml, NodeRef node, boolean isDir)
        throws Exception {

    Attributes nullAttr = getDAVHelper().getNullAttributes();
    String ns = WebDAV.DAV_NS;
    if (node != null) {
        String owner = (String) getNodeService().getProperty(node, ContentModel.PROP_WORKING_COPY_OWNER);
        String lockTocken = WebDAV.makeLockToken(node, owner);
        // Output the XML response

        xml.startElement(ns, WebDAV.XML_LOCK_DISCOVERY, WebDAV.XML_NS_LOCK_DISCOVERY, nullAttr);
        xml.startElement(ns, WebDAV.XML_ACTIVE_LOCK, WebDAV.XML_NS_ACTIVE_LOCK, nullAttr);

        xml.startElement(ns, WebDAV.XML_LOCK_TYPE, WebDAV.XML_NS_LOCK_TYPE, nullAttr);
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_WRITE));
        xml.endElement(ns, WebDAV.XML_LOCK_TYPE, WebDAV.XML_NS_LOCK_TYPE);

        xml.startElement(ns, WebDAV.XML_LOCK_SCOPE, WebDAV.XML_NS_LOCK_SCOPE, nullAttr);
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_EXCLUSIVE));
        xml.endElement(ns, WebDAV.XML_LOCK_SCOPE, WebDAV.XML_NS_LOCK_SCOPE);

        // NOTE: We only support one level of lock at the moment

        xml.startElement(ns, WebDAV.XML_DEPTH, WebDAV.XML_NS_DEPTH, nullAttr);
        xml.write("0");
        xml.endElement(ns, WebDAV.XML_DEPTH, WebDAV.XML_NS_DEPTH);

        xml.startElement(ns, WebDAV.XML_OWNER, WebDAV.XML_NS_OWNER, nullAttr);
        xml.write(owner);
        xml.endElement(ns, WebDAV.XML_OWNER, WebDAV.XML_NS_OWNER);

        xml.startElement(ns, WebDAV.XML_TIMEOUT, WebDAV.XML_NS_TIMEOUT, nullAttr);

        xml.write(WebDAV.SECOND + "604800");

        xml.endElement(ns, WebDAV.XML_TIMEOUT, WebDAV.XML_NS_TIMEOUT);

        xml.startElement(ns, WebDAV.XML_LOCK_TOKEN, WebDAV.XML_NS_LOCK_TOKEN, nullAttr);
        xml.startElement(ns, WebDAV.XML_HREF, WebDAV.XML_NS_HREF, nullAttr);

        xml.write(lockTocken);

        xml.endElement(ns, WebDAV.XML_HREF, WebDAV.XML_NS_HREF);
        xml.endElement(ns, WebDAV.XML_LOCK_TOKEN, WebDAV.XML_NS_LOCK_TOKEN);

        xml.endElement(ns, WebDAV.XML_ACTIVE_LOCK, WebDAV.XML_NS_ACTIVE_LOCK);
        xml.endElement(ns, WebDAV.XML_LOCK_DISCOVERY, WebDAV.XML_NS_LOCK_DISCOVERY);
    }
}

From source file:org.alfresco.module.vti.web.fp.PropfindMethod.java

License:Open Source License

/**
 * Output the supported lock types XML element
 * //from  w w w .  j  av  a 2 s .c om
 * @param xml XMLWriter
 */
protected void writeLockTypes(XMLWriter xml) {
    try {
        AttributesImpl nullAttr = getDAVHelper().getNullAttributes();

        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_SUPPORTED_LOCK, WebDAV.XML_NS_SUPPORTED_LOCK, nullAttr);

        xml.startElement(WebDAV.DAV_NS, "lockentry", "D:lockentry", nullAttr);

        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_SCOPE, WebDAV.XML_NS_LOCK_SCOPE, nullAttr);
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_EXCLUSIVE));
        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_SCOPE, WebDAV.XML_NS_LOCK_SCOPE);

        xml.startElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_TYPE, WebDAV.XML_NS_LOCK_TYPE, nullAttr);
        xml.write(DocumentHelper.createElement(WebDAV.XML_NS_WRITE));
        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_LOCK_TYPE, WebDAV.XML_NS_LOCK_TYPE);

        xml.endElement(WebDAV.DAV_NS, "lockentry", "D:lockentry");

        xml.endElement(WebDAV.DAV_NS, WebDAV.XML_SUPPORTED_LOCK, WebDAV.XML_NS_SUPPORTED_LOCK);
    } catch (Exception ex) {
        throw new AlfrescoRuntimeException("XML write error", ex);
    }
}