javax.jcr.Property.isMultiple()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(97)

本文整理了Java中javax.jcr.Property.isMultiple()方法的一些代码示例,展示了Property.isMultiple()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Property.isMultiple()方法的具体详情如下:
包路径:javax.jcr.Property
类名称:Property
方法名:isMultiple

Property.isMultiple介绍

[英]Returns true if this property is multi-valued and false if this property is single-valued.
[中]如果此属性是多值的,则返回true,如果此属性是单值的,则返回false

代码示例

代码示例来源:origin: info.magnolia/magnolia-templating

@Override
@SneakyThrows(RepositoryException.class)
public boolean hasChildren() {
  return getValue().isMultiple();
}

代码示例来源:origin: org.onehippo.cms7/hippo-cms-translation-repository

private List<String> getValues() throws RepositoryException {
  if (property.isMultiple()) {
    final List<String> values = new ArrayList<>();
    for (Value value : property.getValues()) {
      values.add(value.getString());
    }
    return values;
  }
  else {
    return Arrays.asList(property.getString());
  }
}

代码示例来源:origin: org.onehippo.cms7/hippo-addon-channel-manager-content-service

private void storeProperty(final Collection<FieldValue> values, final Property property) throws RepositoryException {
  if (property.isMultiple()) {
    for (final Value v : property.getValues()) {
      values.add(getFieldValue(v.getString()));
    }
  } else {
    values.add(getFieldValue(property.getString()));
  }
}

代码示例来源:origin: info.magnolia/magnolia-templating

@Override
@SneakyThrows(RepositoryException.class)
public String getValueAsString() {
  if (getValue().isMultiple()) {
    return getName();
  } else {
    return getValue().getString();
  }
}

代码示例来源:origin: org.onehippo.cms7/hippo-repository-connector

private Object getValue(final Property property) {
  try {
    if (property.isMultiple()) {
      return getMultipleValues(property);
    } else {
      return getSingleValue(property);
    }
  } catch (RepositoryException ignore) {}
  return null;
}

代码示例来源:origin: info.magnolia/magnolia-templating

@Override
@SneakyThrows(RepositoryException.class)
public String getDescription() {
  return getValue().isMultiple() ? String.valueOf(getValue().getValues().length) : getName();
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jcr-commons

private Value[] getPropertyValues(PropertyValue operand, Node node)
    throws RepositoryException {
  Property property = getProperty(operand, node);
  if (property == null) {
    return new Value[0];
  } else if (property.isMultiple()) {
    return property.getValues();
  } else {
    return new Value[] { property.getValue() };
  }
}

代码示例来源:origin: info.magnolia/magnolia-core

public static void moveProperty(Property source, Node targetNode) throws RepositoryException {
  // JCR props can't be moved, we gotta recreate w/ same value and delete
  if (source.isMultiple()) {
    targetNode.setProperty(source.getName(), source.getValues());
  } else {
    targetNode.setProperty(source.getName(), source.getValue());
  }
  source.remove();
}

代码示例来源:origin: org.onehippo.cms7/hippo-repository-api

public Object getValue(Property property) throws RepositoryException {
  if (property.isMultiple()) {
    return multiValueGetter.getValue(property.getValues());
  } else {
    return singleValueGetter.getValue(property.getValue());
  }
}

代码示例来源:origin: org.onehippo.cms7/hippo-repository-modules

private void forStringCodecProperties(final Node node, final PropertyVisitor visitor) throws RepositoryException {
  final PropertyIterator properties = node.getProperties();
  while (properties.hasNext()) {
    final Property property = properties.nextProperty();
    if (!property.isMultiple()
        && property.getType() == PropertyType.STRING
        && !property.getName().contains(":")) {
      visitor.visit(property);
    }
  }
}

代码示例来源:origin: ModeShape/modeshape

protected void verifyProperty( Node node,
                String propertyName,
                String expectedValue ) throws RepositoryException {
  Property property = node.getProperty(propertyName);
  Value value = property.isMultiple() ? property.getValues()[0] : property.getValue();
  assertEquals(expectedValue, value.getString());
}

代码示例来源:origin: info.magnolia/magnolia-core

@Override
protected boolean matchesSafely(Property item) {
  try {
    final V valueObject = (V) (item.isMultiple() ? Arrays.stream(item.getValues()).map(value -> PropertyUtil.getValueObject(value)).toArray() : PropertyUtil.getValueObject(item.getValue()));
    return propertyValueMatcher.matches(valueObject);
  } catch (RepositoryException e) {
    throw new RuntimeRepositoryException(e);
  }
}

代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility

@Test
public void setMultiValueProperty() throws Exception {
  // GIVEN
  String[] values = { "Art", "Dan", "Jen" };
  JcrNodeAdapter adapter = new JcrNodeAdapter(node);
  Property<HashSet> property = new ObjectProperty<>(new HashSet<>(Arrays.asList(values)));
  adapter.addItemProperty("multiple", property);
  // WHEN
  Node res = adapter.applyChanges();
  // THEN
  assertTrue(res.getProperty("multiple").isMultiple());
}

代码示例来源:origin: ModeShape/modeshape

private RestProperty createRestProperty( Session session,
                     Property property,
                     String baseUrl ) throws RepositoryException {
  List<String> values = restPropertyValues(property, baseUrl, session);
  String url = RestHelper.urlFrom(baseUrl, ITEMS_METHOD_NAME, encodedPath(property.getPath()));
  String parentUrl = RestHelper.urlFrom(baseUrl, ITEMS_METHOD_NAME, encodedPath(property.getParent().getPath()));
  boolean multiValued = property.isMultiple();
  return new RestProperty(property.getName(), url, parentUrl, values, multiValued);
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test
public void testIsMultiple() throws RepositoryException {
  Property property = new MockProperty("test", "test", null);
  assertTrue(!property.isMultiple());
}

代码示例来源:origin: apache/jackrabbit-oak

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());
  }
}

代码示例来源:origin: apache/jackrabbit-oak

public void testSingleValues() throws Exception {
  superuser.importXML(targetPath, getImportStream(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
  superuser.save();
  Node n = superuser.getNode(targetPath).getNode(nodeName4);
  Property p = n.getNode(nodeName1).getProperty("test:multiProperty");
  assertTrue(p.isMultiple());
  assertTrue(p.getDefinition().isMultiple());
  Assert.assertArrayEquals(new Value[]{vf.createValue("v1")}, p.getValues());
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test
public void testGetMultiValuedWithSingleValue() throws Exception {
  // GIVEN
  final String firstString = "one";
  final MockValue first = new MockValue(firstString);
  // WHEN
  final Property property = new MockProperty("test", new Value[]{first}, null);
  // THEN
  assertTrue(property.isMultiple());
  assertEquals(firstString, property.getValues()[0].getString());
}

代码示例来源:origin: apache/jackrabbit-oak

public void testMultiValues() throws Exception {
  superuser.importXML(targetPath, getImportStream(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
  superuser.save();
  Node n = superuser.getNode(targetPath).getNode(nodeName4);
  Property p = n.getNode(nodeName2).getProperty("test:multiProperty");
  assertTrue(p.isMultiple());
  assertTrue(p.getDefinition().isMultiple());
  Value[] expected = new Value[] {vf.createValue("v1"), vf.createValue("v2")};
  Assert.assertArrayEquals(expected, p.getValues());
}

代码示例来源:origin: apache/jackrabbit

private static void checkLength(Property p) throws RepositoryException {
  if (p.isMultiple()) {
    Value[] vals = p.getValues();
    long[] lengths = p.getLengths();
    for (int i = 0; i < lengths.length; i++) {
      assertTrue("Wrong property length", lengths[i] == getValueLength(vals[i]));
    }
  } else {
    assertTrue("Wrong property length", p.getLength() == getValueLength(p.getValue()));
  }
}

相关文章