Package org.wso2.carbon.registry.core

Examples of org.wso2.carbon.registry.core.ResourceImpl


    }

    // Method to remove a resource, which is used when moving resources.
    private void removeIndividual(ResourceIDImpl resourceID, ResourceDO resourceDO)
            throws RegistryException {
        ResourceImpl resource;
        if (resourceID.isCollection()) {
            resource = new CollectionImpl(resourceID.getPath(), resourceDO);
        } else {
            resource = new ResourceImpl(resourceID.getPath(), resourceDO);
        }
        // we are always creating versions for resources (files), if the resource has changed.
        if (!(resource instanceof Collection) && this.versionOnChange &&
                resource.isVersionableChange()) {
            versionRepository.createSnapshot(resource, false, false);
        } else {
            // just delete the resource and content
            // delete the old entry from the resource table
            removeResource(resource, false);
View Full Code Here


                    targetResourcePath + ". The target path is a part of the source path.";
            log.error(msg);
            throw new RegistryException(msg);
        }

        ResourceImpl sourceResource = (ResourceImpl) get(sourcePath);
        if (sourceResource instanceof CollectionImpl) {
            resourceDAO.fillChildren((CollectionImpl) sourceResource, 0, -1);
        }

        if (resourceDAO.resourceExists(targetPath)) {
            // We need to delete the old one if it is already exists.. 
            delete(targetPath);
        }

        ResourceImpl targetResource = sourceResource.getShallowCopy();
        put(targetPath, targetResource);


        if (sourceResource instanceof CollectionImpl) {
            // copy all the children recursively
            CollectionImpl collection = (CollectionImpl) sourceResource;

            for (String childSourcePath : collection.getChildren()) {
                String childResourceName = RegistryUtils.getResourceName(childSourcePath);
                String childTargetPath =
                        targetPath + RegistryConstants.PATH_SEPARATOR + childResourceName;


                ResourcePath childSourceResourcePath = new ResourcePath(childSourcePath);
                ResourcePath childTargetResourcePath = new ResourcePath(childTargetPath);

                recursionRepository.copy(childSourceResourcePath, childTargetResourcePath);
            }
        }

        commentsDAO.copyComments(sourceResource, targetResource);
        tagsDAO.copyTags(sourceResource, targetResource);
        ratingsDAO.copyRatings(sourceResource, targetResource);
        associationDAO.copyAssociations(sourceResource.getPath(), targetResource.getPath());
        return targetPath;
    }
View Full Code Here

                }
            }
        }
        resourceDAO.update(resource);

        ResourceImpl oldResourceImpl;
        if (oldResourceDO.getName() == null) {
            // this is a collection
            oldResourceImpl = new CollectionImpl(resourceID.getPath(), oldResourceDO);
        } else {
            oldResourceImpl = new ResourceImpl(resourceID.getPath(), oldResourceDO);
        }
        // copying old required attributes to the new version
        commentsDAO.copyComments(oldResourceImpl, resource);
        tagsDAO.copyTags(oldResourceImpl, resource);
        ratingsDAO.copyRatings(oldResourceImpl, resource);
View Full Code Here

            throws RegistryException {
        boolean rootResourceExists = resourceExists(path);
        long currentVersion = -1;
        if (rootResourceExists) {
            // if the target already have resources, delete the node..
            ResourceImpl currentResource = resourceDAO.getResourceMetaData(path);
            if (!(currentResource instanceof Collection)) {
                currentVersion = currentResource.getVersionNumber();
            }
            prepareDumpRestore(path);
        }
        if (!path.equals("/") && path.endsWith("/")) {
            // remove the / suffix
            path = path.substring(0, path.length() - 1);
        }
        if (path.equals(RegistryConstants.ROOT_PATH)) {
            if (!AuthorizationUtils.authorize(path, ActionConstants.PUT)) {
                String msg = "User " + CurrentSession.getUser() + " is not authorized to " +
                        "check in to the path " + path + ".";
                log.warn(msg);
                throw new AuthorizationFailedException(msg);
            }
        } else {
            String parentPath = RegistryUtils.getParentPath(path);
            ResourceImpl parentResource = resourceDAO.getResourceMetaData(parentPath);
            if (parentResource == null) {
                addEmptyCollection(parentPath);
            } else {
                if (!(parentResource instanceof CollectionImpl)) {
                    String msg = "Cannot restore into a non-collection at " + parentPath + ".";
View Full Code Here

            String msg = "Illegal to restore a non-collection in place of root collection.";
            log.error(msg);
            throw new RegistryException(msg);
        }

        ResourceImpl resourceImpl;
        byte[] contentBytes = new byte[0];
        if (isCollection) {
            resourceImpl = new CollectionImpl();
        } else {
            resourceImpl = new ResourceImpl();
        }

        List<CommentDO> commentDOList = new ArrayList<CommentDO>();
        List<TaggingDO> taggingDOList = new ArrayList<TaggingDO>();
        List<RatingDO> ratingDOList = new ArrayList<RatingDO>();
        List<Association> associationList = new ArrayList<Association>();

        boolean isCreatorExisting = false;
        boolean isCreatedTimeExisting = false;
        boolean isUpdaterExisting = false;
        boolean isUpdatedTimeExisting = false;
        long dumpingResourceVersion = -1;

        // traversing to the next element
        do {
            xmlReader.next();
        } while (!xmlReader.isStartElement() && xmlReader.hasNext());

        while (xmlReader.hasNext()) {
            String localName = xmlReader.getLocalName();

            // setMediaType
            if (localName.equals(DumpConstants.MEDIA_TYPE)) {
                String text = xmlReader.getElementText();
                if (text.indexOf("/") < 0) {
                    text = MediaTypesUtils.getMediaType("dummy." + text);
                }
                if (text != null) {
                    resourceImpl.setMediaType(text);
                }
                // now go to the next element
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
            }
            // creator
            else if (localName.equals(DumpConstants.CREATOR)) {
                String text = xmlReader.getElementText();
                if (text != null) {
                    resourceImpl.setAuthorUserName(text);
                    isCreatorExisting = true;
                }
                // now go to the next element
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
            }
            // version: just to keep track of the server changes
            else if (localName.equals(DumpConstants.VERSION)) {
                String text = xmlReader.getElementText();
                if (text != null) {
                    dumpingResourceVersion = Long.parseLong(text);
                }
                // now go to the next element
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
            }
            // createdTime
            else if (localName.equals(DumpConstants.CREATED_TIME)) {
                String text = xmlReader.getElementText();
                if (text != null) {
                    long date = Long.parseLong(text);
                    resourceImpl.setCreatedTime(new Date(date));
                    isCreatedTimeExisting = true;
                }
                // now go to the next element
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
            }
            // setLastUpdater
            else if (localName.equals(DumpConstants.LAST_UPDATER)) {
                String text = xmlReader.getElementText();
                if (text != null) {
                    resourceImpl.setLastUpdaterUserName(text);
                    isUpdaterExisting = true;
                }
                // now go to the next element
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
            }
            // LastModified
            else if (localName.equals(DumpConstants.LAST_MODIFIED)) {
                String text = xmlReader.getElementText();
                if (text != null) {
                    long date = Long.parseLong(text);
                    resourceImpl.setLastModified(new Date(date));
                    isUpdatedTimeExisting = true;
                }
                // now go to the next element
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
            }
            // get description
            else if (localName.equals(DumpConstants.DESCRIPTION)) {
                String text = xmlReader.getElementText();
                if (text != null) {
                    resourceImpl.setDescription(text);
                }
                // now go to the next element
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
            }
            // get properties
            else if (localName.equals(DumpConstants.PROPERTIES)) {
                // iterating trying to find the children..
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
                while (xmlReader.hasNext() &&
                        xmlReader.getLocalName().equals(DumpConstants.PROPERTY_ENTRY)) {
                    String key = xmlReader.getAttributeValue(null, DumpConstants.PROPERTY_ENTRY_KEY);
                    String text = xmlReader.getElementText();
                    if (text.equals("")) {
                        text = null;
                    }
                    if (text != null) {
                        resourceImpl.addPropertyWithNoUpdate(key, text);
                    }
                    do {
                        xmlReader.next();
                    } while (!xmlReader.isStartElement() && xmlReader.hasNext());
                }
            }
            // get content
            else if (localName.equals(DumpConstants.CONTENT)) {
                String text = xmlReader.getElementText();
                // we keep content as base64 encoded
                if (text != null) {
                    contentBytes = Base64.decode(text);
                }
                do {
                    xmlReader.next();
                } while ((!xmlReader.isStartElement() && xmlReader.hasNext()) &&
                            !(xmlReader.isEndElement() &&
                                    xmlReader.getLocalName().equals(DumpConstants.RESOURCE)));
            }
            // getting comment information
            else if (localName.equals(DumpConstants.COMMENTS)) {
                // iterating trying to find the children..
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
                while (xmlReader.hasNext() &&
                        xmlReader.getLocalName().equals(DumpConstants.COMMENT_ENTRY)) {
                    CommentDO commentDO = new CommentDO();

                    do {
                        xmlReader.next();
                    } while (!xmlReader.isStartElement() && xmlReader.hasNext());

                    localName = xmlReader.getLocalName();
                    while (xmlReader.hasNext() &&
                            (localName.equals(DumpConstants.COMMENT_ENTRY_USER) ||
                                    localName.equals(DumpConstants.COMMENT_ENTRY_TEXT))) {
                        if (localName.equals(DumpConstants.COMMENT_ENTRY_USER)) {
                            String text = xmlReader.getElementText();
                            if (text != null) {
                                commentDO.setCommentedUser(text);
                            }
                        } else if (localName.equals(DumpConstants.COMMENT_ENTRY_TEXT)) {
                            String text = xmlReader.getElementText();
                            if (text != null) {
                                commentDO.setCommentText(text);
                            }
                        }

                        do {
                            xmlReader.next();
                        } while (!xmlReader.isStartElement() && xmlReader.hasNext());
                        if (xmlReader.hasNext()) {
                            localName = xmlReader.getLocalName();
                        }
                    }
                    commentDOList.add(commentDO);
                }
            }
            // getting tagging information
            else if (localName.equals(DumpConstants.TAGGINGS)) {
                // iterating trying to find the children..
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
                while (xmlReader.hasNext() &&
                        xmlReader.getLocalName().equals(DumpConstants.TAGGING_ENTRY)) {

                    TaggingDO taggingDO = new TaggingDO();

                    do {
                        xmlReader.next();
                    } while (!xmlReader.isStartElement() && xmlReader.hasNext());

                    localName = xmlReader.getLocalName();
                    while (xmlReader.hasNext() &&
                            (localName.equals(DumpConstants.TAGGING_ENTRY_USER) ||
                                    localName.equals(DumpConstants.TAGGING_ENTRY_DATE) ||
                                    localName.equals(DumpConstants.TAGGING_ENTRY_TAG_NAME))) {
                        if (localName.equals(DumpConstants.TAGGING_ENTRY_USER)) {
                            String text = xmlReader.getElementText();
                            if (text != null) {
                                taggingDO.setTaggedUserName(text);
                            }
                        } else if (localName.equals(DumpConstants.TAGGING_ENTRY_DATE)) {
                            String text = xmlReader.getElementText();
                            if (text != null) {
                                long date = Long.parseLong(text);
                                taggingDO.setTaggedTime(new Date(date));
                            }
                        } else if (localName.equals(DumpConstants.TAGGING_ENTRY_TAG_NAME)) {
                            String text = xmlReader.getElementText();
                            if (text != null) {
                                taggingDO.setTagName(text);
                            }
                        }
                        do {
                            xmlReader.next();
                        } while (!xmlReader.isStartElement() && xmlReader.hasNext());
                        if (xmlReader.hasNext()) {
                            localName = xmlReader.getLocalName();
                        }
                    }
                    taggingDOList.add(taggingDO);
                }
            }
            // getting rating information
            else if (localName.equals(DumpConstants.RATINGS)) {
                // iterating trying to find the children..
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
                while (xmlReader.hasNext() &&
                        xmlReader.getLocalName().equals(DumpConstants.RATING_ENTRY)) {
                    RatingDO ratingDO = new RatingDO();

                    do {
                        xmlReader.next();
                    } while (!xmlReader.isStartElement() && xmlReader.hasNext());

                    localName = xmlReader.getLocalName();
                    while (xmlReader.hasNext() &&
                            (localName.equals(DumpConstants.RATING_ENTRY_USER) ||
                                    localName.equals(DumpConstants.RATING_ENTRY_DATE) ||
                                    localName.equals(DumpConstants.RATING_ENTRY_RATE))) {
                        if (localName.equals(DumpConstants.RATING_ENTRY_USER)) {
                            String text = xmlReader.getElementText();
                            if (text != null) {
                                ratingDO.setRatedUserName(text);
                            }
                        } else if (localName.equals(DumpConstants.RATING_ENTRY_DATE)) {
                            String text = xmlReader.getElementText();
                            if (text != null) {
                                long date = Long.parseLong(text);
                                ratingDO.setRatedTime(new Date(date));
                            }
                        } else if (localName.equals(DumpConstants.RATING_ENTRY_RATE)) {
                            String text = xmlReader.getElementText();
                            if (text != null) {
                                int ratingValue = Integer.parseInt(text);
                                ratingDO.setRating(ratingValue);
                            }
                        }
                        do {
                            xmlReader.next();
                        } while (!xmlReader.isStartElement() && xmlReader.hasNext());
                        if (xmlReader.hasNext()) {
                            localName = xmlReader.getLocalName();
                        }
                    }
                    ratingDOList.add(ratingDO);
                }
            }

            // getting rating information
            else if (localName.equals(DumpConstants.ASSOCIATIONS)) {
                // iterating trying to find the children..
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
                while (xmlReader.hasNext() &&
                        xmlReader.getLocalName().equals(DumpConstants.ASSOCIATION_ENTRY)) {
                    String source = null;
                    String destination = null;
                    String type = null;

                    do {
                        xmlReader.next();
                    } while (!xmlReader.isStartElement() && xmlReader.hasNext());

                    localName = xmlReader.getLocalName();
                    while (xmlReader.hasNext() &&
                            (localName.equals(DumpConstants.ASSOCIATION_ENTRY_SOURCE) ||
                                    localName.equals(DumpConstants.ASSOCIATION_ENTRY_DESTINATION) ||
                                    localName.equals(DumpConstants.ASSOCIATION_ENTRY_TYPE))) {
                        if (localName.equals(DumpConstants.ASSOCIATION_ENTRY_SOURCE)) {
                            String text = xmlReader.getElementText();
                            if (text != null) {
                                source = text;
                            }
                        } else if (localName.equals(DumpConstants.ASSOCIATION_ENTRY_DESTINATION)) {
                            String text = xmlReader.getElementText();
                            if (text != null) {
                                destination = text;
                            }
                        } else if (localName.equals(DumpConstants.ASSOCIATION_ENTRY_TYPE)) {
                            String text = xmlReader.getElementText();
                            if (text != null) {
                                type = text;
                            }
                        }
                        do {
                            xmlReader.next();
                        } while (!xmlReader.isStartElement() && xmlReader.hasNext());
                        if (xmlReader.hasNext()) {
                            localName = xmlReader.getLocalName();
                        }
                    }
                    // get the source and destination as absolute paths
                    source = RegistryUtils.getAbsoluteAssociationPath(source, path);
                    if (destination.startsWith(
                            DumpConstants.EXTERNAL_ASSOCIATION_DESTINATION_PREFIX)) {
                        destination =
                                destination.substring(
                                        DumpConstants.EXTERNAL_ASSOCIATION_DESTINATION_PREFIX.
                                                length());
                    } else {
                        destination =
                                RegistryUtils.getAbsoluteAssociationPath(destination, path);
                    }
                    associationList.add(new Association(source, destination, type));
                }
            }
            // getting children, just storing in array list now, will used at the end
            // we are keeping old name to keep backward compatibility.
            else if (localName.equals(DumpConstants.CHILDREN) ||
                    localName.equals(DumpConstants.CHILDS)) {
                // we keep the stream to call this function recursively
                break;
            } else if (localName.equals(DumpConstants.RESOURCE)) {
                // we keep the stream to call this function recursively
                break;
            } else {
                // we don't mind having unwanted elements, now go to the next element
                do {
                    xmlReader.next();
                } while (!xmlReader.isStartElement() && xmlReader.hasNext());
            }
        }
        if (!ignoreConflicts) {
            // so we handling the conflicts.
            if (dumpingResourceVersion > 0) {
                if (currentVersion == -1) {
                    // the current version == -1 means the resource is deleted in the server
                    // but since the client is sending a version number, it has a previously checkout
                    // resource
                    String msg = "Resource is deleted in the server, resource path: " + path + ".";
                    log.error(msg);
                    throw new RegistryException(msg);
                }
                // we should check whether our dump is up-to-date
                if (currentVersion > dumpingResourceVersion) {
                    // that mean the current resource is updated before the current version
                    // so we have to notify user to get an update
                    String msg = "Resource is in a newer version than the restoring version. " +
                            "resource path: " + path + ".";
                    log.error(msg);
                    throw new RegistryException(msg);
                }
            }
        }

        // completing the empty fields
        if (!isCreatorExisting) {
            String creator = CurrentSession.getUser();
            resourceImpl.setAuthorUserName(creator);
        }
        if (!isCreatedTimeExisting) {
            long now = System.currentTimeMillis();
            resourceImpl.setCreatedTime(new Date(now));
        }
        if (!isUpdaterExisting) {
            String updater = CurrentSession.getUser();
            resourceImpl.setLastUpdaterUserName(updater);
        }
        if (!isUpdatedTimeExisting) {
            long now = System.currentTimeMillis();
            resourceImpl.setLastModified(new Date(now));
        }
        // create sym links
        String linkRestoration = resourceImpl.getProperty(
                RegistryConstants.REGISTRY_LINK_RESTORATION);
        if (linkRestoration != null) {
            String[] parts = linkRestoration.split(RegistryConstants.URL_SEPARATOR);
            if (parts.length == 4) {
                if (parts[2] != null && parts[2].length() == 0) {
                    parts[2] = null;
                }
                if (parts[0] != null && parts[1] != null && parts[3] != null) {
                    RegistryUtils.registerHandlerForRemoteLinks(RegistryContext.getBaseInstance(),
                            parts[0], parts[1], parts[2], parts[3]);
                }
            } else if (parts.length == 3) {
                // here parts[0] the current path, path[1] is the target path.
                if (parts[0] != null && parts[1] != null) {
                    // first we are calculating the relative path of path[1] to path[0]
                    String relativeTargetPath = RegistryUtils.getRelativeAssociationPath(parts[1],
                            parts[0]);
                    // then we derive the absolute path with reference to the current path.
                    String absoluteTargetPath = RegistryUtils.getAbsoluteAssociationPath(
                            relativeTargetPath, path);
                    RegistryUtils.registerHandlerForSymbolicLinks(RegistryContext.getBaseInstance(),
                            path, absoluteTargetPath, parts[2]);
                }
            }
        }

        // creating the resourceID
        ResourceIDImpl resourceID = resourceDAO.getResourceID(path, isCollection);
        if (resourceID == null) {
            // need to create a resourceID
            String parentPath = RegistryUtils.getParentPath(path);

            ResourceIDImpl parentResourceID = resourceDAO.getResourceID(parentPath, true);
            if (parentResourceID == null || !resourceDAO.resourceExists(parentResourceID)) {
                addEmptyCollection(parentPath);
                if (parentResourceID == null) {
                    parentResourceID = resourceDAO.getResourceID(parentPath, true);
                }
            }
            resourceDAO.createAndApplyResourceID(path, parentResourceID, resourceImpl);
        } else {
            resourceImpl.setPathID(resourceID.getPathID());
            resourceImpl.setPath(path);
            resourceImpl.setName(resourceID.getName());
        }

        // adding resource followed by content (for nonCollection
        if (!isCollection) {
            int contentId = 0;
            if (contentBytes.length > 0) {
                contentId = resourceDAO.addContentBytes(new ByteArrayInputStream(contentBytes));
            }
            resourceImpl.setDbBasedContentID(contentId);
        }

        ResourceDO resourceDO = resourceImpl.getResourceDO();
        resourceDAO.addResourceDO(resourceDO);
        resourceImpl.setVersionNumber(resourceDO.getVersion());

        // adding the properties.
        resourceDAO.addProperties(resourceImpl);

        // adding comments
View Full Code Here

    private void dumpRecursively(String path,
                                 XMLStreamWriter xmlWriter,
                                 Writer writer)
            throws RegistryException, XMLStreamException {
        // adding resource meta data
        ResourceImpl resource = resourceDAO.getResourceMetaData(path);
        if (resource == null) {
            return;
        }

        if (!AuthorizationUtils.authorize(path, ActionConstants.GET)) {
            String msg = "User " + CurrentSession.getUser() + " is not authorized to " +
                    "check out the path " + path + ".";
            log.warn(msg);
            throw new AuthorizationFailedException(msg);
        }

        xmlWriter.writeStartElement(DumpConstants.RESOURCE);

        // adding path as an attribute, updated dump has name instead of path
        xmlWriter.writeAttribute(DumpConstants.RESOURCE_NAME, RegistryUtils.getResourceName(path));

        // adding isCollection as an attribute
        xmlWriter.writeAttribute(DumpConstants.RESOURCE_IS_COLLECTION,
                (resource instanceof CollectionImpl) ? DumpConstants.RESOURCE_IS_COLLECTION_TRUE :
                        DumpConstants.RESOURCE_IS_COLLECTION_FALSE);
        OMElement child;

        // set media type
        String mediaType = resource.getMediaType();
        OMFactory factory = OMAbstractFactory.getOMFactory();
        child = factory.createOMElement(new QName(DumpConstants.MEDIA_TYPE));
        child.setText(mediaType);
        child.serialize(xmlWriter);

        // set version
        long version = resource.getVersionNumber();
        child = factory.createOMElement(new QName(DumpConstants.VERSION));
        child.setText(version + "");
        child.serialize(xmlWriter);

        // set creator
        String creator = resource.getAuthorUserName();
        child = factory.createOMElement(new QName(DumpConstants.CREATOR));
        child.setText(creator);
        child.serialize(xmlWriter);

        // set createdTime
        Date createdTime = resource.getCreatedTime();
        child = factory.createOMElement(new QName(DumpConstants.CREATED_TIME));
        child.setText(Long.toString(createdTime.getTime()));
        child.serialize(xmlWriter);

        // set updater
        String updater = resource.getLastUpdaterUserName();
        child = factory.createOMElement(new QName(DumpConstants.LAST_UPDATER));
        child.setText(updater);
        child.serialize(xmlWriter);

        // set LastModified
        Date lastModified = resource.getLastModified();
        child = factory.createOMElement(new QName(DumpConstants.LAST_MODIFIED));
        child.setText(Long.toString(lastModified.getTime()));
        child.serialize(xmlWriter);

        // set Description
        String description = resource.getDescription();
        child = factory.createOMElement(new QName(DumpConstants.DESCRIPTION));
        child.setText(description);
        child.serialize(xmlWriter);

        // fill properties
        resourceDAO.fillResourceProperties(resource);
        Properties properties = resource.getProperties();
        if (properties != null && properties.size() > 0) {
            // properties will be kept inside the <properties> element
            OMElement propertiesOM = factory.createOMElement(new QName(DumpConstants.PROPERTIES));
            for (Object keyObject : properties.keySet()) {
                String key = (String) keyObject;
                List<String> propValues = resource.getPropertyValues(key);
                for (String value : propValues) {
                    OMElement propertyOM = factory.createOMElement(
                            new QName(DumpConstants.PROPERTY_ENTRY));

                    // adding the key and value as attributes
                    OMAttribute keyAttribute = factory.createOMAttribute(
                            DumpConstants.PROPERTY_ENTRY_KEY, null, key);
                    propertyOM.addAttribute(keyAttribute);

                    if (value != null) {
                        propertyOM.setText(value);
                    }

                    propertiesOM.addChild(propertyOM);
                }
            }
            propertiesOM.serialize(xmlWriter);
        }

        // adding contents..
        if (!(resource instanceof CollectionImpl)) {
            resourceDAO.fillResourceContent(resource);

            byte[] content = (byte[]) resource.getContent();
            if (content != null) {
                child = factory.createOMElement(new QName(DumpConstants.CONTENT));
                child.setText(Base64.encode(content));
                child.serialize(xmlWriter);
            }
View Full Code Here

        if (type != null && type.equals(DUMP_TYPE) &&
                method != null && method.equals("POST")) {
            // for restoring a dump we don't need to have available resource
            // here we will create a fake resource to store the path

            resource = new ResourceImpl();
            ((ResourceImpl) resource).setPath(uri);
        } else {
            // in a restore, path don't need to exist.
            try {
                CurrentSession.setUserRealm(registry.getUserRealm());
View Full Code Here

            throws MalformedURLException, RegistryException {
        this(new URL(registryURL), userName, password);
    }

    public Resource newResource() throws RegistryException {
        ResourceImpl resource = new RemoteResourceImpl();
        resource.setAuthorUserName(username);
        return resource;
    }
View Full Code Here

                    "Cached resource returned since no modification has been done on the resource");
            return cache.getCachedResource(path);
        }
        String eTag = clientResponse.getHeader("ETag");
        Element introspection = clientResponse.getDocument().getRoot();
        ResourceImpl resource;
        if (introspection instanceof Feed) {
            // This is a collection
            Feed feed = (Feed) introspection;
            String state = feed.getSimpleExtension(new QName(APPConstants.NAMESPACE, "state"));
            if (state != null && state.equals("Deleted")) {
View Full Code Here

     */
    public static void addMountEntry(Registry registry, RegistryContext registryContext,
                                     String path, String target, String targetSubPath,
                                     String author)
            throws RegistryException {
        Resource r = new ResourceImpl();
        String relativePath = RegistryUtils.getRelativePath(registryContext, path);
        r.addProperty("path", relativePath);
        r.addProperty("target", target);
        r.addProperty("author", author);
        r.addProperty("subPath", targetSubPath);
        String mountPath = RegistryConstants.LOCAL_REPOSITORY_BASE_PATH +
                        RegistryConstants.SYSTEM_MOUNT_PATH + "/" +
                relativePath.replace("/", "-");
        if (!registry.resourceExists(mountPath)) {
            registry.put(mountPath, r);
View Full Code Here

TOP

Related Classes of org.wso2.carbon.registry.core.ResourceImpl

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.