public Path parent() { if (isRoot()) { return null; } else { return new Path(path + "/.."); } }
public Path(String path, boolean canonize) { if (path == null || path.length() == 0) { throw new IllegalArgumentException("Argument 'path' cannot be null or empty"); } if (canonize) { path = new Path(path, false).canonical().path; } if (!path.equals("/") && path.endsWith(SEPARATOR)) { this.path = path.substring(0, path.length() - 1); } else { this.path = path; } }
public Path append(Path relative) { if (relative == null) { throw new IllegalArgumentException("Argument 'relative' cannot be null"); } if (relative.isAbsolute()) { throw new IllegalArgumentException("Cannot append an absolute path"); } StringBuilder appended = new StringBuilder(path.length() + 1 + relative.path.length()); appended.append(path); if (!path.endsWith(SEPARATOR)) { appended.append("/"); } appended.append(relative.path); return new Path(appended.toString()); }
@Override public void afterWorkspaceMove(String srcAbsPath, String destAbsPath) throws RepositoryException { String n1 = new Path(srcAbsPath).getName().toLowerCase(); // check if the item had extension before renaming. This is used to handle special case // when coda creates // "Untitled file" node that is later renamed to real file name if (n1.lastIndexOf('.') > n1.lastIndexOf('/')) { // it had, this is probably not a new file return; } handleNewNode(destAbsPath, null, brix.wrapSession(session), true); } }
public Path subpath(int idx) { if (idx <= 0) { throw new IndexOutOfBoundsException(); } final int size = size(); final boolean abs = isAbsolute(); int chunks = (abs) ? size + 1 : size; if (idx > chunks) { throw new IndexOutOfBoundsException(); } if (idx == chunks) { // shortcut in case we want the entire path return this; } int iterations = ((abs) ? idx - 1 : idx); int end = 1; for (int i = 0; i < iterations; i++) { end = path.indexOf(SEPARATOR, end + 1); } if (end == 0) { return new Path("/"); } String newPath = path.substring(0, end); return new Path(newPath); }
public Path toRelative(Path ancestor) { if (isRoot()) { throw new IllegalStateException("Cannot make root path relative"); } if (!isDescendantOf(ancestor)) { throw new IllegalArgumentException("Cannot create relative path because this path: " + this + " is not descendant of ancestor argument: " + ancestor); } Path fragment = new Path(path.substring(ancestor.path.length()), false); if (fragment.isAbsolute()) { fragment = fragment.toRelative(new Path("/")); } return fragment; } }
public String fromRealWebNodePath(String nodePath) { Path prefix = new Path(getSiteRootPath()); Path path = new Path(nodePath); if (path.equals(prefix)) { path = new Path("/"); } else if (path.isDescendantOf(prefix)) { path = path.toRelative(prefix); } if (!path.isAbsolute()) { path = new Path("/").append(path); } return path.toString(); }
/** * {@inheritDoc} */ public Path getUriPathForNode(Path nodePath, Brix brix) { Path uriPath = prefix; if (!nodePath.isRoot()) { // nodePath is not root, we have to append it to prefix uriPath = prefix.append(nodePath.toRelative(Path.ROOT)); } if(nodePath.toString().endsWith(SitePlugin.BRIX_INDEX_PAGE)) { final String orgUrl = nodePath.toString(); String url = orgUrl.substring(0, orgUrl.length() - SitePlugin.BRIX_INDEX_PAGE.length()); uriPath = new Path(url); } return uriPath; }
builder.append(urlEncodePath(new Path(nodeURL, false)));
private String getCommonParentPath(List<JcrNode> nodes) { Path current = null; String sitePath = SitePlugin.get().getSiteRootPath(); for (JcrNode node : nodes) { if (node.getPath().startsWith(sitePath) && node instanceof GlobalContainerNode == false) { if (current == null) { current = new Path(node.getPath()).parent(); } else { Path another = new Path(node.getPath()).parent(); Path common = Path.ROOT; Iterator<String> i1 = current.iterator(); Iterator<String> i2 = another.iterator(); while (i1.hasNext() && i2.hasNext()) { String s1 = i1.next(); String s2 = i2.next(); if (Objects.equal(s1, s2)) { common = common.append(new Path(s1)); } else { break; } } current = common; } } } if (current == null) { current = Path.ROOT; } return current.toString(); }
Path nodePath = new Path(tileNode.getObject().getParent().getPath());
private void createFolder() { final JcrNode parent = (JcrNode) getModelObject(); final Path path = new Path(parent.getPath()); final Path newPath = path.append(new Path(name)); final JcrSession session = parent.getSession(); if (session.itemExists(newPath.toString())) { class ModelObject implements Serializable { @SuppressWarnings("unused") public String path = SitePlugin.get().fromRealWebNodePath(newPath.toString()); } ; String error = getString("resourceExists", new Model<ModelObject>(new ModelObject())); error(error); } else { FolderNode node = (FolderNode) parent.addNode(name, "nt:folder"); parent.save(); SitePlugin.get().selectNode(this, node, true); } } }
@SuppressWarnings("unchecked") public void validate(IValidatable validatable) { Object o = validatable.getValue(); if (o != null) { JcrNode node = nodeModel.getObject(); Path path = null; if (o instanceof Path) { path = (Path) o; } else { path = new Path(o.toString()); } if (!path.isAbsolute()) { Path parent = new Path(node.getPath()); if (!((BrixNode) node).isFolder()) parent = parent.parent(); path = parent.append(path); } else { path = new Path(SitePlugin.get().toRealWebNodePath(path.toString())); } if (node.getSession().itemExists(path.toString()) == false) { ValidationError error = new ValidationError(); error.setMessage("Node ${path} could not be found"); error.addKey("NodePathValidator"); error.getVariables().put("path", path.toString()); validatable.error(error); } } } }
public JcrNode nodeForPath(BrixNode baseNode, String path) { Path realPath = new Path(SitePlugin.get().toRealWebNodePath(path)); if (realPath.isAbsolute() == false) { Path base = new Path(baseNode.getPath()); if (!baseNode.isFolder()) { base = base.parent(); } realPath = base.append(realPath); } String strPath = realPath.toString(); if (baseNode.getSession().itemExists(strPath) == false) { return null; } else { return ((JcrNode) baseNode.getSession().getItem(strPath)); } }
/** * Creates a uri path for the specified <code>node</code> By default this * method uses {@link BrixConfig#getMapper()} to map node path to a uri * path. * * @param node * node to create uri path for * @return uri path that represents the node */ public Path getUriPathForNode(final BrixNode node) { // allow site plugin to translate jcr path into node path final String jcrPath = SitePlugin.get().fromRealWebNodePath(node.getPath()); final Path nodePath = new Path(jcrPath); // use urimapper to create the uri return brix.getConfig().getMapper().getUriPathForNode(nodePath, brix); }
/** * Creates a uri path for the specified <code>node</code> By default this * method uses {@link BrixConfig#getMapper()} to map node path to a uri * path. * * @param node * node to create uri path for * @return uri path that represents the node */ public Path getUriPathForNode(final BrixNode node) { // allow site plugin to translate jcr path into node path final String jcrPath = SitePlugin.get().fromRealWebNodePath(node.getPath()); final Path nodePath = new Path(jcrPath); // use urimapper to create the uri return brix.getConfig().getMapper().getUriPathForNode(nodePath, brix); }
private BrixPageParameters createBrixPageParams(Url url, Path path) { BrixPageParameters parameters = new BrixPageParameters(); Path nodePath = path; Path requestPath = new Path("/" + url.getPath()); if (nodePath.isAncestorOf(requestPath)) { Path remaining = new Path(requestPath.toString(), false).toRelative(nodePath); int i = 0; for (String s : remaining) { parameters.set(i, urlDecode(s)); ++i; } } for (QueryParameter parameter : url.getQueryParameters()) { String parameterName = parameter.getName(); if (PageComponentInfo.parse(parameterName) == null) { parameters.add(parameterName, parameter.getValue()); } } return parameters; }
@Override public void onRequest() { String path = getRequest().getRequestParameters().getParameterValue("path").toString(); // if (path == null) { // path = getRequestCycle().getPageParameters().getString("path"); // } path = UrlDecoder.QUERY_INSTANCE.decode(path, getRequest().getCharset()); onPathClicked(new Path(path)); } });