/** * Checks if this package id is valid in respect to JCR names. * @return {@code true} if the names are valid */ public boolean isValid() { return PackageId.isValid(group, name, version == null ? null : version.toString()); }
/** * {@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); }
/** * internally adds the packages below {@code root} to the given list * recursively. * * @param root root node * @param packages list for the packages * @throws RepositoryException if an error occurs */ private void listPackages(Node root, Set<PackageId> packages) throws RepositoryException { for (NodeIterator iter = root.getNodes(); iter.hasNext();) { Node child = iter.nextNode(); if (".snapshot".equals(child.getName())) { continue; } try (JcrPackageImpl pack = new JcrPackageImpl(this, child)) { if (pack.isValid()) { // skip packages with illegal names JcrPackageDefinition jDef = pack.getDefinition(); if (jDef == null || !jDef.getId().isValid()) { continue; } packages.add(jDef.getId()); } else if (child.hasNodes()) { listPackages(child, packages); } } } }
if (jDef != null && !jDef.getId().isValid()) { continue;
throw new IllegalArgumentException("Unable to create package. No package pid set."); if (!pid.isValid()) { throw new IllegalArgumentException("Unable to create package. Illegal package name.");
pid = createRandomPid(); if (!pid.isValid()) { throw new RepositoryException("Unable to create package. Illegal package name.");
throw new PackageException("Package definition not unwrapped."); if (!PackageId.isValid(group, name, version)) { throw new RepositoryException("Unable to rename package. Illegal package name.");
pid = createRandomPid(); if (!pid.isValid()) { bin.dispose(); throw new RepositoryException("Unable to create package. Illegal package name.");