Package org.apache.sling.api.resource

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


            resolver.refresh();
            newRefreshed = true;
        }
        try {
            Resource resource = resolver.getResource(path);
            final ValueMap props = resource.adaptTo(ValueMap.class);
            if (props.containsKey(PROP_VANITY_PATH)) {
                doAddVanity(path);
            }
            if (props.containsKey(ResourceResolverImpl.PROP_ALIAS)) {
                doAddAlias(path);
            }
            if (path.startsWith(this.mapRoot)) {
                doUpdateConfiguration();
            }
View Full Code Here


        vanityTargets.remove(actualContentPath);
    }

    private void doUpdateVanityOrder(String path, boolean deletion) {
        Resource resource = resolver.getResource(path);
        final ValueMap props = resource.adaptTo(ValueMap.class);

        long vanityOrder;
        if (deletion) {
            vanityOrder = 0;
        } else {
            vanityOrder = props.get(PROP_VANITY_ORDER, Long.class);
        }

        String actualContentPath = getActualContentPath(path);
        List<String> vanityPaths = vanityTargets.get(actualContentPath);
        if (vanityPaths != null) {
View Full Code Here

     *         converted into the requested {@code type}
     */
    public static <Type> Type getProperty(final Resource res, final String propName, final Class<Type> type) {

        // check the property in the resource itself
        final ValueMap props = res.adaptTo(ValueMap.class);
        if (props != null) {
            Type prop = props.get(propName, type);
            if (prop != null) {
                return prop;
            }
            // otherwise, check it in the jcr:content child resource
            // This is a special case checking for JCR based resources
            // we directly use the deep resolution of properties of the
            // JCR value map implementation - this does not work
            // in non JCR environments, however in non JCR envs there
            // is usually no "jcr:content" child node anyway
            prop = props.get("jcr:content/" + propName, type);
            return prop;
        }

        return null;
    }
View Full Code Here

            if (path.endsWith("/jcr:content")) {
                path =  path.substring(0, path.length() - "/jcr:content".length());
                final Resource resource = resolver.getResource(path)
                if (resource != null) {
                    path =  resource.getPath();           
                    final ValueMap props = resource.adaptTo(ValueMap.class);
                    if (props.get(ResourceResolverImpl.PROP_ALIAS, String[].class) != null) {
                        doAddAlias(path);
                    }
                }
            } 
        } else {
            final Resource resource = resolver.getResource(path)
            if (resource != null) {
                if (resource.getName().equals("jcr:content")) { 
                    final Resource parent = resource.getParent();
                    path =  parent.getPath();           
                    final ValueMap props = parent.adaptTo(ValueMap.class);
                    if (props.get(ResourceResolverImpl.PROP_ALIAS, String[].class) != null) {
                        doAddAlias(path);
                    }
                } else if (resource.getChild("jcr:content") != null) {
                    Resource jcrContent = resource.getChild("jcr:content");
                    path =  jcrContent.getPath();        
                    final ValueMap props = jcrContent.adaptTo(ValueMap.class);
                    if (props.get(ResourceResolverImpl.PROP_ALIAS, String[].class) != null) {
                        doAddAlias(path);
                    }
                }
            }
        }
View Full Code Here

                log.debug("isValidVanityPath: not valid as not in white list {}", resource);
                return false;
            }
        }
        // require properties
        final ValueMap props = resource.adaptTo(ValueMap.class);
        if (props == null) {
            log.debug("isValidVanityPath: not valid {} without properties", resource);
            return false;
        }
        return true;
View Full Code Here

                    final Resource parent, final String parentPath) {
        // scheme list
        final Iterator<Resource> children = parent.listChildren();
        while (children.hasNext()) {
            final Resource child = children.next();
            final ValueMap vm = ResourceUtil.getValueMap(child);

            String name = vm.get(PROP_REG_EXP, String.class);
            boolean trailingSlash = false;
            if (name == null) {
                name = child.getName().concat("/");
                trailingSlash = true;
            }
View Full Code Here

            log.debug("loadAliases: Ignoring {}", resource);
            return;
        }

        // require properties
        final ValueMap props = resource.adaptTo(ValueMap.class);
        if (props == null) {
            log.debug("loadAliases: Ignoring {} without properties", resource);
            return;
        }

        final String resourceName;
        final String parentPath;
        if (resource.getName().equals("jcr:content")) {
            final Resource containingResource = resource.getParent();
            parentPath = containingResource.getParent().getPath();
            resourceName = containingResource.getName();
        } else {
            parentPath = resource.getParent().getPath();
            resourceName = resource.getName();
        }
        Map<String, String> parentMap = map.get(parentPath);
        for (final String alias : props.get(ResourceResolverImpl.PROP_ALIAS, String[].class)) {
            if (parentMap != null && parentMap.containsKey(alias)) {
                log.warn("Encountered duplicate alias {} under parent path {}. Refusing to replace current target {} with {}.", new Object[] {
                        alias,
                        parentPath,
                        parentMap.get(alias),
View Full Code Here

       
        if (!isValidVanityPath(resource)) {           
            return;
        }
       
        final ValueMap props = resource.adaptTo(ValueMap.class);
        long vanityOrder = 0;
        if (props.containsKey(PROP_VANITY_ORDER)) {
            vanityOrder = props.get(PROP_VANITY_ORDER, Long.class);
        }  

        // url is ignoring scheme and host.port and the path is
        // what is stored in the sling:vanityPath property
        final String[] pVanityPaths = props.get(PROP_VANITY_PATH, new String[0]);
        for (final String pVanityPath : pVanityPaths) {
            final String[] result = this.getVanityPathDefinition(pVanityPath);
            if (result != null) {
                final String url = result[0] + result[1];
                // redirect target is the node providing the
                // sling:vanityPath
                // property (or its parent if the node is called
                // jcr:content)
                final Resource redirectTarget;
                if (resource.getName().equals("jcr:content")) {
                    redirectTarget = resource.getParent();
                } else {
                    redirectTarget = resource;
                }
                final String redirect = redirectTarget.getPath();
                final String redirectName = redirectTarget.getName();

                // whether the target is attained by a external redirect or
                // by an internal redirect is defined by the sling:redirect
                // property
                final int status = props.get(PROP_REDIRECT_EXTERNAL, false) ? props.get(
                        PROP_REDIRECT_EXTERNAL_REDIRECT_STATUS, factory.getDefaultVanityPathRedirectStatus())
                        : -1;

                final String checkPath = result[1];
View Full Code Here

        return null;
    }

    public static MapEntry createResolveEntry(String url, final Resource resource,
                    final boolean trailingSlash) {
        final ValueMap props = resource.adaptTo(ValueMap.class);
        if (props != null) {

            // ensure the url contains a port number (if possible)
            url = fixUriPath(url);

            final String redirect = props.get(
                            MapEntries.PROP_REDIRECT_EXTERNAL, String.class);
            if (redirect != null) {
                final int status = props
                                .get(MapEntries.PROP_REDIRECT_EXTERNAL_STATUS,
                                                302);
                return new MapEntry(url, status, trailingSlash, 0, redirect);
            }

            final String[] internalRedirectProps = props.get(ResourceResolverImpl.PROP_REDIRECT_INTERNAL,
                String[].class);
            final String[] internalRedirect = filterRegExp(internalRedirectProps);
            if (internalRedirect != null) {
                return new MapEntry(url, -1, trailingSlash, 0, internalRedirect);
            }
View Full Code Here

            private ValueMap nextObject = this.seek();

            private Iterator<ValueMap> nextResourceIter;

            private ValueMap seek() {
                ValueMap result = null;
                if ( nextResourceIter == null || !nextResourceIter.hasNext() ) {
                    nextResourceIter = null;
                    while ( i.hasNext() && nextResourceIter == null ) {
                        final QueriableResourceProvider adap = i.next();
                        nextResourceIter = adap.queryResources(resolver, query, language);
                    }
                }
                if ( nextResourceIter != null ) {
                    while ( nextResourceIter.hasNext() && result == null ) {
                        result = nextResourceIter.next();
                    }
                    if ( result == null ) {
                        result = seek();
                    }
                }
                return result;
            }

            /**
             * @see java.util.Iterator#hasNext()
             */
            public boolean hasNext() {
                return this.nextObject != null;
            }

            /**
             * @see java.util.Iterator#next()
             */
            public ValueMap next() {
                if ( this.nextObject == null ) {
                    throw new NoSuchElementException();
                }
                final ValueMap result = this.nextObject;
                this.nextObject = this.seek();
                return result;
            }

            /**
 
View Full Code Here

TOP

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

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.