List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:videoquotes.controller.VideoDLSvc.java
@RequestMapping(value = "/video", method = RequestMethod.GET) public void findOne(@RequestParam String id, HttpServletResponse response) throws IOException { response.sendRedirect(URLDecoder.decode(videoDLs.findOne(id).getUrl(), "UTF-8")); }
From source file:com.acciente.commons.loader.ClassFinder.java
public static Set find(ClassLoader oClassLoader, String[] asPackageNames, Pattern oClassPattern) throws IOException { Set oClassNameSet = new HashSet(); for (int i = 0; i < asPackageNames.length; i++) { String sPackageName = asPackageNames[i]; Enumeration oResources = oClassLoader.getResources(sPackageName.replace('.', '/')); if (!oResources.hasMoreElements()) { __oLog.info("classloader scan for package: " + sPackageName + " found no resources!"); }//from www.j av a 2 s . co m while (oResources.hasMoreElements()) { String sResourceURL = URLDecoder.decode(((URL) oResources.nextElement()).toString(), "UTF-8"); if (sResourceURL.startsWith(URL_PREFIX_JARFILE)) { int iDelimPos = sResourceURL.indexOf(URL_DELIM_JARFILE); if (iDelimPos != -1) { File oJarFile = new File(sResourceURL.substring(URL_PREFIX_JARFILE.length() - 1, iDelimPos + ".jar".length())); __oLog.info("scanning jar: " + oJarFile); findInJar(oJarFile, sPackageName, oClassPattern, oClassNameSet); } } else if (sResourceURL.startsWith(URL_PREFIX_FILE)) { File oDirectory = new File(sResourceURL.substring(URL_PREFIX_FILE.length() - 1)); __oLog.info("scanning dir: " + oDirectory); findInDirectory(oDirectory, sPackageName, oClassPattern, oClassNameSet); } } } // if the classloader is a ReloadingClassLoader the above loop would have processed the classed reachable via // the parent classloader, now we process the classes reachable via this classloader if (oClassLoader instanceof ReloadingClassLoader) { __oLog.info("reloading classloader detected, scanning..."); ReloadingClassLoader oReloadingClassLoader = (ReloadingClassLoader) oClassLoader; for (Iterator oClassDefLoaderIter = oReloadingClassLoader.getClassDefLoaders() .iterator(); oClassDefLoaderIter.hasNext();) { ClassDefLoader oClassDefLoader = (ClassDefLoader) oClassDefLoaderIter.next(); Set oAddClassNameSet = oClassDefLoader.findClassNames(asPackageNames, oClassPattern); oClassNameSet.addAll(oAddClassNameSet); } } return oClassNameSet; }
From source file:it.cnr.isti.hpc.dexter.spot.cleanpipe.cleaner.HtmlCleaner.java
public String clean(String spot) { spot = StringEscapeUtils.unescapeHtml(spot); try {//from w w w .jav a 2 s . co m spot = URLDecoder.decode(spot, "UTF-8"); } catch (UnsupportedEncodingException e) { logger.debug("error trying to convert the text from javascript to string"); } catch (IllegalArgumentException e) { logger.debug("error trying to convert the text from javascript to string"); } return spot; }
From source file:com.microsoft.tfs.client.common.ui.wit.form.link.VersionedItemLinkParser.java
/** * Parses the tool-specific ID out of a versioned item {@link ArtifactID} * and returns the item path, changeset and deletion id referred to by this * artifact.//from w w w.j a va 2 s . c om * * @throws RuntimeException * if the artifact could not be parsed * @param versionedArtifactId * An {@link ArtifactID} of type VersionedItemLink or LatestVersion * (not <code>null</code>) * @return A {@link VersionedItemLinkData} with the appropriate data, never * <code>null</code> */ public static VersionedItemLinkData parse(final ArtifactID versionedArtifactId) { Check.notNull(versionedArtifactId, "versionedArtifactId"); //$NON-NLS-1$ if (!VersionedItemLinkTypeNames.VERSIONED_ITEM.equals(versionedArtifactId.getArtifactType())) { throw new RuntimeException("Artifact is not a versioned item artifact"); //$NON-NLS-1$ } if (versionedArtifactId.getToolSpecificID() == null || versionedArtifactId.getToolSpecificID().length() == 0) { throw new RuntimeException("Invalid versioned item ID for artifact"); //$NON-NLS-1$ } try { final String decodedToolId = URLDecoder.decode(versionedArtifactId.getToolSpecificID(), URL_ENCODING); /* * The tool ID should contain at least three segments - the first * segment must be the item path, and then attributes * (changesetVersion= and deletionId= are currently the only * attributes known, and changesetVersion is required. Others are * ignored for forward compatibility). * * The item path itself is *also* URI encoded to allow us to split * the tool id properly (so that we don't split parts of the item * that contain an ampersand.) */ final String[] toolComponents = decodedToolId.split("&"); //$NON-NLS-1$ final String itemPath = "$/" + URLDecoder.decode(toolComponents[0], URL_ENCODING); //$NON-NLS-1$ int changesetVersion = -1; int deletionId = 0; for (int i = 1; i < toolComponents.length; i++) { if (toolComponents[i].startsWith("changesetVersion=")) //$NON-NLS-1$ { final String c = toolComponents[i].substring(17); try { changesetVersion = Integer.parseInt(c); } catch (final NumberFormatException e) { throw new RuntimeException( MessageFormat.format("The changeset version {0} is not valid", c)); //$NON-NLS-1$ } } else if (toolComponents[i].startsWith("deletionId=")) //$NON-NLS-1$ { final String d = toolComponents[i].substring(11); try { deletionId = Integer.parseInt(d); } catch (final NumberFormatException e) { throw new RuntimeException(MessageFormat.format("The deletion ID {0} is not valid", d)); //$NON-NLS-1$ } } else { log.info(MessageFormat.format("Unknown versioned item artifact component: {0}", //$NON-NLS-1$ toolComponents[i])); } } /* Ensure changeset version was seen */ if (changesetVersion < 0) { throw new RuntimeException( "Invalid version ID for artifact - changesetVersion is a required parameter"); //$NON-NLS-1$ } return new VersionedItemLinkData(itemPath, changesetVersion, deletionId); } catch (final UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:framework.JarResourceStore.java
public synchronized byte[] read(String pResourceName) { JarFile jar = null;/*from www. j a v a2s. c o m*/ try { jar = new JarFile(URLDecoder.decode(filename, "utf-8")); JarEntry jarEntry = jar.getJarEntry(pResourceName); if (jarEntry != null) { InputStream inputStream = jar.getInputStream(jarEntry); try { return IOUtils.toByteArray(inputStream); } finally { inputStream.close(); } } } catch (IOException e) { Loggers.RELOADER.error(e.getMessage(), e); } finally { if (jar != null) { try { jar.close(); } catch (IOException e2) { Loggers.RELOADER.error(e2.getMessage(), e2); } } } return null; }
From source file:io.mapzone.controller.vm.repository.ProjectInstanceIdentifier.java
/** * /*from w w w .j ava 2s. c om*/ * @param request */ public ProjectInstanceIdentifier(HttpServletRequest request) { try { String[] parts = split(URLDecoder.decode(request.getPathInfo(), "UTF8"), "/"); this.project = parts[1]; this.organization = parts[0]; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:org.obiba.mica.file.FileUtils.java
public static String decode(String path) { if (path == null) return null; try {/*from w w w .j a v a 2 s .c om*/ return URLDecoder.decode(path, "UTF-8"); } catch (UnsupportedEncodingException e) { return path; } }
From source file:com.switchfly.inputvalidation.canonicalizer.HtmlAndQueryStringCanonicalizer.java
@Override public String execute(String content) { if (StringUtils.isBlank(content)) { return content; }/* w w w . j a va 2s.c o m*/ String s = super.execute(content); try { s = StringEscapeUtils.unescapeHtml(s); } catch (Exception e) { throw new IllegalArgumentException("Canonicalization error", e); } try { s = URLDecoder.decode(s, "UTF-8"); } catch (Exception e) { // ignore and move on } return s; }
From source file:com.ibm.mobilefirstplatform.clientsdk.android.security.mca.internal.Utils.java
/** * Obtains a parameter with specified name from from query string. The query should be in format * param=value¶m=value ...//from ww w .ja va 2 s . c o m * * @param query Queery in "url" format. * @param paramName Parameter name. * @return Parameter value, or null. */ public static String getParameterValueFromQuery(String query, String paramName) { String[] components = query.split("&"); for (String keyValuePair : components) { String[] pairComponents = keyValuePair.split("="); if (pairComponents.length == 2) { try { String key = URLDecoder.decode(pairComponents[0], "utf-8"); if (key.compareTo(paramName) == 0) { return URLDecoder.decode(pairComponents[1], "utf-8"); } } catch (UnsupportedEncodingException e) { logger.error("getParameterValueFromQuery failed with exception: " + e.getLocalizedMessage(), e); } } } return null; }
From source file:io.cloudslang.content.httpclient.build.Utils.java
public static String urlEncodeQueryParams(String params, boolean urlEncode) throws UrlEncodeException { String encodedParams = params; if (!urlEncode) { try {// ww w .ja va2 s . c o m encodedParams = URLDecoder.decode(params, DEFAULT_CHARACTER_SET); } catch (UnsupportedEncodingException e) { // never happens throw new RuntimeException(e); } catch (IllegalArgumentException ie) { throw new UrlEncodeException(ie.getMessage(), ie); } } return encodedParams; }