/** * 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, '/'); }
public TxInfo(TxInfo parent, String path) { log.trace("New TxInfo {}" , path); this.parent = parent; this.path = path; this.name = Text.getName(path); }
/** * 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); }
/** * Generates the relative key used for tracking nodes and properties. * @param aggregatePath the absolute path of the node being aggregated. * @param path the path of the item being checksumed * @return the key */ protected String getChecksumKey(String aggregatePath, String path) { if ("/".equals(aggregatePath) && "/".equals(path)) { return "/"; } else if ("/".equals(aggregatePath)) { return path; } String baseNodeName = Text.getName(aggregatePath); String relPath = StringUtils.removeStart(path, aggregatePath); return baseNodeName + relPath; }
public String getName() { return Text.getName(getRelPath()); }
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; } } } }
/** * {@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); }
/** * {@inheritDoc} */ @Override public void onNodeIgnored(Node node, int depth) throws RepositoryException { // just add an empty node. used for ordering String label = Text.getName(node.getPath()); String elemName = ISO9075.encode(label); Name qName = getQName(elemName); try { contentHandler.startElement(qName.getNamespaceURI(), qName.getLocalName(), elemName, null); contentHandler.endElement(qName.getNamespaceURI(), qName.getLocalName(), elemName); } catch (SAXException e) { throw new RepositoryException(e); } } }
final String name = Text.getName(systemId); if (Constants.FILTER_XML.equals(name)) {
private JcrPackage createNew(@Nonnull Node parent, @Nonnull PackageId pid, @Nonnull Binary bin, @Nonnull MemoryArchive archive) throws RepositoryException, IOException { Node node = parent.addNode(Text.getName(getInstallationPath(pid) + ".zip"), JcrConstants.NT_FILE); Node content = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE); content.addMixin(JcrPackage.NT_VLT_PACKAGE);
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;
/** * {@inheritDoc} */ @Override public void onNodeEnd(Node node, boolean included, int level) throws RepositoryException { String label = Text.getName(node.getPath()); String elemName; if (node.getDepth() == 0) { // root node needs a name elemName = jcrRoot; } else { // encode node name to make sure it's a valid xml name elemName = ISO9075.encode(label); } // end element (node) Name qName = getQName(elemName); try { contentHandler.endElement(qName.getNamespaceURI(), qName.getLocalName(), elemName); } catch (SAXException e) { throw new RepositoryException(e); } }
/** * {@inheritDoc} */ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { // special handling for root node if (stack.parent == null) { if (localName.equals(NameConstants.JCR_ROOT.getLocalName()) && uri.equals(NameConstants.JCR_ROOT.getNamespaceURI())) { qName = Text.getName(rootPath); } } String label = ISO9075.decode(qName); String name = label; int idx = name.lastIndexOf('['); if (idx > 0) { name = name.substring(0, idx); } stack = stack.push(name); if (attributes.getLength() == 0) { listener.onNode(stack.getPath(), true, ""); } else { // currently ignore namespace mappings in node type values // todo: fix String pt = attributes.getValue(NameConstants.JCR_PRIMARYTYPE.getNamespaceURI(), NameConstants.JCR_PRIMARYTYPE.getLocalName()); listener.onNode(stack.getPath(), false, pt == null ? "" : pt); } }
String label = Text.getName(node.getPath()); String elemName; if (level == 0 || node.getDepth() == 0) {
/** * computes configured package based on expression configuration (either existing or creating it) * @throws IOException problem with binary * @throws RepositoryException problem with package persistence * @throws IOException problem with package build * @throws ScriptException problem with some expression/path compute */ protected void init() throws IOException, RepositoryException, ScriptException { if (jcrPackage == null){ String packagePath = getExpr(); if (StringUtils.isNotBlank(packagePath)) { JcrPackageManager mgr = PackagingService.getPackageManager(resolver.adaptTo(Session.class)); Resource packageResource = resolver.getResource(packagePath); if (packageResource != null) { jcrPackage = mgr.open(packageResource.adaptTo(Node.class)); } else { String parent = Text.getRelativeParent(packagePath, 1); Resource folderResource = resolver.getResource(parent); if (folderResource == null) { LOGGER.error("folder of configured path should exists"); } else { String name = Text.getName(packagePath); jcrPackage = mgr.create(folderResource.adaptTo(Node.class), name); } } } else { LOGGER.error("expression should not be blank as it's supposed to hold package path"); } } }
public ArtifactSet getArtifacts() throws RepositoryException { if (artifacts == null) { assertAttached(); load(); artifacts = (ArtifactSetImpl) aggregator.createArtifacts(this); if (filterArtifacts) { // filter out all non-directory and non .content.xml artifacts ArtifactSetImpl na = new ArtifactSetImpl(); na.addAll(artifacts); for (Artifact a: na.values()) { if (a.getType() != ArtifactType.DIRECTORY) { if (!".content.xml".equals(Text.getName(a.getPlatformPath()))) { artifacts.remove(a); } } } } } return artifacts; }
protected void doExecute(VaultFsConsoleExecutionContext ctx, CommandLine cl) throws Exception { // overwrite this, since it takes the mounted vault fs into account String jcrPath = (String) cl.getValue(argJcrPath); String localPath = (String) cl.getValue(argLocalPath); VaultFile remoteFile = ctx.getVaultFsApp().getVaultFile(jcrPath, true); RepositoryAddress addr = remoteFile.getAggregate().getManager().getMountpoint(); if (localPath == null) { if (jcrPath == null) { localPath = Text.getName(addr.toString()); } else { localPath = Text.getName(jcrPath); } } File localFile = ctx.getVaultFsApp().getPlatformFile(localPath, false); if (localFile.isFile()) { throw new ExecutionException("Local file must be a directory: " + localFile.getPath()); } if (!localFile.exists()) { localFile.mkdir(); } VltContext vCtx = ctx.getVaultFsApp().createVaultContext(localFile); vCtx.setVerbose(cl.hasOption(OPT_VERBOSE)); vCtx.setQuiet(cl.hasOption(OPT_QUIET)); Checkout c = new Checkout(addr, jcrPath, localFile); c.setForce(cl.hasOption(optForce)); vCtx.execute(c); }
protected void doExecute(VaultFsConsoleExecutionContext ctx, CommandLine cl) throws Exception { String name = (String) cl.getValue(argLocalPath); String jcrPath = (String) cl.getValue(argJcrPath); VaultFile file; if (jcrPath == null) { jcrPath = Text.getName(name); if (jcrPath.equals("")) { jcrPath = name; } } File local = ctx.getVaultFsApp().getPlatformFile(name, true); VaultFile cwd = ctx.getVaultFsApp().getVaultFile("", true); file = cwd.getFileSystem().getFile(cwd, jcrPath); if (file == null) { // do add jcrPath = PathUtil.makePath(cwd.getPath(), jcrPath); doAdd(local, cwd, jcrPath); } else { doPut(local, file); } }