Node getLeafNode(final Session session, final String absPath) throws RepositoryException { if ("/".equals(absPath)) { return session.getRootNode(); } else { final String parentPath = Text.getRelativeParent(absPath, 1, true); final Node parent = getLeafNode(session, parentPath); final String name = Text.getName(absPath, true); if (parent.getPath().equals(parentPath) && parent.hasNode(name)) { return parent.getNode(name); } else { return parent; } } } }
/** * returns an array of strings decomposed of the original string, split at * every occurrence of 'ch'. if 2 'ch' follow each other with no intermediate * characters, empty "" entries are avoided. * * @param str the string to decompose * @param ch the character to use a split pattern * @return an array of strings */ public static String[] explode(String str, int ch) { return explode(str, ch, false); }
byte b = utf8[k]; if (b == escape) { out.write((decodeDigit(utf8[++k]) << 4) + decodeDigit(utf8[++k]));
/** * Returns the name part of the path. If the given path is already a name * (i.e. contains no slashes) it is returned. * * @param path the path * @return the name part or {@code null} if {@code path} is {@code null}. */ public static String getName(String path) { return getName(path, '/'); }
/** * Same as {@link #getRelativeParent(String, int)} but adding the possibility * to pass paths that end with a trailing '/' * * @param path The path. * @param level The level if the parent. * @param ignoreTrailingSlash {@code true} to ignore the trailing slash * @return the path of hte paerent * @see #getRelativeParent(String, int) */ public static String getRelativeParent(String path, int level, boolean ignoreTrailingSlash) { if (ignoreTrailingSlash && path.endsWith("/") && path.length() > 1) { path = path.substring(0, path.length()-1); } return getRelativeParent(path, level); }
String nodePath = pkg.getValue(); if (Text.isDescendantOrEqual(DEFAULT_PACKAGE_ROOT_PATH, nodePath)) { continue; etcPath = Text.getRelativeParent(etcPath, 1); addr = new RepositoryAddress(Text.escapePath("/" + session.getWorkspace().getName() + Text.getRelativeParent(nodePath, 1))); } catch (URISyntaxException e) { throw new IllegalArgumentException(e);
/** * Digest the plain string using the given algorithm. * * @param algorithm The alogrithm for the digest. This algorithm must be * supported by the MessageDigest class. * @param data The plain text String to be digested. * @param enc The character encoding to use * @return The digested plain text String represented as Hex digits. * @throws java.security.NoSuchAlgorithmException if the desired algorithm is not supported by * the MessageDigest class. * @throws java.io.UnsupportedEncodingException if the encoding is not supported */ public static String digest(String algorithm, String data, String enc) throws NoSuchAlgorithmException, UnsupportedEncodingException { return digest(algorithm, data.getBytes(enc)); }
private void print(Mode mode, String action, String path, String msg) { try { action = Text.encodeIllegalXMLCharacters(action); path = Text.encodeIllegalXMLCharacters(path); msg = msg == null ? null : Text.encodeIllegalXMLCharacters(msg); out.write("<span class=\""); out.write(action);
public TxInfo(TxInfo parent, String path) { log.trace("New TxInfo {}" , path); this.parent = parent; this.path = path; this.name = Text.getName(path); }
/** * {@inheritDoc} */ public void startDocument() throws SAXException { stack = new StackElement(null, Text.getRelativeParent(rootPath,1)); }
/** * Returns the platform path for the given repository one. * @param repoPath the repository path * @return the platform path */ public static String getPlatformPath(String repoPath) { String[] elems = Text.explode(repoPath, '/', true); for (int i=0; i<elems.length; i++) { if (elems[i].length() > 0) { elems[i] = getPlatformName(elems[i]); } } return Text.implode(elems, "/"); }
/** * Calculate an MD5 hash of the string given. * * @param data the data to encode * @param enc the character encoding to use * @return a hex encoded string of the md5 digested input * @throws UnsupportedEncodingException if the encoding is not supported */ public static String md5(String data, String enc) throws UnsupportedEncodingException { try { return digest("MD5", data.getBytes(enc)); } catch (NoSuchAlgorithmException e) { throw new InternalError("MD5 digest not available???"); } }
/** * {@inheritDoc} */ public JcrPackage create(String group, String name, String version) throws RepositoryException, IOException { // sanitize name String ext = Text.getName(name, '.'); if ("zip".equals(ext) || "jar".equals(ext)) { name = name.substring(0, name.length() - 4); } if (!PackageId.isValid(group, name, version)) { throw new RepositoryException("Unable to create package. Illegal package name."); } PackageId pid = new PackageId(group, name, version); Node folder = mkdir(Text.getRelativeParent(getInstallationPath(pid), 1), false); return createNew(folder, pid, null, true); }
/** * Same as {@link #getName(String)} but adding the possibility * to pass paths that end with a trailing '/' * * @param path the path to get the name from * @param ignoreTrailingSlash {@code true} to ignore the trailing slash * @see #getName(String) * @return the name */ public static String getName(String path, boolean ignoreTrailingSlash) { if (ignoreTrailingSlash && path != null && path.endsWith("/") && path.length() > 1) { path = path.substring(0, path.length()-1); } return getName(path); }
private Node<E> get(String path, boolean create) { String[] segs = Text.explode(path, separator); Node<E> n = root; for (String name: segs) { Node<E> c = n.get(name, create); if (c == null) { return null; } n = c; } return n; }
public Node getParentNode(Session s) throws RepositoryException { String parentPath = emptyPathToRoot(Text.getRelativeParent(path, 1)); return s.nodeExists(parentPath) ? s.getNode(parentPath) : null; }
/** * Returns the repository path for the given platform one. * @param path the platform path * @return the repository path */ public static String getRepositoryPath(String path) { String[] elems = Text.explode(path, '/', true); for (int i=0; i<elems.length; i++) { if (elems[i].length() > 0) { elems[i] = getRepositoryName(elems[i]); } } return Text.implode(elems, "/"); }
return session.getNode(path); String parentPath = Text.getRelativeParent(path, 1); if (path == null || ("/".equals(path) && parentPath.equals(path))) { throw new RepositoryException("could not crete intermediate nodes"); for (int i=0; node == null && i<FOLDER_TYPES.length; i++) { try { node = parent.addNode(Text.getName(path), FOLDER_TYPES[i]); } catch (RepositoryException e) { lastError = e;