Package org.wso2.carbon.registry.core

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


     */
    public static void addMountEntry(Registry registry, RegistryContext registryContext,
                                     String path, String target, boolean remote, String author)
            throws RegistryException {
        //persist mount details
        Resource r = new ResourceImpl();
        String relativePath;
        if (remote) {
            relativePath = path;
        } else {
            relativePath = RegistryUtils.getRelativePath(registryContext, path);
        }
        r.addProperty("path", relativePath);
        r.addProperty("target", RegistryUtils.getRelativePath(registryContext,
                target));
        r.addProperty("author", author);
        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


            throws RegistryException {
        ResourceIDImpl resourceID = resourceDAO.getResourceID(path);
        if (resourceID == null) {
            return null;
        }
        ResourceImpl resourceImpl;
        if (resourceID.isCollection()) {
            resourceImpl = new CollectionImpl();
        } else {
            resourceImpl = new ResourceImpl();
        }
        if (versioned) {
            resourceImpl.setVersionNumber(resourceDAO.getVersion(resourceID));
        } else {
            resourceImpl.setName(resourceID.getName());
            resourceImpl.setPathID(resourceID.getPathID());
        }
        resourceImpl.setPath(path);
        return resourceImpl;
    }
View Full Code Here


        // we are always creating versions for resources (files), if the resource has changed.
        if (!(resource instanceof Collection) && this.versionOnChange &&
                resource.isVersionableChange()) {
            ResourceImpl oldResourceImpl = new ResourceImpl(resourceID.getPath(), oldResourceDO);
            versionRepository.createSnapshot(oldResourceImpl, false, false);
        } else {
            ResourceImpl oldResourceImpl;
            if (resourceID.isCollection()) {
                oldResourceImpl = new CollectionImpl(resourceID.getPath(), oldResourceDO);
            } else {
                oldResourceImpl = new ResourceImpl(resourceID.getPath(), oldResourceDO);
            }
            // just delete the resource and content
            // delete the old entry from the resource table
            removeResource(oldResourceImpl, false);
        }
View Full Code Here

     * @throws RegistryException if the operation failed.
     */
    public void deleteNode(ResourceIDImpl resourceID,
                              ResourceDO resourceDO,
                              boolean keepAuthorization) throws RegistryException {
        ResourceImpl resourceImpl;
        if (resourceID.isCollection()) {
            resourceImpl = new CollectionImpl(resourceID.getPath(), resourceDO);
        } else {
            resourceImpl = new ResourceImpl(resourceID.getPath(), resourceDO);
        }

        // now do the versioning as delete is considered as a change, where
        // non-collections are versioned automatically unless it is configured otherwise
        if (!(resourceImpl instanceof CollectionImpl) && this.versionOnChange &&
                resourceImpl.isVersionableChange()) {

            // we are creating snapshot without renewing old contents..
            versionRepository.createSnapshot(resourceImpl, false, true);

            // Just delete the associations along with the path.
            associationDAO.removeAllAssociations(resourceImpl.getPath());

        } else {
            // just delete the resource and content
            // delete the old entry from the resource table
            boolean isResourcePathVersioned = resourceVersionDAO.isResourceHistoryExist(
                    resourceImpl.getResourceIDImpl());
            removeResource(resourceImpl, isResourcePathVersioned);

            if (!StaticConfiguration.isVersioningComments() && !isResourcePathVersioned) {
                commentsDAO.removeComments(resourceImpl);
            }
            if (!StaticConfiguration.isVersioningTags() && !isResourcePathVersioned) {
                tagsDAO.removeTags(resourceImpl);
            }
            if (!StaticConfiguration.isVersioningRatings() && !isResourcePathVersioned) {
                ratingsDAO.removeRatings(resourceImpl);
            }
            // Just delete the associations along with the path.
            Association[] associations = associationDAO.getAllAssociations(resourceImpl.getPath());
            if (associations != null && associations.length > 0) {
                associationDAO.removeAllAssociations(resourceImpl.getPath());
            }


            if (!keepAuthorization && !isResourcePathVersioned) {
                // for an empty root, we are not clearing the authorization..
View Full Code Here

    private void handleFileUpload(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        try {
            Registry registry = Utils.getSecureRegistry(request);
            ResourceImpl fileElement =
                    FileUploadUtil.processUpload(request);
            String path = fileElement.getPath();
            registry.put(path, fileElement);
            request.getSession().setAttribute(RegistryConstants.STATUS_MESSAGE_NAME,
                    "Resource " + path +
                            " was successfully added to the registry.");
            response.setContentType("text/html");
View Full Code Here

    public static ResourceImpl processUpload(HttpServletRequest req)
            throws IOException, ServletException {
        RequestContext reqContext = new ServletRequestContext(req);
        boolean isMultipart = ServletFileUpload.isMultipartContent(reqContext);
        if (isMultipart) {
            ResourceImpl resource = new ResourceImpl();
            try {
                //Create a factory for disk-based file items
                FileItemFactory factory = new DiskFileItemFactory();
                //Create a new file upload handler
                ServletFileUpload upload = new ServletFileUpload(factory);
                List items = upload.parseRequest(req);
                // Process the uploaded items
                Iterator iter = items.iterator();

                String parentPath = "";
                String resourceName = "";

                while (iter.hasNext()) {
                    FileItem item = (FileItem) iter.next();

                    if (item.isFormField()) {
                        if (item.getFieldName().equalsIgnoreCase("path")) {
                            parentPath = item.getString();
                        } else if (item.getFieldName().equalsIgnoreCase("filename")) {
                            resourceName = item.getString();
                        } else if (item.getFieldName().equalsIgnoreCase("description")) {
                            resource.setDescription(item.getString());
                        } else if (item.getFieldName().equalsIgnoreCase("mediaType")) {
                            resource.setMediaType(item.getString());
                        }
                    } else {
                        InputStream in = item.getInputStream();

                        //ByteArrayOutputStream out = new ByteArrayOutputStream();
                        //byte[] buffer = new byte[1024];
                        //int c;
                        //while ((c = in.read(buffer)) != -1) {
                        //    out.write(buffer, 0, c);
                        //}
                        //out.flush();

                        resource.setContentStream(in);
                    }

                    resource.setPath(calcualtePath(parentPath, resourceName));
                }
            } catch (Exception e) {
                req.setAttribute("status", "failure");
                req.setAttribute("cause", e.getMessage());
            }
View Full Code Here

                CollectionImpl resource = new CollectionImpl();
                resource.setPath(resourcePath);
                registry.put(resourcePath, resource);
            }
        } else {
            ResourceImpl resource = new ResourceImpl();
            resource.setContent(new FileInputStream(file));
            resource.setPath(resourcePath);
            registry.put(resourcePath, resource);
        }
    }
View Full Code Here

            Resource resource1 = registry.get(path);

            assertEquals("File content is not matching", new String((byte[]) resource1.getContent()),
                    new String((byte[]) res1.getContent()));

            Resource resource = new ResourceImpl();
            byte[] r1content1 = "R2 content updated".getBytes();
            resource.setContent(r1content1);
            resource.setProperty("abc", "abc");

            registry.put(path, resource);

            Resource resource2 = registry.get(path);

            assertEquals("File content is not matching", new String((byte[]) resource.getContent()),
                    new String((byte[]) resource2.getContent()));

            resource.discard();
            res1.discard();
            resource1.discard();
            resource2.discard();
            Thread.sleep(100);
        }
View Full Code Here

        tempPath = tempPath.substring(0, (tempPath.length()) - (tempArr[tempArr.length - 1].length()) - 1);
        String prop = "";
        String propName = tempArr[tempArr.length - 1];
        List propList = null;
        boolean resFlag = false;
        ResourceImpl res = null;

        try {

            regProp = new RegistryProperty((CollectionImpl) userRegistry.get(tempPath), this,
                    tempArr[tempArr.length - 1]);

            if (userRegistry.resourceExists(absPath)) {

                res = (ResourceImpl) userRegistry.get(absPath);
                resFlag = true;

            }

            if ((!resFlag) && (userRegistry.resourceExists(tempPath)) && (userRegistry.get(tempPath) != null)) {

                propList = userRegistry.get(tempPath).getPropertyValues(propName);

                if ((propList != null) && (propList.size() == 1)) {
                    prop = propList.get(0).toString();
                    regProp.setValue(prop);

                } else {

                    if (propList != null) {
                        String[] arr = new String[propList.size()];

                        int i = 0;

                        for (Object ob : propList) {

                            arr[i] = ob.toString();
                            i++;
                        }

                        regProp.setValue(arr);
                    }

                }

            } else if (res != null) {

                if ((res.getProperty("registry.jcr.property.type") != null) &&
                        (res.getProperty("registry.jcr.property.type").equals("input_stream"))) {

                    regProp.setValue(res.getContentStream());
                } else if ((res.getProperty("registry.jcr.property.type") != null) &&
                        (res.getProperty("registry.jcr.property.type").equals("values_type"))) {

                    List<String> valuesProp = res.getPropertyValues(propName);

                    if (valuesProp != null) {
                        int i = 0;
                        Value[] values = new RegistryValue[valuesProp.size()];

                        for (int j = 0; j < values.length; j++) {

                            values[j] = new RegistryValue(valuesProp.get(j));

                        }

                        regProp.setValue(values);
                    }
                } else if (res.getContent() instanceof String) {

                    prop = res.getContent().toString();
                } else if (res.getContent() instanceof byte[]) {

                    prop = new String((byte[]) res.getContent());

                } else if (prop.equals("")) {

                    throw new PathNotFoundException();

                }

                regProp = RegistrySession.getRegistryProperty(res.getProperty("registry.jcr.property.type"),
                        prop, regProp);

                resFlag = false;
            }
View Full Code Here

                        Resource resourceImpl = ((RegistryResource) resource).getUnderLineResource();
                        boolean isCollection = resourceImpl instanceof Collection;
                        // 'resourceImpl == null' indicates it's a new non-collection resource created by the client
                        // @see:  org.wso2.carbon.registry.webdav.RegistryServlet.doMkCol()
                        if (null == resourceImpl) {
                            resourceImpl = isCollection ? new CollectionImpl() : new ResourceImpl();
                            //setting path and underline resource only for newly created resources
                            ((ResourceImpl) resourceImpl).setPath(resource.getResourcePath());
                            ((RegistryResource) resource).setUnderLineResource(resourceImpl);
                            //if (!isCollection) {
                            resourceCache.updateDavResourceMimeType((RegistryResource) resource);
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.