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.propfind;
 
 
 import java.util.Set;
 
Created by The eXo Platform SARL .

Author(s):
Gennady Azarenkov
Version:
$Id: $
 
 
 public class PropFindResponseEntity implements StreamingOutput
 {

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

   
XML writer.
 
    protected XMLStreamWriter xmlStreamWriter;

   
Output stream.
 
    protected OutputStream outputStream;

   
Namespace context.
 
    protected final WebDavNamespaceContext namespaceContext;

   
Root resource.
 
    protected final Resource rootResource;

   
The list of properties to get.
 
    protected Set<QNamepropertyNames;

   
Request depth.
 
    protected final int depth;

   
Boolean flag, shows if only property names a requested.
 
    protected final boolean propertyNamesOnly;
   
   
Session.
 
    protected final Session session;

   
Constructor.

Parameters:
depth reqest depth.
rootResource root resource.
propertyNames the list of properties requested
propertyNamesOnly if only property names a requested
   public PropFindResponseEntity(int depthResource rootResourceSet<QNamepropertyNamesboolean propertyNamesOnly,
            Session session)
   {
      this. = rootResource;
      this. = rootResource.getNamespaceContext();
      this. = propertyNames;
      this. = depth;
      this. = propertyNamesOnly;
      this. = session;
   }
   public PropFindResponseEntity(int depthResource rootResourceSet<QNamepropertyNamesboolean propertyNamesOnly)
   {
      this(depthrootResourcepropertyNamespropertyNamesOnlynull);
   }

   
   public void write(OutputStream streamthrows IOException
   {
      this. = stream;
      try
      {
         this. =
            XMLOutputFactory.newInstance().createXMLStreamWriter(.);
         .writeStartElement("D""multistatus""DAV:");
         .writeNamespace("D""DAV:");
         .writeAttribute("xmlns:b""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/");
         traverseResources(, 0);
         // D:multistatus
         .writeEndElement();
         // rootNode.accept(this);
      }
      catch (Exception exc)
      {
         .error(exc.getMessage(), exc);
         throw new IOException(exc.getMessage());
      }
   }

   
   private void traverseResources(Resource resourceint counterthrows XMLStreamExceptionRepositoryException,
   {
      .writeStartElement("DAV:""response");
      .writeStartElement("DAV:""href");
      String href = resource.getIdentifier().toASCIIString();
      if (resource.isCollection())
      {
         .writeCharacters(href + "/");
      }
      else
      {
         .writeCharacters(href);
      }
      PropstatGroupedRepresentation propstat =
      PropertyWriteUtil.writePropStats(propstat.getPropStats());
      int d = ;
      if (resource.isCollection())
      {
         if (counter < d)
         {
            CollectionResource collection = (CollectionResource)resource;
            for (Resource child : collection.getResources())
            {
               traverseResources(childcounter + 1);
            }
         }
      }
   }
New to GrepCode? Check out our FAQ X