Package org.jdesktop.wonderland.modules.contentrepo.common

Examples of org.jdesktop.wonderland.modules.contentrepo.common.ContentCollection


    protected ContentNode translatePath(WebContentRepository wcr, String path)
        throws ContentRepositoryException
    {
        // find the root (system or users)
        ContentCollection root = null;

        if (path == null || path.equals("/")) {
            root = wcr.getRoot();
        } else if (path.startsWith("/system")) {
            path = path.substring("/system".length());
            root = wcr.getSystemRoot();
        } else if (path.startsWith("/users/")) {
            path = path.substring("/users/".length());
            String userId = path;

            int endIdx = path.indexOf("/");
            if (endIdx != -1) {
                userId = path.substring(0, endIdx);
                path = path.substring(endIdx);
            } else {
                path = null;
            }

            root = wcr.getUserRoot(userId);
        } else {
            root = wcr.getRoot();
        }

        if (root == null) {
            return null;
        }

        if (path == null || path.length() == 0 || path.equals("/")) {
            return root;
        }

        return root.getChild(path);
    }
View Full Code Here


    protected ContentNode handleDelete(HttpServletRequest request,
                                       HttpServletResponse response,
                                       ContentNode node, String action)
        throws ServletException, IOException, ContentRepositoryException
    {
        ContentCollection parent = node.getParent();
        if (parent == null) {
            error(request, response, "Cannot delete top-level node.");
            return null;
        }

        parent.removeChild(node.getName());
        return parent;
    }
View Full Code Here

        if (!(node instanceof ContentCollection)) {
            error(request, response, "Not a directory");
            return null;
        }
       
        ContentCollection dir = (ContentCollection) node;
       
        /* Check that we have a file upload request */
        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        if (isMultipart == false) {
            logger.warning("[Runner] UPLOAD Bad request");
            String message = "Unable to recognize upload request. Please " +
                             "try again.";
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
            return null;
        }

        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload();

        // Parse the request
        try {
            FileItemIterator iter = upload.getItemIterator(request);
            while (iter.hasNext() == true) {
                FileItemStream item = iter.next();
                String name = item.getName();
                InputStream stream = item.openStream();
                if (item.isFormField() == false) {
                    ContentResource child = (ContentResource)
                            dir.createChild(name, ContentNode.Type.RESOURCE);

                    File tmp = File.createTempFile("contentupload", "tmp");
                    RunUtil.writeToFile(stream, tmp);
                    child.put(tmp);
                    tmp.delete();
View Full Code Here

        }
               
        try {
            WebContentRepository repo =
                    WebContentRepositoryRegistry.getInstance().getRepository(context);
            ContentCollection root = repo.getRoot();
            ContentResource obj = (ContentResource) root.getChild(url.getHost() + "/" + url.getPath());
           
            return new WlContentURLConnection(url, obj);
           
        } catch (ContentRepositoryException ce) {
            throw new IOException(ce);
View Full Code Here

            return null;
        }

        // Fetch the content node for the "placemarks/" directory under "system".
        // If "placemarks/" isn't there, then create it.
        ContentCollection sysRoot = wcr.getSystemRoot();
        ContentCollection c = (ContentCollection)sysRoot.getChild("placemarks");
        if (c == null) {
            c = (ContentCollection)sysRoot.createChild("placemarks", Type.COLLECTION);
        }

        // Try to find the "placemarks.xml" file. If it does not exist, then
        // create it with an empty PlacemarksList.
        ContentResource r = (ContentResource)c.getChild("placemarks.xml");
        if (r == null) {
            r = (ContentResource)c.createChild("placemarks.xml", Type.RESOURCE);
            PlacemarkList placemarkList = new PlacemarkList();
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            Writer w = new OutputStreamWriter(os);
            placemarkList.encode(w);
            r.put(os.toByteArray());
View Full Code Here

    }//GEN-LAST:event_submitCancelButtonActionPerformed

    public static ErrorReport read(String id)
            throws ContentRepositoryException, JAXBException
    {
        ContentCollection dir = getContentDir();
        ContentResource resource = (ContentResource) dir.getChild(id);
        if (resource == null) {
            throw new ContentRepositoryException("No such file: " + id);
        }
       
        Unmarshaller u = getContext().createUnmarshaller();
View Full Code Here

        return cr.getSystemRoot();
    }
    private static ContentCollection getGroupUsersRepo() {
        try {
            if(grpusrRepo == null) {
                ContentCollection collection = getSystemContentRepository(LoginManager.getPrimary());
                ContentCollection grps = (ContentCollection) collection.getParent().getChild("groups");
                if(grps==null) {
                    grps = (ContentCollection) collection.getParent().createChild("groups", ContentNode.Type.COLLECTION);
                }
                ContentCollection grpusrs = (ContentCollection) grps.getChild("users");
                if(grpusrs == null) {
                    grpusrs = (ContentCollection) grps.createChild("users", ContentNode.Type.COLLECTION);
                }
                grpusrRepo = grpusrs;
                return grpusrs;
View Full Code Here

       
        String uri = "";
        ContentRepositoryRegistry registry = ContentRepositoryRegistry.getInstance();
        ContentRepository repo = registry.getRepository(LoginManager.getPrimary());
        try {
            ContentCollection c = repo.getUserRoot();
            try {
                /*
                 * Remove file if it exists.
                 */
                ContentResource r = (ContentResource) c.removeChild(image.getName());
            } catch (Exception e) {
            }
           
            ContentResource r = (ContentResource) c.createChild(
                image.getName(), ContentNode.Type.RESOURCE);
            try {
               
                r.put(image);
               
View Full Code Here

   
    public static void submit(ErrorReport report)
            throws ContentRepositoryException, JAXBException
    {
        ServerSessionManager ssm = LoginManager.getPrimary();   
        ContentCollection dir = getContentDir();
       
        ContentResource file;
        if (report.getId() == null) {
            // create a new file
            String fileName;       
            int index = 0;
            DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
            do {
                fileName = ssm.getUsername() + "-" + df.format(new Date());
                fileName += (index == 0)?"":index;
           
                index++;
            } while (dir.getChild(fileName) != null);
       
            file = (ContentResource)
                dir.createChild(fileName, ContentNode.Type.RESOURCE);
        } else {
            // update an existing file
            file = (ContentResource) dir.getChild(report.getId());
        }
       
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Marshaller m = getContext().createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
View Full Code Here

   
    private static ContentCollection getContentDir() throws ContentRepositoryException {
        ServerSessionManager ssm = LoginManager.getPrimary();
        ContentRepository repo = ContentRepositoryRegistry.getInstance().getRepository(ssm);
   
        ContentCollection dir = (ContentCollection)
                repo.getRoot().getChild("groups/users/" + ErrorReport.DIR_NAME);
        if (dir == null) {
            throw new ContentRepositoryException("No such directory");
        }
       
View Full Code Here

TOP

Related Classes of org.jdesktop.wonderland.modules.contentrepo.common.ContentCollection

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.