List of usage examples for org.apache.commons.codec.net URLCodec decode
public Object decode(Object pObject) throws DecoderException
From source file:jp.dip.komusubi.botter.util.TinyUrlUtil.java
@Override public String shorten(String url) { String responseLine = null;/*from w w w.j a v a 2s . co m*/ try { URLCodec codec = new URLCodec(); String requestUrl = SHORTEN_SERVICE_URL + "?url=" + codec.decode(url); responseLine = UrlAccessDelegate.readFirstLine(requestUrl); if (responseLine == null) logger.warn("tinyurl response is null, URL is :{}", requestUrl); } catch (DecoderException e) { throw new BotterException(e); } return responseLine; }
From source file:NetUsage.java
public void start() throws EncoderException, DecoderException { String urlData1 = "This#is^a&String with reserved @/characters"; URLCodec encoder = new URLCodec(); String result = encoder.encode(urlData1); System.err.println("URL Encoding result: " + result); System.err.println("URL Decoding result: " + encoder.decode(result)); }
From source file:edu.lternet.pasta.portal.ReportViewerServlet.java
/** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * /*from w ww .java2 s. c o m*/ * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); if (uid == null || uid.isEmpty()) uid = "public"; String packageId = request.getParameter("packageid"); String encodedPath = request.getParameter("localPath"); String scope = null; Integer identifier = null; String revision = null; String xml = null; String html = null; try { String[] tokens = packageId.split("\\."); if (tokens.length == 3) { scope = tokens[0]; identifier = Integer.valueOf(tokens[1]); revision = tokens[2]; /* * The quality report XML could be read either from a local file * or from PASTA via the DataPackageManagerClient. */ if (encodedPath != null && encodedPath.length() > 0) { URLCodec urlCodec = new URLCodec(); String localPath = urlCodec.decode(encodedPath); File xmlFile = new File(localPath); if (xmlFile != null && xmlFile.exists()) { xml = FileUtils.readFileToString(xmlFile); } } else { DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid); xml = dpmClient.readDataPackageReport(scope, identifier, revision); } ReportUtility qrUtility = new ReportUtility(xml); html = HTMLHEAD + "<div class=\"qualityreport\">" + qrUtility.xmlToHtmlTable(cwd + xslpath) + "</div>" + HTMLTAIL; } else { String msg = String.format( "packageId '%s' is not in the correct form of 'scope.identifier.revision' (e.g., 'knb-lter-lno.1.1')", packageId); throw new UserErrorException(msg); } } catch (Exception e) { handleDataPortalError(logger, e); } response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.print(html); out.flush(); out.close(); }
From source file:com.rackspacecloud.client.cloudfiles.FilesClient.java
/** * URI/*from ww w. java 2s . c o m*/ * @param str * URI * @return */ public static String unencodeURI(String str) { URLCodec codec = new URLCodec(); try { return codec.decode(str); } catch (DecoderException ee) { logger.warn("Error trying to encode string for URI", ee); return str; } }
From source file:nor.util.Codec.java
public static String urlDecode(final String str) { String ret = str;//from w w w . j av a2 s . co m try { ret = URLCodec.decode(str); } catch (DecoderException e) { LOGGER.severe(e.getLocalizedMessage()); } return ret; }
From source file:org.apache.streams.urls.LinkResolver.java
/** * Removes the protocol, if it exists, from the front and * removes any random encoding characters * Extend this to do other url cleaning/pre-processing * * @param url - The String URL to normalize * @return normalizedUrl - The String URL that has no junk or surprises *//*w w w .j a va 2 s . c o m*/ public static String normalizeURL(String url) { // Decode URL to remove any %20 type stuff String normalizedUrl = url; try { // Replaced URLDecode with commons-codec b/c of failing tests URLCodec codec = new URLCodec(); normalizedUrl = codec.decode(url); // Remove the protocol, http:// ftp:// or similar from the front if (normalizedUrl.contains("://")) normalizedUrl = normalizedUrl.split(":/{2}")[1]; } catch (NullPointerException npe) { System.err.println("NPE Decoding URL. Decoding skipped."); npe.printStackTrace(); } catch (Throwable e) { System.err.println("Misc error Decoding URL. Decoding skipped."); e.printStackTrace(); } // Room here to do more pre-processing return normalizedUrl; }
From source file:org.mule.module.pubsubhubbub.Utils.java
private static void addQueryStringToParameterMap(final String queryString, final Map<String, List<String>> paramMap, final String outputEncoding) throws DecoderException { final String[] pairs = queryString.split("&"); for (final String pair : pairs) { final String[] nameValue = pair.split("="); if (nameValue.length == 2) { final URLCodec codec = new URLCodec(outputEncoding); final String key = codec.decode(nameValue[0]); final String value = codec.decode(nameValue[1]); addToParameterMap(paramMap, key, value); }//from w ww . j a v a 2 s . com } }
From source file:org.mule.transport.http.transformers.HttpRequestBodyToParamMap.java
protected void addQueryStringToParameterMap(String queryString, Map<String, Object> paramMap, String outputEncoding) throws Exception { String[] pairs = queryString.split("&"); for (String pair : pairs) { String[] nameValue = pair.split("="); if (nameValue.length == 2) { URLCodec codec = new URLCodec(outputEncoding); String key = codec.decode(nameValue[0]); String value = codec.decode(nameValue[1]); addToParameterMap(paramMap, key, value); }/*from w ww . ja va 2 s.c o m*/ } }
From source file:org.opendatakit.aggregate.server.SubmissionServiceImpl.java
@Override public String getSubmissionAuditCSV(String keyString) throws RequestFailureException { HttpServletRequest req = this.getThreadLocalRequest(); CallingContext cc = ContextFactory.getCallingContext(this, req); URLCodec urlCodec = new URLCodec(); String decode = null;//w ww .j av a 2 s .c om try { decode = urlCodec.decode(keyString); } catch (DecoderException e) { e.printStackTrace(); throw new RuntimeException(e); } SubmissionKey key = new SubmissionKey(decode); List<SubmissionKeyPart> parts = key.splitSubmissionKey(); if (parts.get(0).getElementName().equals(PersistentResults.FORM_ID_PERSISTENT_RESULT)) return new String(getBytes(cc, key)); Submission sub = getSubmission(cc, parts); BlobSubmissionType b = getBlobSubmissionType(parts, sub); return new String(getBytes(cc, parts, b)); }