List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:org.fishwife.jrugged.spring.jmx.MBeanStringSanitizer.java
/** * Convert a URL Encoded name back to the original form. * @param name the name to URL urlDecode. * @param encoding the string encoding to be used (i.e. UTF-8) * @return the name in original form./*from w w w .jav a2s . c om*/ * @throws UnsupportedEncodingException if the encoding is not supported. */ String urlDecode(String name, String encoding) throws UnsupportedEncodingException { return URLDecoder.decode(name, encoding); }
From source file:controllers.api.v1.ScriptFinder.java
public static Result getScripts() { ObjectNode result = Json.newObject(); int page = 1; String pageStr = request().getQueryString("page"); if (StringUtils.isBlank(pageStr)) { page = 1;//from w w w . j a v a 2s . c om } else { try { page = Integer.parseInt(pageStr); } catch (NumberFormatException e) { Logger.error("ScriptFinder Controller getPagedScripts wrong page parameter. Error message: " + e.getMessage()); page = 1; } } int size = 10; String sizeStr = request().getQueryString("size"); if (StringUtils.isBlank(sizeStr)) { size = 10; } else { try { size = Integer.parseInt(sizeStr); } catch (NumberFormatException e) { Logger.error("ScriptFinder Controller getPagedScripts wrong size parameter. Error message: " + e.getMessage()); size = 10; } } String filterOptStr = request().getQueryString("query"); JsonNode filterOpt = null; try { String filterOptStrDecode = URLDecoder.decode(filterOptStr, "UTF-8"); filterOpt = Json.parse(filterOptStrDecode); } catch (Exception e) { Logger.error("ScriptFinder Controller getScripts query filterOpt wrong JSON format. Error message: " + e.getMessage()); filterOpt = null; } result.put("status", "ok"); result.set("data", ScriptFinderDAO.getPagedScripts(filterOpt, page, size)); return ok(result); }
From source file:cn.guoyukun.spring.web.controller.DownloadController.java
@RequestMapping(value = "/download") public String download(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "filename") String filename) throws Exception { filename = filename.replace("/", "\\"); if (StringUtils.isEmpty(filename) || filename.contains("\\.\\.")) { response.setContentType("text/html;charset=utf-8"); response.getWriter().write("??"); return null; }// w ww . j av a2s .c o m filename = URLDecoder.decode(filename, Constants.ENCODING); String filePath = FileUploadUtils.extractUploadDir(request) + "/" + filename; DownloadUtils.download(request, response, filePath, prefixFilename + filename); return null; }
From source file:com.depas.utils.FileUtils.java
public static String getConfigDirectoryPath(Class<?> c) { try {//from w w w .j a v a 2 s .c o m String pathToIwc = getConfigDirectoryPath(c, "iwc"); if (pathToIwc != null) { File iwcDir = new File(pathToIwc); if (iwcDir.exists()) { File configDir = iwcDir.getParentFile(); String path = configDir.getPath(); if (!path.endsWith("\\") && !path.endsWith("/")) { path += "/"; } return URLDecoder.decode(path, "UTF-8"); } } } catch (Exception ex) { logger.warn("Error obtaining file path to config directory: " + ex); } return null; }
From source file:com.pureinfo.tgirls.servlet.SearchUserPicsServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = URLDecoder.decode(request.getParameter("name"), "utf-8"); JsonBase result = new JsonBase(); response.setContentType("text/json; charset=utf-8"); logger.debug("to search " + name + " pics"); if (StringUtils.isEmpty(name)) { result.setErrorCode(ErrorCode.ERROR.getCode()); result.setErrorMsg("??"); response.getWriter().write(result.toString()); return;//from w w w . ja va 2 s . c om } try { if (mgr == null) { mgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class); } User u = mgr.lookupByName(name); if (u == null) { throw new Exception("."); } if (pmgr == null) { pmgr = (IPhotoMgr) ArkContentHelper.getContentMgrOf(Photo.class); } List<Photo> pics = pmgr.getUserUploadPublicPics(u.getTaobaoID()); if (pics == null || pics.isEmpty()) { throw new Exception(""); } result.put("picId", pics.get(0).getId()); response.getWriter().write(result.toString()); return; } catch (Exception e) { result.setErrorCode(ErrorCode.ERROR.getCode()); if (StringUtils.isNotEmpty(e.getMessage())) { result.setErrorMsg(e.getMessage()); } else { result.setErrorMsg(""); } response.getWriter().write(result.toString()); return; } }
From source file:com.gc.iotools.fmt.base.TestUtils.java
/** * @deprecated/*from w w w . j a va 2s .co m*/ * @see FileUtils#iterate(); * @param allowed * @return * @throws IOException */ @Deprecated public static String[] listFilesIncludingExtension(final String[] allowed) throws IOException { final URL fileURL = TestUtils.class.getResource("/testFiles"); String filePath = URLDecoder.decode(fileURL.getPath(), "UTF-8"); final File dir = new File(filePath); final String[] files = dir.list(); final Collection<String> goodFiles = new Vector<String>(); if (!filePath.endsWith(File.separator)) { filePath = filePath + File.separator; } for (final String file : files) { for (final String element : allowed) { if (file.endsWith(element)) { goodFiles.add(filePath + file); } } } return goodFiles.toArray(new String[goodFiles.size()]); }
From source file:com.moss.bdbadmin.api.util.KeyFactory.java
public static byte[] decode(String urlEncodedKey) { try {//from w w w . ja va 2 s . c o m String utfBase64 = URLDecoder.decode(urlEncodedKey, ENCODING); byte[] base64 = utfBase64.getBytes(ENCODING); byte[] key = Base64.decodeBase64(base64); return key; } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:de.zib.gndms.gndmc.utils.DefaultResponseExtractor.java
public static String getLocation(final HttpHeaders headers) { for (String header : headers.keySet()) { if ("Location".equals(header)) { try { return URLDecoder.decode(headers.get(header).get(0), "utf8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("The system does not support utf8 decoding!"); }//from ww w. ja v a 2 s. co m } } return null; }
From source file:lv.semti.morphology.webservice.NormalizePhraseResource.java
@Get public String retrieve() { String query = (String) getRequest().getAttributes().get("phrase"); try {//from w ww . ja va2 s. c om query = URLDecoder.decode(query, "UTF8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String category = getQuery().getValues("category"); MorphoServer.analyzer.enableGuessing = true; MorphoServer.analyzer.enableVocative = true; MorphoServer.analyzer.guessVerbs = false; MorphoServer.analyzer.guessParticiples = false; MorphoServer.analyzer.guessAdjectives = false; MorphoServer.analyzer.guessInflexibleNouns = true; MorphoServer.analyzer.enableAllGuesses = true; Expression e = new Expression(query, category, false); //e.describe(new PrintWriter(System.err)); // ko tad tageris im ir sadom?jis String pamatforma = e.normalize(); MorphoServer.analyzer.defaultSettings(); return pamatforma; }
From source file:org.vietspider.server.handler.cms.metas.FilterContentHandler.java
public String handle(final HttpRequest request, final HttpResponse response, final HttpContext context, String... params) throws Exception { String pattern = params[1];/*from www. j a va 2 s . co m*/ int idx = pattern.indexOf('='); if (idx < 0 || idx >= pattern.length() - 1) { throw new IndexOutOfBoundsException("Incorrect parammeter"); } String filter = URLDecoder.decode(pattern.substring(idx + 1), "UTF-8"); MetaList metas = new MetaList(); metas.setAction("FILTER"); metas.setCurrentPage(Integer.parseInt(params[0])); File file = UtilFile.getFile("system/plugin/filter", NameConverter.encode(filter)); if (file.exists() && file.length() > 0) { String text = new String(RWData.getInstance().load(file), Application.CHARSET); int start = 0; while (start < text.length()) { char c = text.charAt(start); if (Character.isLetterOrDigit(c)) break; start++; } int end = text.length() - 1; while (end > 0) { char c = text.charAt(end); if (Character.isLetterOrDigit(c)) break; end--; } StringBuilder builder = new StringBuilder("\""); for (int i = start; i <= end; i++) { char c = text.charAt(i); if (c == ',') { builder.append("\" AND \""); } else if (c == '\n') { builder.append("\" OR \""); } else if (Character.isLetterOrDigit(c)) { builder.append(c); } else if (Character.isSpaceChar(c) || Character.isWhitespace(c)) { builder.append(' '); } } builder.append("\""); // System.out.println(" thay co filter "+ builder); ArticleSearchQuery query = new ArticleSearchQuery(); query.setPattern(builder.toString()); if (Application.LICENSE != Install.PERSONAL) { query.setHighlightStart("no"); ArticleIndexStorage.getInstance().search(metas, query); } } metas.setTitle(filter); metas.setUrl("?text=" + pattern.substring(idx + 1)); return write(request, response, context, metas, params); }