/** * Creates a new property definition based on <code>propDef</code>. * * @param propDef the JCR property definition. * @param resolver the name/path resolver of the session that provided * the property definition. * @param qValueFactory the QValue factory. * @throws RepositoryException if an error occurs while reading from * <code>propDef</code>. */ public QPropertyDefinitionImpl(PropertyDefinition propDef, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException { this(propDef.getName().equals(NameConstants.ANY_NAME.getLocalName()) ? NameConstants.ANY_NAME : resolver.getQName(propDef.getName()), resolver.getQName(propDef.getDeclaringNodeType().getName()), propDef.isAutoCreated(), propDef.isMandatory(), propDef.getOnParentVersion(), propDef.isProtected(), convertValues(propDef.getDefaultValues(), resolver, qValueFactory), propDef.isMultiple(), propDef.getRequiredType(), ValueConstraint.create(propDef.getRequiredType(), propDef.getValueConstraints(), resolver), propDef.getAvailableQueryOperators(), propDef.isFullTextSearchable(), propDef.isQueryOrderable()); }
private PropertyDefinitionImpl(PropertyDefinition definition) { super(definition); type = definition.getRequiredType(); valueConstraints = definition.getValueConstraints(); defaultValues = definition.getDefaultValues(); isMultiple = definition.isMultiple(); availableQueryOperators = definition.getAvailableQueryOperators(); isFullTextSearchable = definition.isFullTextSearchable(); isQueryOrderable = definition.isQueryOrderable(); }
public PropertyDefinitionInfo(PropertyDefinition propertyDefinition) { this.name = propertyDefinition.getName(); this.type = propertyDefinition.getRequiredType(); this.multiple = propertyDefinition.isMultiple(); }
private boolean canSetProperty(NodeType nodeType, String propertyName, int propertyType, boolean isMultiple) { PropertyDefinition propDefs[] = nodeType.getPropertyDefinitions(); for (int i = 0; i < propDefs.length; i++) { if (propDefs[i].getName().equals(propertyName) || propDefs[i].getName().equals("*")) { if ((propDefs[i].getRequiredType() == propertyType || propDefs[i].getRequiredType() == PropertyType.UNDEFINED) && propDefs[i].isMultiple() == isMultiple) { return true; } } } return false; }
public void testMixTitleOnFolder() throws Exception { Node n = testRootNode.addNode("folder", JcrConstants.NT_FOLDER); n.addMixin("mix:title"); superuser.save(); // create jcr:title property with type STRING (converted) => declaring NT is mix:title (and Property title = n.setProperty("jcr:title", 12345); assertEquals(PropertyType.STRING, title.getType()); PropertyDefinition def = title.getDefinition(); assertEquals("mix:title", def.getDeclaringNodeType().getName()); assertEquals(PropertyType.STRING, def.getRequiredType()); // set value to BINARY -> changes value but not definition (binary gets converted) title.setValue(superuser.getValueFactory().createValue("abc", PropertyType.BINARY)); assertEquals(PropertyType.STRING, title.getType()); assertEquals(PropertyType.STRING, title.getValue().getType()); def = title.getDefinition(); assertEquals("mix:title", def.getDeclaringNodeType().getName()); assertEquals(PropertyType.STRING, def.getRequiredType()); superuser.save(); }
/** * Copies nodes. * * @param node Node to copy * @param destinationParent Destination parent node * @throws RepositoryException if problem with jcr repository occurred */ public void copyNode(Node node, Node destinationParent) throws RepositoryException { LOG.debug("Copying node '{}' into '{}'", node.getPath(), destinationParent.getPath()); Node newNode = destinationParent.addNode(node.getName(), node.getPrimaryNodeType().getName()); PropertyIterator it = node.getProperties(); while (it.hasNext()) { Property property = it.nextProperty(); if (!property.getDefinition().isProtected()) { newNode .setProperty(property.getName(), property.getValue().getString(), property.getType()); } } NodeIterator nodeIterator = node.getNodes(); while (nodeIterator.hasNext()) { copyNode(nodeIterator.nextNode(), newNode); } }
public void testEmptyValues() throws Exception { superuser.importXML(targetPath, getImportStream(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); superuser.save(); Node n = superuser.getNode(targetPath).getNode(nodeName4); Property p = n.getNode(nodeName3).getProperty("test:multiProperty"); assertTrue(p.isMultiple()); assertTrue(p.getDefinition().isMultiple()); Assert.assertArrayEquals(new String[0], p.getValues()); } }
/** * Test adding mixin(s) to sessionA, while the other sessionB * doesn't have any mixins defined. The changes should be merged as there * is no conflict. * * @throws RepositoryException */ public void testMixinAddedInSessionA2() throws RepositoryException { assertFalse(testNode.hasProperty("jcr:mixinTypes")); testNode.addMixin("test:mixinProp_1"); testNodeB.setProperty("test:prop_double", sessionB.getValueFactory().createValue(false)); sessionB.save(); superuser.save(); assertTrue(testNode.isNodeType("test:mixinProp_1")); assertEquals(PropertyType.BOOLEAN, testNode.getProperty("test:prop_double").getType()); testNodeB.refresh(false); assertTrue(testNodeB.isNodeType("test:mixinProp_1")); assertEquals(PropertyType.BOOLEAN, testNodeB.getProperty("test:prop_double").getType()); assertEquals(testNode.getProperty("test:prop_double").getString(), testNodeB.getProperty("test:prop_double").getString()); assertEquals("nt:unstructured", testNode.getProperty("test:prop_double").getDefinition().getDeclaringNodeType().getName()); }
out.println(n.getPath()); PropertyIterator pit = n.getProperties(); while (pit.hasNext()) { try { Property p = pit.nextProperty(); out.print(p.getPath() + "="); if (p.getDefinition().isMultiple()) { Value[] values = p.getValues(); for (int i = 0; i < values.length; i++) { if (i > 0) { out.print(","); out.print(values[i].getString()); } else if (p.getType() == PropertyType.BINARY) { NodeIterator nit = n.getNodes(); while (nit.hasNext()) { Node cn = nit.nextNode(); dump(cn, level, out); } else { out.println(cn.getPath() + "[" + cn.getPrimaryNodeType().getName() + "]");
/** * Tests if removing a <code>InputStream</code> property with * <code>Node.setProperty(String, null)</code> works with * <code>parentNode.save()</code> */ public void testRemoveInputStreamPropertyParent() throws Exception { testNode.setProperty(propertyName1, is1); testRootNode.getSession().save(); Property property = testNode.getProperty(propertyName1); if (property.getDefinition().isMandatory() || property.getDefinition().isProtected()) { throw new NotExecutableException("property " + property.getName() + " can not be removed"); } testNode.setProperty(propertyName1, (InputStream) null); testRootNode.getSession().save(); assertFalse("Removing property with Node.setProperty(String, (InputStream)null) and parentNode.save() not working", testNode.hasProperty(propertyName1)); }
private static void setProperty(final Node node, final PropertyDefinition propertyDefinition, final Node prototypeNode) throws RepositoryException, ValueFormatException, VersionException, LockException, ConstraintViolationException { final String propertyName = propertyDefinition.getName(); final Logger log = LoggerFactory.getLogger(EditorUtils.class); } else { try { if (propertyDefinition.isMultiple()) { Value[] propValues = prototypeNode.getProperty(propertyName).getValues(); if (node.hasProperty(propertyName)){ node.getProperty(propertyName).remove(); node.setProperty(propertyName, propValues); } else { Value propValue = prototypeNode.getProperty(propertyName).getValue(); if (node.hasProperty(propertyName)){ node.getProperty(propertyName).remove(); node.setProperty(propertyName, propValue); log.debug("Set '{}' to the property '{}' at the node '{}'", propValue.getString(), propertyName, node.getPath());
public void testIndexedPropertyDefinition() throws Exception { String ntPath = NodeTypeConstants.NODE_TYPES_PATH + '/' + NodeTypeConstants.NT_VERSION; assertTrue(superuser.nodeExists(ntPath + "/jcr:propertyDefinition")); assertTrue(superuser.nodeExists(ntPath + "/jcr:propertyDefinition[1]")); Node pdNode = superuser.getNode(ntPath + "/jcr:propertyDefinition[1]"); assertEquals(ntPath + "/jcr:propertyDefinition", pdNode.getPath()); List<String> defNames = new ArrayList(); NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(NodeTypeConstants.NT_VERSION); for (PropertyDefinition nd : nt.getDeclaredPropertyDefinitions()) { defNames.add(nd.getName()); } Node ntNode = superuser.getNode(ntPath); NodeIterator it = ntNode.getNodes("jcr:propertyDefinition*"); while (it.hasNext()) { Node def = it.nextNode(); int index = getIndex(def); String name = (def.hasProperty(NodeTypeConstants.JCR_NAME)) ? def.getProperty(NodeTypeConstants.JCR_NAME).getString() : NodeTypeConstants.RESIDUAL_NAME; assertEquals(name, defNames.get(index-1)); } }
@FixFor( "MODE-793" ) public void testPropertyCardinalityShouldPropagateToFrozenNode() throws Exception { session = getHelper().getReadWriteSession(); VersionManager versionManager = session.getWorkspace().getVersionManager(); Node root = getTestRoot(session); Node parentNode = root.addNode("checkedOutNodeNopTest"); parentNode.addMixin("mix:versionable"); parentNode.setProperty("foo", new String[] {"bar", "baz"}); session.save(); assertEquals(true, parentNode.getProperty("foo").getDefinition().isMultiple()); Version version = versionManager.checkin(parentNode.getPath()); Node frozenNode = version.getFrozenNode(); assertEquals(true, frozenNode.getProperty("foo").getDefinition().isMultiple()); }
message(node.getPath()); if (node.getName().equals("jcr:system")) { return; if (node.getName().equals("jcr:content")) { return; while (properties.hasNext()) { final Property property = properties.nextProperty(); if (property.getDefinition().isMultiple()) { final Value[] values = property.getValues(); for (final Value value : values) { message(property.getPath() + " = " + value.getString());
/** * {@inheritDoc} */ public Dependency[] getDependencies() { try { if (defNode.hasProperty(PN_DEPENDENCIES)) { Property p = defNode.getProperty(PN_DEPENDENCIES); List<Dependency> deps = new LinkedList<>(); if (p.getDefinition().isMultiple()) { for (Value v: p.getValues()) { Dependency dep = Dependency.fromString(v.getString()); if (dep != null) { deps.add(dep); } } } else { Dependency dep = Dependency.fromString(p.getString()); if (dep != null) { deps.add(dep); } } return deps.toArray(new Dependency[deps.size()]); } } catch (RepositoryException e) { log.error("Error during getDependencies()", e); } return Dependency.EMPTY; }
Property prop; try { String nodeType = propDef.getDeclaringNodeType().getName(); node = testRootNode.addNode(nodeName2, nodeType); prop = node.setProperty(propDef.getName(), new Value[]{valueSatisfied}); testRootNode.getSession().save(); } catch (ConstraintViolationException e) { prop.setValue(new Value[]{valueNotSatisfied}); node.save(); fail("setValue(Value[] values) must throw a ConstraintViolationException " +
private void clear(final Node node) throws RepositoryException { for (Property property : new PropertyIterable(node.getProperties())) { if (!property.getDefinition().isProtected()) { property.remove(); } } for (Node child : new NodeIterable(node.getNodes())) { if (!child.getDefinition().isProtected()) { child.remove(); } } for (NodeType nodeType : node.getMixinNodeTypes()) { if (!nodeType.isNodeType(JcrConstants.MIX_VERSIONABLE)) { node.removeMixin(nodeType.getName()); } } }
/** * Returns the XML characters for the given node. The node must be an XML text node, as defined in * {@link #isXmlTextNode(Node)}. * * @param node the node for which XML characters will be retrieved. * @return the xml characters for this node * @throws RepositoryException if there is an error accessing this node */ private String getXmlCharacters( Node node ) throws RepositoryException { // ./xmltext/xmlcharacters exception (see JSR-170 Spec 6.4.2.3) assert isXmlTextNode(node); Property xmlCharacters = node.getProperty(getPrefixedName(JcrLexicon.XMLCHARACTERS)); assert xmlCharacters != null; if (xmlCharacters.getDefinition().isMultiple()) { StringBuilder bf = new StringBuilder(); for (Value value : xmlCharacters.getValues()) { bf.append(value.getString()); } return bf.toString(); } return xmlCharacters.getValue().getString(); }
public void testStringRequiredTypeBoolean() throws Exception { Value stringValue = superuser.getValueFactory().createValue("true", PropertyType.STRING); Property p = node.setProperty(BOOLEAN_PROP_NAME, stringValue); assertEquals(PropertyType.BOOLEAN, p.getType()); assertEquals(PropertyType.BOOLEAN, p.getValue().getType()); assertTrue(p.getBoolean()); PropertyDefinition def = p.getDefinition(); assertEquals(PropertyType.BOOLEAN, def.getRequiredType()); assertEquals(NT_NAME, def.getDeclaringNodeType().getName()); }
@Override protected Item createRemoveItem() throws NotExecutableException, RepositoryException, LockException, ConstraintViolationException, ItemExistsException, NoSuchNodeTypeException, VersionException { Property removeProperty; if (testRootNode.hasProperty(propertyName1)) { removeProperty = testRootNode.getProperty(propertyName1); if (removeProperty.getDefinition().isProtected() || removeProperty.getDefinition().isMandatory()) { throw new NotExecutableException("Property to be remove must be mandatory nor protected '" + propertyName1 + "'."); } } else { removeProperty = testRootNode.setProperty(propertyName1, "anyString"); } // make sure the new node is persisted. testRootNode.save(); return removeProperty; }