Package org.modeshape.webdav

Examples of org.modeshape.webdav.StoredObject


                                HttpServletResponse resp ) throws IOException, WebdavException {

        resp.setStatus(WebdavStatus.SC_NO_CONTENT);

        if (!readOnly) {
            StoredObject so = store.getStoredObject(transaction, path);
            if (so != null) {
                if (so.isResource()) {
                    store.removeObject(transaction, path);
                } else {
                    if (so.isFolder()) {
                        deleteFolder(transaction, path, errorList);
                        store.removeObject(transaction, path);
                    } else {
                        resp.sendError(WebdavStatus.SC_NOT_FOUND);
                    }
View Full Code Here


                               String path,
                               Hashtable<String, Integer> errorList ) throws WebdavException {

        String[] children = store.getChildrenNames(transaction, path);
        children = children == null ? new String[] {} : children;
        StoredObject so = null;
        for (int i = children.length - 1; i >= 0; i--) {
            children[i] = "/" + children[i];
            try {
                so = store.getStoredObject(transaction, path + children[i]);
                if (so == null) {
                    errorList.put(path + children[i], WebdavStatus.SC_NOT_FOUND);
                    continue;
                }
                if (so.isResource()) {
                    store.removeObject(transaction, path + children[i]);

                } else {
                    deleteFolder(transaction, path + children[i], errorList);
                    store.removeObject(transaction, path + children[i]);
View Full Code Here

        }
        depth = getDepth(req);

        if (resourceLocks.lock(transaction, path, tempLockOwner, false, depth, TEMP_TIMEOUT, TEMPORARY)) {

            StoredObject so = null;
            try {
                so = store.getStoredObject(transaction, path);
                if (so == null) {
                    resp.setContentType("text/xml; charset=UTF-8");
                    resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getRequestURI());
View Full Code Here

                                  String path,
                                  int type,
                                  Vector<String> propertiesVector,
                                  String mimeType ) throws WebdavException {

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

        boolean isFolder = so.isFolder();
        final String creationdate = creationDateFormat(so.getCreationDate());
        final String lastModified = lastModifiedDateFormat(so.getLastModified());
        String resourceLength = String.valueOf(so.getResourceLength());

        // ResourceInfo resourceInfo = new ResourceInfo(path, resources);

        generatedXML.writeElement("DAV::response", XMLWriter.OPENING);
        String status = "HTTP/1.1 " + WebdavStatus.SC_OK + " " + WebdavStatus.getStatusText(WebdavStatus.SC_OK);

        // Generating href element
        generatedXML.writeElement("DAV::href", XMLWriter.OPENING);

        String href = req.getContextPath();
        String servletPath = req.getServletPath();
        if (servletPath != null) {
            if ((href.endsWith("/")) && (servletPath.startsWith("/"))) {
                href += servletPath.substring(1);
            } else {
                href += servletPath;
            }
        }
        if ((href.endsWith("/")) && (path.startsWith("/"))) {
            href += path.substring(1);
        } else {
            href += path;
        }
        if ((isFolder) && (!href.endsWith("/"))) {
            href += "/";
        }

        generatedXML.writeText(rewriteUrl(href));

        generatedXML.writeElement("DAV::href", XMLWriter.CLOSING);

        String resourceName = path;
        int lastSlash = path.lastIndexOf('/');
        if (lastSlash != -1) {
            resourceName = resourceName.substring(lastSlash + 1);
        }

        switch (type) {

            case FIND_ALL_PROP:
                generatedXML.writeElement("DAV::propstat", XMLWriter.OPENING);

                generatedXML.writeElement("DAV::prop", XMLWriter.OPENING);
                writeCustomProperties(transaction, generatedXML, path, true, propertiesVector);

                generatedXML.writeProperty("DAV::creationdate", creationdate);
                generatedXML.writeElement("DAV::displayname", XMLWriter.OPENING);
                generatedXML.writeData(resourceName);
                generatedXML.writeElement("DAV::displayname", XMLWriter.CLOSING);
                if (!isFolder) {
                    generatedXML.writeProperty("DAV::getlastmodified", lastModified);
                    generatedXML.writeProperty("DAV::getcontentlength", resourceLength);
                    if (mimeType != null) {
                        generatedXML.writeProperty("DAV::getcontenttype", mimeType);
                    }
                    generatedXML.writeProperty("DAV::getetag", getETag(so));
                    generatedXML.writeElement("DAV::resourcetype", XMLWriter.NO_CONTENT);
                } else {
                    generatedXML.writeElement("DAV::resourcetype", XMLWriter.OPENING);
                    generatedXML.writeElement("DAV::collection", XMLWriter.NO_CONTENT);
                    generatedXML.writeElement("DAV::resourcetype", XMLWriter.CLOSING);
                }

                writeSupportedLockElements(transaction, generatedXML, path);

                writeLockDiscoveryElements(transaction, generatedXML, path);

                generatedXML.writeProperty("DAV::source", "");
                generatedXML.writeElement("DAV::prop", XMLWriter.CLOSING);
                generatedXML.writeElement("DAV::status", XMLWriter.OPENING);
                generatedXML.writeText(status);
                generatedXML.writeElement("DAV::status", XMLWriter.CLOSING);
                generatedXML.writeElement("DAV::propstat", XMLWriter.CLOSING);

                break;

            case FIND_PROPERTY_NAMES:
                generatedXML.writeElement("DAV::propstat", XMLWriter.OPENING);
                generatedXML.writeElement("DAV::prop", XMLWriter.OPENING);

                writeCustomProperties(transaction, generatedXML, path, false, propertiesVector);
                generatedXML.writeElement("DAV::creationdate", XMLWriter.NO_CONTENT);
                generatedXML.writeElement("DAV::displayname", XMLWriter.NO_CONTENT);
                if (!isFolder) {
                    generatedXML.writeElement("DAV::getcontentlanguage", XMLWriter.NO_CONTENT);
                    generatedXML.writeElement("DAV::getcontentlength", XMLWriter.NO_CONTENT);
                    generatedXML.writeElement("DAV::getcontenttype", XMLWriter.NO_CONTENT);
                    generatedXML.writeElement("DAV::getetag", XMLWriter.NO_CONTENT);
                    generatedXML.writeElement("DAV::getlastmodified", XMLWriter.NO_CONTENT);
                }
                generatedXML.writeElement("DAV::resourcetype", XMLWriter.NO_CONTENT);
                generatedXML.writeElement("DAV::supportedlock", XMLWriter.NO_CONTENT);
                generatedXML.writeElement("DAV::source", XMLWriter.NO_CONTENT);

                generatedXML.writeElement("DAV::prop", XMLWriter.CLOSING);
                generatedXML.writeElement("DAV::status", XMLWriter.OPENING);
                generatedXML.writeText(status);
                generatedXML.writeElement("DAV::status", XMLWriter.CLOSING);
                generatedXML.writeElement("DAV::propstat", XMLWriter.CLOSING);

                break;

            case FIND_BY_PROPERTY:

                Vector<String> propertiesNotFound = new Vector<String>();

                // Parse the list of properties

                generatedXML.writeElement("DAV::propstat", XMLWriter.OPENING);
                generatedXML.writeElement("DAV::prop", XMLWriter.OPENING);

                writeCustomProperties(transaction, generatedXML, path, true, propertiesVector);

                Enumeration<String> properties = propertiesVector.elements();

                while (properties.hasMoreElements()) {

                    String property = properties.nextElement();

                    if (property.equals("DAV::creationdate")) {
                        generatedXML.writeProperty("DAV::creationdate", creationdate);
                    } else if (property.equals("DAV::displayname")) {
                        generatedXML.writeElement("DAV::displayname", XMLWriter.OPENING);
                        generatedXML.writeData(resourceName);
                        generatedXML.writeElement("DAV::displayname", XMLWriter.CLOSING);
                    } else if (property.equals("DAV::getcontentlanguage")) {
                        if (isFolder) {
                            propertiesNotFound.addElement(property);
                        } else {
                            generatedXML.writeElement("DAV::getcontentlanguage", XMLWriter.NO_CONTENT);
                        }
                    } else if (property.equals("DAV::getcontentlength")) {
                        if (isFolder) {
                            propertiesNotFound.addElement(property);
                        } else {
                            generatedXML.writeProperty("DAV::getcontentlength", resourceLength);
                        }
                    } else if (property.equals("DAV::getcontenttype")) {
                        if (isFolder) {
                            propertiesNotFound.addElement(property);
                        } else {
                            generatedXML.writeProperty("DAV::getcontenttype", mimeType);
                        }
                    } else if (property.equals("DAV::getetag")) {
                        if (isFolder || so.isNullResource()) {
                            propertiesNotFound.addElement(property);
                        } else {
                            generatedXML.writeProperty("DAV::getetag", getETag(so));
                        }
                    } else if (property.equals("DAV::getlastmodified")) {
View Full Code Here

        // Retrieve the resources
        String tempLockOwner = "doProppatch" + System.currentTimeMillis() + req.toString();

        if (resourceLocks.lock(transaction, path, tempLockOwner, false, 0, TEMP_TIMEOUT, TEMPORARY)) {
            StoredObject so = null;
            LockedObject lo = null;
            try {
                so = store.getStoredObject(transaction, path);
                lo = resourceLocks.getLockedObjectByPath(transaction, getCleanPath(path));

                if (so == null) {
                    resp.sendError(HttpServletResponse.SC_NOT_FOUND);
                    return;
                    // we do not to continue since there is no root
                    // resource
                }

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

                String[] lockTokens = getLockIdFromIfHeader(req);
                boolean lockTokenMatchesIfHeader = (lockTokens != null && lockTokens[0].equals(lo.getID()));
                if (lo != null && lo.isExclusive() && !lockTokenMatchesIfHeader) {
                    // Object on specified path is LOCKED
                    errorList = new Hashtable<String, Integer>();
                    errorList.put(path, WebdavStatus.SC_LOCKED);
                    sendReport(req, resp, errorList);
                    return;
                }

                Map<String, Object> propertiesToSet = new HashMap<String, Object>();
                List<String> propertiesToRemove = new ArrayList<String>();
                List<String> allProperties = new Vector<String>();
                Map<String, String> response = null;

                path = getCleanPath(getRelativePath(req));

                Node tosetNode = null;
                Node toremoveNode = null;

                if (RequestUtil.streamNotConsumed(req)) {
                    DocumentBuilder documentBuilder = getDocumentBuilder();
                    try {
                        Document document = documentBuilder.parse(new InputSource(req.getInputStream()));
                        // Get the root element of the document
                        Element rootElement = document.getDocumentElement();

                        tosetNode = XMLHelper.findSubElement(XMLHelper.findSubElement(rootElement, "set"), "prop");
                        if (tosetNode != null) {
                            propertiesToSet = XMLHelper.getPropertiesWithValuesFromXML(tosetNode);
                        }

                        toremoveNode = XMLHelper.findSubElement(XMLHelper.findSubElement(rootElement, "remove"), "prop");
                        if (toremoveNode != null) {
                            propertiesToRemove = XMLHelper.getPropertiesFromXML(toremoveNode);
                        }
                        if (!propertiesToSet.isEmpty() || !propertiesToRemove.isEmpty()) {
                            response = store.setCustomProperties(transaction, path, propertiesToSet, propertiesToRemove);
                        }
                    } catch (Exception e) {
                        resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
                        return;
                    }
                } else {
                    // no content: error
                    resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
                    return;
                }

                allProperties.addAll(propertiesToSet.keySet());
                allProperties.addAll(propertiesToRemove);

                HashMap<String, String> namespaces = new HashMap<String, String>();
                namespaces.put("DAV:", "D");

                resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
                resp.setContentType("text/xml; charset=UTF-8");

                // Create multistatus object
                XMLWriter generatedXML = new XMLWriter(resp.getWriter(), namespaces);
                generatedXML.writeXMLHeader();
                generatedXML.writeElement("DAV::multistatus", XMLWriter.OPENING);

                generatedXML.writeElement("DAV::response", XMLWriter.OPENING);

                // Generating href element
                generatedXML.writeElement("DAV::href", XMLWriter.OPENING);

                String href = req.getContextPath();
                if ((href.endsWith("/")) && (path.startsWith("/"))) {
                    href += path.substring(1);
                } else {
                    href += path;
                }
                if ((so.isFolder()) && (!href.endsWith("/"))) {
                    href += "/";
                }

                generatedXML.writeText(rewriteUrl(href));
View Full Code Here

                }
            }

            String tempLockOwner = "doPut" + System.currentTimeMillis() + req.toString();
            if (resourceLocks.lock(transaction, path, tempLockOwner, false, 0, TEMP_TIMEOUT, TEMPORARY)) {
                StoredObject parentSo, so = null;
                try {
                    parentSo = store.getStoredObject(transaction, parentPath);
                    if (parentPath != null && parentSo != null && parentSo.isResource()) {
                        resp.sendError(WebdavStatus.SC_FORBIDDEN);
                        return;

                    } else if (parentPath != null && parentSo == null && lazyFolderCreationOnPut) {
                        store.createFolder(transaction, parentPath);
View Full Code Here

            return;
        }

        String tempLockOwner = "doMkcol" + System.currentTimeMillis() + req.toString();

        StoredObject parentSo, so = null;
        try {
            if (!resourceLocks.lock(transaction, path, tempLockOwner, false, 0, TEMP_TIMEOUT, TEMPORARY)) {
                logger.debug("Resource lock failed.");
                resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
                return;
            }
            parentSo = store.getStoredObject(transaction, parentPath);
            if (parentSo == null) {
                // parent not exists
                logger.debug("Parent not exists for " + path);
                resp.sendError(WebdavStatus.SC_CONFLICT);
                return;
            }
            if (parentPath != null && parentSo.isFolder()) {
                so = store.getStoredObject(transaction, path);
                if (so == null) {
                    store.createFolder(transaction, path);
                    resp.setStatus(WebdavStatus.SC_CREATED);
                    return;
                }
                // object already exists
                if (so.isNullResource()) {
                    LockedObject nullResourceLo = resourceLocks.getLockedObjectByPath(transaction, path);
                    if (nullResourceLo == null) {
                        resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
                        return;
                    }
                    String nullResourceLockToken = nullResourceLo.getID();
                    String[] lockTokens = getLockIdFromIfHeader(req);
                    String lockToken = null;
                    if (lockTokens != null) {
                        lockToken = lockTokens[0];
                    } else {
                        resp.sendError(WebdavStatus.SC_BAD_REQUEST);
                        return;
                    }
                    if (lockToken.equals(nullResourceLockToken)) {
                        so.setNullResource(false);
                        so.setFolder(true);

                        String[] nullResourceLockOwners = nullResourceLo.getOwner();
                        String owner = null;
                        if (nullResourceLockOwners != null) {
                            owner = nullResourceLockOwners[0];
                        }

                        if (resourceLocks.unlock(transaction, lockToken, owner)) {
                            resp.setStatus(WebdavStatus.SC_CREATED);
                        } else {
                            resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
                        }

                    } else {
                        errorList.put(path, WebdavStatus.SC_LOCKED);
                        sendReport(req, resp, errorList);
                    }

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

            } else if (parentPath != null && parentSo.isResource()) {
                String methodsAllowed = DeterminableMethod.determineMethodsAllowed(parentSo);
                resp.addHeader("Allow", methodsAllowed);
                resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);

            } else {
View Full Code Here

                                owner = owners[0];
                            }
                        }

                        if (resourceLocks.unlock(transaction, lockId, owner)) {
                            StoredObject so = store.getStoredObject(transaction, path);
                            if (so == null) {
                                resp.setStatus(WebdavStatus.SC_NOT_FOUND);
                            } else {
                                if (so.isNullResource()) {
                                    store.removeObject(transaction, path);
                                }
                                resp.setStatus(WebdavStatus.SC_NO_CONTENT);
                            }
                        } else {
View Full Code Here

        logger.trace("-- " + this.getClass().getName());

        String tempLockOwner = "doOptions" + System.currentTimeMillis() + req.toString();
        String path = getRelativePath(req);
        if (resourceLocks.lock(transaction, path, tempLockOwner, false, 0, TEMP_TIMEOUT, TEMPORARY)) {
            StoredObject so = null;
            try {
                resp.addHeader("DAV", "1, 2");

                so = store.getStoredObject(transaction, path);
                String methodsAllowed = determineMethodsAllowed(so);
View Full Code Here

        boolean bUriExists = false;

        String path = getRelativePath(req);
        logger.trace("-- " + this.getClass().getName());

        StoredObject so = store.getStoredObject(transaction, path);
        if (so == null) {
            if (this.insteadOf404 != null && !insteadOf404.trim().equals("")) {
                path = this.insteadOf404;
                so = store.getStoredObject(transaction, this.insteadOf404);
            }
        } else {
            bUriExists = true;
        }

        if (so != null) {
            if (so.isFolder()) {
                if (dftIndexFile != null && !dftIndexFile.trim().equals("")) {
                    resp.sendRedirect(resp.encodeRedirectURL(req.getRequestURI() + this.dftIndexFile));
                    return;
                }
            } else if (so.isNullResource()) {
                String methodsAllowed = DeterminableMethod.determineMethodsAllowed(so);
                resp.addHeader("Allow", methodsAllowed);
                resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
                return;
            }

            String tempLockOwner = "doGet" + System.currentTimeMillis() + req.toString();

            if (resourceLocks.lock(transaction, path, tempLockOwner, false, 0, TEMP_TIMEOUT, TEMPORARY)) {
                try {
                    String eTagMatch = req.getHeader("If-None-Match");
                    if (eTagMatch != null) {
                        if (eTagMatch.equals(getETag(so))) {
                            resp.setStatus(WebdavStatus.SC_NOT_MODIFIED);
                            return;
                        }
                    }

                    if (so.isResource()) {
                        // path points to a file but ends with / or \
                        if (path.endsWith("/") || (path.endsWith("\\"))) {
                            resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getRequestURI());
                        } else {

                            // setting headers
                            long lastModified = so.getLastModified().getTime();
                            resp.setDateHeader("last-modified", lastModified);

                            String eTag = getETag(so);
                            resp.addHeader("ETag", eTag);

                            long resourceLength = so.getResourceLength();

                            if (contentLength == 1) {
                                if (resourceLength > 0) {
                                    if (resourceLength <= Integer.MAX_VALUE) {
                                        resp.setContentLength((int)resourceLength);
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.