Package org.apache.sling.api.resource

Examples of org.apache.sling.api.resource.ModifiableValueMap


    store.save(msg);

    final Resource r = resolver.getResource(getResourcePath(msg, store));
    assertNotNull("Expecting non-null Resource", r);
    final ModifiableValueMap m = r.adaptTo(ModifiableValueMap.class);

    File bodyFile = new File(TU.TEST_FOLDER, specialPathFromFilePath(messageFile, BODY_SUFFIX));
    if (bodyFile.exists()) {
      String expectedBody = readTextFile(bodyFile);
      assertValueMap(m, "Body", expectedBody);
View Full Code Here


    /**
     * {@inheritDoc}
     */
    public boolean add(Resource res, Map<String, Object> properties) throws PersistenceException {
        if (res != null && !contains(res)) {
          ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
          String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
         
          order = (String[]) ArrayUtils.add(order, res.getPath());
          vm.put(ResourceCollectionConstants.REFERENCES_PROP, order);
         
          if (properties == null) {
            properties = new HashMap<String, Object>();
          }
            properties.put(ResourceCollectionConstants.REF_PROPERTY, res.getPath());
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public boolean add(Resource res) throws PersistenceException {
        if (res != null && !contains(res)) {
          ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
          String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
         
          order = (String[]) ArrayUtils.add(order, res.getPath());
          vm.put(ResourceCollectionConstants.REFERENCES_PROP, order);
         
          Map<String, Object> properties = new HashMap<String, Object>();
          properties.put(ResourceCollectionConstants.REF_PROPERTY, res.getPath());
            resolver.create(
                membersResource,
View Full Code Here

        if (tobeRemovedRes == null) {
          return false;
        }
        resolver.delete(tobeRemovedRes);
        //remove from order array
        ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
      String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
     
      int index = ArrayUtils.indexOf(order, res.getPath(), 0);
     
      order = (String[]) ArrayUtils.remove(order, index);
      vm.put(ResourceCollectionConstants.REFERENCES_PROP, order);
     
      return true;
    }
View Full Code Here

     *
     * @param type <code>sling:resourceType</code> to be set on the content node
     * @return
     */
    public void setType(String type) throws PersistenceException {
        ModifiableValueMap mvp = resource.adaptTo(ModifiableValueMap.class);
        mvp.put(RESOURCE_TYPE, type);
    }
View Full Code Here

     public void orderBefore(Resource srcResource, Resource destResource) {
    if (srcResource == null) {
      throw new IllegalArgumentException("Source Resource can not be null");
    }
    ModifiableValueMap vm = membersResource.adaptTo(ModifiableValueMap.class);
      String[] order = vm.get(ResourceCollectionConstants.REFERENCES_PROP, new String[]{});
      String srcPath = srcResource.getPath();
    int srcIndex = ArrayUtils.indexOf(order, srcPath);
      if (srcIndex < 0) {
        log.warn("Collection ordering failed, as there is no resource {} in collection {} for destResource",
            srcPath, getPath());
        return ;
      }
    if (destResource == null) {
      //add it to the end.
      order = (String[]) ArrayUtils.remove(order, srcIndex);
      order = (String[]) ArrayUtils.add(order, srcPath);
    } else {
      String destPath = destResource.getPath();
     
      if (destPath.equals(srcPath)) {
        String message = MessageFormat.format("Collection ordering failed, as source {0} and destination {1} can not be same",
              srcPath, destPath);
        log.error(message);
        throw new IllegalArgumentException(message);
      }
     
      int destIndex = ArrayUtils.indexOf(order, destPath);
     
      if (destIndex < 0) {
        log.warn("Collection ordering failed, as there is no resource {} in collection {} for destResource",
            destPath, getPath());
        return;
      }
     
      order = (String[]) ArrayUtils.remove(order, srcIndex);
      if (srcIndex < destIndex) { //recalculate dest index
        destIndex = ArrayUtils.indexOf(order, destPath);
      }
      order = (String[]) ArrayUtils.add(order, destIndex, srcPath);
    }
   
    vm.put(ResourceCollectionConstants.REFERENCES_PROP, order);
  }
View Full Code Here

    }

    public void acquire() {
        synchronized (syncObject) {
            Resource resource = getProxyResource();
            ModifiableValueMap valueMap = resource.adaptTo(ModifiableValueMap.class);
            int refCount = valueMap.get(PN_REFERENCE_COUNT, 0);
            refCount ++;
            valueMap.put(PN_REFERENCE_COUNT, refCount);

            try {
                resourceResolver.commit();
            } catch (PersistenceException e) {
                log.error("cannot release package", e);
View Full Code Here

    }

    public void release() {
        synchronized (syncObject) {
            Resource resource = getProxyResource();
            ModifiableValueMap valueMap = resource.adaptTo(ModifiableValueMap.class);
            int refCount = valueMap.get(PN_REFERENCE_COUNT, 0);
            refCount --;

            if (refCount > 0) {
                valueMap.put(PN_REFERENCE_COUNT, refCount);
            }
            else {
                delete();
            }
View Full Code Here

      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
    } else if (type.equals(ModifiableValueMap.class)) {
      return (AdapterType) new ModifiableValueMap() {

        public Collection<Object> values() {
          throw new UnsupportedOperationException();
        }
View Full Code Here

            final Resource parentResource = ResourceUtil.getOrCreateResource(resolver, ResourceUtil.getParent(createPath), (String)null, null, false);
            resolver.create(parentResource, ResourceUtil.getName(createPath), properties);
        } else {
            final Resource hidingResource = resolver.getResource(holder.highestResourcePath);
            if ( hidingResource != null ) {
                final ModifiableValueMap mvm = hidingResource.adaptTo(ModifiableValueMap.class);
                mvm.remove(MergedResourceConstants.PN_HIDE_RESOURCE);
                mvm.putAll(properties);
            }
            // TODO check parent hiding
        }
        return this.getResource(resolver, path);
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.api.resource.ModifiableValueMap

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.