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; }
/** * 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); }
/** * Creates a new version from the given string. * * @param str the version string. * @return the new version or {@link Version#EMPTY} if {@code str} is an empty string. * @since 2.2.4 */ @Nonnull public static Version create(@Nullable String str) { if (str == null || str.length() == 0) { return Version.EMPTY; } return Version.create(Text.explode(str, '.')); }
/** * {@inheritDoc} */ @Override @Nonnull public String map(@Nonnull String path, boolean reverse) { if (path.length() == 0 || "/".equals(path)) { return path; } Map<String, String> lookup = reverse ? reverseLinks : links; String[] segs = Text.explode(path, '/'); String ret = ""; for (String name: segs) { ret += "/" + name; String link = lookup.get(ret); if (link != null) { ret = link; } } return ret; } }
public TxInfo findChild(String absPath) { if (path.equals(absPath)) { return this; } if (!absPath.startsWith(path + "/")) { return null; } absPath = absPath.substring(path.length()); TxInfo root = this; for (String name: Text.explode(absPath, '/')) { root = root.children().get(name); if (root == null) { break; } } return root; }
/** * 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, "/"); }
/** * 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, "/"); }
@Override public Entry getEntry(String path) throws IOException { String[] segs = Text.explode(path, '/'); Entry root = getRoot(); for (String name: segs) { root = root.getChild(name); if (root == null) { break; } } return root; }
public static String makePath(String parent, String relPath) { String[] ret = makePath(Text.explode(parent, '/'), relPath); return "/" + Text.implode(ret, "/"); }
/** * Returns the repository path for the given platform one. * @param path the platform path * @param respectDotDir if {@code true}, all ".dir" are removed. * @return the repository path */ public static String getRepositoryPath(String path, boolean respectDotDir) { String[] elems = Text.explode(path, '/', true); for (int i=0; i<elems.length; i++) { if (elems[i].length() > 0) { if (respectDotDir && elems[i].endsWith(".dir")) { elems[i] = getRepositoryName(elems[i].substring(0, elems[i].length() - 4)); } else { elems[i] = getRepositoryName(elems[i]); } } } return Text.implode(elems, "/"); }
private Node getOrCreateItem(String relPath, boolean isDir) throws IOException { try { String[] segments = Text.explode(relPath, '/'); Node root = localParent; for (int i=0; i<segments.length; i++) { String s = segments[i]; if (root.hasNode(s)) { root = root.getNode(s); if (isDir) { exportInfo.update(ExportInfo.Type.NOP, root.getPath()); } else { exportInfo.update(ExportInfo.Type.UPDATE, root.getPath()); } } else { if (i == segments.length -1 && !isDir) { root = root.addNode(s, JcrConstants.NT_FILE); exportInfo.update(ExportInfo.Type.ADD, root.getPath()); } else { root = root.addNode(s, JcrConstants.NT_FOLDER); exportInfo.update(ExportInfo.Type.MKDIR, root.getPath()); } } } return root; } catch (RepositoryException e) { IOException io = new IOException("Error while creating item " + relPath); io.initCause(e); throw io; } }
private Aggregate getAggregate(String[] pathElems, int pos) throws RepositoryException { if (pos < pathElems.length) { String elem = pathElems[pos]; if ("..".equals(elem)) { return parent == null ? null : parent.getAggregate(pathElems, pos + 1); } // find suitable leaf load(); if (leaves != null && !leaves.isEmpty()) { for (AggregateImpl a: leaves) { String[] le = Text.explode(a.getRelPath(), '/'); int i=0; while (i<le.length && i+pos < pathElems.length) { if (!le[i].equals(pathElems[i+pos])) { break; } i++; } if (i==le.length) { return a.getAggregate(pathElems, i+pos); } } } return null; } return this; }
/** * Checks if the package id is valid in respect to JCR names. * @param group the package group name * @param name the package name * @param version the (optional) version * @return {@code true} if the names are valid */ public static boolean isValid(String group, String name, String version) { try { assertValidJcrName(name); if (version != null && !version.isEmpty()) { assertValidJcrName(version); } for (String groupSegment: Text.explode(group, '/')) { assertValidJcrName(groupSegment); } return true; } catch (IllegalArgumentException e) { return false; } }
String[] names = Text.explode(name, '/'); byte[] data = entry.isDirectory() ? null : IOUtils.toByteArray(zin); if (names.length > 0) {
/** * Decorates the jcr entries while applying the path mapping. this cannot be done with parallel traversal, because * the remapping could create holes in the entry tree. * * @param src the source entry * @param jcrPath the jcr path of the source entry */ private void applyMapping(@Nonnull Entry src, @Nonnull String jcrPath) { for (Entry child: src.getChildren()) { String path = jcrPath + "/" + child.getName(); String mappedPath = mapping.map(path); // add entry to tree String[] segments = Text.explode(mappedPath, '/'); VirtualEntry entry = jcrRoot; for (String seg: segments) { entry = entry.add(seg, null); } if (entry.baseEntry != null) { log.warn("Path mapping maps multiple paths to the same destination: {} -> {}. ignoring this source.", path, mappedPath); } else { entry.baseEntry = child; } applyMapping(child, path); } }
String name = names.nextElement().toString(); if (name.startsWith(VaultPackage.PREFIX_INSTALL_HOOK)) { String[] segs = Text.explode(name.substring(VaultPackage.PREFIX_INSTALL_HOOK.length()), '.'); if (segs.length == 0 || segs.length > 2 || !"class".equals(segs[1])) { throw new PackageException("Invalid installhook property: " + name);
rootPath = rootPath.substring(parentPath.length()); String[] segments = Text.explode(rootPath, '/'); TxInfo current = root; StringBuilder path = new StringBuilder();