/** * Quotes a URI path token. For example, a blob filename. It replaces "/" by "-". * * @since 7.3 * @param s the uri path token to quote */ public static String quoteURIPathToken(String s) { return quoteURIPathComponent(s, "-", "%40"); }
/** * Quotes a URI path component, with ability to quote "/" and "@" characters or not depending on the URI path * * @since 5.6 * @param s the uri path to quote * @param quoteSlash true if "/" character should be quoted and replaced by %2F * @param quoteAt true if "@" character should be quoted and replaced by %40 */ public static String quoteURIPathComponent(String s, boolean quoteSlash, boolean quoteAt) { return quoteURIPathComponent(s, quoteSlash ? "%2F" : null, quoteAt ? "%40" : null); }
public static String quoteURIPathComponent(String s, boolean quoteSlash) { return quoteURIPathComponent(s, quoteSlash, true); }
@Override public String getDownloadUrl(String repositoryName, String docId, String xpath, String filename, String changeToken) { StringBuilder sb = new StringBuilder(); sb.append(NXFILE); sb.append("/").append(repositoryName); sb.append("/").append(docId); if (xpath != null) { sb.append("/").append(xpath); if (filename != null) { // make sure filename doesn't contain path separators filename = getSanitizedFilenameWithoutPath(filename); sb.append("/").append(URIUtils.quoteURIPathComponent(filename, true)); } } if (StringUtils.isNotEmpty(changeToken)) { try { sb.append("?") .append(CoreSession.CHANGE_TOKEN) .append("=") .append(URLEncoder.encode(changeToken, "UTF-8")); } catch (UnsupportedEncodingException e) { log.error("Cannot append changeToken", e); } } return sb.toString(); }
/** * Gets the full URL of where a blob can be downloaded. * * @since 5.9.3 */ private static String getBlobUrl(Property prop, String filesBaseUrl) throws PropertyException { StringBuilder blobUrlBuilder = new StringBuilder(filesBaseUrl); String xpath = prop.getXPath(); if (!xpath.contains(":")) { // if no prefix, use schema name as prefix: xpath = prop.getSchema().getName() + ":" + xpath; } blobUrlBuilder.append(xpath); blobUrlBuilder.append("/"); String filename = ((Blob) prop.getValue()).getFilename(); if (filename != null) { blobUrlBuilder.append(URIUtils.quoteURIPathComponent(filename, true)); } return blobUrlBuilder.toString(); }
@Override public Resource initialize(WebContext ctx, ResourceType type, Object... args) { this.ctx = ctx; this.type = (T) type; path = ctx.getUriInfo().getMatchedURIs().get(0); // quote path component to replace special characters (except slash and // @ chars) path = URIUtils.quoteURIPathComponent(path, false, false); // avoid paths ending in / -> this will mess-up URLs in FTL files. if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } // resteasy doesn't return correct paths - that should be relative as // is JAX-RS specs on resteasy paths begin with a / StringBuilder buf = new StringBuilder(64).append(ctx.getBasePath()); if (!path.startsWith("/")) { buf.append('/'); } path = buf.append(path).toString(); if (!this.type.getGuard().check(this)) { throw new WebSecurityException( "Failed to initialize object: " + path + ". Object is not accessible in the current context"); } initialize(args); return this; }
/** * Get the url from a DocumentView for a user or a group. */ public String getUrlFromDocumentViewAndID(DocumentView docView, String paramName) { String id = docView.getParameter(paramName); if (id != null) { docView.removeParameter(paramName); List<String> items = new ArrayList<>(); items.add(getPrefix()); items.add(URIUtils.quoteURIPathComponent(id, true, false)); String viewId = docView.getViewId(); if (viewId != null) { items.add(viewId); } String uri = String.join("/", items); Map<String, String> parameters = docView.getParameters(); if (parameters == null) { parameters = new HashMap<>(); } return URIUtils.addParametersToURIQuery(uri, parameters); } return null; }
@POST public Response doPost() { String name = ctx.getForm().getString("name"); DocumentModel newDoc = DocumentHelper.createDocument(ctx, doc, name); String pathSegment = URIUtils.quoteURIPathComponent(newDoc.getName(), true); return redirect(getPath() + '/' + pathSegment); }
items.add(URIUtils.quoteURIPathComponent(path, false));