Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2009 eXo Platform SAS.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.exoplatform.services.jcr.webdav.command.dasl;
 
 
 import java.net.URI;
 import java.util.Set;
 
 import javax.jcr.Node;
Created by The eXo Platform SAS. Author : Vitaly Guly

Version:
$Id: $
 
 
 public class SearchResultResponseEntity implements StreamingOutput
 {

   
logger.
 
    private static Log log = ExoLogger.getLogger("exo.jcr.component.webdav.SearchResultResponseEntity");

   
Namespace conetext.
 
    private final WebDavNamespaceContext nsContext;

   
Query result.
 
    private QueryResult queryResult;

   
base uri.
 
    private String baseURI;

   
The list of properties.
 
    private static Set<QNameproperties = new HashSet<QName>();
 
    static
    {
       .add(new QName("DAV:""displayname"));
       .add(new QName("DAV:""resourcetype"));
       .add(new QName("DAV:""creationdate"));
       .add(new QName("DAV:""getlastmodified"));
       .add(new QName("DAV:""getcontentlength"));
       .add(new QName("DAV:""getcontenttype"));
    }

   
Constructor.

Parameters:
queryResult Result of request
nsContext namespace context
baseURI base uri
   public SearchResultResponseEntity(QueryResult queryResultfinal WebDavNamespaceContext nsContextString baseURI)
   {
      this. = queryResult;
      this. = nsContext;
      this. = baseURI;
   }

   
   public void write(OutputStream outStreamthrows IOException
   {
      try
      {
         XMLStreamWriter xmlStreamWriter =
            XMLOutputFactory.newInstance().createXMLStreamWriter(outStream.);
         xmlStreamWriter.setNamespaceContext();
         xmlStreamWriter.writeStartDocument();
         xmlStreamWriter.writeStartElement("D""multistatus""DAV:");
         xmlStreamWriter.writeNamespace("D""DAV:");
         xmlStreamWriter.writeAttribute("xmlns:b""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/");
         NodeIterator nodeIter = .getNodes();
         while (nodeIter.hasNext())
         {
            Node nextNode = nodeIter.nextNode();
            if (nextNode.isNodeType("nt:resource"))
            {
               if (nextNode.getParent().isNodeType("nt:file"))
               {
                  nextNode = nextNode.getParent();
               }
               else
               {
                  // skipping
                  continue;
               }
            }
            URI uri = new URI(TextUtil.escape( + nextNode.getPath(), '%'true));
            Resource resource;
            if (ResourceUtil.isVersioned(nextNode))
            {
               if (ResourceUtil.isFile(nextNode))
               {
                  resource = new VersionedFileResource(urinextNode);
               }
               else
               {
                  resource = new VersionedCollectionResource(urinextNode);
               }
            }
            else
            {
               if (ResourceUtil.isFile(nextNode))
               {
                  resource = new FileResource(urinextNode);
               }
               else
               {
                  resource = new CollectionResource(urinextNode);
               }
            }
            xmlStreamWriter.writeStartElement("DAV:""response");
            xmlStreamWriter.writeStartElement("DAV:""href");
            xmlStreamWriter.writeCharacters(resource.getIdentifier().toASCIIString());
            xmlStreamWriter.writeEndElement();
            PropstatGroupedRepresentation propstat = new PropstatGroupedRepresentation(resourcefalse);
            PropertyWriteUtil.writePropStats(xmlStreamWriterpropstat.getPropStats());
            xmlStreamWriter.writeEndElement();
         }
         // D:multistatus
         xmlStreamWriter.writeEndElement();
         xmlStreamWriter.writeEndDocument();
      }
      catch (XMLStreamException exc)
      {
         throw new IOException(exc.getMessage());
      }
      catch (Exception exc)
      {
         .error(exc.getMessage(), exc);
         throw new IOException(exc.getMessage());
      }
   }
New to GrepCode? Check out our FAQ X