Java Code Examples for javax.jcr.Node#hasProperty()
The following examples show how to use
javax.jcr.Node#hasProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Purge.java From APM with Apache License 2.0 | 6 votes |
private void purge(final Context context, final ActionResult actionResult) throws RepositoryException, ActionExecutionException { NodeIterator iterator = getPermissions(context); String normalizedPath = normalizePath(path); while (iterator != null && iterator.hasNext()) { Node node = iterator.nextNode(); if (node.hasProperty(PermissionConstants.REP_ACCESS_CONTROLLED_PATH)) { String parentPath = node.getProperty(PermissionConstants.REP_ACCESS_CONTROLLED_PATH) .getString(); String normalizedParentPath = normalizePath(parentPath); boolean isUsersPermission = parentPath.startsWith(context.getCurrentAuthorizable().getPath()); if (StringUtils.startsWith(normalizedParentPath, normalizedPath) && !isUsersPermission) { RemoveAll removeAll = new RemoveAll(parentPath); ActionResult removeAllResult = removeAll.execute(context); if (Status.ERROR.equals(removeAllResult.getStatus())) { copyErrorMessages(removeAllResult, actionResult); } } } } }
Example 2
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 6 votes |
private static Optional<MailingList> getMailinglist(Node mailinglistNode) { try { String mailingListName = mailinglistNode.getName(); MailingList mailinglist = new MailingList(); mailinglist.setName(mailingListName); mailinglist.setMainArchiveUrl(getPropertyString(mailinglistNode, "archive")); String n = "otherArchives"; if (mailinglistNode.hasProperty(n)) { mailinglist.setOtherArchives(Arrays.asList(getPropertyString(mailinglistNode, n).split(","))); } else { mailinglist.setOtherArchives(Collections.<String>emptyList()); } mailinglist.setPostAddress(getPropertyString(mailinglistNode, "post")); mailinglist.setSubscribeAddress(getPropertyString(mailinglistNode, "subscribe")); mailinglist.setUnsubscribeAddress(getPropertyString(mailinglistNode, "unsubscribe")); return Optional.of(mailinglist); } catch (RepositoryException e) { return Optional.empty(); } }
Example 3
Source File: PropertyValueArtifact.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public String getContentType() { String ct = super.getContentType(); if (ct == null && tmpFile == null) { try { Node parent = property.getParent(); if (parent.hasProperty(JcrConstants.JCR_MIMETYPE)) { ct = parent.getProperty(JcrConstants.JCR_MIMETYPE).getString(); } } catch (RepositoryException e) { // ignore } super.setContentType(ct); } return ct; }
Example 4
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 6 votes |
private Node getOrAddNodeByPath(Node baseNode, String name, String nodeType, boolean primaryType) throws RepositoryException { log.debug("getOrAddNodeByPath " + baseNode + " " + name + " " + nodeType); Node node = baseNode; for (String n : name.split("/")) { if (nodeType != null && primaryType) { node = JcrUtils.getOrAddNode(node, n, nodeType); } else { node = JcrUtils.getOrAddNode(node, n); if (nodeType != null && !node.isNodeType(nodeType)) { node.addMixin(nodeType); } } if (!node.hasProperty("id")) { node.setProperty("id", n); } } return node; }
Example 5
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 6 votes |
private Node getOrAddNodeByPath(Node baseNode, String name, String primaryType, String... mixinTypes) throws RepositoryException { log.debug("getOrAddNodeByPath baseNode={}, name={}, primary={}, mixin={}", baseNode, name, primaryType, mixinTypes); Node node = baseNode; for (String n : name.split("/")) { node = JcrUtils.getOrAddNode(node, n, primaryType); for (String mixin : mixinTypes) { if (mixin != null && !node.isNodeType(mixin)) { node.addMixin(mixin); } } if (!node.hasProperty("id")) { node.setProperty("id", n); } } return node; }
Example 6
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 6 votes |
private <T extends MetadataFacet> Function<Row, Optional<T>> getFacetFromRowFunc(MetadataFacetFactory<T> factory, String repositoryId) { return (Row row) -> { try { Node node = row.getNode("facet"); if (node.hasProperty("archiva:name")) { String facetName = node.getProperty("archiva:name").getString(); return Optional.ofNullable(createFacetFromNode(factory, node, repositoryId, facetName)); } else { return Optional.empty(); } } catch (RepositoryException e) { log.error("Exception encountered {}", e.getMessage()); return Optional.empty(); } }; }
Example 7
Source File: PageServiceImpl.java From mycollab with GNU Affero General Public License v3.0 | 6 votes |
private Folder convertNodeToFolder(Node node) { try { Folder folder = new Folder(); folder.setCreatedTime(node.getProperty("jcr:created").getDate()); folder.setCreatedUser(node.getProperty("wiki:createdUser").getString()); if (node.hasProperty("wiki:description")) { folder.setDescription(node.getProperty("wiki:description").getString()); } else { folder.setDescription(""); } folder.setName(node.getProperty("wiki:name").getString()); String folderPath = node.getPath(); if (folderPath.startsWith("/")) { folderPath = folderPath.substring(1); } folder.setPath(folderPath); return folder; } catch (Exception e) { throw new MyCollabException(e); } }
Example 8
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
@Override public void addMetadataFacet(RepositorySession session, String repositoryId, MetadataFacet metadataFacet) throws MetadataRepositoryException { final Session jcrSession = getSession(session); try { Node repo = getOrAddRepositoryNode(jcrSession, repositoryId); Node facets = JcrUtils.getOrAddNode(repo, "facets", FACETS_FOLDER_TYPE); String id = metadataFacet.getFacetId(); Node facetNode = JcrUtils.getOrAddNode(facets, id, FACET_ID_CONTAINER_TYPE); if (!facetNode.hasProperty("id")) { facetNode.setProperty("id", id); } Node facetInstance = getOrAddNodeByPath(facetNode, metadataFacet.getName(), FACET_NODE_TYPE, true); if (!facetInstance.hasProperty("archiva:facetId")) { facetInstance.setProperty("archiva:facetId", id); facetInstance.setProperty("archiva:name", metadataFacet.getName()); } for (Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet()) { facetInstance.setProperty(entry.getKey(), entry.getValue()); } session.save(); } catch (RepositoryException | MetadataSessionException e) { throw new MetadataRepositoryException(e.getMessage(), e); } }
Example 9
Source File: LinkHelper.java From sling-samples with Apache License 2.0 | 5 votes |
public void createLink(Node source, Node target, String name) throws PathNotFoundException, RepositoryException { String targetPath = target.getPath(); ArrayList<String> newSourceLinks = new ArrayList<String>(); if (source.hasProperty(name)) { Value[] sourceLinks = source.getProperty(name).getValues(); for (Value sourceLink : sourceLinks) { newSourceLinks.add(sourceLink.getString()); } } if (!newSourceLinks.contains(targetPath)) { newSourceLinks.add(targetPath); } String[] newSourceLinksArray = new String[newSourceLinks.size()]; source.setProperty(name, newSourceLinks.toArray(newSourceLinksArray)); }
Example 10
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 5 votes |
private Node getOrAddRepositoryNode(Session jcrSession, String repositoryId) throws RepositoryException { log.debug("getOrAddRepositoryNode " + repositoryId); Node root = jcrSession.getRootNode(); Node node = JcrUtils.getOrAddNode(root, "repositories"); log.debug("Repositories " + node); node = JcrUtils.getOrAddNode(node, repositoryId, REPOSITORY_NODE_TYPE); if (!node.hasProperty("id")) { node.setProperty("id", repositoryId); } return node; }
Example 11
Source File: BaseRepositoryService.java From urule with Apache License 2.0 | 5 votes |
@Override public List<VersionFile> getVersionFiles(String path) throws Exception{ path = processPath(path); Node rootNode=getRootNode(); if (!rootNode.hasNode(path)) { throw new RuleException("File [" + path + "] not exist."); } List<VersionFile> files = new ArrayList<VersionFile>(); Node fileNode = rootNode.getNode(path); VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath()); VersionIterator iterator = versionHistory.getAllVersions(); while (iterator.hasNext()) { Version version = iterator.nextVersion(); String versionName = version.getName(); if (versionName.startsWith("jcr:")) { continue; // skip root version } Node fnode = version.getFrozenNode(); VersionFile file = new VersionFile(); file.setName(version.getName()); file.setPath(fileNode.getPath()); Property prop = fnode.getProperty(CRATE_USER); file.setCreateUser(prop.getString()); prop = fnode.getProperty(CRATE_DATE); file.setCreateDate(prop.getDate().getTime()); if(fnode.hasProperty(VERSION_COMMENT)){ prop=fnode.getProperty(VERSION_COMMENT); file.setComment(prop.getString()); } files.add(file); } return files; }
Example 12
Source File: CNDSerializer.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void writePropDef(Writer out, Node node, String primary) throws IOException, RepositoryException { out.write("\n" + INDENT + "- "); String name = "*"; if (node.hasProperty(JcrConstants.JCR_NAME)) { name = node.getProperty(JcrConstants.JCR_NAME).getString(); } out.write(name); out.write(" ("); out.write(node.getProperty(JcrConstants.JCR_REQUIREDTYPE).getString().toLowerCase()); out.write(")"); if (node.hasProperty(JcrConstants.JCR_DEFAULTVALUES)) { writeDefaultValues(out, node.getProperty(JcrConstants.JCR_DEFAULTVALUES).getValues()); } if (primary != null && primary.equals(name)) { out.write(" primary"); } if (node.getProperty(JcrConstants.JCR_MANDATORY).getBoolean()) { out.write(" mandatory"); } if (node.getProperty(JcrConstants.JCR_AUTOCREATED).getBoolean()) { out.write(" autocreated"); } if (node.getProperty(JcrConstants.JCR_PROTECTED).getBoolean()) { out.write(" protected"); } if (node.getProperty(JcrConstants.JCR_MULTIPLE).getBoolean()) { out.write(" multiple"); } String opv = node.getProperty(JcrConstants.JCR_ONPARENTVERSION).getString().toLowerCase(); if (!opv.equals("copy")) { out.write(" "); out.write(opv); } if (node.hasProperty(JcrConstants.JCR_VALUECONSTRAINTS)) { writeValueConstraints(out, node.getProperty(JcrConstants.JCR_VALUECONSTRAINTS).getValues()); } }
Example 13
Source File: CNDSerializer.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private void writeNodeDef(Writer out, Node node, String primary) throws IOException, RepositoryException { out.write("\n" + INDENT + "+ "); String name = "*"; if (node.hasProperty(JcrConstants.JCR_NAME)) { name = node.getProperty(JcrConstants.JCR_NAME).getString(); } out.write(name); writeRequiredTypes(out, node.getProperty(JcrConstants.JCR_REQUIREDPRIMARYTYPES).getValues()); if (node.hasProperty(JcrConstants.JCR_DEFAULTPRIMARYTYPE)) { writeDefaultType(out, node.getProperty(JcrConstants.JCR_DEFAULTPRIMARYTYPE).getString()); } if (primary != null && primary.equals(name)) { out.write(" primary"); } if (node.getProperty(JcrConstants.JCR_MANDATORY).getBoolean()) { out.write(" mandatory"); } if (node.getProperty(JcrConstants.JCR_AUTOCREATED).getBoolean()) { out.write(" autocreated"); } if (node.getProperty(JcrConstants.JCR_PROTECTED).getBoolean()) { out.write(" protected"); } if (node.getProperty(JcrConstants.JCR_SAMENAMESIBLINGS).getBoolean()) { out.write(" multiple"); } String opv = node.getProperty(JcrConstants.JCR_ONPARENTVERSION).getString().toLowerCase(); if (!opv.equals("copy")) { out.write(" "); out.write(opv); } }
Example 14
Source File: CIFProductFieldHelper.java From commerce-cif-connector with Apache License 2.0 | 5 votes |
private boolean isCloudBoundFolder(Resource resource) { if (isVirtual(resource)) { return false; } Node node = resource.adaptTo(Node.class); try { return node.hasProperty("cq:catalogDataResourceProviderFactory"); } catch (RepositoryException ex) { return false; } }
Example 15
Source File: DocViewProperty.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
/** * Sets this property on the given node * * @param node the node * @return {@code true} if the value was modified. * @throws RepositoryException if a repository error occurs */ public boolean apply(Node node) throws RepositoryException { Property prop = node.hasProperty(name) ? node.getProperty(name) : null; // check if multiple flags are equal if (prop != null && isMulti != prop.getDefinition().isMultiple()) { prop.remove(); prop = null; } if (prop != null) { int propType = prop.getType(); if (propType != type && (propType != PropertyType.STRING || type != PropertyType.UNDEFINED)) { // never compare if types differ prop = null; } } if (isMulti) { // todo: handle multivalue binaries and reference binaries Value[] vs = prop == null ? null : prop.getValues(); if (vs != null && vs.length == values.length) { // quick check all values boolean modified = false; for (int i=0; i<vs.length; i++) { if (!vs[i].getString().equals(values[i])) { modified = true; } } if (!modified) { return false; } } if (type == PropertyType.UNDEFINED) { node.setProperty(name, values); } else { node.setProperty(name, values, type); } // assume modified return true; } else { Value v = prop == null ? null : prop.getValue(); if (type == PropertyType.BINARY) { if (isReferenceProperty) { ReferenceBinary ref = new SimpleReferenceBinary(values[0]); Binary binary = node.getSession().getValueFactory().createValue(ref).getBinary(); if (v != null) { Binary bin = v.getBinary(); if (bin.equals(binary)) { return false; } } node.setProperty(name, binary); } // the binary property is always modified (TODO: check if still correct with JCRVLT-110) return true; } if (v == null || !v.getString().equals(values[0])) { try { if (type == PropertyType.UNDEFINED) { node.setProperty(name, values[0]); } else { node.setProperty(name, values[0], type); } } catch (ValueFormatException e) { // forcing string node.setProperty(name, values[0], PropertyType.STRING); } return true; } } return false; }
Example 16
Source File: CatalogDataResourceProviderManagerImpl.java From commerce-cif-connector with Apache License 2.0 | 4 votes |
/** * Handle resource events to add or remove virtual catalog data registrations. */ public void onEvent(EventIterator events) { try { // collect all actions to be performed for this event final Map<String, Boolean> actions = new HashMap<>(); boolean nodeAdded = false; boolean nodeRemoved = false; while (events.hasNext()) { final Event event = events.nextEvent(); final String path = event.getPath(); final int eventType = event.getType(); if (eventType == Event.NODE_ADDED) { nodeAdded = true; Session session = resolver.adaptTo(Session.class); final Node node = session.getNode(path); if (node != null && node.isNodeType(JcrResourceConstants.NT_SLING_FOLDER) && node.hasProperty( CatalogDataResourceProviderFactory.PROPERTY_FACTORY_ID) || node.hasProperty(CONF_ROOT)) { actions.put(path, true); } } else if (eventType == Event.NODE_REMOVED && providers.containsKey(path)) { nodeRemoved = true; actions.put(path, false); } else if ((eventType == Event.PROPERTY_CHANGED || eventType == Event.PROPERTY_ADDED || eventType == Event.PROPERTY_REMOVED) && isRelevantPath(path)) { // narrow down the properties to be watched. // force re-registering nodeAdded = true; nodeRemoved = true; } } for (Map.Entry<String, Boolean> action : actions.entrySet()) { if (action.getValue()) { final Resource rootResource = resolver.getResource(action.getKey()); if (rootResource != null) { registerDataRoot(rootResource); } } else { final ResourceProvider provider = providers.remove(action.getKey()); if (provider != null) { unregisterService(provider); } } } if (nodeAdded && nodeRemoved) { // maybe a virtual catalog was moved, re-register all virtual catalogs // (existing ones will be skipped) registerDataRoots(); } } catch (RepositoryException e) { log.error("Unexpected repository exception during event processing.", e); } }
Example 17
Source File: ItemResourceImpl.java From jackalope with Apache License 2.0 | 4 votes |
protected String getResourceTypeForNode(Node node) throws RepositoryException { return node.hasProperty(SLING_RESOURCE_TYPE_PROPERTY) ? node.getProperty(SLING_RESOURCE_TYPE_PROPERTY).getString() : node.getPrimaryNodeType().getName(); }
Example 18
Source File: FileArtifactHandler.java From jackrabbit-filevault with Apache License 2.0 | 4 votes |
private boolean importNtResource(ImportInfo info, Node content, Artifact artifact) throws RepositoryException, IOException { String path = content.getPath(); boolean modified = false; if (explodeXml && !content.isNodeType(JcrConstants.NT_RESOURCE)) { // explode xml InputStream in = artifact.getInputStream(); try { content.getSession().importXML(path, in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); // can't really augment info here } finally { in.close(); } modified = true; } else { ValueFactory factory = content.getSession().getValueFactory(); Value value = factory.createValue(artifact.getInputStream()); if (!content.hasProperty(JcrConstants.JCR_DATA) || !value.equals(content.getProperty(JcrConstants.JCR_DATA).getValue())) { content.setProperty(JcrConstants.JCR_DATA, value); modified = true; } // always update last modified if binary was modified (bug #22969) if (!content.hasProperty(JcrConstants.JCR_LASTMODIFIED) || modified) { Calendar lastMod = Calendar.getInstance(); content.setProperty(JcrConstants.JCR_LASTMODIFIED, lastMod); modified = true; } if (!content.hasProperty(JcrConstants.JCR_MIMETYPE)) { String mimeType = artifact.getContentType(); if (mimeType == null) { mimeType = Text.getName(artifact.getRelativePath(), '.'); mimeType = MimeTypes.getMimeType(mimeType, MimeTypes.APPLICATION_OCTET_STREAM); } content.setProperty(JcrConstants.JCR_MIMETYPE, mimeType); modified = true; } if (content.isNew()) { // mark binary data as modified info.onCreated(path + "/" + JcrConstants.JCR_DATA); info.onNop(path); } else if (modified) { // mark binary data as modified info.onModified(path + "/" + JcrConstants.JCR_DATA); info.onModified(path); } } return modified; }
Example 19
Source File: JcrMetadataRepository.java From archiva with Apache License 2.0 | 4 votes |
private ArtifactMetadata getArtifactFromNode(String repositoryId, Node artifactNode) throws RepositoryException { String id = artifactNode.getName(); ArtifactMetadata artifact = new ArtifactMetadata(); artifact.setId(id); artifact.setRepositoryId(repositoryId == null ? artifactNode.getAncestor(2).getName() : repositoryId); Node projectVersionNode = artifactNode.getParent(); Node projectNode = projectVersionNode.getParent(); Node namespaceNode = projectNode.getParent(); artifact.setNamespace(namespaceNode.getProperty("namespace").getString()); artifact.setProject(projectNode.getName()); artifact.setProjectVersion(projectVersionNode.getName()); artifact.setVersion(artifactNode.hasProperty("version") ? artifactNode.getProperty("version").getString() : projectVersionNode.getName()); if (artifactNode.hasProperty(JCR_LAST_MODIFIED)) { artifact.setFileLastModified(artifactNode.getProperty(JCR_LAST_MODIFIED).getDate().getTimeInMillis()); } if (artifactNode.hasProperty("whenGathered")) { Calendar cal = artifactNode.getProperty("whenGathered").getDate(); artifact.setWhenGathered(ZonedDateTime.ofInstant(cal.toInstant(), cal.getTimeZone().toZoneId())); } if (artifactNode.hasProperty("size")) { artifact.setSize(artifactNode.getProperty("size").getLong()); } Node cslistNode = getOrAddNodeByPath(artifactNode, "checksums"); NodeIterator csNodeIt = cslistNode.getNodes("*"); while (csNodeIt.hasNext()) { Node csNode = csNodeIt.nextNode(); if (csNode.isNodeType(CHECKSUM_NODE_TYPE)) { addChecksum(artifact, csNode); } } retrieveFacetProperties(artifact, artifactNode); return artifact; }
Example 20
Source File: JcrStorageDao.java From nextreports-server with Apache License 2.0 | 4 votes |
private Node addNodeWithUUID(Node parentNode, Entity entity, String UUID) { try { Node node; JcrNode jcrNode = ReflectionUtils.getJcrNodeAnnotation(entity.getClass()); // check if we should use a specific node type if (jcrNode == null || jcrNode.nodeType().equals("nt:unstructured")) { if (parentNode instanceof NodeImpl) { node = ((NodeImpl) parentNode).addNodeWithUuid(entity.getName(), UUID); } else { node = parentNode.addNode(entity.getName()); } } else { if (parentNode instanceof NodeImpl) { node = ((NodeImpl) parentNode).addNodeWithUuid(entity.getName(), jcrNode.nodeType(), UUID); } else { node = parentNode.addNode(entity.getName(), jcrNode.nodeType()); } } // add annotated mixin types if (jcrNode != null && jcrNode.mixinTypes() != null) { for (String mixinType : jcrNode.mixinTypes()) { if (node.canAddMixin(mixinType)) { node.addMixin(mixinType); } } } // update the object name and path setNodeName(entity, node.getName()); setNodePath(entity, node.getPath()); if (node.hasProperty("jcr:uuid")) { setUUID(entity, node.getIdentifier()); } // map the class name to a property if (jcrNode != null && !jcrNode.classNameProperty().equals("none")) { node.setProperty(jcrNode.classNameProperty(), entity.getClass().getCanonicalName()); } // do update to make internal jcrom business! getJcrom().updateNode(node, entity); return node; } catch (Exception e) { throw new JcrMappingException("Could not create node from object", e); } }