Package org.modeshape.webdav

Examples of org.modeshape.webdav.StoredObject


    protected void doBody( ITransaction transaction,
                           HttpServletResponse resp,
                           String path ) {

        try {
            StoredObject so = store.getStoredObject(transaction, path);
            if (so == null) {
                resp.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
            if (so.isNullResource()) {
                String methodsAllowed = DeterminableMethod.determineMethodsAllowed(so);
                resp.addHeader("Allow", methodsAllowed);
                resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
                return;
            }
View Full Code Here


    protected void folderBody( ITransaction transaction,
                               String path,
                               HttpServletResponse resp,
                               HttpServletRequest req ) throws IOException {

        StoredObject so = store.getStoredObject(transaction, path);
        if (so == null) {
            resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getRequestURI());
        } else {

            if (so.isNullResource()) {
                String methodsAllowed = DeterminableMethod.determineMethodsAllowed(so);
                resp.addHeader("Allow", methodsAllowed);
                resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
                return;
            }

            if (so.isFolder()) {
                // TODO some folder response (for browsers, DAV tools use propfind) in html?
                DateFormat shortDF = getDateTimeFormat(req.getLocale());
                resp.setContentType("text/html");
                resp.setCharacterEncoding("UTF-8");
                OutputStream out = resp.getOutputStream();
                String[] children = store.getChildrenNames(transaction, path);
                // Make sure it's not null
                children = children == null ? new String[] {} : children;
                // Sort by name
                Arrays.sort(children);
                StringBuilder childrenTemp = new StringBuilder();
                childrenTemp.append("<html><head><title>Content of folder");
                childrenTemp.append(path);
                childrenTemp.append("</title><style type=\"text/css\">");
                childrenTemp.append(getCSS());
                childrenTemp.append("</style></head>");
                childrenTemp.append("<body>");
                childrenTemp.append(getHeader(transaction, path, resp, req));
                childrenTemp.append("<table>");
                childrenTemp.append("<tr><th>Name</th><th>Size</th><th>Created</th><th>Modified</th></tr>");
                childrenTemp.append("<tr>");
                childrenTemp.append("<td colspan=\"4\"><a href=\"../\">Parent</a></td></tr>");
                boolean isEven = false;
                for (String child : children) {
                    isEven = !isEven;
                    childrenTemp.append("<tr class=\"");
                    childrenTemp.append(isEven ? "even" : "odd");
                    childrenTemp.append("\">");
                    childrenTemp.append("<td>");
                    childrenTemp.append("<a href=\"");

                    // CHECKSTYLE IGNORE check FOR NEXT 1 LINES
                    StringBuffer childURL = req.getRequestURL();
                    if (!(childURL.charAt(childURL.length() - 1) == '/')) {
                        childURL.append("/");
                    }

                    // we need to URL encode the child, but just the special chars, UTF-8 encoding is done at the end of this
                    // method
                    childURL.append(URL_ENCODER.encode(child));

                    StoredObject obj = store.getStoredObject(transaction, path + "/" + child);
                    if (obj == null) {
                        logger.error(new TextI18n("Should not return null for " + path + "/" + child));
                    }
                    if (obj != null && obj.isFolder()) {
                        childURL.append("/");
                    }

                    childrenTemp.append(childURL);

                    childrenTemp.append("\">");
                    childrenTemp.append(child);
                    childrenTemp.append("</a></td>");
                    if (obj != null && obj.isFolder()) {
                        childrenTemp.append("<td>Folder</td>");
                    } else {
                        childrenTemp.append("<td>");
                        if (obj != null) {
                            childrenTemp.append(obj.getResourceLength());
                        } else {
                            childrenTemp.append("Unknown");
                        }
                        childrenTemp.append(" Bytes</td>");
                    }
                    if (obj != null && obj.getCreationDate() != null) {
                        childrenTemp.append("<td>");
                        childrenTemp.append(shortDF.format(obj.getCreationDate()));
                        childrenTemp.append("</td>");
                    } else {
                        childrenTemp.append("<td></td>");
                    }
                    if (obj != null && obj.getLastModified() != null) {
                        childrenTemp.append("<td>");
                        childrenTemp.append(shortDF.format(obj.getLastModified()));
                        childrenTemp.append("</td>");
                    } else {
                        childrenTemp.append("<td></td>");
                    }
                    childrenTemp.append("</tr>");
View Full Code Here

        // Overwriting the destination
        String lockOwner = "copyResource" + System.currentTimeMillis() + req.toString();

        if (resourceLocks.lock(transaction, destinationPath, lockOwner, false, 0, TEMP_TIMEOUT, TEMPORARY)) {
            StoredObject copySo, destinationSo = null;
            try {
                copySo = store.getStoredObject(transaction, path);
                // Retrieve the resources
                if (copySo == null) {
                    resp.sendError(HttpServletResponse.SC_NOT_FOUND);
                    return false;
                }

                if (copySo.isNullResource()) {
                    String methodsAllowed = DeterminableMethod.determineMethodsAllowed(copySo);
                    resp.addHeader("Allow", methodsAllowed);
                    resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
                    return false;
                }
View Full Code Here

                       String destinationPath,
                       Hashtable<String, Integer> errorList,
                       HttpServletRequest req,
                       HttpServletResponse resp ) throws WebdavException, IOException {

        StoredObject sourceSo = store.getStoredObject(transaction, sourcePath);
        if (sourceSo == null) {
            resp.setStatus(WebdavStatus.SC_NOT_FOUND);
            return;
        }
        if (sourceSo.isResource()) {
            store.createResource(transaction, destinationPath);
            long resourceLength = store.setResourceContent(transaction,
                                                           destinationPath,
                                                           store.getResourceContent(transaction, sourcePath),
                                                           null,
                                                           null);

            if (resourceLength != -1) {
                StoredObject destinationSo = store.getStoredObject(transaction, destinationPath);
                destinationSo.setResourceLength(resourceLength);
            }

        } else {

            if (sourceSo.isFolder()) {
View Full Code Here

        }
        if (infiniteDepth) {
            String[] children = store.getChildrenNames(transaction, sourcePath);
            children = children == null ? new String[] {} : children;

            StoredObject childSo;
            for (int i = children.length - 1; i >= 0; i--) {
                children[i] = "/" + children[i];
                try {
                    childSo = store.getStoredObject(transaction, (sourcePath + children[i]));
                    if (childSo == null) {
                        errorList.put(destinationPath + children[i], WebdavStatus.SC_NOT_FOUND);
                        continue;
                    }
                    if (childSo.isResource()) {
                        store.createResource(transaction, destinationPath + children[i]);
                        long resourceLength = store.setResourceContent(transaction,
                                                                       destinationPath + children[i],
                                                                       store.getResourceContent(transaction, sourcePath
                                                                                                             + children[i]),
                                                                       null,
                                                                       null);

                        if (resourceLength != -1) {
                            StoredObject destinationSo = store.getStoredObject(transaction, destinationPath + children[i]);
                            destinationSo.setResourceLength(resourceLength);
                        }

                    } else {
                        copyFolder(transaction, sourcePath + children[i], destinationPath + children[i], errorList, req, resp);
                    }
View Full Code Here

    private void doLock( ITransaction transaction,
                         HttpServletRequest req,
                         HttpServletResponse resp ) throws IOException, LockFailedException {

        StoredObject so = store.getStoredObject(transaction, path);

        if (so != null) {
            doLocking(transaction, req, resp);
        } else {
            // resource doesn't exist, null-resource lock
View Full Code Here

    private void doNullResourceLock( ITransaction transaction,
                                     HttpServletRequest req,
                                     HttpServletResponse resp ) throws IOException {

        StoredObject parentSo, nullSo = null;

        try {
            parentSo = store.getStoredObject(transaction, parentPath);
            if (parentPath != null && parentSo == null) {
                store.createFolder(transaction, parentPath);
            } else if (parentPath != null && parentSo != null && parentSo.isResource()) {
                resp.sendError(WebdavStatus.SC_PRECONDITION_FAILED);
                return;
            }

            nullSo = store.getStoredObject(transaction, path);
View Full Code Here

                                               "text/plain",
                                               "UTF-8");

        assertThat((int)length, is(TEST_STRING.getBytes().length));

        StoredObject ob = store.getStoredObject(tx, TEST_URI);

        assertThat(ob, is(notNullValue()));
    }
View Full Code Here

                                         String uri ) {
        if (uri.length() == 0) {
            uri = "/";
        }

        StoredObject ob = new StoredObject();
        try {
            logger.trace("WebDAV getStoredObject at \"" + uri + "\"");
            ResolvedRequest resolved = resolveRequest(uri);
            logger.debug("WebDAV getStoredObject at \"" + uri + "\" resolved to \"" + resolved + "\"");
            String path = resolved.getPath();
            if (path == null) {
                // It does not resolve to the path of a node, so see if the repository/workspace exist ...
                if (repositoryAndWorkspaceExist(transaction, resolved)) {
                    ob.setFolder(true);
                    Date now = new Date();
                    ob.setCreationDate(now);
                    ob.setLastModified(now);
                    ob.setResourceLength(0);
                    return ob;
                }
                // It does not exist, so return null
                return null;
            }

            int ind = path.lastIndexOf('/');
            String resourceName = path.substring(ind + 1);
            if (resourceName.startsWith("._")) {
                // OS-X uses these hidden files ...
                return null;
            }

            Node node = nodeFor(transaction, resolved);

            if (isFolder(node)) {
                ob.setFolder(true);
                Date createDate = null;
                if (node.hasProperty(CREATED_PROP_NAME)) {
                    createDate = node.getProperty(CREATED_PROP_NAME).getDate().getTime();
                } else {
                    createDate = new Date();
                }
                ob.setCreationDate(createDate);
                ob.setLastModified(new Date());
                ob.setResourceLength(0);
            } else if (isFile(node)) {
                ob.setFolder(false);
                Date createDate = null;
                if (node.hasProperty(CREATED_PROP_NAME)) {
                    createDate = node.getProperty(CREATED_PROP_NAME).getDate().getTime();
                } else {
                    createDate = new Date();
                }
                ob.setCreationDate(createDate);
                ob.setLastModified(contentMapper.getLastModified(node));
                ob.setResourceLength(contentMapper.getResourceLength(node));
            } else {
                ob.setNullResource(true);
            }

        } catch (PathNotFoundException pnfe) {
            return null;
        } catch (IOException ioe) {
View Full Code Here

TOP

Related Classes of org.modeshape.webdav.StoredObject

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.