本文整理汇总了Java中javax.jcr.Property.isMultiple方法的典型用法代码示例。如果您正苦于以下问题:Java Property.isMultiple方法的具体用法?Java Property.isMultiple怎么用?Java Property.isMultiple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jcr.Property
的用法示例。
在下文中一共展示了Property.isMultiple方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSinglePropertyAs
import javax.jcr.Property; //导入方法依赖的package包/类
/**
* Takes type, resource, and propertyName and returns its value of the object based on the given type
*
* @param type This is type parameter
* @param resource The resource to fetch the value from
* @param propertyName The property name to be used to fetch the value from the resource
* @return value The value of the object based on the given type
*/
private static <T> T getSinglePropertyAs(Class<T> type, Resource resource, String propertyName) {
T val = null;
try {
if (null != resource) {
Node node = resource.adaptTo(Node.class);
if (null != node) {
if (node.hasProperty(propertyName)) {
Property property = node.getProperty(propertyName);
if (!property.isMultiple()) {
Value value = property.getValue();
val = PropertyUtils.as(type, value);
}
}
}
}
} catch (Exception e) {
LOG.error(ERROR, e);
}
return val;
}
示例2: getMultiplePropertyAs
import javax.jcr.Property; //导入方法依赖的package包/类
/**
* Takes type, resource, and property name and returns the list of value of the object based on the given type
*
* @param type This is type parameter
* @param resource The resource to fetch the value from
* @param propertyName The property name to be used to fetch the value from the resource
* @return valueList The list of values of the object based on the given type
*/
private static <T> List<T> getMultiplePropertyAs(Class<T> type, Resource resource, String propertyName) {
List<T> val = Collections.EMPTY_LIST;
try {
if (null != resource) {
Node node = resource.adaptTo(Node.class);
if (null != node) {
if (node.hasProperty(propertyName)) {
Property property = node.getProperty(propertyName);
if (property.isMultiple()) {
Value[] value = property.getValues();
val = PropertyUtils.as(type, value);
}
}
}
}
} catch (Exception e) {
LOG.error(ERROR, e);
}
return val;
}
示例3: getPropertyValues
import javax.jcr.Property; //导入方法依赖的package包/类
private Value[] getPropertyValues(Node node, String propertyName) throws RepositoryException {
if (node.hasProperty(propertyName)) {
Property prop = node.getProperty(propertyName);
Value[] values;
// This check is necessary to ensure a multi-valued field is applied...
if (prop.isMultiple()) {
values = prop.getValues();
} else {
values = new Value[1];
values[0] = prop.getValue();
}
return values;
}
return new Value[0];
}
示例4: getPropertyRepresentation
import javax.jcr.Property; //导入方法依赖的package包/类
/**
* Get a presentation of a JCR property.
* @param property the property
* @return a {@link org.onehippo.forge.webservices.jaxrs.jcr.model.JcrProperty}
* @throws RepositoryException
*/
public static JcrProperty getPropertyRepresentation(Property property) throws RepositoryException {
JcrProperty data = new JcrProperty();
data.setName(property.getName());
data.setType(PropertyType.nameFromValue(property.getType()));
data.setMultiple(property.isMultiple());
List<String> values = new ArrayList<String>();
if (property.isMultiple()) {
for (Value propertyValue : property.getValues()) {
values.add(getPropertyValueAsString(propertyValue));
}
} else {
values.add(getPropertyValueAsString(property.getValue()));
}
data.setValues(values);
return data;
}
示例5: getNodePropertySize
import javax.jcr.Property; //导入方法依赖的package包/类
/**
* Get the total size of a Node's properties
*
* @param node the node
* @return size in bytes
* @throws RepositoryException if repository exception occurred
*/
public static Long getNodePropertySize(final Node node)
throws RepositoryException {
Long size = 0L;
for (final PropertyIterator i = node.getProperties(); i.hasNext();) {
final Property p = i.nextProperty();
if (p.isMultiple()) {
for (final Value v : p.getValues()) {
size += v.getBinary().getSize();
}
} else {
size += p.getBinary().getSize();
}
}
return size;
}
示例6: computeNext
import javax.jcr.Property; //导入方法依赖的package包/类
@Override
protected Value computeNext() {
try {
if (currentValues != null && currentValues.hasNext()) {
return currentValues.next();
}
if (properties.hasNext()) {
final Property property = properties.next();
if (property.isMultiple()) {
currentValues = Iterators.forArray(property.getValues());
if (currentValues.hasNext()) {
return currentValues.next();
}
return endOfData();
}
currentValues = null;
return property.getValue();
}
return endOfData();
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}
示例7: setProperty
import javax.jcr.Property; //导入方法依赖的package包/类
/**
* Sets the Value for the given name. If a value existed, it is replaced,
* if not it is created.
*
* @param relPath The relative path to the property or the property name.
* @param value The property value.
* @throws RepositoryException If the specified name defines a property
* that needs to be modified by this user API or setting the corresponding
* JCR property fails.
* @see Authorizable#setProperty(String, Value)
*/
public synchronized void setProperty(String relPath, Value value) throws RepositoryException {
String name = Text.getName(relPath);
String intermediate = (relPath.equals(name)) ? null : Text.getRelativeParent(relPath, 1);
checkProtectedProperty(name);
try {
Node n = getOrCreateTargetNode(intermediate);
// check if the property has already been created as multi valued
// property before -> in this case remove in order to avoid
// ValueFormatException.
if (n.hasProperty(name)) {
Property p = n.getProperty(name);
if (p.isMultiple()) {
p.remove();
}
}
n.setProperty(name, value);
if (entityManager.isAutoSave()) {
node.save();
}
} catch (RepositoryException e) {
log.debug("Failed to set Property " + name + " for " + this, e);
node.refresh(false);
throw e;
}
}
示例8: InertProperty
import javax.jcr.Property; //导入方法依赖的package包/类
private InertProperty(Property property)
throws RepositoryException {
type = property.getType();
name = property.getName();
values = (property.isMultiple()) ? Arrays.asList(property.getValues()) : Lists.newArrayList(property.getValue());
nodePath = property.getParent().getPath();
}
示例9: getPropertyValues
import javax.jcr.Property; //导入方法依赖的package包/类
/**
* Internal method to get all values for a multi-value property.
*
* @param resource The resource from which to get the property.
* @param namePattern Property name.
* @return Property values.
*/
private static Value[] getPropertyValues(Resource resource, String namePattern) throws RepositoryException {
Property prop = getProperty(resource, namePattern);
if (prop != null) {
if (prop.isMultiple()) {
return prop.getValues();
} else {
return (new Value[]{prop.getValue()});
}
}
return new Value[0];
}
示例10: propertyToJavaObject
import javax.jcr.Property; //导入方法依赖的package包/类
@SuppressWarnings("squid:S3776")
private static Object propertyToJavaObject(Property property)
throws RepositoryException {
// multi-value property: return an array of values
if (property.isMultiple()) {
Value[] values = property.getValues();
final Object firstValue = values.length > 0 ? valueToJavaObject(values[0]) : null;
final Object[] result;
if ( firstValue instanceof Boolean ) {
result = new Boolean[values.length];
} else if ( firstValue instanceof Calendar ) {
result = new Calendar[values.length];
} else if ( firstValue instanceof Double ) {
result = new Double[values.length];
} else if ( firstValue instanceof Long ) {
result = new Long[values.length];
} else if ( firstValue instanceof BigDecimal) {
result = new BigDecimal[values.length];
} else if ( firstValue instanceof InputStream) {
result = new Object[values.length];
} else {
result = new String[values.length];
}
for (int i = 0; i < values.length; i++) {
Value value = values[i];
if (value != null) {
result[i] = valueToJavaObject(value);
}
}
return result;
}
// single value property
return valueToJavaObject(property.getValue());
}
示例11: getPropertyValues
import javax.jcr.Property; //导入方法依赖的package包/类
/**
* Normalizes a property values to a list; allows single and multi-values to be treated the same in code.
* @param property the propert to get the value(s) from
* @return a list of the property's value(s)
* @throws RepositoryException
*/
private List<Value> getPropertyValues(final Property property) throws RepositoryException {
final List<Value> values = new ArrayList<>();
if (property.isMultiple()) {
values.addAll(Arrays.asList(property.getValues()));
} else {
values.add(property.getValue());
}
return values;
}
示例12: toJavaObject
import javax.jcr.Property; //导入方法依赖的package包/类
/**
* Converts the value(s) of a JCR Property to a corresponding Java Object.
* If the property has multiple values the result is an array of Java
* Objects representing the converted values of the property.
*/
public static Object toJavaObject(Property property)
throws RepositoryException {
// multi-value property: return an array of values
if (property.isMultiple()) {
Value[] values = property.getValues();
final Object firstValue = values.length > 0 ? toJavaObject(values[0]) : null;
final Object[] result;
if ( firstValue instanceof Boolean ) {
result = new Boolean[values.length];
} else if ( firstValue instanceof Calendar ) {
result = new Calendar[values.length];
} else if ( firstValue instanceof Double ) {
result = new Double[values.length];
} else if ( firstValue instanceof Long ) {
result = new Long[values.length];
} else if ( firstValue instanceof BigDecimal) {
result = new BigDecimal[values.length];
} else if ( firstValue instanceof InputStream) {
result = new Object[values.length];
} else {
result = new String[values.length];
}
for (int i = 0; i < values.length; i++) {
Value value = values[i];
if (value != null) {
result[i] = toJavaObject(value);
}
}
return result;
}
// single value property
return toJavaObject(property.getValue());
}
示例13: getProperty
import javax.jcr.Property; //导入方法依赖的package包/类
/**
* @see #hasProperty(String)
* @see Entity#getProperty(String)
*/
public Value[] getProperty(String relPath) throws RepositoryException {
if (node.hasProperty(relPath)) {
Property prop = node.getProperty(relPath);
if (isEntityProperty(prop, true)) {
if (prop.isMultiple()) {
return prop.getValues();
} else {
return new Value[]{prop.getValue()};
}
}
}
return null;
}
示例14: distill
import javax.jcr.Property; //导入方法依赖的package包/类
/**
* Extract property based on their type and return as object (of Property)
*
* @param property This is a property
* @return content This is node property object
* @throws Exception
*/
public static Object distill(Property property)
throws Exception {
Object content;
boolean isMulti = property.isMultiple();
switch (property.getType()) {
case PropertyType.LONG:
if (isMulti)
content = asLongs(property);
else
content = property.getLong();
break;
case PropertyType.DECIMAL:
case PropertyType.DOUBLE:
if (isMulti)
content = asDoubles(property);
else
content = property.getDouble();
break;
case PropertyType.BOOLEAN:
if (isMulti)
content = asBooleans(property);
else
content = property.getBoolean();
break;
case PropertyType.DATE:
if (isMulti)
content = asDates(property);
else
content = property.getValue().getString();
break;
case PropertyType.NAME:
case PropertyType.STRING:
case PropertyType.PATH:
case PropertyType.URI:
default:
if (isMulti)
content = asStrings(property);
else
content = property.getString();
break;
}
return content;
}
示例15: setProperty
import javax.jcr.Property; //导入方法依赖的package包/类
void setProperty( final Session session,
final Node node,
final String name,
final Object... values ) throws Exception {
final ValueFactory factory = session.getValueFactory();
try {
final boolean exists = node.hasProperty( name );
// remove property
if ( values == null ) {
if ( exists ) {
node.getProperty( name ).remove();
} else {
throw new ModelspaceException( ModelspaceI18n.localize( UNABLE_TO_REMOVE_PROPERTY_THAT_DOES_NOT_EXIST,
name,
node.getName() ) );
}
} else {
// must be an array at this point
final int count = values.length;
if ( exists ) {
final Property property = node.getProperty( name );
final int type = property.getType();
final boolean multiple = property.isMultiple();
if ( count == 0 ) {
if ( multiple ) {
property.remove();
} else {
throw new ModelspaceException( ModelspaceI18n.localize( UNABLE_TO_REMOVE_SINGLE_VALUE_PROPERTY_WITH_EMPTY_ARRAY,
name,
node.getName() ) );
}
} else if ( count > 1 ) {
if ( multiple ) {
setMultiValuedProperty( session, node, factory, name, values, type );
} else {
throw new ModelspaceException( ModelspaceI18n.localize( UNABLE_TO_SET_SINGLE_VALUE_PROPERTY_WITH_MULTIPLE_VALUES,
name,
node.getName() ) );
}
} else {
// only one value so set property
if ( multiple ) {
setMultiValuedProperty( session, node, factory, name, values, type );
} else {
node.setProperty( name, ModelProperty.Util.createValue( factory, values[ 0 ] ) );
}
}
} else {
// property does not exist and no values being set
if ( count == 0 ) {
throw new ModelspaceException( ModelspaceI18n.localize( UNABLE_TO_REMOVE_PROPERTY_THAT_DOES_NOT_EXIST,
name,
node.getName() ) );
}
if ( count > 1 ) {
setMultiValuedProperty( session, node, factory, name, values, PropertyType.UNDEFINED );
} else {
node.setProperty( name, ModelProperty.Util.createValue( factory, values[ 0 ] ) );
}
}
}
} catch ( final ConstraintViolationException | PathNotFoundException | ValueFormatException e ) {
throw new IllegalArgumentException( e );
}
}