List of usage examples for java.util Vector elements
public Enumeration<E> elements()
From source file:org.apache.webdav.lib.WebdavResource.java
public Enumeration reportMethod(HttpURL httpURL, Vector properties, Vector histUri, int depth) throws HttpException, IOException { setClient();/*from www.ja v a 2 s . c o m*/ // Default depth=0, type=by_name ReportMethod method = new ReportMethod(httpURL.getEscapedPath(), depth, properties.elements(), histUri.elements()); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Vector results = new Vector(); Enumeration responses = method.getResponses(); while (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); String href = response.getHref(); String sResult = href; // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; Enumeration responseProperties = method.getResponseProperties(href); while (responseProperties.hasMoreElements()) { Property property = (Property) responseProperties.nextElement(); sResult += "\n" + property.getName() + ":\t" + DOMUtils.getTextValue(property.getElement()); } results.addElement(sResult); } return results.elements(); }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute PROPFIND method for the given path and properties. * Get list of given WebDAV properties on the given resource. * * @param path the server relative path of the resource to request * @param properties the WebDAV properties to find. * @return Enumeration list of WebDAV properties on a resource. * @exception HttpException// ww w. j av a 2 s . c om * @exception IOException */ public Enumeration propfindMethod(String path, Vector properties) throws HttpException, IOException { setClient(); // Default depth=0, type=by_name PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path), DepthSupport.DEPTH_0, properties.elements()); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); int status = client.executeMethod(method); // Also accept OK sent by buggy servers. if (status != HttpStatus.SC_MULTI_STATUS && status != HttpStatus.SC_OK) { HttpException ex = new HttpException(); ex.setReasonCode(status); throw ex; } // It contains the results. Vector results = new Vector(); Enumeration responses = method.getResponses(); if (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); String href = response.getHref(); // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; Enumeration responseProperties = method.getResponseProperties(href); while (responseProperties.hasMoreElements()) { Property property = (Property) responseProperties.nextElement(); results.addElement(property.getPropertyAsString()); } } return results.elements(); }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Return the <code>AclProperty</code> for the resource at the given path * * @param path the server relative path of the resource to request * @return acl property, null if the server doesn't respond with * <code>AclProperty</code>/* www . jav a 2 s .c o m*/ */ public AclProperty aclfindMethod(String path) throws HttpException, IOException { setClient(); AclProperty acl = null; Vector properties = new Vector(); properties.addElement(AclProperty.TAG_NAME); // Default depth=0, type=by_name PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path), DepthSupport.DEPTH_0, properties.elements()); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Enumeration responses = method.getResponses(); if (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); String href = response.getHref(); // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; Enumeration responseProperties = method.getResponseProperties(href); while (responseProperties.hasMoreElements()) { Property property = (Property) responseProperties.nextElement(); if (property instanceof AclProperty) { acl = (AclProperty) property; } } } return acl; }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Return the LockDiscoveryProperty for the resource at the given path * * @param path the server relative path of the resource to request * @return null if the server doesn't respond with a LockDiscoveryProperty */// www. ja v a2s .c o m public LockDiscoveryProperty lockDiscoveryPropertyFindMethod(String path) throws HttpException, IOException { setClient(); LockDiscoveryProperty set = null; Vector properties = new Vector(); properties.addElement(LockDiscoveryProperty.TAG_NAME); // Default depth=0, type=by_name PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path), DepthSupport.DEPTH_0, properties.elements()); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Enumeration responses = method.getResponses(); if (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); String href = response.getHref(); // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; Enumeration responseProperties = method.getResponseProperties(href); while (responseProperties.hasMoreElements()) { Property property = (Property) responseProperties.nextElement(); if (property instanceof LockDiscoveryProperty) { set = (LockDiscoveryProperty) property; } } } return set; }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Get the <code>PrincipalCollectionSetProperty</code> for the resource. * * @param path the server relative path of the resource to request * @return principal collection set Property, null if the server doesn't * respond with a <code>PrincipalCollectionSetProperty</code> *//*from w w w .j a v a 2 s. c om*/ public PrincipalCollectionSetProperty principalCollectionSetFindMethod(String path) throws HttpException, IOException { setClient(); PrincipalCollectionSetProperty set = null; Vector properties = new Vector(); properties.addElement(PrincipalCollectionSetProperty.TAG_NAME); // Default depth=0, type=by_name PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path), DepthSupport.DEPTH_0, properties.elements()); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Enumeration responses = method.getResponses(); if (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); String href = response.getHref(); // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; Enumeration responseProperties = method.getResponseProperties(href); while (responseProperties.hasMoreElements()) { Property property = (Property) responseProperties.nextElement(); if (property instanceof PrincipalCollectionSetProperty) { set = (PrincipalCollectionSetProperty) property; } } } return set; }
From source file:com.zeroio.webdav.WebdavServlet.java
/** * LOCK Method.//from w w w .j av a 2 s. co m * * @param context Description of the Parameter * @throws ServletException Description of the Exception * @throws IOException Description of the Exception */ protected void doLock(ActionContext context) throws ServletException, IOException { if (readOnly) { context.getResponse().sendError(WebdavStatus.SC_FORBIDDEN); return; } if (isLocked(context.getRequest())) { context.getResponse().sendError(WebdavStatus.SC_LOCKED); return; } LockInfo lock = new LockInfo(); // Parsing lock request // Parsing depth header String depthStr = context.getRequest().getHeader("Depth"); if (depthStr == null) { lock.depth = INFINITY; } else { if (depthStr.equals("0")) { lock.depth = 0; } else { lock.depth = INFINITY; } } // Parsing timeout header int lockDuration = DEFAULT_TIMEOUT; String lockDurationStr = context.getRequest().getHeader("Timeout"); if (lockDurationStr == null) { lockDuration = DEFAULT_TIMEOUT; } else { int commaPos = lockDurationStr.indexOf(","); // If multiple timeouts, just use the first if (commaPos != -1) { lockDurationStr = lockDurationStr.substring(0, commaPos); } if (lockDurationStr.startsWith("Second-")) { lockDuration = (new Integer(lockDurationStr.substring(7))).intValue(); } else { if (lockDurationStr.equalsIgnoreCase("infinity")) { lockDuration = MAX_TIMEOUT; } else { try { lockDuration = (new Integer(lockDurationStr)).intValue(); } catch (NumberFormatException e) { lockDuration = MAX_TIMEOUT; } } } if (lockDuration == 0) { lockDuration = DEFAULT_TIMEOUT; } if (lockDuration > MAX_TIMEOUT) { lockDuration = MAX_TIMEOUT; } } lock.expiresAt = System.currentTimeMillis() + (lockDuration * 1000); int lockRequestType = LOCK_CREATION; Node lockInfoNode = null; DocumentBuilder documentBuilder = getDocumentBuilder(); try { Document document = documentBuilder.parse(new InputSource(context.getRequest().getInputStream())); // Get the root element of the document Element rootElement = document.getDocumentElement(); lockInfoNode = rootElement; } catch (Exception e) { lockRequestType = LOCK_REFRESH; } if (lockInfoNode != null) { // Reading lock information NodeList childList = lockInfoNode.getChildNodes(); StringWriter strWriter = null; DOMWriter domWriter = null; Node lockScopeNode = null; Node lockTypeNode = null; Node lockOwnerNode = null; for (int i = 0; i < childList.getLength(); i++) { Node currentNode = childList.item(i); switch (currentNode.getNodeType()) { case Node.TEXT_NODE: break; case Node.ELEMENT_NODE: String nodeName = currentNode.getNodeName(); if (nodeName.endsWith("lockscope")) { lockScopeNode = currentNode; } if (nodeName.endsWith("locktype")) { lockTypeNode = currentNode; } if (nodeName.endsWith("owner")) { lockOwnerNode = currentNode; } break; } } if (lockScopeNode != null) { childList = lockScopeNode.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { Node currentNode = childList.item(i); switch (currentNode.getNodeType()) { case Node.TEXT_NODE: break; case Node.ELEMENT_NODE: String tempScope = currentNode.getNodeName(); if (tempScope.indexOf(':') != -1) { lock.scope = tempScope.substring(tempScope.indexOf(':') + 1); } else { lock.scope = tempScope; } break; } } if (lock.scope == null) { // Bad request context.getResponse().setStatus(WebdavStatus.SC_BAD_REQUEST); } } else { // Bad request context.getResponse().setStatus(WebdavStatus.SC_BAD_REQUEST); } if (lockTypeNode != null) { childList = lockTypeNode.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { Node currentNode = childList.item(i); switch (currentNode.getNodeType()) { case Node.TEXT_NODE: break; case Node.ELEMENT_NODE: String tempType = currentNode.getNodeName(); if (tempType.indexOf(':') != -1) { lock.type = tempType.substring(tempType.indexOf(':') + 1); } else { lock.type = tempType; } break; } } if (lock.type == null) { // Bad request context.getResponse().setStatus(WebdavStatus.SC_BAD_REQUEST); } } else { // Bad request context.getResponse().setStatus(WebdavStatus.SC_BAD_REQUEST); } if (lockOwnerNode != null) { childList = lockOwnerNode.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { Node currentNode = childList.item(i); switch (currentNode.getNodeType()) { case Node.TEXT_NODE: lock.owner += currentNode.getNodeValue(); break; case Node.ELEMENT_NODE: strWriter = new StringWriter(); domWriter = new DOMWriter(strWriter, true); domWriter.setQualifiedNames(false); domWriter.print(currentNode); lock.owner += strWriter.toString(); break; } } if (lock.owner == null) { // Bad request context.getResponse().setStatus(WebdavStatus.SC_BAD_REQUEST); } } else { lock.owner = new String(); } } String path = getRelativePath(context.getRequest()); //Fix for MACOSX finder. Do not allow requests for files starting with a period if (path.indexOf("/.") > -1 || path.indexOf(".DS_Store") > -1) { return; } lock.path = path; // Retrieve the resources DirContext resources = getResources(); if (resources == null) { context.getResponse().sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } boolean exists = true; Object object = null; try { object = resources.lookup(path); } catch (NamingException e) { exists = false; } Enumeration locksList = null; if (lockRequestType == LOCK_CREATION) { // Generating lock id String lockTokenStr = context.getRequest().getServletPath() + "-" + lock.type + "-" + lock.scope + "-" + context.getRequest().getUserPrincipal() + "-" + lock.depth + "-" + lock.owner + "-" + lock.tokens + "-" + lock.expiresAt + "-" + System.currentTimeMillis() + "-" + secret; String lockToken = md5Encoder.encode(md5Helper.digest(lockTokenStr.getBytes())); if ((exists) && (object instanceof DirContext) && (lock.depth == INFINITY)) { // Locking a collection (and all its member resources) // Checking if a child resource of this collection is // already locked Vector lockPaths = new Vector(); locksList = collectionLocks.elements(); while (locksList.hasMoreElements()) { LockInfo currentLock = (LockInfo) locksList.nextElement(); if (currentLock.hasExpired()) { resourceLocks.remove(currentLock.path); continue; } if ((currentLock.path.startsWith(lock.path)) && ((currentLock.isExclusive()) || (lock.isExclusive()))) { // A child collection of this collection is locked lockPaths.addElement(currentLock.path); } } locksList = resourceLocks.elements(); while (locksList.hasMoreElements()) { LockInfo currentLock = (LockInfo) locksList.nextElement(); if (currentLock.hasExpired()) { resourceLocks.remove(currentLock.path); continue; } if ((currentLock.path.startsWith(lock.path)) && ((currentLock.isExclusive()) || (lock.isExclusive()))) { // A child resource of this collection is locked lockPaths.addElement(currentLock.path); } } if (!lockPaths.isEmpty()) { // One of the child paths was locked // We generate a multistatus error report Enumeration lockPathsList = lockPaths.elements(); context.getResponse().setStatus(WebdavStatus.SC_CONFLICT); XMLWriter generatedXML = new XMLWriter(); generatedXML.writeXMLHeader(); generatedXML.writeElement(null, "multistatus" + generateNamespaceDeclarations(), XMLWriter.OPENING); while (lockPathsList.hasMoreElements()) { generatedXML.writeElement(null, "response", XMLWriter.OPENING); generatedXML.writeElement(null, "href", XMLWriter.OPENING); generatedXML.writeText((String) lockPathsList.nextElement()); generatedXML.writeElement(null, "href", XMLWriter.CLOSING); generatedXML.writeElement(null, "status", XMLWriter.OPENING); generatedXML.writeText("HTTP/1.1 " + WebdavStatus.SC_LOCKED + " " + WebdavStatus.getStatusText(WebdavStatus.SC_LOCKED)); generatedXML.writeElement(null, "status", XMLWriter.CLOSING); generatedXML.writeElement(null, "response", XMLWriter.CLOSING); } generatedXML.writeElement(null, "multistatus", XMLWriter.CLOSING); Writer writer = context.getResponse().getWriter(); writer.write(generatedXML.toString()); writer.close(); return; } boolean addLock = true; // Checking if there is already a shared lock on this path locksList = collectionLocks.elements(); while (locksList.hasMoreElements()) { LockInfo currentLock = (LockInfo) locksList.nextElement(); if (currentLock.path.equals(lock.path)) { if (currentLock.isExclusive()) { context.getResponse().sendError(WebdavStatus.SC_LOCKED); return; } else { if (lock.isExclusive()) { context.getResponse().sendError(WebdavStatus.SC_LOCKED); return; } } currentLock.tokens.addElement(lockToken); lock = currentLock; addLock = false; } } if (addLock) { lock.tokens.addElement(lockToken); collectionLocks.addElement(lock); } } else { // Locking a single resource // Retrieving an already existing lock on that resource LockInfo presentLock = (LockInfo) resourceLocks.get(lock.path); if (presentLock != null) { if ((presentLock.isExclusive()) || (lock.isExclusive())) { // If either lock is exclusive, the lock can't be // granted context.getResponse().sendError(WebdavStatus.SC_PRECONDITION_FAILED); return; } else { presentLock.tokens.addElement(lockToken); lock = presentLock; } } else { lock.tokens.addElement(lockToken); resourceLocks.put(lock.path, lock); // Checking if a resource exists at this path exists = true; try { object = resources.lookup(path); } catch (NamingException e) { exists = false; } if (!exists) { // "Creating" a lock-null resource int slash = lock.path.lastIndexOf('/'); String parentPath = lock.path.substring(0, slash); Vector lockNulls = (Vector) lockNullResources.get(parentPath); if (lockNulls == null) { lockNulls = new Vector(); lockNullResources.put(parentPath, lockNulls); } //System.out.println("ADDED LOCK AT PATH: " + lock.path); lockNulls.addElement(lock.path); } // Add the Lock-Token header as by RFC 2518 8.10.1 // - only do this for newly created locks context.getResponse().addHeader("Lock-Token", "<opaquelocktoken:" + lockToken + ">"); } } } if (lockRequestType == LOCK_REFRESH) { String ifHeader = context.getRequest().getHeader("If"); if (ifHeader == null) { ifHeader = ""; } // Checking resource locks LockInfo toRenew = (LockInfo) resourceLocks.get(path); Enumeration tokenList = null; if (lock != null) { // At least one of the tokens of the locks must have been given tokenList = toRenew.tokens.elements(); while (tokenList.hasMoreElements()) { String token = (String) tokenList.nextElement(); if (ifHeader.indexOf(token) != -1) { toRenew.expiresAt = lock.expiresAt; lock = toRenew; } } } // Checking inheritable collection locks Enumeration collectionLocksList = collectionLocks.elements(); while (collectionLocksList.hasMoreElements()) { toRenew = (LockInfo) collectionLocksList.nextElement(); if (path.equals(toRenew.path)) { tokenList = toRenew.tokens.elements(); while (tokenList.hasMoreElements()) { String token = (String) tokenList.nextElement(); if (ifHeader.indexOf(token) != -1) { toRenew.expiresAt = lock.expiresAt; lock = toRenew; } } } } } // Set the status, then generate the XML response containing // the lock information XMLWriter generatedXML = new XMLWriter(); generatedXML.writeXMLHeader(); generatedXML.writeElement(null, "prop" + generateNamespaceDeclarations(), XMLWriter.OPENING); generatedXML.writeElement(null, "lockdiscovery", XMLWriter.OPENING); lock.toXML(generatedXML); generatedXML.writeElement(null, "lockdiscovery", XMLWriter.CLOSING); generatedXML.writeElement(null, "prop", XMLWriter.CLOSING); context.getResponse().setStatus(WebdavStatus.SC_OK); context.getResponse().setContentType("text/xml; charset=UTF-8"); Writer writer = context.getResponse().getWriter(); writer.write(generatedXML.toString()); writer.close(); }
From source file:org.apache.webdav.lib.WebdavResource.java
public Enumeration reportMethod(HttpURL httpURL, String sQuery, int depth) throws HttpException, IOException { setClient();//from w w w .ja va 2 s .com // Default depth=0, type=by_name ReportMethod method = new ReportMethod(httpURL.getEscapedPath(), depth, sQuery); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Vector results = new Vector(); Enumeration responses = method.getResponses(); while (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); //String href = (String) response.getHref(); String sResult; //= href; // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; sResult = response.toString(); /*while (responseProperties.hasMoreElements()) { Property property = (Property) responseProperties.nextElement(); sResult += "\t" + DOMUtils.getTextValue(property.getElement()); }*/ results.addElement(sResult); } return results.elements(); }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute the REPORT method./*from w w w . j a v a 2 s . co m*/ */ public Enumeration reportMethod(HttpURL httpURL, int depth) throws HttpException, IOException { setClient(); // Default depth=0, type=by_name ReportMethod method = new ReportMethod(httpURL.getEscapedPath(), depth); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Vector results = new Vector(); Enumeration responses = method.getResponses(); while (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); String href = response.getHref(); String sResult = href; // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; Enumeration responseProperties = method.getResponseProperties(href); while (responseProperties.hasMoreElements()) { Property property = (Property) responseProperties.nextElement(); sResult += "\n" + property.getName() + ":\t" + DOMUtils.getTextValue(property.getElement()); } results.addElement(sResult); } return results.elements(); }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute OPTIONS method for the given http URL, DELTAV * * @param httpURL the http URL./*from www . j a v a 2 s.com*/ * @return the allowed methods and capabilities. * @exception HttpException * @exception IOException */ public Enumeration optionsMethod(HttpURL httpURL, int type) throws HttpException, IOException { HttpClient client = getSessionInstance(httpURL, true); OptionsMethod method = new OptionsMethod(httpURL.getEscapedPath(), type); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Vector options = new Vector(); int statusCode = method.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { Enumeration responses = method.getResponses(); if (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); // String sResult=""; if (type == OPTIONS_WORKSPACE) { Enumeration workspaces = response.getWorkspaces(); while (workspaces.hasMoreElements()) { options.add(workspaces.nextElement().toString()); } } else if (type == OPTIONS_VERSION_HISTORY) { Enumeration histories = response.getHistories(); while (histories.hasMoreElements()) { options.add(histories.nextElement().toString()); } } // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; // options.addElement(sResult); } } return options.elements(); }
From source file:org.apache.webdav.lib.WebdavResource.java
/** * Execute OPTIONS method for the given path. * * @param path the server relative path of the resource to request * @return the allowed methods and capabilities. * @exception HttpException/* www. ja va 2 s. c o m*/ * @exception IOException * @see #getAllowedMethods() */ public Enumeration optionsMethod(String path, int type) throws HttpException, IOException { setClient(); OptionsMethod method = new OptionsMethod(URIUtil.encodePath(path), type); method.setDebug(debug); method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); generateAdditionalHeaders(method); client.executeMethod(method); Vector options = new Vector(); int statusCode = method.getStatusLine().getStatusCode(); if (statusCode >= 200 && statusCode < 300) { Enumeration responses = method.getResponses(); if (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); // String sResult=""; if (type == OPTIONS_WORKSPACE) { Enumeration workspaces = response.getWorkspaces(); while (workspaces.hasMoreElements()) { options.add(workspaces.nextElement().toString()); } } else if (type == OPTIONS_VERSION_HISTORY) { Enumeration histories = response.getHistories(); while (histories.hasMoreElements()) { options.add(histories.nextElement().toString()); } } // Set status code for this resource. if ((thisResource == true) && (response.getStatusCode() > 0)) setStatusCode(response.getStatusCode()); thisResource = false; // options.addElement(sResult); } } return options.elements(); }