Package org.apache.slide.common

Examples of org.apache.slide.common.Uri


    public ObjectNode retrieve(SlideToken token, String strUri,
                               boolean translateLastUriElement)
        throws ServiceAccessException, ObjectNotFoundException,
        LinkedObjectNotFoundException, AccessDeniedException {
       
        Uri uri = namespace.getUri(token, strUri);
       
        ObjectNode result = null;
       
        // First of all, we try to load the object directly from the given Uri.
        try {
            result = uri.getStore().retrieveObject(uri);
            securityHelper.checkCredentials
                (token, result, namespaceConfig.getReadObjectAction());
            if ((translateLastUriElement) && (result instanceof LinkNode)) {
                LinkNode link = (LinkNode) result;
                Uri linkedUri = namespace.getUri(token, link.getLinkedUri());
                result = linkedUri.getStore()
                    .retrieveObject(linkedUri);
                securityHelper.checkCredentials
                    (token, result, namespaceConfig.getReadObjectAction());
            }
        } catch (ObjectNotFoundException e) {
        }
       
        // If the attempt to load the uri failed, it means there is at least
        // one link in the uri (or that the uri doe'sn't have any associated
        // object).
        if (result == null) {
           
            String resolvedUri = uri.toString();
           
            // 1 - Tokemization of the Uri
            UriTokenizer uriTokenizer = new UriTokenizer(token, uri.getNamespace(),
                                                         resolvedUri);
           
            // 2 - For each element of the Uri
            Uri courUri = null;
            ObjectNode courObject = null;
            while (uriTokenizer.hasMoreElements()) {
               
                // 3 - Load object's class from the uri. If the object
                // does not exist, a DataException is thrown.
                courUri = uriTokenizer.nextUri();
                courObject = courUri.getStore()
                    .retrieveObject(courUri);
               
                // We check to see if the credentials gives access to
                //the current object
                securityHelper.checkCredentials
                    (token, courObject, namespaceConfig.getReadObjectAction());
               
                // 4 - Test if object is a link, ie if it is an instance
                // of LinkNode or one of its subclasses
                if (((translateLastUriElement)
                         && (courObject instanceof LinkNode)) ||
                        ((!translateLastUriElement)
                             && (uriTokenizer.hasMoreElements())
                             && (courObject instanceof LinkNode))
                   ) {
                   
                    // 5 - If the object is a link, we get the uri of
                    // the linked object
                    // Note : courUri still IS the Uri of the link, and so,
                    // in a way courUri is the parent of linkedUri.
                    Uri linkedUri = namespace
                        .getUri(((LinkNode) courObject).getLinkedUri());
                   
                    // 6 - We replace the courUri scope in the original uri
                    String courStrUri = courUri.toString();
                    resolvedUri = linkedUri.toString()
                        + resolvedUri.substring(courStrUri.length());
                   
                    // 7 - We tokenize again the uri
                    uriTokenizer = new UriTokenizer(token, uri.getNamespace(),
                                                    resolvedUri);
                   
                    // 8 - We parse it till we get back to the point
                    // where we stopped
                    boolean isUriFound = false;
                    while ((!isUriFound) && (uriTokenizer.hasMoreElements())) {
                        if (linkedUri.equals(uriTokenizer.nextUri())) {
                            isUriFound = true;
                        }
                    }
                    if (!isUriFound) {
                        throw new LinkedObjectNotFoundException(courUri,
View Full Code Here


        Enumeration roles = securityHelper.getRoles(object);
        while (roles.hasMoreElements()) {
            if (!securityHelper.hasRole(token, (String)roles.nextElement())) {
                // Allow only the namespace admin to create roles
                // he doesn't have
                Uri rootUri = namespace.getUri(token, "/");
                ObjectNode rootObject =
                    rootUri.getStore().retrieveObject(rootUri);
                securityHelper.checkCredentials
                    (token, rootObject,
                     namespaceConfig.getGrantPermissionAction());
                break;
            }
        }
       
        String resolvedUri = strUri;
       
        // 1 - Tokenization of the Uri
        UriTokenizer uriTokenizer = new UriTokenizer(token, namespace, resolvedUri);
       
        // 2 - For each element of the Uri
        Uri courUri = null;
        ObjectNode courObject = null;
        ObjectNode parentObject = null;
       
        boolean alreadyExists = false;
       
        while (uriTokenizer.hasMoreElements()) {
           
            parentObject = courObject;
           
            // 3 - Load object's class from the uri. If the object does
            // not exist, a DataException is thrown.
            courUri = uriTokenizer.nextUri();
            try {
                courObject = courUri.getStore()
                    .retrieveObject(courUri);
                securityHelper
                    .checkCredentials(token, courObject,
                                      namespaceConfig.getReadObjectAction());
                if (!uriTokenizer.hasMoreElements()) {
                    // The object already exists
                    alreadyExists = true;
                }
            } catch (ObjectNotFoundException e) {
                // Load failed, probably because object was not found
                // We try to create a new one.
                // We have to test if the uri is the last in the list,
                // we must create the requested element.
                // By default, we create a SubjectNode.
                ObjectNode newObject = null;
                if (uriTokenizer.hasMoreElements()) {
                    throw new ObjectNotFoundException(courUri);
                } else {
                    newObject = object;
                }
                if (parentObject != null) {
                    securityHelper
                        .checkCredentials(token, courObject, namespaceConfig
                                              .getBindMemberAction());
                   
                    // Now creating the new object
                    newObject.setUri(courUri.toString());
                    courUri.getStore().createObject(courUri, newObject);
                   
                    // re-read to obtain UURI
                    //                    newObject = courUri.getStore().retrieveObject(courUri);
                   
                    // re-read the parent taking the forceEnlistment flag into account
                    Uri parentUri = namespace.getUri(token, parentObject.getUri());
                    parentObject = parentUri.getStore().retrieveObject(parentUri);
                    // Add the newly created object to its parent's
                    // children list
                    ObjectNode oldChild = null;
                    // we can check the parentUri, it's in the same store as newObject
                    if (Configuration.useBinding(parentUri.getStore())) {
                        String bindingName = newObject.getPath().lastSegment();
                        if (parentObject.hasBinding(bindingName)) {
                            oldChild = retrieve(token, parentObject.getUri()+"/"+bindingName, false);
                            parentObject.removeChild(oldChild);
                            store(token, oldChild);
                        }
                    }
                    lockHelper.checkLock
                        (token, parentObject, namespaceConfig.getCreateObjectAction());
                    parentObject.addChild(newObject);
                    //namespace.getUri(token, parentObject.getUri())
                    //.getDataSource().storeObject(parentObject, false);
                    store(token, parentObject, true);
                    store(token, newObject);
                   
                } else {
                    throw new ObjectNotFoundException(courUri);
                }
                courObject = newObject;
            }
           
            // 4 - Test if object is a link, ie if it is an instance of
            // LinkNode or one of its subclasses
            if ((uriTokenizer.hasMoreElements())
                && (courObject instanceof LinkNode)) {
               
                // 5 - If the object is a link, we get the uri of the
                // linked object
                // Note : courUri still IS the Uri of the link, and so,
                // in a way courUri is the parent of linkedUri.
                Uri linkedUri = namespace
                    .getUri(((LinkNode) courObject).getLinkedUri());
               
                // 6 - We replace the courUri scope in the original uri
                String courStrUri = courUri.toString();
                resolvedUri = linkedUri.toString()
                    + resolvedUri.substring(courStrUri.length());
               
                // 7 - We tokenize again the uri
                uriTokenizer = new UriTokenizer(token, namespace, resolvedUri);
               
                // 8 - We parse it till we get back to the point
                // where we stopped
                boolean isUriFound = false;
                while ((!isUriFound) && (uriTokenizer.hasMoreElements())) {
                    if (linkedUri.equals(uriTokenizer.nextUri())) {
                        isUriFound = true;
                    }
                }
                if (!isUriFound) {
                    throw new LinkedObjectNotFoundException
View Full Code Here

        Enumeration roles = securityHelper.getRoles(object);
        while (roles.hasMoreElements()) {
            if (!securityHelper.hasRole(token, (String)roles.nextElement())) {
                // Allow only the namespace admin to create roles
                // he doesn't have
                Uri rootUri = namespace.getUri(token, "/");
                ObjectNode rootObject =
                    rootUri.getStore().retrieveObject(rootUri);
                securityHelper.checkCredentials
                    (token, rootObject,
                     namespaceConfig.getGrantPermissionAction());
                break;
            }
        }
       
        ObjectNode realObject = retrieve(token, object.getUri(), false);
        securityHelper
            .checkCredentials(token, realObject,
                              namespaceConfig.getCreateObjectAction());
        Uri realObjectUri = namespace.getUri(token, realObject.getUri());
        Store store = realObjectUri.getStore();
        store.storeObject(realObjectUri, object);
       
        if (setModificationDate) {
            try {
                NodeRevisionDescriptor revisionDescriptor = store.retrieveRevisionDescriptor(realObjectUri, new NodeRevisionNumber());
View Full Code Here

     */
    public void addBinding(SlideToken token, ObjectNode collectionNode, String segment, ObjectNode sourceNode) throws ServiceAccessException, ObjectNotFoundException, AccessDeniedException, LinkedObjectNotFoundException, ObjectLockedException, CrossServerBindingException {
        if (Configuration.useBinding(namespace.getUri(token, collectionNode.getUri()).getStore())) {
            collectionNode = retrieve(token, collectionNode.getUri(), false);
            sourceNode = retrieve(token, sourceNode.getUri(), false);
            Uri collectionUri = namespace.getUri(token, collectionNode.getUri());
            Uri sourceUri = namespace.getUri(token, sourceNode.getUri());
           
//            if (collectionUri.getStore() != sourceUri.getStore()) {
//                throw new CrossServerBindingException(collectionNode.getUri(), sourceNode.getUri());
//            }
           
View Full Code Here

        }
       
        if (pathOnly) {
            String[] uriTokens = object.getPath().tokens();
            UriPath path = new UriPath("/");
            Uri currentUri = namespace.getUri(token, path.toString());
            Uri objectUri = namespace.getUri(token, object.getUri());
            if (!storeOnly || currentUri.getStore() == objectUri.getStore()) {
                result.add( retrieve(token, path.toString()) );
            }
           
            for (int i = 0; i < uriTokens.length; i++) {
                path = path.child( uriTokens[i] );
                currentUri = namespace.getUri(token, path.toString());
                if (i == uriTokens.length - 1 && !includeSelf) {
                    break;
                }
                if (!storeOnly || currentUri.getStore() == objectUri.getStore()) {
                    result.add( retrieve(token, path.toString()) );
                }
            }
}
        else {
View Full Code Here

            ObjectNode aNode = structure.retrieve(slideToken, aUriAsString);
            if (aNode.hasChildren()) {
                result = findAction(aNode.getChildren().iterator(), privilegeName, privilegeNamespace);
            }
            else {
                Uri aUri = token.getUri(slideToken, aUriAsString);
                NodeRevisionDescriptors nrds = aUri.getStore().retrieveRevisionDescriptors(aUri);
                NodeRevisionDescriptor latestNrd = aUri.getStore().retrieveRevisionDescriptor(aUri, nrds.getLatestRevision());
                NodeProperty aNamespaceAsNode = latestNrd.getProperty(AclConstants.P_PRIVILEGE_NAMESPACE, WebdavConstants.S_DAV);
                String aNamespace = aNamespaceAsNode == null ? null : aNamespaceAsNode.getValue().toString();
                String aUriLastSegment = aUriAsString.substring(aUriAsString.lastIndexOf('/') + 1);
                if (aUriLastSegment.equals(privilegeName)
                        && ((aNamespace != null && privilegeNamespace.equals(aNamespace))
View Full Code Here

        try {
            ctx = getContext();
        } catch ( ServiceConnectionFailedException e ) {
            throw new ServiceAccessException(this, e);
        }
        Uri parentUri = uri.getParentUri();
    String objectName = getObjectNameFromUri( uri );
   
    Vector parentBindings = new Vector();
    Vector childBindings = new Vector();

    // As long as this node isn't the root node create a parent binding.
    // This doesn't appear to do anything, but just in case.
    if ( !uri.toString().equals( "/" ) ) {
      parentBindings.add( new ObjectNode.Binding( objectName, parentUri.toString() ) );
    }
   
    SearchControls controls = new SearchControls();
    controls.setSearchScope( searchScope );
View Full Code Here

        throws SlideRuntimeException
    {
        BasicQueryImpl query = null;
       
//      Uri uri = new Uri (namespace, slideScope);
        Uri uri = namespace.getUri(token.getSlideToken(), slideScope);
       
       
        AbstractStore store = (AbstractStore)uri.getStore();
       
        // todo: can we make the query storeindependant?
        String className = (String)store.getParameter
            (BasicSearchLanguage.BASIC_QUERY_CLASS);
       
View Full Code Here

            ObjectNode node = uri.getStore().retrieveObject(uri);
            securityHelper.checkCredentials(uri.getToken(), node, action);
            Iterator i = node.getChildren().iterator();
            while (i.hasNext()) {
                String child = (String) i.next();
                Uri childUri = namespace.getUri(uri.getToken(), child);
                recursiveAccessCheck(childUri, action);
            }
        } catch (ObjectNotFoundException onfe) {
            // if it is not there it access can not be denied
        }
View Full Code Here

            ActionNode action = namespaceConfig.getCreateObjectAction();
            lockHelper.checkLock(uri.getToken(), node, action);
            Iterator i = node.getChildren().iterator();
            while (i.hasNext()) {
                String child = (String) i.next();
                Uri childUri = namespace.getUri(uri.getToken(), child);
                recursiveLockCheck(childUri);
            }
        } catch (ObjectNotFoundException onfe) {
            // if it is not there it can not be locked
        }
View Full Code Here

TOP

Related Classes of org.apache.slide.common.Uri

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.