public static Name getPrimaryTypeName(PropertyState ps) throws RepositoryException { if (!NameConstants.JCR_PRIMARYTYPE.equals(ps.getName())) { throw new IllegalArgumentException(); } QValue[] values = ps.getValues(); return values[0].getName(); }
public static Name getPrimaryTypeName(PropertyState ps) throws RepositoryException { if (!NameConstants.JCR_PRIMARYTYPE.equals(ps.getName())) { throw new IllegalArgumentException(); } QValue[] values = ps.getValues(); return values[0].getName(); }
/** * * @param ps * @return * @throws IllegalArgumentException if the name of the PropertyState is NOT * {@link NameConstants#JCR_MIXINTYPES} */ public static Name[] getMixinNames(PropertyState ps) { if (!NameConstants.JCR_MIXINTYPES.equals(ps.getName())) { throw new IllegalArgumentException(); } if (ps.getStatus() == Status.REMOVED) { return Name.EMPTY_ARRAY; } else { QValue[] values = ps.getValues(); Name[] newMixins = new Name[values.length]; for (int i = 0; i < values.length; i++) { try { newMixins[i] = values[i].getName(); } catch (RepositoryException e) { // ignore: should never occur. } } return newMixins; } }
/** * * @param ps * @return * @throws IllegalArgumentException if the name of the PropertyState is NOT * {@link NameConstants#JCR_MIXINTYPES} */ public static Name[] getMixinNames(PropertyState ps) { if (!NameConstants.JCR_MIXINTYPES.equals(ps.getName())) { throw new IllegalArgumentException(); } if (ps.getStatus() == Status.REMOVED) { return Name.EMPTY_ARRAY; } else { QValue[] values = ps.getValues(); Name[] newMixins = new Name[values.length]; for (int i = 0; i < values.length; i++) { try { newMixins[i] = values[i].getName(); } catch (RepositoryException e) { // ignore: should never occur. } } return newMixins; } }
void setPropertyInfos(PropertyInfoImpl[] propInfos, IdFactory idFactory) throws RepositoryException { boolean resolveUUID = false; for (PropertyInfoImpl propInfo : propInfos) { Name pn = propInfo.getId().getName(); if (NameConstants.JCR_UUID.equals(pn)) { id = idFactory.createNodeId(propInfo.getValues()[0].getString()); resolveUUID = true; } else if (NameConstants.JCR_PRIMARYTYPE.equals(pn)) { primaryNodeTypeName = propInfo.getValues()[0].getName(); } else if (NameConstants.JCR_MIXINTYPES.equals(pn)) { QValue[] vs = propInfo.getValues(); Name[] mixins = new Name[vs.length]; for (int i = 0; i < vs.length; i++) { mixins[i] = vs[i].getName(); } mixinNodeTypeNames = mixins; } } propertyIds.clear(); for (PropertyInfoImpl propInfo : propInfos) { if (resolveUUID) { propInfo.setId(idFactory.createPropertyId(id, propInfo.getName())); } propertyIds.add(propInfo.getId()); } }
public void testAnyValueGetName() throws RepositoryException { try { factory.create(12345).getName(); fail("12345 is not a valid Name value -> QValue.getName() should fail."); } catch (ValueFormatException e) { // ok } }
public void testNameValueGetName() throws RepositoryException { QValue v = factory.create(testName); assertTrue(v.getName().equals(testName)); }
public void testNameValueGetName() throws RepositoryException { QValue v = factory.create(testName); assertTrue(v.getName().equals(testName)); }
void setPropertyInfos(PropertyInfoImpl[] propInfos, IdFactory idFactory) throws RepositoryException { boolean resolveUUID = false; for (PropertyInfoImpl propInfo : propInfos) { Name pn = propInfo.getId().getName(); if (NameConstants.JCR_UUID.equals(pn)) { id = idFactory.createNodeId(propInfo.getValues()[0].getString()); resolveUUID = true; } else if (NameConstants.JCR_PRIMARYTYPE.equals(pn)) { primaryNodeTypeName = propInfo.getValues()[0].getName(); } else if (NameConstants.JCR_MIXINTYPES.equals(pn)) { QValue[] vs = propInfo.getValues(); Name[] mixins = new Name[vs.length]; for (int i = 0; i < vs.length; i++) { mixins[i] = vs[i].getName(); } mixinNodeTypeNames = mixins; } } propertyIds.clear(); for (PropertyInfoImpl propInfo : propInfos) { if (resolveUUID) { propInfo.setId(idFactory.createPropertyId(id, propInfo.getName())); } propertyIds.add(propInfo.getId()); } }
public void testAnyValueGetName() throws RepositoryException { try { factory.create(12345).getName(); fail("12345 is not a valid Name value -> QValue.getName() should fail."); } catch (ValueFormatException e) { // ok } }
/** * @see org.apache.jackrabbit.spi.QValueConstraint#check(QValue) */ public void check(QValue value) throws ConstraintViolationException, RepositoryException { if (value == null) { throw new ConstraintViolationException("null value does not satisfy the constraint '" + getString() + "'"); } switch (value.getType()) { case PropertyType.NAME: Name n = value.getName(); if (!name.equals(n)) { throw new ConstraintViolationException(n + " does not satisfy the constraint '" + getString() + "'"); } return; default: String msg = "NAME constraint can not be applied to value of type: " + PropertyType.nameFromValue(value.getType()); log.debug(msg); throw new RepositoryException(msg); } }
/** * @see org.apache.jackrabbit.spi.QValueConstraint#check(QValue) */ public void check(QValue value) throws ConstraintViolationException, RepositoryException { if (value == null) { throw new ConstraintViolationException("null value does not satisfy the constraint '" + getString() + "'"); } switch (value.getType()) { case PropertyType.NAME: Name n = value.getName(); if (!name.equals(n)) { throw new ConstraintViolationException(n + " does not satisfy the constraint '" + getString() + "'"); } return; default: String msg = "NAME constraint can not be applied to value of type: " + PropertyType.nameFromValue(value.getType()); log.debug(msg); throw new RepositoryException(msg); } }
/** * {@inheritDoc} */ public InputStream getStream() throws IllegalStateException, RepositoryException { setStreamConsumed(); if (stream == null) { if (getType() == PropertyType.NAME || getType() == PropertyType.PATH) { // needs namespace mapping try { String l_s = getType() == PropertyType.NAME ? resolver.getJCRName(qvalue.getName()) : resolver.getJCRPath(qvalue.getPath()); stream = new ByteArrayInputStream(l_s.getBytes("UTF-8")); } catch (UnsupportedEncodingException ex) { throw new RepositoryException(ex); } } else { stream = qvalue.getStream(); } } return stream; }
/** * @see javax.jcr.Value#getString() */ public String getString() throws RepositoryException { if (getType() == PropertyType.NAME) { // qualified name value needs to be resolved return resolver.getJCRName(qvalue.getName()); } else if (getType() == PropertyType.PATH) { // qualified path value needs to be resolved return resolver.getJCRPath(qvalue.getPath()); } else { return qvalue.getString(); } }
/** * @see javax.jcr.Value#getString() */ public String getString() throws RepositoryException { if (getType() == PropertyType.NAME) { // qualified name value needs to be resolved return resolver.getJCRName(qvalue.getName()); } else if (getType() == PropertyType.PATH) { // qualified path value needs to be resolved return resolver.getJCRPath(qvalue.getPath()); } else { return qvalue.getString(); } }
/** * {@inheritDoc} */ public String getString() throws RepositoryException { setValueConsumed(); if (getType() == PropertyType.NAME) { // needs formatting return resolver.getJCRName(qvalue.getName()); } else if (getType() == PropertyType.PATH) { // needs formatting return resolver.getJCRPath(qvalue.getPath()); } else { return qvalue.getString(); } }
allNtNames = new Name[values.length + 1]; for (int i = 0; i < values.length; i++) { allNtNames[i] = values[i].getName();
/** * * @param paramName * @param value * @param resolver * @throws RepositoryException */ static void addPart(String paramName, QValue value, NamePathResolver resolver, List<FormBodyPart> parts, List<QValue> binaries) throws RepositoryException { FormBodyPartBuilder builder = FormBodyPartBuilder.create().setName(paramName); ContentType ctype = ContentType.create(JcrValueType.contentTypeFromType(value.getType()), DEFAULT_CHARSET); FormBodyPart part; switch (value.getType()) { case PropertyType.BINARY: binaries.add(value); // server detects binaries based on presence of filename parameters (JCR-4154) part = builder.setBody(new InputStreamBody(value.getStream(), ctype, paramName)).build(); break; case PropertyType.NAME: part = builder.setBody(new StringBody(resolver.getJCRName(value.getName()), ctype)).build(); break; case PropertyType.PATH: part = builder.setBody(new StringBody(resolver.getJCRPath(value.getPath()), ctype)).build(); break; default: part = builder.setBody(new StringBody(value.getString(), ctype)).build(); } parts.add(part); }
/** * * @param paramName * @param value * @param resolver * @throws RepositoryException */ static void addPart(String paramName, QValue value, NamePathResolver resolver, List<FormBodyPart> parts, List<QValue> binaries) throws RepositoryException { FormBodyPartBuilder builder = FormBodyPartBuilder.create().setName(paramName); ContentType ctype = ContentType.create(JcrValueType.contentTypeFromType(value.getType()), DEFAULT_CHARSET); FormBodyPart part; switch (value.getType()) { case PropertyType.BINARY: binaries.add(value); // server detects binaries based on presence of filename parameters (JCR-4154) part = builder.setBody(new InputStreamBody(value.getStream(), ctype, paramName)).build(); break; case PropertyType.NAME: part = builder.setBody(new StringBody(resolver.getJCRName(value.getName()), ctype)).build(); break; case PropertyType.PATH: part = builder.setBody(new StringBody(resolver.getJCRPath(value.getPath()), ctype)).build(); break; default: part = builder.setBody(new StringBody(value.getString(), ctype)).build(); } parts.add(part); }
public void testSetNameValue() throws RepositoryException { NodeId nid = getNodeId(testPath); Name propName = resolver.getQName("nameProp"); QValue[] vs = new QValue[] { rs.getQValueFactory().create(NameConstants.JCR_BASEVERSION), rs.getQValueFactory().create(NameConstants.JCR_DEFAULTPRIMARYTYPE), rs.getQValueFactory().create(NameConstants.MIX_LOCKABLE), rs.getQValueFactory().create(NameConstants.JCR_PRIMARYTYPE), rs.getQValueFactory().create(NameConstants.NT_VERSION) }; Batch b = rs.createBatch(si, nid); b.addProperty(nid, propName, vs); rs.submit(b); PropertyInfo pi = rs.getPropertyInfo(si, getPropertyId(nid, propName)); assertTrue(pi.isMultiValued()); assertEquals(Arrays.asList(vs), Arrays.asList(pi.getValues())); assertEquals(PropertyType.NAME, pi.getType()); pi = getPropertyInfo(nid, propName); assertEquals(vs[0].getName(), pi.getValues()[0].getName()); assertEquals(Arrays.asList(vs), Arrays.asList(pi.getValues())); assertEquals(PropertyType.NAME, pi.getType()); }