List of usage examples for java.net URI toASCIIString
public String toASCIIString()
From source file:org.linagora.linshare.webservice.utils.DocumentStreamReponseBuilder.java
private static String getContentDispositionHeader(String fileName) { String encodeFileName = null; try {//from ww w.ja v a 2s . co m URI uri = new URI(null, null, fileName, null); encodeFileName = uri.toASCIIString(); } catch (URISyntaxException e) { e.printStackTrace(); } StringBuilder sb = new StringBuilder(); sb.append("attachment; "); // Adding filename using the old way for old browser compatibility sb.append("filename=\"" + fileName + "\"; "); // Adding UTF-8 encoded filename. If the browser do not support this // parameter, it will use the old way. if (encodeFileName != null) { sb.append("filename*= UTF-8''" + encodeFileName); } return sb.toString(); }
From source file:org.opf_labs.fmts.fidget.TikaIdentifier.java
static MediaType identify(final MimeTypes mimeRepo, final InputStream input, URI loc) { Metadata metadata = new Metadata(); metadata.set(Metadata.RESOURCE_NAME_KEY, loc.toASCIIString()); MediaType mediaType;//from w w w. ja va 2s . com try { mediaType = mimeRepo.detect(TikaInputStream.get(input), metadata); } catch (IOException e) { e.printStackTrace(); return null; } return mediaType; }
From source file:com.omnigon.aem.common.utils.url.SlingUrlBuilder.java
public static SlingUrlBuilder create(final String uri) { if (StringUtils.isNotBlank(uri)) { try {//from w ww . j a v a 2 s . c om URI u = URLUtils.createURI(uri); String path = u.getPath(); if (u.isAbsolute() || StringUtils.isBlank(path)) { return new AbsoluteUrlBuilder(u.toASCIIString()); } else { if (!StringUtils.startsWith(path, "/")) { path = "/" + path; } return create(new PathInfo(path)); } } catch (Exception e) { LOG.error(e.getMessage(), e); } } return new NullUrlBuilder(); }
From source file:de.thischwa.pmcms.tool.PathTool.java
/** * Encodes a path for using in links./*from w w w. j a v a 2 s . c om*/ * * @param path * @return Encoded path. * @throws RuntimeException, if the (internal used) {@link URI} throws an {@link URISyntaxException}. */ public static String encodePath(final String path) { try { URI uri = new URI(null, path, null); return uri.toASCIIString(); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:eionet.web.util.JstlFunctions.java
/** * URLEncodes given String./*w ww . j a v a 2s .c om*/ * * @param str value to urlencode * @return encoded value */ public static java.lang.String urlEncode(String str) { try { URI uri = new URI(null, str, null); return uri.toASCIIString(); } catch (URISyntaxException e) { return str; } }
From source file:at.bitfire.davdroid.URIUtils.java
/** * Parse a received absolute/relative URL and generate a normalized URI that can be compared. * @param original URI to be parsed, may be absolute or relative * @param mustBePath true if it's known that original is a path (may contain ":") and not an URI, i.e. ":" is not the scheme separator * @return normalized URI//w w w .j ava2 s . c om * @throws URISyntaxException */ public static URI parseURI(String original, boolean mustBePath) throws URISyntaxException { if (mustBePath) { // may contain ":" // case 1: "my:file" won't be parsed by URI correctly because it would consider "my" as URI scheme // case 2: "path/my:file" will be parsed by URI correctly // case 3: "my:path/file" won't be parsed by URI correctly because it would consider "my" as URI scheme int idxSlash = original.indexOf('/'), idxColon = original.indexOf(':'); if (idxColon != -1) { // colon present if ((idxSlash != -1) && idxSlash < idxColon) // There's a slash, and it's before the colon everything OK ; else // No slash before the colon; we have to put it there original = "./" + original; } } // escape some common invalid characters servers keep sending unescaped crap like "my calendar.ics" or "{guid}.vcf" // this is only a hack, because for instance, "[" may be valid in URLs (IPv6 literal in host name) String repaired = original.replaceAll(" ", "%20").replaceAll("\\{", "%7B").replaceAll("\\}", "%7D"); if (!repaired.equals(original)) Log.w(TAG, "Repaired invalid URL: " + original + " -> " + repaired); URI uri = new URI(repaired); URI normalized = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment()); Log.v(TAG, "Normalized URL " + original + " -> " + normalized.toASCIIString()); return normalized; }
From source file:SageCollegeProject.guideBox.java
public static String GetEncWebCall(String webcall) { try {/*from w w w . ja v a 2s. c o m*/ URL url = new URL(webcall); URI test = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); return test.toASCIIString(); } catch (URISyntaxException | MalformedURLException ex) { Logger.getLogger(guideBox.class.getName()).log(Level.SEVERE, null, ex); } return ""; }
From source file:fr.dutra.confluence2wordpress.util.UrlUtils.java
/** * Sanitizes the given URL by escaping the path and query parameters, if necessary. * @see "http://stackoverflow.com/questions/724043/http-url-address-encoding-in-java" * @param url/* w w w .j av a2 s . c o m*/ * @return * @throws URISyntaxException * @throws MalformedURLException */ public static String sanitize(String url) throws URISyntaxException, MalformedURLException { URL temp = new URL(url); URI uri = new URI(temp.getProtocol(), temp.getUserInfo(), temp.getHost(), temp.getPort(), temp.getPath(), temp.getQuery(), temp.getRef()); return uri.toASCIIString(); }
From source file:org.b3log.latke.util.StaticResources.java
/** * Initializes the static resource path patterns. *///from w w w . j a v a 2 s. co m private static synchronized void init() { LOGGER.trace("Reads static resources definition from [static-resources.xml]"); final File staticResources = Latkes.getWebFile("/WEB-INF/static-resources.xml"); if (null == staticResources || !staticResources.exists()) { throw new IllegalStateException("Not found static resources definition from [static-resources.xml]"); } final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try { final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); final Document document = documentBuilder.parse(staticResources); final Element root = document.getDocumentElement(); root.normalize(); final StringBuilder logBuilder = new StringBuilder("Reading static files: [") .append(Strings.LINE_SEPARATOR); final NodeList includes = root.getElementsByTagName("include"); for (int i = 0; i < includes.getLength(); i++) { final Element include = (Element) includes.item(i); String path = include.getAttribute("path"); final URI uri = new URI("http", "b3log.org", path, null); final String s = uri.toASCIIString(); path = StringUtils.substringAfter(s, "b3log.org"); STATIC_RESOURCE_PATHS.add(path); logBuilder.append(" ").append("path pattern [").append(path).append("]"); if (i < includes.getLength() - 1) { logBuilder.append(","); } logBuilder.append(Strings.LINE_SEPARATOR); } logBuilder.append("]"); if (LOGGER.isTraceEnabled()) { LOGGER.debug(logBuilder.toString()); } } catch (final Exception e) { LOGGER.log(Level.ERROR, "Reads [" + staticResources.getName() + "] failed", e); throw new RuntimeException(e); } final StringBuilder logBuilder = new StringBuilder("Static files: [").append(Strings.LINE_SEPARATOR); final Iterator<String> iterator = STATIC_RESOURCE_PATHS.iterator(); while (iterator.hasNext()) { final String pattern = iterator.next(); logBuilder.append(" ").append(pattern); if (iterator.hasNext()) { logBuilder.append(','); } logBuilder.append(Strings.LINE_SEPARATOR); } logBuilder.append("], ").append('[').append(STATIC_RESOURCE_PATHS.size()).append("] path patterns"); if (LOGGER.isTraceEnabled()) { LOGGER.trace(logBuilder.toString()); } inited = true; }
From source file:org.emergent.android.weave.client.WeaveMain.java
public static String retrieveRaw(String nodepath) throws Exception { String userEmail = getUserEmail(); UserWeave weave = smWeaveFactory.createUserWeave(URI.create(getServerUrl()), userEmail, getPassword()); URI uri = weave.buildSyncUriFromSubpath(nodepath); System.err.println("GETURI: " + uri.toASCIIString()); WeaveResponse response = weave.getNode(uri); return response.getBody(); }