List of usage examples for org.apache.commons.httpclient.util URIUtil encodePath
public static String encodePath(String unescaped, String charset) throws URIException
From source file:com.datos.vfs.provider.URLFileName.java
/** * Get the path encoded suitable for url like filesystem e.g. (http, webdav). * * @param charset the charset used for the path encoding * @return The encoded path.//from w w w .ja v a 2 s . c o m * @throws URIException If an error occurs encoding the URI. * @throws FileSystemException If some other error occurs. */ public String getPathQueryEncoded(final String charset) throws URIException, FileSystemException { if (getQueryString() == null) { if (charset != null) { return URIUtil.encodePath(getPathDecoded(), charset); } else { return URIUtil.encodePath(getPathDecoded()); } } final StringBuilder sb = new StringBuilder(BUFFER_SIZE); if (charset != null) { sb.append(URIUtil.encodePath(getPathDecoded(), charset)); } else { sb.append(URIUtil.encodePath(getPathDecoded())); } sb.append("?"); sb.append(getQueryString()); return sb.toString(); }
From source file:davmail.caldav.CaldavConnection.java
static String encodePath(CaldavRequest request, String path) throws URIException { if (request.isIcal5()) { return URIUtil.encode(path, ical_allowed_abs_path, "UTF-8"); } else {//from w w w.j av a 2 s . c o m return URIUtil.encodePath(path, "UTF-8"); } }
From source file:de.innovationgate.utils.URLBuilder.java
/** * Rebuilds the URL to a string.// ww w. java 2 s . c o m * @param absolute Specify true for an absolute URL. false will rebuild it only from the path part on, omitting protocol, port and host. * @return The rebuilt URL as string */ public String build(boolean absolute) { try { StringBuffer newURL = new StringBuffer(); if (absolute) { newURL.append(this._protocol).append("://").append(this._host); if (this._port != -1 && !isDefaultPortForProtocol(this._port, this._protocol)) { newURL.append(":").append(_port); } } newURL.append(URIUtil.encodePath(_path, _encoding)).append(this.rebuildQuery()); if (!WGUtils.isEmpty(_fragment)) { newURL.append("#").append(URIUtil.encodePath(_fragment, _encoding)); } return newURL.toString(); } catch (URIException e) { throw new RuntimeException(e); } }
From source file:org.alfresco.module.vti.web.fp.GetDocsMetaInfoMethod.java
private boolean urlIsAbsolute(String url) { String pathEncodedURL;//from ww w .j a va 2s .c om try { // Encode the path part of since this may have spaces in it, for example. pathEncodedURL = URIUtil.encodePath(url, "UTF-8"); } catch (URIException error) { throw new IllegalArgumentException("Invalid URL: " + url, error); } URI uriObj = URI.create(pathEncodedURL); return uriObj.isAbsolute(); }
From source file:org.apache.hadoop.util.ServletUtil.java
/** * Escape and encode a string regarded as the path component of an URI. * @param path the path component to encode * @return encoded path, null if UTF-8 is not supported *//* w w w .j a v a2 s .co m*/ public static String encodePath(final String path) { try { return URIUtil.encodePath(path, "UTF-8"); } catch (URIException e) { throw new AssertionError("JVM does not support UTF-8"); // should never happen! } }
From source file:org.elasticsearch.hadoop.util.StringUtils.java
public static String encodePath(String path) { try {/*w w w . j a v a 2s .c o m*/ return URIUtil.encodePath(path, "UTF-8"); } catch (URIException ex) { throw new EsHadoopIllegalArgumentException("Cannot encode path" + path, ex); } }
From source file:org.wso2.carbon.appmgt.impl.publishers.WSO2ExternalAppStorePublisher.java
/** * Get the UUID of the given web app from external store. * * @param webApp Web App//from w w w. ja v a2s . c o m * @param externalPublisher Web App provider * @param storeEndpoint Publisher url of external store * @param httpContext * @return uuid * @throws AppManagementException */ private String getUUID(WebApp webApp, String externalPublisher, String storeEndpoint, HttpContext httpContext) throws AppManagementException { String provider = AppManagerUtil.replaceEmailDomain(externalPublisher); String appName = webApp.getId().getApiName(); String appVersion = webApp.getId().getVersion(); try { String urlSuffix = provider + "/" + appName + "/" + appVersion; urlSuffix = URIUtil.encodePath(urlSuffix, "UTF-8"); storeEndpoint = storeEndpoint + AppMConstants.APP_STORE_GET_UUID_URL + urlSuffix; HttpGet httpGet = new HttpGet(storeEndpoint); HttpClient httpClient = AppManagerUtil.getHttpClient(storeEndpoint); //Execute and get the response. HttpResponse response = httpClient.execute(httpGet, httpContext); HttpEntity entity = response.getEntity(); //{"error" : false, "uuid" : "bbfa1766-e36a-4676-bb61-fdf2ba1f5327"} // or {"error" : false, "uuid" : null, "message" : "Could not find UUID for given webapp"} String responseString = EntityUtils.toString(entity, "UTF-8"); JSONObject responseJson = (JSONObject) JSONValue.parse(responseString); boolean isError = true; if (responseJson != null) { Object error = responseJson.get("error"); if (error != null) isError = Boolean.parseBoolean(error.toString().trim()); } if (!isError) { Object assetId = responseJson.get("uuid"); if (assetId != null) { return assetId.toString().trim(); } return null; } else { throw new AppManagementException("Error while getting UUID of APP - " + appName + "" + " from the external AppStore - for provider " + externalPublisher + ".Reason -" + responseString); } } catch (IOException e) { throw new AppManagementException("Error while getting UUID of APP : " + appName + " " + "from the external AppStore - " + externalPublisher, e); } }
From source file:pl.nask.hsn2.normalizers.URLNormalizerUtils.java
static String encodePath(StringBuilder pathIn, int start, int end) throws URLParseException { StringBuilder sb = new StringBuilder(pathIn.substring(start, end)); if (!processIISenc()) { removeObfuscatedEncoding(sb, new EncodingType[] { EncodingType.PATH_ALLOWED, EncodingType.IIS_ENC }); } else {// ww w . j ava 2 s . co m removeObfuscatedEncoding(sb, new EncodingType[] { EncodingType.PATH_ALLOWED }); } int find = 0; while ((find = findFirstMatch(sb, new String[] { "//" }, 0)) >= 0) { sb.replace(find, find + 2, "/"); } String ignore = "%+"; // URIUtils doen't conform to RFC 3986 spec regarding '+' encoding find = findFirstMatch(sb, ignore, 0); if (find >= 0) { ArrayList<Integer> toIgnore = new ArrayList<Integer>(); while (find >= 0) { if (percentEnc.matcher(sb.substring(find)).matches() || sb.codePointAt(find) == '+') { toIgnore.add(find); } find = findFirstMatch(sb, ignore, find + 1); } StringBuilder enc = new StringBuilder(); try { if (toIgnore.size() > 0) { int tmpBeg = 0; for (int i = 0; i < toIgnore.size(); i++) { enc.append(URIUtil.encodePath(sb.substring(tmpBeg, toIgnore.get(i)), DEFAULT_CHARSET)); tmpBeg = toIgnore.get(i) + 1; enc.append(sb.charAt(toIgnore.get(i))); } enc.append(URIUtil.encodePath(sb.substring(tmpBeg), DEFAULT_CHARSET)); } else { enc.append(URIUtil.encodePath(sb.toString())); } } catch (URIException e) { LOG.error(e.getMessage(), e); throw new URLParseException("Cannot parse path:" + sb.substring(start, end), e); } pathIn.replace(start, end, enc.toString()); return enc.toString(); } else { try { String enc = URIUtil.encodePath(sb.toString(), DEFAULT_CHARSET); pathIn.replace(start, end, enc); return enc; } catch (URIException e) { LOG.error(e.getMessage(), e); throw new URLParseException("Cannot parse path:" + sb.substring(start, end), e); } } }
From source file:uk.ac.ebi.generic.util.ExcelWorkBook.java
public ExcelWorkBook(String[] titles, Object[][] tableData, String sheetTitle) throws Exception { this.wb = new XSSFWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); // create a new sheet XSSFSheet sheet = wb.createSheet(sheetTitle); XSSFPrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true);/*from www . j av a 2s .c om*/ sheet.setFitToPage(true); sheet.setHorizontallyCenter(true); //header row XSSFRow headerRow = sheet.createRow(0); //headerRow.setHeightInPoints(40); XSSFCell headerCell; for (int j = 0; j < titles.length; j++) { headerCell = headerRow.createCell(j); headerCell.setCellValue(titles[j]); //headerCell.setCellStyle(styles.get("header")); } // data rows // Create a row and put some cells in it. Rows are 0 based. // Then set value for that created cell for (int k = 0; k < tableData.length; k++) { XSSFRow row = sheet.createRow(k + 1); // data starts from row 1 for (int l = 0; l < tableData[k].length; l++) { XSSFCell cell = row.createCell(l); String cellStr = null; try { cellStr = tableData[k][l].toString(); } catch (Exception e) { cellStr = ""; } //System.out.println("cell " + l + ": " + cellStr); // make hyperlink in cell if ((cellStr.startsWith("http://") || cellStr.startsWith("https://")) && !cellStr.contains("|")) { //need to encode URI for this version of ExcelWorkBook cellStr = URIUtil.encodePath(cellStr, "UTF-8"); cellStr = cellStr.replace("%3F", "?"); // so that url link would work //System.out.println("cellStr: " + cellStr); XSSFHyperlink url_link = (XSSFHyperlink) createHelper.createHyperlink(Hyperlink.LINK_URL); url_link.setAddress(cellStr); cell.setCellValue(cellStr); cell.setHyperlink(url_link); } else { cell.setCellValue(cellStr); } //System.out.println((String)tableData[k][l]); } } }