List of usage examples for java.net URLDecoder decode
@Deprecated public static String decode(String s)
From source file:org.openmrs.module.sdmxhdintegration.web.controller.MapIndicatorDialogController.java
/** * Shows the indicator mapping dialog//from w ww.ja v a 2 s. com * @param model the model * @param sdmxhdIndicator the SDMX indicator * @param messageId the SDMX message id * @param keyFamilyId the key family id * @throws UnsupportedEncodingException */ @RequestMapping(method = RequestMethod.GET) public void showDialog(ModelMap model, @RequestParam("sdmxhdIndicator") String sdmxhdIndicator, @RequestParam("messageId") Integer messageId, @RequestParam("keyFamilyId") String keyFamilyId) throws UnsupportedEncodingException { sdmxhdIndicator = URLDecoder.decode(sdmxhdIndicator); // get indicators IndicatorService is = Context.getService(IndicatorService.class); List<Indicator> omrsIndicators = is.getAllDefinitions(false); model.addAttribute("omrsIndicators", omrsIndicators); model.addAttribute("sdmxIndicator", sdmxhdIndicator); model.addAttribute("messageId", messageId); SDMXHDService sdmxhdService = Context.getService(SDMXHDService.class); SDMXHDMessage sdmxhdMessage = sdmxhdService.getMessage(messageId); KeyFamilyMapping keyFamilyMapping = sdmxhdService.getKeyFamilyMapping(sdmxhdMessage, keyFamilyId); // if a OMRS DSD is attached then get the mapped indicator as well if (keyFamilyMapping.getReportDefinitionId() != null) { DataSetDefinitionService dss = Context.getService(DataSetDefinitionService.class); SDMXHDCohortIndicatorDataSetDefinition omrsDSD = Utils.getDataSetDefinition(sdmxhdMessage, keyFamilyId); Integer omrsMappedIndicatorId = omrsDSD.getOMRSMappedIndicator(sdmxhdIndicator); model.addAttribute("mappedOMRSIndicatorId", omrsMappedIndicatorId); } }
From source file:com.aujur.ebookreader.catalog.DownloadLocalFileTask.java
@Override protected String doInBackground(String... params) { try {/*from w ww . ja v a 2s . c o m*/ String url = params[0]; // url = "vademecum/Editora AuJur/Codigo Civil (1)/Codigo Civil - Editora AuJur.epub"; // vademecum/Editora AuJur/Codigo Civil (1)/Codigo Civil - Editora AuJur.epub LOG.debug("Downloading: " + url); String fileName = url.substring(url.lastIndexOf('/') + 1); fileName = fileName.replaceAll("\\?|&|=", "_"); File destFolder = new File(config.getDownloadsFolder()); if (!destFolder.exists()) { destFolder.mkdirs(); } /** * Make sure we always store downloaded files as .epub, so they show * up in scans later on. */ if (!fileName.endsWith(".epub")) { fileName = fileName + ".epub"; } destFile = new File(destFolder, URLDecoder.decode(fileName)); if (destFile.exists()) { destFile.delete(); } // lenghtOfFile is used for calculating download progress AssetFileDescriptor fd = context.getAssets().openFd(url); long lenghtOfFile = fd.getLength(); // this is where the file will be seen after the download FileOutputStream f = new FileOutputStream(destFile); try { // file input is from the url AssetManager assetManager = context.getAssets(); InputStream in = assetManager.open(url); // here's the download code byte[] buffer = new byte[1024]; int len1 = 0; long total = 0; while ((len1 = in.read(buffer)) > 0 && !isCancelled()) { // Make sure the user can cancel the download. if (isCancelled()) { return null; } total += len1; publishProgress(total, lenghtOfFile, (long) ((total * 100) / lenghtOfFile)); f.write(buffer, 0, len1); } } finally { f.close(); } if (!isCancelled()) { // FIXME: This doesn't belong here really... Book book = new EpubReader().readEpubLazy(destFile.getAbsolutePath(), "UTF-8"); libraryService.storeBook(destFile.getAbsolutePath(), book, false, config.isCopyToLibrayEnabled()); } } catch (Exception e) { LOG.error("Download failed.", e); this.failure = e; } return null; }
From source file:net.netne.mina.MessagetHandler.java
@Override public void messageReceived(IoSession session, Object message) throws Exception { try {// w ww. j av a 2 s .c o m String params = String.valueOf(message); String encodeMsg = null; if (AESEncrypter.isDecryption) { encodeMsg = AESEncrypter.decrypt(params); if (StringUtils.isEmpty(encodeMsg)) { params = URLDecoder.decode(params); encodeMsg = AESEncrypter.decrypt(params); } LOGGER.info("mina-rev:" + encodeMsg); } if (encodeMsg != null) { encodeMsg = encodeMsg.trim(); } MinaResult result = execute(session, encodeMsg); String resultMsg = JSON.toJSONString(result, SerializerFeature.WriteMapNullValue); LOGGER.info("mina-send:" + resultMsg); if (AESEncrypter.isDecryption) { resultMsg = AESEncrypter.encrypt(resultMsg); } session.write(resultMsg); } catch (Exception e) { LOGGER.error(e.getMessage(), e); session.close(true); } }
From source file:com.cloud.cluster.ClusterServiceServletHttpHandler.java
@SuppressWarnings("deprecation") private void parseRequest(HttpRequest request) throws IOException { if (request instanceof HttpEntityEnclosingRequest) { HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request; String body = EntityUtils.toString(entityRequest.getEntity()); if (body != null) { String[] paramArray = body.split("&"); if (paramArray != null) { for (String paramEntry : paramArray) { String[] paramValue = paramEntry.split("="); if (paramValue.length != 2) { continue; }// w ww. j ava2 s.com String name = URLDecoder.decode(paramValue[0]); String value = URLDecoder.decode(paramValue[1]); if (s_logger.isTraceEnabled()) { s_logger.trace("Parsed request parameter " + name + "=" + value); } request.getParams().setParameter(name, value); } } } } }
From source file:org.openmrs.module.sdmxhdintegration.web.controller.MapDimensionDialogController.java
/** * Shows the dimensions mapping dialog/*w w w. j av a 2s . c o m*/ * @param model the model * @param sdmxhdIndicator the SDMX indicator * @param messageId the SDMX message id * @param keyFamilyId the key family id * @throws UnsupportedEncodingException */ @RequestMapping(method = RequestMethod.GET) public void showDialog(ModelMap model, @RequestParam("sdmxhdDimension") String sdmxhdDimension, @RequestParam("messageId") Integer messageId, @RequestParam(value = "omrsDimension", required = false) Integer omrsDimension, @RequestParam("keyFamilyId") String keyFamilyId) throws IOException, XMLStreamException, ExternalRefrenceNotFoundException, ValidationException, SchemaValidationException { sdmxhdDimension = URLDecoder.decode(sdmxhdDimension); keyFamilyId = URLDecoder.decode(keyFamilyId); model.addAttribute("sdmxhdDimension", sdmxhdDimension); model.addAttribute("messageId", messageId); model.addAttribute("keyFamilyId", keyFamilyId); // get all omrs Dimensions DimensionService ds = Context.getService(DimensionService.class); List<org.openmrs.module.reporting.indicator.dimension.Dimension> omrsDimensions = ds .getAllDefinitions(false); model.addAttribute("omrsDimensions", omrsDimensions); SDMXHDService sdmxhdService = Context.getService(SDMXHDService.class); SDMXHDMessage sdmxhdMessage = sdmxhdService.getMessage(messageId); DSD sdmxhdDSD = Utils.getDataSetDefinition(sdmxhdMessage); List<String> sdmxhdDimensionOptions = new ArrayList<String>(); Dimension sdmxhdDimensionObj = sdmxhdDSD.getDimension(sdmxhdDimension, keyFamilyId); CodeList codeList = sdmxhdDSD.getCodeList(sdmxhdDimensionObj.getCodelistRef()); for (Code c : codeList.getCodes()) { sdmxhdDimensionOptions.add(c.getDescription().getDefaultStr()); } model.addAttribute("sdmxhdDimensionOptions", sdmxhdDimensionOptions); KeyFamilyMapping keyFamilyMapping = sdmxhdService.getKeyFamilyMapping(sdmxhdMessage, keyFamilyId); SDMXHDCohortIndicatorDataSetDefinition omrsDSD = null; // if a OMRS DSD is attached then get the mapped dimension and the dimension options mappings if (keyFamilyMapping.getReportDefinitionId() != null) { omrsDSD = Utils.getDataSetDefinition(sdmxhdMessage, keyFamilyId); // get mapped dimension if none is specified in the request if (omrsDimension == null) { DataSetDefinitionService dss = Context.getService(DataSetDefinitionService.class); Integer omrsMappedDimensionId = omrsDSD.getOMRSMappedDimension(sdmxhdDimension); model.addAttribute("mappedOMRSDimensionId", omrsMappedDimensionId); omrsDimension = omrsMappedDimensionId; // get sdmx-hd -> omrs Dimension mappings for mapped Dimension if (omrsMappedDimensionId != null) { Map<String, String> mappedDimensionOptions = omrsDSD .getOMRSMappedDimensionOptions(sdmxhdDimension); model.addAttribute("mappedDimOpts", mappedDimensionOptions); } } // else set the dimension specified in the request else { model.addAttribute("mappedOMRSDimensionId", omrsDimension); } } else if (omrsDimension != null) { model.addAttribute("mappedOMRSDimensionId", omrsDimension); } // get omrs Dimension Options if there is a valid dimension to work with if (omrsDimension != null) { org.openmrs.module.reporting.indicator.dimension.Dimension omrsDimensionObj = ds .getDefinition(CohortDimension.class, omrsDimension); List<String> omrsDimensionOptions = omrsDimensionObj.getOptionKeys(); model.addAttribute("omrsDimensionOptions", omrsDimensionOptions); } // get fixed value data if (omrsDSD != null) { String fixedDimensionValue = omrsDSD.getFixedDimensionValues(sdmxhdDimension); if (fixedDimensionValue != null) { model.addAttribute("fixedValue", fixedDimensionValue); model.addAttribute("fixedValueCheckbox", true); } else { model.addAttribute("fixedValueCheckbox", false); } } else { model.addAttribute("fixedValueCheckbox", false); } }
From source file:net.facework.core.http.ModAssetServer.java
@Override public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException { AbstractHttpEntity body = null;/* w w w . j av a2s. co m*/ final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH); if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) { throw new MethodNotSupportedException(method + " method not supported"); } final String url = URLDecoder.decode(request.getRequestLine().getUri()); if (request instanceof HttpEntityEnclosingRequest) { HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); byte[] entityContent = EntityUtils.toByteArray(entity); Log.d(TAG, "Incoming entity content (bytes): " + entityContent.length); } final String location = "www" + (url.equals("/") ? "/index.htm" : url); response.setStatusCode(HttpStatus.SC_OK); try { Log.i(TAG, "Requested: \"" + url + "\""); // Compares the Last-Modified date header (if present) with the If-Modified-Since date if (request.containsHeader("If-Modified-Since")) { try { Date date = DateUtils.parseDate(request.getHeaders("If-Modified-Since")[0].getValue()); if (date.compareTo(mServer.mLastModified) <= 0) { // The file has not been modified response.setStatusCode(HttpStatus.SC_NOT_MODIFIED); return; } } catch (DateParseException e) { e.printStackTrace(); } } // We determine if the asset is compressed try { AssetFileDescriptor afd = mAssetManager.openFd(location); // The asset is not compressed FileInputStream fis = new FileInputStream(afd.getFileDescriptor()); fis.skip(afd.getStartOffset()); body = new InputStreamEntity(fis, afd.getDeclaredLength()); Log.d(TAG, "Serving uncompressed file " + "www" + url); } catch (FileNotFoundException e) { // The asset may be compressed // AAPT compresses assets so first we need to uncompress them to determine their length InputStream stream = mAssetManager.open(location, AssetManager.ACCESS_STREAMING); ByteArrayOutputStream buffer = new ByteArrayOutputStream(64000); byte[] tmp = new byte[4096]; int length = 0; while ((length = stream.read(tmp)) != -1) buffer.write(tmp, 0, length); body = new InputStreamEntity(new ByteArrayInputStream(buffer.toByteArray()), buffer.size()); stream.close(); Log.d(TAG, "Serving compressed file " + "www" + url); } body.setContentType(getMimeMediaType(url) + "; charset=UTF-8"); response.addHeader("Last-Modified", DateUtils.formatDate(mServer.mLastModified)); } catch (IOException e) { // File does not exist response.setStatusCode(HttpStatus.SC_NOT_FOUND); body = new EntityTemplate(new ContentProducer() { @Override public void writeTo(final OutputStream outstream) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8"); writer.write("<html><body><h1>"); writer.write("File "); writer.write("www" + url); writer.write(" not found"); writer.write("</h1></body></html>"); writer.flush(); } }); Log.d(TAG, "File " + "www" + url + " not found"); body.setContentType("text/html; charset=UTF-8"); } response.setEntity(body); }
From source file:com.wifi.brainbreaker.mydemo.http.ModAssetServer.java
public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException { AbstractHttpEntity body = null;/*from ww w . j av a 2 s . c o m*/ final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH); if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) { throw new MethodNotSupportedException(method + " method not supported"); } final String url = URLDecoder.decode(request.getRequestLine().getUri()); if (request instanceof HttpEntityEnclosingRequest) { HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); byte[] entityContent = EntityUtils.toByteArray(entity); Log.d(TAG, "Incoming entity content (bytes): " + entityContent.length); } final String location = "www" + (url.equals("/") ? "/index.htm" : url); response.setStatusCode(HttpStatus.SC_OK); try { Log.i(TAG, "Requested: \"" + url + "\""); // Compares the Last-Modified date header (if present) with the If-Modified-Since date if (request.containsHeader("If-Modified-Since")) { try { Date date = DateUtils.parseDate(request.getHeaders("If-Modified-Since")[0].getValue()); if (date.compareTo(mServer.mLastModified) <= 0) { // The file has not been modified response.setStatusCode(HttpStatus.SC_NOT_MODIFIED); return; } } catch (DateParseException e) { e.printStackTrace(); } } // We determine if the asset is compressed try { AssetFileDescriptor afd = mAssetManager.openFd(location); // The asset is not compressed FileInputStream fis = new FileInputStream(afd.getFileDescriptor()); fis.skip(afd.getStartOffset()); body = new InputStreamEntity(fis, afd.getDeclaredLength()); Log.d(TAG, "Serving uncompressed file " + "www" + url); } catch (FileNotFoundException e) { // The asset may be compressed // AAPT compresses assets so first we need to uncompress them to determine their length InputStream stream = mAssetManager.open(location, AssetManager.ACCESS_STREAMING); ByteArrayOutputStream buffer = new ByteArrayOutputStream(64000); byte[] tmp = new byte[4096]; int length = 0; while ((length = stream.read(tmp)) != -1) buffer.write(tmp, 0, length); body = new InputStreamEntity(new ByteArrayInputStream(buffer.toByteArray()), buffer.size()); stream.close(); Log.d(TAG, "Serving compressed file " + "www" + url); } body.setContentType(getMimeMediaType(url) + "; charset=UTF-8"); response.addHeader("Last-Modified", DateUtils.formatDate(mServer.mLastModified)); } catch (IOException e) { // File does not exist response.setStatusCode(HttpStatus.SC_NOT_FOUND); body = new EntityTemplate(new ContentProducer() { public void writeTo(final OutputStream outstream) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8"); writer.write("<html><body><h1>"); writer.write("File "); writer.write("www" + url); writer.write(" not found"); writer.write("</h1></body></html>"); writer.flush(); } }); Log.d(TAG, "File " + "www" + url + " not found"); body.setContentType("text/html; charset=UTF-8"); } response.setEntity(body); }
From source file:com.aujur.ebookreader.catalog.DownloadFileTask.java
@Override protected String doInBackground(String... params) { try {/*from w ww. j a v a2 s.c o m*/ String url = params[0]; LOG.debug("Downloading: " + url); String fileName = url.substring(url.lastIndexOf('/') + 1); fileName = fileName.replaceAll("\\?|&|=", "_"); HttpGet get = new HttpGet(url); get.setHeader("User-Agent", config.getUserAgent()); HttpResponse response = httpClient.execute(get); if (response.getStatusLine().getStatusCode() == 200) { File destFolder = new File(config.getDownloadsFolder()); if (!destFolder.exists()) { destFolder.mkdirs(); } /** * Make sure we always store downloaded files as .epub, * so they show up in scans later on. */ if (!fileName.endsWith(".epub")) { fileName = fileName + ".epub"; } destFile = new File(destFolder, URLDecoder.decode(fileName)); if (destFile.exists()) { destFile.delete(); } // lenghtOfFile is used for calculating download progress long lenghtOfFile = response.getEntity().getContentLength(); // this is where the file will be seen after the download FileOutputStream f = new FileOutputStream(destFile); try { // file input is from the url InputStream in = response.getEntity().getContent(); // here's the download code byte[] buffer = new byte[1024]; int len1 = 0; long total = 0; while ((len1 = in.read(buffer)) > 0 && !isCancelled()) { // Make sure the user can cancel the download. if (isCancelled()) { return null; } total += len1; publishProgress(total, lenghtOfFile, (long) ((total * 100) / lenghtOfFile)); f.write(buffer, 0, len1); } } finally { f.close(); } if (!isCancelled()) { //FIXME: This doesn't belong here really... Book book = new EpubReader().readEpubLazy(destFile.getAbsolutePath(), "UTF-8"); libraryService.storeBook(destFile.getAbsolutePath(), book, false, config.isCopyToLibrayEnabled()); } } else { this.failure = new RuntimeException(response.getStatusLine().getReasonPhrase()); LOG.error("Download failed: " + response.getStatusLine().getReasonPhrase()); } } catch (Exception e) { LOG.error("Download failed.", e); this.failure = e; } return null; }
From source file:org.socialsignin.springframework.data.dynamodb.demo.config.DemoRestMvcConfiguration.java
public Converter<String, ReplyId> stringToReplyIdConverter() { return new Converter<String, ReplyId>() { @SuppressWarnings("deprecation") @Override// ww w .ja v a 2 s . c om public ReplyId convert(String source) { ReplyId id = new ReplyId(); ThreadIdMarshaller threadIdMarshaller = new ThreadIdMarshaller(); String[] parts = source.split("-"); id.setThreadId(threadIdMarshaller.unmarshall(ThreadId.class, URLDecoder.decode(parts[1]))); String replyDateTime = DemoRepositoryLinkBuilder.DATE_FORMAT .format(new Date(Long.parseLong(parts[0]))); id.setReplyDateTime(replyDateTime); return id; } }; }