List of usage examples for org.apache.commons.httpclient.util URIUtil decode
public static String decode(String escaped) throws URIException
From source file:org.pengyou.client.lib.DavResource.java
protected void setEncodedPath(String path) { try {/* w w w . java2 s.co m*/ setPath(URIUtil.decode(path)); } catch (URIException e) { this.path = path; log.warn("can't decode the path ", e); } }
From source file:org.pengyou.client.lib.DavResource.java
/** * Set WebDAV properties following to the given http URL. * This method is fundamental for getting information of a collection. * * @param responses An enumeration over {@link ResponseEntity} items, one * for each resource for which information was returned via PROPFIND. * * @exception HttpException//from ww w . ja va 2 s. c om * @exception IOException The socket error with a server. */ protected void setWebdavProperties(Enumeration responses) throws HttpException, IOException { // Make the resources in the collection empty. childResources.removeAll(); while (responses.hasMoreElements()) { ResponseEntity response = (ResponseEntity) responses.nextElement(); boolean itself = false; String href = response.getHref(); if (!href.startsWith("/")) href = URIUtil.getPath(href); href = decodeMarks(href); /* * Decode URIs to common (unescaped) format for comparison * as HttpClient.URI.setPath() doesn't escape $ and : chars. */ //String httpURLPath = httpURL.getPath(); String httpURLPath = context.getBaseUrl() + getPath(); String escapedHref = URIUtil.decode(href); // Normalize them to both have trailing slashes if they differ by one in length. int lenDiff = escapedHref.length() - httpURLPath.length(); int compareLen = 0; if (lenDiff == -1 && !escapedHref.endsWith("/")) { compareLen = escapedHref.length(); lenDiff = 0; } else if (lenDiff == 1 && !httpURLPath.endsWith("/")) { compareLen = httpURLPath.length(); lenDiff = 0; } // if they are the same length then compare them. if (lenDiff == 0) { if ((compareLen == 0 && httpURLPath.equals(escapedHref)) || httpURLPath.regionMatches(0, escapedHref, 0, compareLen)) { // escaped href and http path are the same // Set the status code for this resource. if (response.getStatusCode() > 0) this.statusCode = response.getStatusCode(); this.exist = true; itself = true; } } // Get to know each resource. DavResource workingResource = null; if (itself) { workingResource = this; } else { workingResource = createWebdavResource(client); } // clear the current lock set workingResource.setLockDiscovery(null); // Process the resource's properties Enumeration properties = response.getProperties(); while (properties.hasMoreElements()) { Property property = (Property) properties.nextElement(); // ------------------------------ Checking WebDAV properties workingResource.processProperty(property); } String displayName = workingResource.displayName; if (displayName == null || displayName.trim().equals("")) { displayName = getName(href); } if (!itself) { String myPath = getPath(); String childPath = myPath + (myPath.endsWith("/") ? "" : "/") + DavResource.getName(href); //(myPath.endsWith("/") ? "" : "/") + URIUtil.getName(href); workingResource.setEncodedPath(childPath); workingResource.setExistence(true); } if (!itself) childResources.addResource(workingResource); } }
From source file:org.pengyou.client.lib.DavResource.java
private static String getName(String uri) { String escapedName = URIUtil.getName(uri.endsWith("/") ? uri.substring(0, uri.length() - 1) : uri); try {// ww w. ja v a2 s .c o m return URIUtil.decode(escapedName); } catch (URIException e) { return escapedName; } }
From source file:org.pengyou.client.lib.properties.AclProperty.java
/** * Parse an ace./* ww w .ja v a 2 s .c o m*/ */ protected Ace parseAce(Element element) { String principal = null; Element child = DOMUtils.getFirstElement(element, "DAV:", "principal"); if (child == null) { System.err.println("Error: mandatory element <principal> is missing !"); System.err.println("element: " + element); return null; } Element href = DOMUtils.getFirstElement(child, "DAV:", "href"); if (href != null) { principal = DOMUtils.getTextValue(href); try { principal = URIUtil.decode(principal); } catch (URIException e) { System.err.println("Warning: decoding href element failed!"); System.err.println("reason: " + e.getReason()); } } String[] types = { "all", "authenticated", "unauthenticated", "property", "self" }; for (int i = 0; i < types.length && principal == null; i++) { Element type = DOMUtils.getFirstElement(child, "DAV:", types[i]); if (type != null) { principal = types[i]; } } if (principal == null) { System.err.println("Error: unknown type of principal"); System.err.println("element: " + element); return null; } Ace ace = new Ace(principal); child = DOMUtils.getFirstElement(element, "DAV:", "grant"); if (child == null) { child = DOMUtils.getFirstElement(element, "DAV:", "deny"); ace.setNegative(true); } if (child != null) { NodeList privilegeElements = child.getElementsByTagNameNS("DAV:", "privilege"); for (int i = 0; i < privilegeElements.getLength(); i++) { Element privilegeElement = (Element) privilegeElements.item(i); NodeList privileges = privilegeElement.getElementsByTagName("*"); for (int j = 0; j < privileges.getLength(); j++) { Element privilege = (Element) privileges.item(j); ace.addPrivilege(parsePrivilege(privilege)); } } } child = DOMUtils.getFirstElement(element, "DAV:", "inherited"); if (child != null) { href = DOMUtils.getFirstElement(child, "DAV:", "href"); String shref = null; if (href != null) { shref = DOMUtils.getTextValue(href); if (!shref.equals(response.getHref())) { ace.setInherited(true); ace.setInheritedFrom(shref); } } else { System.err.println("Error: mandatory element <href> is missing !"); return null; } } child = DOMUtils.getFirstElement(element, "DAV:", "protected"); if (child != null) { ace.setProtected(true); } return ace; }
From source file:org.pengyou.ooo.utils.WebDavStore.java
public Vector getMyVersions() { Vector<String[]> version = new Vector<String[]>(); try {//from w w w . ja v a2 s . c om Enumeration versions = webdavResource.reportMethod(webdavResource.getHttpURL(), 1); while (versions.hasMoreElements()) { String filename = (String) versions.nextElement(); filename = URIUtil.decode(filename); WebdavResource res = allocResource(null, filename, connectionUrl + connectionBaseDirectory, connectionPassword, filename.substring(connectionUrl.length() + 1 + String.valueOf(connectionPort).length())); String[] t = new String[4]; t[0] = URIUtil.decode(res.getName()); t[1] = res.getOwner(); t[2] = Long.toString(res.getGetLastModified()); t[3] = res.getPath(); version.add(t); } return version; } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:org.pengyou.ooo.utils.WebDavStore.java
public Vector getVersions() throws HttpException { Vector<Vector<String>> versionVector = new Vector<Vector<String>>(); try {//from w w w . j a va 2s. c o m Enumeration versions = webdavResource.reportMethod(webdavResource.getHttpURL(), 0); while (versions.hasMoreElements()) { String filename = (String) versions.nextElement(); filename = URIUtil.decode(filename); WebdavResource res; res = allocResource(null, filename, connectionUrl + connectionBaseDirectory, connectionPassword, filename.substring(connectionUrl.length() + 1 + String.valueOf(connectionPort).length())); Vector<String> versionInfo = new Vector<String>(); versionInfo.add(res.getDisplayName()); versionInfo.add(filename); //SimpleDateFormat dateFormat = new SimpleDateFormat(configuration.getConfigurationValue("Application","dateformat")); SimpleDateFormat dateFormat = new SimpleDateFormat(); Date lastModified = new Date(res.getGetLastModified()); versionInfo.add(dateFormat.format(lastModified)); versionInfo.add(res.getOwner()); versionVector.add(versionInfo); } } catch (Exception e) { return null; } return versionVector; }
From source file:org.uberfire.java.nio.fs.jgit.JGitFileSystemProvider.java
private String extractPath(final URI uri) { checkNotNull("uri", uri); final String host = extractHost(uri); final String path; try {/*from www.j a v a 2 s. c om*/ path = URIUtil.decode(uri.toString()).substring(getSchemeSize(uri) + host.length()); } catch (URIException e) { return null; } if (path.startsWith("/:")) { return path.substring(2); } return path; }