/** * Does a URL decoding of the <code>string</code>. Please note that in * opposite to the {@link java.net.URLDecoder} it does not transform the + * into spaces. * * @param string the string to decode * @return the decoded string * @throws NullPointerException if <code>string</code> is <code>null</code>. * @throws ArrayIndexOutOfBoundsException if not enough character follow an * escape character * @throws IllegalArgumentException if the 2 characters following the escape * character do not represent a hex-number. */ public static String unescape(String string) { return unescape(string, '%'); }
/** * Does a URL decoding of the <code>string</code>. Please note that in * opposite to the {@link java.net.URLDecoder} it does not transform the + * into spaces. * * @param string the string to decode * @return the decoded string * @throws NullPointerException if <code>string</code> is <code>null</code>. * @throws ArrayIndexOutOfBoundsException if not enough character follow an * escape character * @throws IllegalArgumentException if the 2 characters following the escape * character do not represent a hex-number. */ public static String unescape(String string) { return unescape(string, '%'); }
/** * Does a URL decoding of the <code>string</code>. Please note that in * opposite to the {@link java.net.URLDecoder} it does not transform the + * into spaces. * * @param string the string to decode * @return the decoded string * @throws NullPointerException if <code>string</code> is <code>null</code>. * @throws ArrayIndexOutOfBoundsException if not enough character follow an * escape character * @throws IllegalArgumentException if the 2 characters following the escape * character do not represent a hex-number. */ public static String unescape(String string) { return unescape(string, '%'); }
/** * Does a URL decoding of the <code>string</code>. Please note that in * opposite to the {@link java.net.URLDecoder} it does not transform the + * into spaces. * * @param string the string to decode * @return the decoded string * @throws NullPointerException if <code>string</code> is <code>null</code>. * @throws ArrayIndexOutOfBoundsException if not enough character follow an * escape character * @throws IllegalArgumentException if the 2 characters following the escape * character do not represent a hex-number. */ public static String unescape(String string) { return unescape(string, '%'); }
/** * Does a URL decoding of the <code>string</code>. Please note that in * opposite to the {@link java.net.URLDecoder} it does not transform the + * into spaces. * * @param string the string to decode * @return the decoded string * @throws NullPointerException if <code>string</code> is <code>null</code>. * @throws ArrayIndexOutOfBoundsException if not enough character follow an * escape character * @throws IllegalArgumentException if the 2 characters following the escape * character do not represent a hex-number. */ public static String unescape(String string) { return unescape(string, '%'); }
public static String getJcrLockToken(String token) throws RepositoryException { if (token.startsWith(OPENPREFIX)) { return Text.unescape(token.substring(OPENPREFIX.length())); } else { throw new RepositoryException("not a token for an open-scoped JCR lock: " + token); } }
/** * Creates an external identity reference from a string representation. * @param str the string * @return the reference */ @NotNull public static ExternalIdentityRef fromString(@NotNull String str) { int idx = str.indexOf(';'); if (idx < 0) { return new ExternalIdentityRef(Text.unescape(str), null); } else { return new ExternalIdentityRef( Text.unescape(str.substring(0, idx)), Text.unescape(str.substring(idx+1)) ); } }
public DavResourceLocator createResourceLocator(String prefix, String href) { // build prefix string and remove all prefixes from the given href. StringBuffer b = new StringBuffer(""); if (prefix != null && prefix.length() > 0) { b.append(prefix); if (href.startsWith(prefix)) { href = href.substring(prefix.length()); } } if (repositoryPrefix != null && repositoryPrefix.length() > 0 && !prefix.endsWith(repositoryPrefix)) { b.append(repositoryPrefix); if (href.startsWith(repositoryPrefix)) { href = href.substring(repositoryPrefix.length()); } } // special treatment for root item, that has no name but '/' path. if (href == null || "".equals(href)) { href = "/"; } return new Locator(b.toString(), Text.unescape(href), this); }
public DavResourceLocator createResourceLocator(String prefix, String href) { if (href == null) { throw new IllegalArgumentException( "Request handle must not be null."); } // if href starts with the prefix, cut the prefix off the href if (prefix != null && prefix.length() > 0) { if (href.startsWith(prefix)) { href = href.substring(prefix.length()); } } // remove trailing "/" that is present with collections if (href.endsWith("/")) { href = href.substring(0, href.length() - 1); } // an empty requestHandle (after removal of the "/") signifies a request // to the root that does not represent a repository item. String resourcePath; if ("".equals(href)) { resourcePath = "/"; } else { resourcePath = Text.unescape(href); } return new SlingResourceLocator(prefix, workspaceName, resourcePath, this); }
public DavResourceLocator createResourceLocator( String prefix, String href ) { // build prefix string and remove all prefixes from the given href. StringBuilder b = new StringBuilder(); if ( prefix != null && prefix.length() > 0 ) { b.append( prefix ); if ( !prefix.endsWith( "/" ) ) { b.append( '/' ); } if ( href.startsWith( prefix ) ) { href = href.substring( prefix.length() ); } } // special treatment for root item, that has no name but '/' path. if ( href == null || "".equals( href ) ) { href = "/"; } final int projectId = WorkingCopyPathUtil.getProjectId( href ); return new ContinuumBuildAgentDavResourceLocator( b.toString(), Text.unescape( href ), this, projectId ); }
@Override public DavResourceLocator createResourceLocator( String prefix, String href ) { // build prefix string and remove all prefixes from the given href. StringBuilder b = new StringBuilder(); if ( prefix != null && prefix.length() > 0 ) { b.append( prefix ); if ( !prefix.endsWith( "/" ) ) { b.append( '/' ); } if ( href.startsWith( prefix ) ) { href = href.substring( prefix.length() ); } } // special treatment for root item, that has no name but '/' path. if ( href == null || "".equals( href ) ) { href = "/"; } final String repository = RepositoryPathUtil.getRepositoryName( href ); return new ArchivaDavResourceLocator( b.toString(), Text.unescape( href ), repository, this ); }
public static LabelHeader parse(WebdavRequest request) { String hv = request.getHeader(DeltaVConstants.HEADER_LABEL); if (hv == null) { return null; } else { return new LabelHeader(Text.unescape(hv)); } } }
/** * @inheritDoc */ public Path getQPath(String uri, SessionInfo sessionInfo) throws RepositoryException { String rootUri = getRootItemUri(sessionInfo.getWorkspaceName()); String jcrPath; if (uri.startsWith(rootUri)) { jcrPath = uri.substring(rootUri.length()); } else { // todo: probably rather an error? jcrPath = uri; } try { return service.getNamePathResolver(sessionInfo).getQPath(Text.unescape(jcrPath)); } catch (NameException e) { throw new RepositoryException(e); } }
/** * @inheritDoc */ public Path getQPath(String uri, SessionInfo sessionInfo) throws RepositoryException { String rootUri = getRootItemUri(sessionInfo.getWorkspaceName()); String jcrPath; if (uri.startsWith(rootUri)) { jcrPath = uri.substring(rootUri.length()); } else { // todo: probably rather an error? jcrPath = uri; } try { return service.getNamePathResolver(sessionInfo).getQPath(Text.unescape(jcrPath)); } catch (NameException e) { throw new RepositoryException(e); } }
@Nullable private Set<Principal> readGroupsFromCache(@NotNull Tree authorizableNode) { Tree principalCache = authorizableNode.getChild(CacheConstants.REP_CACHE); if (!principalCache.exists()) { log.debug("No group cache at " + authorizableNode.getPath()); return null; } if (isValidCache(principalCache)) { log.debug("Reading group membership at " + authorizableNode.getPath()); String str = TreeUtil.getString(principalCache, CacheConstants.REP_GROUP_PRINCIPAL_NAMES); if (str == null || str.isEmpty()) { return Collections.emptySet(); } Set<Principal> groups = new HashSet<>(); for (String s : Text.explode(str, ',')) { final String name = Text.unescape(s); groups.add(new CachedGroupPrincipal(name, namePathMapper, root, config)); } return groups; } else { log.debug("Expired group cache for " + authorizableNode.getPath()); return null; } }
/** * @see IdFactory#fromJcrIdentifier(String) */ public NodeId fromJcrIdentifier(String jcrIdentifier) { // TODO improve int pos = jcrIdentifier.indexOf(DELIMITER); switch (pos) { case -1: return createNodeId(jcrIdentifier); case 0: return createNodeId((String) null, getPathFactory().create(jcrIdentifier.substring(1))); default: String uniqueId = Text.unescape(jcrIdentifier.substring(0, pos), DELIMITER); Path path = getPathFactory().create(jcrIdentifier.substring(pos+1)); return createNodeId(uniqueId, path); } }
@Nullable private Set<Principal> readGroupsFromCache(@NotNull Tree authorizableNode) { Tree principalCache = authorizableNode.getChild(CacheConstants.REP_CACHE); if (!principalCache.exists()) { log.debug("No group cache at " + authorizableNode.getPath()); return null; } if (isValidCache(principalCache)) { log.debug("Reading group membership at " + authorizableNode.getPath()); String str = TreeUtil.getString(principalCache, CacheConstants.REP_GROUP_PRINCIPAL_NAMES); if (str == null || str.isEmpty()) { return Collections.emptySet(); } Set<Principal> groups = new HashSet<>(); for (String s : Text.explode(str, ',')) { final String name = Text.unescape(s); groups.add(new CachedGroupPrincipal(name, namePathMapper, root, config)); } return groups; } else { log.debug("Expired group cache for " + authorizableNode.getPath()); return null; } }
/** * @see IdFactory#fromJcrIdentifier(String) */ public NodeId fromJcrIdentifier(String jcrIdentifier) { // TODO improve int pos = jcrIdentifier.indexOf(DELIMITER); switch (pos) { case -1: return createNodeId(jcrIdentifier); case 0: return createNodeId((String) null, getPathFactory().create(jcrIdentifier.substring(1))); default: String uniqueId = Text.unescape(jcrIdentifier.substring(0, pos), DELIMITER); Path path = getPathFactory().create(jcrIdentifier.substring(pos+1)); return createNodeId(uniqueId, path); } }
@CheckForNull private Set<Group> readGroupsFromCache(@Nonnull Tree authorizableNode) { Tree principalCache = authorizableNode.getChild(CacheConstants.REP_CACHE); if (!principalCache.exists()) { log.debug("No group cache at " + authorizableNode.getPath()); return null; } if (isValidCache(principalCache)) { log.debug("Reading group membership at " + authorizableNode.getPath()); String str = TreeUtil.getString(principalCache, CacheConstants.REP_GROUP_PRINCIPAL_NAMES); if (str == null || str.isEmpty()) { return new HashSet<Group>(1); } Set<Group> groups = new HashSet<Group>(); for (String s : Text.explode(str, ',')) { final String name = Text.unescape(s); groups.add(new CachedGroupPrincipal(name)); } return groups; } else { log.debug("Expired group cache for " + authorizableNode.getPath()); return null; } }
/** * @inheritDoc */ public PropertyId getPropertyId(String uri, SessionInfo sessionInfo) throws RepositoryException { IdURICache cache = getCache(sessionInfo.getWorkspaceName()); ItemId id = cache.getItemId(uri); if (id != null) { if (!id.denotesNode()) { return (PropertyId) id; } } // separate parent uri and property JCRName String parentUri = Text.getRelativeParent(uri, 1, true); // make sure propName is unescaped String propName = Text.unescape(Text.getName(uri, true)); // retrieve parent node id NodeId parentId = getNodeId(parentUri, sessionInfo, false); // build property id try { Name name = service.getNamePathResolver(sessionInfo).getQName(propName); PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name); cache.add(uri, propertyId); return propertyId; } catch (NameException e) { throw new RepositoryException(e); } } }