List of usage examples for org.apache.commons.httpclient.util URIUtil decode
public static String decode(String escaped) throws URIException
From source file:davmail.exchange.dav.DavExchangeSession.java
protected String getURLPropertyIfExists(DavPropertySet properties, String alias) throws URIException { String result = getPropertyIfExists(properties, alias); if (result != null) { result = URIUtil.decode(result); }/* w w w . j a va 2s . c om*/ return result; }
From source file:davmail.exchange.dav.DavExchangeSession.java
protected Message buildMessage(MultiStatusResponse responseEntity) throws URIException, DavMailException { Message message = new Message(); message.messageUrl = URIUtil.decode(responseEntity.getHref()); DavPropertySet properties = responseEntity.getProperties(HttpStatus.SC_OK); message.permanentUrl = getURLPropertyIfExists(properties, "permanenturl"); message.size = getIntPropertyIfExists(properties, "messageSize"); message.uid = getPropertyIfExists(properties, "uid"); message.contentClass = getPropertyIfExists(properties, "contentclass"); message.imapUid = getLongPropertyIfExists(properties, "imapUid"); message.read = "1".equals(getPropertyIfExists(properties, "read")); message.junk = "1".equals(getPropertyIfExists(properties, "junk")); message.flagged = "2".equals(getPropertyIfExists(properties, "flagStatus")); message.draft = (getIntPropertyIfExists(properties, "messageFlags") & 8) != 0; String lastVerbExecuted = getPropertyIfExists(properties, "lastVerbExecuted"); message.answered = "102".equals(lastVerbExecuted) || "103".equals(lastVerbExecuted); message.forwarded = "104".equals(lastVerbExecuted); message.date = convertDateFromExchange(getPropertyIfExists(properties, "date")); message.deleted = "1".equals(getPropertyIfExists(properties, "deleted")); String lastmodified = convertDateFromExchange(getPropertyIfExists(properties, "lastmodified")); message.recent = !message.read && lastmodified != null && lastmodified.equals(message.date); message.keywords = getPropertyIfExists(properties, "keywords"); if (LOGGER.isDebugEnabled()) { StringBuilder buffer = new StringBuilder(); buffer.append("Message"); if (message.imapUid != 0) { buffer.append(" IMAP uid: ").append(message.imapUid); }/* w w w . j av a2s. c o m*/ if (message.uid != null) { buffer.append(" uid: ").append(message.uid); } buffer.append(" href: ").append(responseEntity.getHref()).append(" permanenturl:") .append(message.permanentUrl); LOGGER.debug(buffer.toString()); } return message; }
From source file:davmail.exchange.dav.DavExchangeSession.java
/** * create a fake event to get VTIMEZONE body *///from ww w. jav a 2 s . co m @Override protected void loadVtimezone() { try { // create temporary folder String folderPath = getFolderPath("davmailtemp"); createCalendarFolder(folderPath, null); String fakeEventUrl = null; if ("Exchange2003".equals(serverVersion)) { PostMethod postMethod = new PostMethod(URIUtil.encodePath(folderPath)); postMethod.addParameter("Cmd", "saveappt"); postMethod.addParameter("FORMTYPE", "appointment"); try { // create fake event int statusCode = httpClient.executeMethod(postMethod); if (statusCode == HttpStatus.SC_OK) { fakeEventUrl = StringUtil.getToken(postMethod.getResponseBodyAsString(), "<span id=\"itemHREF\">", "</span>"); if (fakeEventUrl != null) { fakeEventUrl = URIUtil.decode(fakeEventUrl); } } } finally { postMethod.releaseConnection(); } } // failover for Exchange 2007, use PROPPATCH with forced timezone if (fakeEventUrl == null) { ArrayList<PropEntry> propertyList = new ArrayList<PropEntry>(); propertyList.add(Field.createDavProperty("contentclass", "urn:content-classes:appointment")); propertyList.add(Field.createDavProperty("outlookmessageclass", "IPM.Appointment")); propertyList.add(Field.createDavProperty("instancetype", "0")); // get forced timezone id from settings String timezoneId = Settings.getProperty("davmail.timezoneId"); if (timezoneId == null) { // get timezoneid from OWA settings timezoneId = getTimezoneIdFromExchange(); } // without a timezoneId, use Exchange timezone if (timezoneId != null) { propertyList.add(Field.createDavProperty("timezoneid", timezoneId)); } String patchMethodUrl = folderPath + '/' + UUID.randomUUID().toString() + ".EML"; PropPatchMethod patchMethod = new PropPatchMethod(URIUtil.encodePath(patchMethodUrl), propertyList); try { int statusCode = httpClient.executeMethod(patchMethod); if (statusCode == HttpStatus.SC_MULTI_STATUS) { fakeEventUrl = patchMethodUrl; } } finally { patchMethod.releaseConnection(); } } if (fakeEventUrl != null) { // get fake event body GetMethod getMethod = new GetMethod(URIUtil.encodePath(fakeEventUrl)); getMethod.setRequestHeader("Translate", "f"); try { httpClient.executeMethod(getMethod); this.vTimezone = new VObject( "BEGIN:VTIMEZONE" + StringUtil.getToken(getMethod.getResponseBodyAsString(), "BEGIN:VTIMEZONE", "END:VTIMEZONE") + "END:VTIMEZONE\r\n"); } finally { getMethod.releaseConnection(); } } // delete temporary folder deleteFolder("davmailtemp"); } catch (IOException e) { LOGGER.warn("Unable to get VTIMEZONE info: " + e, e); } }
From source file:org.apache.hadoop.fs.azure.MockStorageInterface.java
/** * Utility function used to convert a given URI to a decoded string * representation sent to the backing store. URIs coming as input * to this class will be encoded by the URI class, and we want * the underlying storage to store keys in their original UTF-8 form. */// w w w .java2s .c o m private static String convertUriToDecodedString(URI uri) { try { String result = URIUtil.decode(uri.toString()); return result; } catch (URIException e) { throw new AssertionError("Failed to decode URI: " + uri.toString()); } }
From source file:org.apache.hadoop.hive.ql.parse.LoadSemanticAnalyzer.java
private URI initializeFromURI(String fromPath, boolean isLocal) throws IOException, URISyntaxException { URI fromURI = new Path(fromPath).toUri(); String fromScheme = fromURI.getScheme(); String fromAuthority = fromURI.getAuthority(); String path = fromURI.getPath(); // generate absolute path relative to current directory or hdfs home // directory/*ww w .ja v a 2 s . co m*/ if (!path.startsWith("/")) { if (isLocal) { path = URIUtil.decode(new Path(System.getProperty("user.dir"), fromPath).toUri().toString()); } else { path = new Path(new Path("/user/" + System.getProperty("user.name")), path).toString(); } } // set correct scheme and authority if (StringUtils.isEmpty(fromScheme)) { if (isLocal) { // file for local fromScheme = "file"; } else { // use default values from fs.default.name URI defaultURI = FileSystem.get(conf).getUri(); fromScheme = defaultURI.getScheme(); fromAuthority = defaultURI.getAuthority(); } } // if scheme is specified but not authority then use the default authority if ((!fromScheme.equals("file")) && StringUtils.isEmpty(fromAuthority)) { URI defaultURI = FileSystem.get(conf).getUri(); fromAuthority = defaultURI.getAuthority(); } LOG.debug(fromScheme + "@" + fromAuthority + "@" + path); return new URI(fromScheme, fromAuthority, path, null, null); }
From source file:org.apache.webdav.lib.WebdavResource.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// w w w . ja va2 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 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) setStatusCode(response.getStatusCode()); setExistence(true); itself = true; } } // Get to know each resource. WebdavResource workingResource = null; if (itself) { workingResource = this; } else { workingResource = createWebdavResource(client); workingResource.setDebug(debug); } // 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.getDisplayName(); if (displayName == null || displayName.trim().equals("")) { displayName = getName(href, true); } if (!itself) { String myURI = httpURL.getEscapedURI(); char[] childURI = (myURI + (myURI.endsWith("/") ? "" : "/") + getName(href, false)).toCharArray(); HttpURL childURL = httpURL instanceof HttpsURL ? new HttpsURL(childURI) : new HttpURL(childURI); childURL.setRawAuthority(httpURL.getRawAuthority()); workingResource.setHttpURL(childURL, NOACTION, defaultDepth); workingResource.setExistence(true); workingResource.setOverwrite(getOverwrite()); } workingResource.setDisplayName(displayName); if (!itself) childResources.addResource(workingResource); } }
From source file:org.apache.webdav.lib.WebdavResource.java
private static String getName(String uri, boolean decode) { String escapedName = URIUtil.getName(uri.endsWith("/") ? uri.substring(0, uri.length() - 1) : uri); if (decode) { try {/*from www . j a v a 2 s. c o m*/ return URIUtil.decode(escapedName); } catch (URIException e) { // Oh well } } return escapedName; }
From source file:org.apache.webdav.lib.methods.LockMethod.java
/** * Parse response./*from w w w .jav a2 s. c o m*/ * * @param input Input stream */ public void parseResponse(InputStream input, HttpState state, HttpConnection conn) throws IOException, HttpException { int status = getStatusLine().getStatusCode(); if (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_MULTI_STATUS) { parseXMLResponse(input); NodeList list = getResponseDocument().getDocumentElement().getElementsByTagNameNS("DAV:", "locktoken"); if (list.getLength() == 1) { Element locktoken = (Element) list.item(0); NodeList list2 = locktoken.getElementsByTagNameNS("DAV:", "href"); if (list2.getLength() == 1) { this.lockToken = DOMUtils.getTextValue(list2.item(0)); if (state instanceof WebdavState) { /* * lockMethod/unlockMethod take unescaped URIs but LockMathod.getPath() * func returns an escaped URI so searching for the lock by path name in * the state object doesn't work. Convert escaped back to unescaped. */ ((WebdavState) state).addLock(URIUtil.decode(getPath()), this.lockToken); } } } list = getResponseDocument().getDocumentElement().getElementsByTagNameNS("DAV:", "owner"); if (list.getLength() == 1) { Element owner = (Element) list.item(0); this.owner = DOMUtils.getTextValue(owner); } } }
From source file:org.apache.webdav.lib.properties.AclProperty.java
/** * Parse an ace./* w ww . java 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); } child = DOMUtils.getFirstElement(element, "http://jakarta.apache.org/slide/", "non-inheritable"); if (child != null) { ace.setInheritable(false); } return ace; }
From source file:org.apache.webdav.lib.WebdavFile.java
public String getName() { if (relPath != null) return relPath; String escapedPath = httpUrl.getEscapedPath(); String escapedName = URIUtil.getName( escapedPath.endsWith("/") ? escapedPath.substring(0, escapedPath.length() - 1) : escapedPath); try {/*from w ww . j a v a 2 s. c om*/ return URIUtil.decode(escapedName); } catch (URIException e) { return escapedName; } }