Package org.exoplatform.services.jcr.webdav.resource

Examples of org.exoplatform.services.jcr.webdav.resource.Resource


         Node node = (Node)session.getItem(path);

         WebDavNamespaceContext nsContext = new WebDavNamespaceContext(session);
         URI uri = new URI(TextUtil.escape(baseURI + node.getPath(), '%', true));

         Resource resource;
         InputStream istream;

         if (ResourceUtil.isFile(node))
         {

            HierarchicalProperty lastModifiedProperty;
           
            if (version != null)
            {
               VersionedResource versionedFile = new VersionedFileResource(uri, node, nsContext);
               resource = versionedFile.getVersionHistory().getVersion(version);
              
               lastModifiedProperty = resource.getProperty(FileResource.GETLASTMODIFIED);
               istream = ((VersionResource)resource).getContentAsStream();
            }
            else
            {
               resource = new FileResource(uri, node, nsContext);
              
               lastModifiedProperty = resource.getProperty(FileResource.GETLASTMODIFIED);
               istream = ((FileResource)resource).getContentAsStream();
            }

            // check before any other reads
            if (ifModifiedSince != null)
            {
               DateFormat dateFormat = new SimpleDateFormat(WebDavConst.DateFormat.MODIFICATION, Locale.US);
               Date lastModifiedDate = dateFormat.parse(lastModifiedProperty.getValue());
              
               dateFormat = new SimpleDateFormat(WebDavConst.DateFormat.IF_MODIFIED_SINCE_PATTERN, Locale.US);
               Date ifModifiedSinceDate = dateFormat.parse(ifModifiedSince);
              
               if(ifModifiedSinceDate.getTime() >= lastModifiedDate.getTime()){
                  return Response.notModified().entity("Not Modified").build();
               }
            }

            HierarchicalProperty contentLengthProperty = resource.getProperty(FileResource.GETCONTENTLENGTH);
            long contentLength = new Long(contentLengthProperty.getValue());

            // content length is not present
            if (contentLength == 0)
            {
               return Response.ok().header(ExtHttpHeaders.ACCEPT_RANGES, "bytes").entity(istream).build();
            }

            HierarchicalProperty mimeTypeProperty = resource.getProperty(FileResource.GETCONTENTTYPE);
            String contentType = mimeTypeProperty.getValue();

            // no ranges request
            if (ranges.size() == 0)
            {
View Full Code Here


         Node node = (Node)session.getItem(path);

         WebDavNamespaceContext nsContext = new WebDavNamespaceContext(session);
         URI uri = new URI(TextUtil.escape(baseURI + node.getPath(), '%', true));

         Resource resource;
         InputStream istream;

         if (ResourceUtil.isFile(node))
         {

            HierarchicalProperty lastModifiedProperty;
           
            if (version != null)
            {
               VersionedResource versionedFile = new VersionedFileResource(uri, node, nsContext);
               resource = versionedFile.getVersionHistory().getVersion(version);
              
               lastModifiedProperty = resource.getProperty(FileResource.GETLASTMODIFIED);
               istream = ((VersionResource)resource).getContentAsStream();
            }
            else
            {
               resource = new FileResource(uri, node, nsContext);
              
               lastModifiedProperty = resource.getProperty(FileResource.GETLASTMODIFIED);
               istream = ((FileResource)resource).getContentAsStream();
            }

            // check before any other reads
           
            if (ifModifiedSince != null)
            {
               DateFormat dateFormat = new SimpleDateFormat(WebDavConst.DateFormat.MODIFICATION, Locale.US);
               Date lastModifiedDate = dateFormat.parse(lastModifiedProperty.getValue());
              
               dateFormat = new SimpleDateFormat(WebDavConst.DateFormat.IF_MODIFIED_SINCE_PATTERN, Locale.US);
               Date ifModifiedSinceDate = dateFormat.parse(ifModifiedSince);
              
               if(ifModifiedSinceDate.getTime() >= lastModifiedDate.getTime()){
                  return Response.notModified().entity("Not Modified").build();
               }
            }

            HierarchicalProperty contentLengthProperty = resource.getProperty(FileResource.GETCONTENTLENGTH);
            long contentLength = new Long(contentLengthProperty.getValue());

            // content length is not present
            if (contentLength == 0)
            {
               return Response.ok().header(ExtHttpHeaders.ACCEPT_RANGES, "bytes").entity(istream).build();
            }

            HierarchicalProperty mimeTypeProperty = resource.getProperty(FileResource.GETCONTENTTYPE);
            String contentType = mimeTypeProperty.getValue();

            // no ranges request
            if (ranges.size() == 0)
            {
View Full Code Here

         Node node = (Node)session.getItem(path);

         WebDavNamespaceContext nsContext = new WebDavNamespaceContext(session);
         URI uri = new URI(TextUtil.escape(baseURI + node.getPath(), '%', true));

         Resource resource;

         if (ResourceUtil.isFile(node))
         {
            HierarchicalProperty lastModifiedProperty;
            String resourceEntityTag;

            if (version != null)
            {
               VersionedResource versionedFile = new VersionedFileResource(uri, node, nsContext);
               resource = versionedFile.getVersionHistory().getVersion(version);

               lastModifiedProperty = resource.getProperty(FileResource.GETLASTMODIFIED);
            }
            else
            {
               resource = new FileResource(uri, node, nsContext);

               lastModifiedProperty = resource.getProperty(FileResource.GETLASTMODIFIED);
            }

            resourceEntityTag = ResourceUtil.generateEntityTag(node, lastModifiedProperty.getValue());

            // check before any other reads
            if (ifNoneMatch != null)
            {
               if ("*".equals(ifNoneMatch))
               {
                  return Response.notModified().entity("Not Modified").build();
               }
               for (String eTag : ifNoneMatch.split(","))
               {
                  if (resourceEntityTag.equals(eTag))
                  {
                     return Response.notModified().entity("Not Modified").build();
                  }
               }
            }
            else if (ifModifiedSince != null)
            {
               DateFormat dateFormat = new SimpleDateFormat(WebDavConst.DateFormat.MODIFICATION, Locale.US);
               Date lastModifiedDate = dateFormat.parse(lastModifiedProperty.getValue());

               dateFormat = new SimpleDateFormat(WebDavConst.DateFormat.IF_MODIFIED_SINCE_PATTERN, Locale.US);
               Date ifModifiedSinceDate = dateFormat.parse(ifModifiedSince);

               if (ifModifiedSinceDate.getTime() >= lastModifiedDate.getTime())
               {
                  return Response.notModified().entity("Not Modified").build();
               }
            }

            HierarchicalProperty contentLengthProperty = resource.getProperty(FileResource.GETCONTENTLENGTH);
            long contentLength = new Long(contentLengthProperty.getValue());

            // content length is not present
            if (contentLength == 0)
            {
               istream = openStream(resource, version != null);
               return Response.ok().header(ExtHttpHeaders.ACCEPT_RANGES, "bytes").entity(istream).build();
            }

            HierarchicalProperty mimeTypeProperty = resource.getProperty(FileResource.GETCONTENTTYPE);
            String contentType = mimeTypeProperty.getValue();

            // no ranges request
            if (ranges.size() == 0)
            {
View Full Code Here

         LOG.error(exc.getMessage(), exc);
         return Response.serverError().entity(exc.getMessage()).build();
      }

      WebDavNamespaceContext nsContext;
      Resource resource;
      try
      {
         nsContext = new WebDavNamespaceContext(session);

         resource = null;
View Full Code Here

         WebDavNamespaceContext nsContext = new WebDavNamespaceContext(session);
         URI uri = new URI(TextUtil.escape(baseURI + node.getPath(), '%', true));

         if (ResourceUtil.isFile(node))
         {
            Resource resource = new FileResource(uri, node, nsContext);

            String lastModified = resource.getProperty(PropertyConstants.GETLASTMODIFIED).getValue();
            String contentType = resource.getProperty(PropertyConstants.GETCONTENTTYPE).getValue();
            String contentLength = resource.getProperty(PropertyConstants.GETCONTENTLENGTH).getValue();

            return Response.ok().header(ExtHttpHeaders.LAST_MODIFIED, lastModified).header(ExtHttpHeaders.CONTENT_TYPE,
               contentType).header(ExtHttpHeaders.CONTENT_LENGTH, contentLength).build();
         }
View Full Code Here

            URI uri = new URI(TextUtil.escape(baseURI + nextNode.getPath(), '%', true));

            // if URI is new, and wasn't previously being written, then write it
            if (resultNodes.add(uri))
            {
               Resource resource;
               if (ResourceUtil.isVersioned(nextNode))
               {
                  if (ResourceUtil.isFile(nextNode))
                  {
                     resource = new VersionedFileResource(uri, nextNode, nsContext);
                  }
                  else
                  {
                     resource = new VersionedCollectionResource(uri, nextNode, nsContext);
                  }
               }
               else
               {
                  if (ResourceUtil.isFile(nextNode))
                  {
                     resource = new FileResource(uri, nextNode, nsContext);
                  }
                  else
                  {
                     resource = new CollectionResource(uri, nextNode, nsContext);
                  }
               }

               xmlStreamWriter.writeStartElement("DAV:", "response");

               xmlStreamWriter.writeStartElement("DAV:", "href");
               xmlStreamWriter.writeCharacters(resource.getIdentifier().toASCIIString());
               xmlStreamWriter.writeEndElement();

               PropstatGroupedRepresentation propstat = new PropstatGroupedRepresentation(resource, properties, false);

               PropertyWriteUtil.writePropStats(xmlStreamWriter, propstat.getPropStats());
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.webdav.resource.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.