Package org.exoplatform.common.util

Examples of org.exoplatform.common.util.HierarchicalProperty


      node.getNode("jcr:content").addNode("node", "nt:unstructured").setProperty("node-prop", "prop");
      node.getNode("jcr:content").setProperty("exo:prop", "prop");

      // test
      HierarchicalProperty body = new HierarchicalProperty("D:propfind", null, "DAV:");
      body.addChild(new HierarchicalProperty("D:allprop", null, "DAV:"));
      Response resp = new PropFindCommand().propfind(session, path, body, Depth.INFINITY_VALUE, "http://localhost");

      ByteArrayOutputStream bas = new ByteArrayOutputStream();
      ((PropFindResponseEntity)resp.getEntity()).write(bas);
      System.out.println(">>>>>>>>>>RESSSSSSSSSSSP>>>>>>>>>>>>>>> " + new String(bas.toByteArray()));
View Full Code Here


      node.getNode("jcr:content").addNode("node", "nt:unstructured").setProperty("node-prop", "prop");
      node.getNode("jcr:content").setProperty("exo:prop", "prop");
      node.save();

      // test
      HierarchicalProperty body = new HierarchicalProperty("D:propfind", null, "DAV:");
      body.addChild(new HierarchicalProperty("D:allprop", null, "DAV:"));
      Response resp = new PropFindCommand().propfind(session, path, body, Depth.INFINITY_VALUE, "http://localhost");
      ByteArrayOutputStream bas = new ByteArrayOutputStream();
      ((PropFindResponseEntity)resp.getEntity()).write(bas);
      String find = new String(bas.toByteArray());
      assertFalse(find.contains("jcr:lockOnwer"));
View Full Code Here

      assertEquals(HTTPStatus.MULTISTATUS, response.getStatus());
      assertNotNull(response.getEntity());

      HierarchicalPropertyEntityProvider provider = new HierarchicalPropertyEntityProvider();
      InputStream inputStream = TestUtils.getResponseAsStream(response);
      HierarchicalProperty multistatus = provider.readFrom(null, null, null, null, null, inputStream);

      assertEquals(new QName("DAV:", "multistatus"), multistatus.getName());
      assertEquals(1, multistatus.getChildren().size());

      HierarchicalProperty resourceProp = multistatus.getChildren().get(0);

      HierarchicalProperty resourceHref = resourceProp.getChild(new QName("DAV:", "href"));
      assertNotNull(resourceHref);
      assertEquals(BASE_URI + getPathWS() + "/", resourceHref.getValue());

      HierarchicalProperty propstatProp = resourceProp.getChild(new QName("DAV:", "propstat"));
      HierarchicalProperty propProp = propstatProp.getChild(new QName("DAV:", "prop"));

      HierarchicalProperty ownerProp = propProp.getChild(new QName("DAV:", "owner"));
      HierarchicalProperty ownerHrefProp = ownerProp.getChild(new QName("DAV:", "href"));

      assertEquals("__system", ownerHrefProp.getValue());

      HierarchicalProperty aclProp = propProp.getChild(ACLProperties.ACL);
      assertEquals(1, aclProp.getChildren().size());

      HierarchicalProperty aceProp = aclProp.getChild(ACLProperties.ACE);
      assertEquals(2, aceProp.getChildren().size());

      HierarchicalProperty principalProp = aceProp.getChild(ACLProperties.PRINCIPAL);
      assertEquals(1, principalProp.getChildren().size());

      HierarchicalProperty allProp = principalProp.getChild(ACLProperties.ALL);
      assertNotNull(allProp);

      HierarchicalProperty grantProp = aceProp.getChild(ACLProperties.GRANT);
      assertEquals(2, grantProp.getChildren().size());

      HierarchicalProperty writeProp = grantProp.getChild(0).getChild(ACLProperties.WRITE);
      assertNotNull(writeProp);
      HierarchicalProperty readProp = grantProp.getChild(1).getChild(ACLProperties.READ);
      assertNotNull(readProp);
   }
View Full Code Here

      assertEquals(HTTPStatus.MULTISTATUS, cres.getStatus());

      HierarchicalPropertyEntityProvider provider = new HierarchicalPropertyEntityProvider();
      InputStream inputStream = TestUtils.getResponseAsStream(cres);
      HierarchicalProperty multistatus = provider.readFrom(null, null, null, null, null, inputStream);

      assertEquals(new QName("DAV:", "multistatus"), multistatus.getName());
      assertEquals(1, multistatus.getChildren().size());

      HierarchicalProperty resourceProp = multistatus.getChildren().get(0);

      HierarchicalProperty resourceHref = resourceProp.getChild(new QName("DAV:", "href"));
      assertNotNull(resourceHref);
      assertEquals(BASE_URI + getPathWS() + testNode.getPath() + "/", resourceHref.getValue());

      HierarchicalProperty propstatProp = resourceProp.getChild(new QName("DAV:", "propstat"));
      HierarchicalProperty propProp = propstatProp.getChild(new QName("DAV:", "prop"));

      HierarchicalProperty aclProp = propProp.getChild(ACLProperties.ACL);
      assertEquals(1, aclProp.getChildren().size());

      HierarchicalProperty aceProp = aclProp.getChild(ACLProperties.ACE);
      assertEquals(2, aceProp.getChildren().size());

      HierarchicalProperty principalProp = aceProp.getChild(ACLProperties.PRINCIPAL);
      assertEquals(1, principalProp.getChildren().size());

      assertEquals(userName, principalProp.getChildren().get(0).getValue());

      HierarchicalProperty grantProp = aceProp.getChild(ACLProperties.GRANT);
      assertEquals(2, grantProp.getChildren().size());

      HierarchicalProperty writeProp = grantProp.getChild(0).getChild(ACLProperties.WRITE);
      assertNotNull(writeProp);
      HierarchicalProperty readProp = grantProp.getChild(1).getChild(ACLProperties.READ);
      assertNotNull(readProp);

   }
View Full Code Here

            writeAttributes(xmlStreamWriter, prop);

            for (int i = 0; i < prop.getChildren().size(); i++)
            {
               HierarchicalProperty property = prop.getChildren().get(i);
               writeProperty(xmlStreamWriter, property);
            }
            xmlStreamWriter.writeEndElement();
         }
         else
View Full Code Here

   public HierarchicalProperty getProperty(QName name) throws PathNotFoundException, AccessDeniedException,
      RepositoryException
   {
      if (DeltaVConstants.VERSIONNAME.equals(name))
      {
         return new HierarchicalProperty(name, version.getName());
      }
      else if (DeltaVConstants.DISPLAYNAME.equals(name))
      {
         return new HierarchicalProperty(name, version.getName());
      }
      else if (DeltaVConstants.VERSIONHISTORY.equals(name))
      {
         return new HierarchicalProperty(name);
      }
      else if (DeltaVConstants.CHECKEDIN.equals(name))
      {

         HierarchicalProperty checkedInProperty = new HierarchicalProperty(name);
         HierarchicalProperty href = checkedInProperty.addChild(new HierarchicalProperty(new QName("DAV:", "href")));
         href.setValue(identifier.toASCIIString());
         return checkedInProperty;

      }
      else if (DeltaVConstants.PREDECESSORSET.equals(name))
      {
         Version[] predecessors = version.getPredecessors();
         HierarchicalProperty predecessorsProperty = new HierarchicalProperty(name);
         for (Version curVersion : predecessors)
         {
            if ("jcr:rootVersion".equals(curVersion.getName()))
            {
               continue;
            }

            String versionHref =
               versionedResource.getIdentifier().toASCIIString() + "/?version=" + curVersion.getName();
            HierarchicalProperty href =
               predecessorsProperty.addChild(new HierarchicalProperty(new QName("DAV:", "href")));
            href.setValue(versionHref);
         }
         return predecessorsProperty;

      }
      else if (DeltaVConstants.SUCCESSORSET.equals(name))
      {
         Version[] successors = version.getSuccessors();
         HierarchicalProperty successorsProperty = new HierarchicalProperty(name);
         for (Version curVersion : successors)
         {
            String versionHref =
               versionedResource.getIdentifier().toASCIIString() + "/?version=" + curVersion.getName();
            HierarchicalProperty href =
               successorsProperty.addChild(new HierarchicalProperty(new QName("DAV:", "href")));
            href.setValue(versionHref);
         }
         return successorsProperty;

      }
      else if (DeltaVConstants.RESOURCETYPE.equals(name))
      {
         HierarchicalProperty resourceType = new HierarchicalProperty(name);
         if (versionedResource.isCollection())
         {
            // new HierarchicalProperty("DAV:", "collection")
            resourceType.addChild(new HierarchicalProperty(new QName("DAV:", "collection")));
         }
         return resourceType;

      }
      else if (DeltaVConstants.GETCONTENTLENGTH.equals(name))
      {
         if (versionedResource.isCollection())
         {
            throw new PathNotFoundException();
         }
         HierarchicalProperty getContentLength = new HierarchicalProperty(name);
         Property jcrDataProperty = contentNode().getProperty("jcr:data");
         getContentLength.setValue("" + jcrDataProperty.getLength());
         return getContentLength;

      }
      else if (DeltaVConstants.GETCONTENTTYPE.equals(name))
      {
         if (versionedResource.isCollection())
         {
            throw new PathNotFoundException();
         }

         HierarchicalProperty getContentType = new HierarchicalProperty(name);
         Property mimeType = contentNode().getProperty("jcr:mimeType");
         getContentType.setValue(mimeType.getString());
         return getContentType;

      }
      else if (DeltaVConstants.CREATIONDATE.equals(name))
      {
         Calendar created = version.getNode("jcr:frozenNode").getProperty("jcr:created").getDate();
         HierarchicalProperty creationDate = new HierarchicalProperty(name, created, CREATION_PATTERN);
         creationDate.setAttribute("b:dt", "dateTime.tz");
         return creationDate;

      }
      else if (DeltaVConstants.GETLASTMODIFIED.equals(name))
      {
         Calendar created = version.getNode("jcr:frozenNode").getProperty("jcr:created").getDate();
         HierarchicalProperty creationDate = new HierarchicalProperty(name, created, MODIFICATION_PATTERN);
         creationDate.setAttribute("b:dt", "dateTime.rfc1123");
         return creationDate;

      }
      else
      {
View Full Code Here

         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)
            {
               return Response.ok().header(HttpHeaders.CONTENT_LENGTH, Long.toString(contentLength)).header(
View Full Code Here

   public Set<HierarchicalProperty> getProperties(boolean namesOnly) throws PathNotFoundException,
      AccessDeniedException, RepositoryException
   {
      Set<HierarchicalProperty> props = super.getProperties(namesOnly);

      props.add(namesOnly ? new HierarchicalProperty(GETLASTMODIFIED) : getProperty(GETLASTMODIFIED));
      props.add(namesOnly ? new HierarchicalProperty(GETCONTENTLENGTH) : getProperty(GETCONTENTLENGTH));
      props.add(namesOnly ? new HierarchicalProperty(GETCONTENTTYPE) : getProperty(GETCONTENTTYPE));

      QName nodeTypeName = namespaceContext.createQName("jcr:nodeType");
      HierarchicalProperty noneTypeProp =
         new HierarchicalProperty(nodeTypeName, contentNode().getPrimaryNodeType().getName());
      props.add(noneTypeProp);

      Set<QName> presents = new HashSet<QName>();

      PropertyIterator jcrProps = node.getProperties();
      while (jcrProps.hasNext())
      {
         Property property = jcrProps.nextProperty();
         if (!FILE_SKIP.contains(property.getName()))
         {
            QName name = namespaceContext.createQName(property.getName());
            presents.add(name);
            props.add((namesOnly) ? new HierarchicalProperty(name) : getProperty(name));
            if (name.getLocalPart().equals("isCheckedOut"))
            {
               QName qname = namespaceContext.createQName("D:checked-in");
               presents.add(qname);
               props.add(new HierarchicalProperty(qname));
            }
         }
      }

      jcrProps = contentNode().getProperties();
      HierarchicalProperty jcrContentProp =
         new HierarchicalProperty(namespaceContext.createQName(WebDavConst.NodeTypes.JCR_CONTENT));

      while (jcrProps.hasNext())
      {
         Property property = jcrProps.nextProperty();
         if (!CONTENT_SKIP.contains(property.getName()))
         {
            QName name = namespaceContext.createQName(property.getName());

            if (presents.contains(name))
            {
               continue;
            }

            jcrContentProp.addChild((namesOnly) ? new HierarchicalProperty(name) : getProperty(name));
         }
      }

      if (!jcrContentProp.getChildren().isEmpty())
      {
         props.add(jcrContentProp);
      }
      return props;
   }
View Full Code Here

   public HierarchicalProperty getProperty(QName name) throws PathNotFoundException, AccessDeniedException,
      RepositoryException
   {
      if (name.equals(DISPLAYNAME))
      {
         return new HierarchicalProperty(name, node.getName());
      }
      else if (name.equals(CREATIONDATE))
      {
         Calendar created = node.getProperty("jcr:created").getDate();

         HierarchicalProperty creationDate = new HierarchicalProperty(name, created, CREATION_PATTERN);
         creationDate.setAttribute("b:dt", "dateTime.tz");
         return creationDate;
      }
      else if (name.equals(CHILDCOUNT))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(GETCONTENTLENGTH))
      {
         return new HierarchicalProperty(name, String.valueOf(dataProperty().getLength()));
      }
      else if (name.equals(GETCONTENTTYPE))
      {
         return new HierarchicalProperty(name, contentNode().getProperty("jcr:mimeType").getString());
      }
      else if (name.equals(GETLASTMODIFIED))
      {
         Calendar modified;
         try
         {
            modified = contentNode().getProperty("jcr:lastModified").getDate();
         }
         catch (PathNotFoundException e)
         {
            modified = node.getProperty("jcr:created").getDate();
         }
         HierarchicalProperty lastModified = new HierarchicalProperty(name, modified, MODIFICATION_PATTERN);
         lastModified.setAttribute("b:dt", "dateTime.rfc1123");
         return lastModified;
      }
      else if (name.equals(HASCHILDREN))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(ISCOLLECTION))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(ISFOLDER))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(ISROOT))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(PARENTNAME))
      {
         return new HierarchicalProperty(name, node.getParent().getName());
      }
      else if (name.equals(RESOURCETYPE))
      {
         return new HierarchicalProperty(name);
      }
      else if (name.equals(SUPPORTEDLOCK))
      {
         if (!node.canAddMixin("mix:lockable"))
         {
            throw new PathNotFoundException();
         }
         return supportedLock();
      }
      else if (name.equals(LOCKDISCOVERY))
      {
         if (node.isLocked())
         {
            String token = node.getLock().getLockToken();
            String owner = node.getLock().getLockOwner();
            return lockDiscovery(token, owner, "86400");
         }
         else
         {
            throw new PathNotFoundException();
         }
      }
      else if (name.equals(ISVERSIONED))
      {
         return new HierarchicalProperty(name, "0");
      }
      else if (name.equals(SUPPORTEDMETHODSET))
      {
         return supportedMethodSet();
      }
      else
      {
         try
         {
            Property property = node.getProperty(WebDavNamespaceContext.createName(name));
            String propertyValue;
            if (property.getDefinition().isMultiple())
            {
               if (property.getValues().length == 0)
               {
                  throw new PathNotFoundException();
               }

               propertyValue = property.getValues()[0].getString();
            }
            else
            {
               propertyValue = property.getString();
            }
            return new HierarchicalProperty(name, propertyValue);
         }
         catch (PathNotFoundException e)
         {
            Property property = contentNode().getProperty(WebDavNamespaceContext.createName(name));
            String propertyValue;
            if (property.getDefinition().isMultiple())
            {
               if (property.getValues().length >= 1)
               {
                  propertyValue = property.getValues()[0].getString();
               }
               else
               {
                  // this means that we return empty value, because according to WebDAV spec:
                  // this is a property whose semantics and syntax are not enforced by the server
                  // the server only records the value of a dead property;
                  // the client is responsible for maintaining the consistency of the syntax and semantics of a dead property.
                  propertyValue = "";
               }
            }
            else
            {
               propertyValue = property.getString();
            }
            return new HierarchicalProperty(name, propertyValue);
         }
      }
   }
View Full Code Here

         {
            QName name = namespaceContext.createQName(property.getName());

            try
            {
               props.add((namesOnly) ? new HierarchicalProperty(name) : getProperty(name));
            }
            catch (Exception exc)
            {
               if (LOG.isDebugEnabled())
                  LOG.error(exc.getMessage(), exc);
View Full Code Here

TOP

Related Classes of org.exoplatform.common.util.HierarchicalProperty

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.