本文整理汇总了Java中javax.jcr.Value类的典型用法代码示例。如果您正苦于以下问题:Java Value类的具体用法?Java Value怎么用?Java Value使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Value类属于javax.jcr包,在下文中一共展示了Value类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSinglePropertyAs
import javax.jcr.Value; //导入依赖的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.Value; //导入依赖的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: as
import javax.jcr.Value; //导入依赖的package包/类
/**
* Takes a generic type and a Value and turns the Value into the Object of that given type.
*
* @param type This is a type parameter
* @param value This is the value
* @return castedValue This is the value of the given type
* @throws Exception
*/
public static <T> T as(Class<T> type, Value value)
throws Exception {
if (type == Long.class)
return (T) new Long(value.getLong());
if (type == Double.class)
return (T) new Double(value.getDouble());
if (type == Boolean.class)
return (T) new Boolean(value.getBoolean());
if (type == String.class)
return (T) value.getString();
if (type == Date.class)
return (T) value.getString();
if (type == Calendar.class)
return (T) value.getDate();
return null;
}
示例4: reportsNoValidationViolations_forPopulatedField
import javax.jcr.Value; //导入依赖的package包/类
@Test
public void reportsNoValidationViolations_forPopulatedField() throws Exception {
// given
final Value valueObject = mock(Value.class);
given(valueObject.getString()).willReturn("a non blank value");
given(fieldModel.getValue()).willReturn(valueObject);
// when
final Set<Violation> actualValidationViolations =
blankStaticDropdownSelectionFieldValidator.validate(fieldValidator, documentNodeModel, fieldModel);
// then
then(valueObject).should().getString();
assertThat("No violation has been reported.", actualValidationViolations, is(empty()));
}
开发者ID:NHS-digital-website,项目名称:hippo,代码行数:17,代码来源:BlankStaticDropdownSelectionFieldValidatorTest.java
示例5: fromValue
import javax.jcr.Value; //导入依赖的package包/类
public static Value[] fromValue(Object... values) throws RepositoryException {
if (values.length > 0) {
Value[] result = new Value[values.length];
for (int idx = 0, valuesLength = values.length; idx < valuesLength; idx++) {
Object value = values[idx];
if (value instanceof String) {
result[idx] = new MockValue((String) value);
} else if (value instanceof Boolean) {
result[idx] = new MockValue((boolean) value);
} else if (value instanceof Calendar) {
result[idx] = new MockValue((Calendar) value);
} else if (value instanceof Double) {
result[idx] = new MockValue((double) value);
} else if (value instanceof InputStream) {
result[idx] = new MockValue((InputStream) value);
} else if (value instanceof Long) {
result[idx] = new MockValue((long) value);
}
}
return result;
}
throw new RepositoryException();
}
示例6: setPropertyStringValueArrayWithStringValues
import javax.jcr.Value; //导入依赖的package包/类
@Test
public void setPropertyStringValueArrayWithStringValues() throws Exception {
Node testObj = aNode();
Property expected = testObj.setProperty("zip", new Value[] { new StringValue("zap"), new StringValue("zup") });
assertArrayEquals(expected.getValues(), testObj.getProperty("zip").getValues());
assertEquals(expected, testObj.getProperty("zip"));
}
示例7: getPropertyValues
import javax.jcr.Value; //导入依赖的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];
}
示例8: setUp
import javax.jcr.Value; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
super.setUp();
Session session = openSession();
Node node = session.getRootNode().addNode("home").addNode("test");
node.setProperty("content.approved", APPROVED);
node.setProperty("my.contents.property", CONTENT);
ValueFactory valFact = session.getValueFactory();
Value[] vals = new Value[] {valFact.createValue("value-1"), valFact.createValue("value-2")};
node.setProperty("my.multi.valued", vals);
identifier = node.getIdentifier();
session.save();
session.logout();
}
示例9: process
import javax.jcr.Value; //导入依赖的package包/类
private ActionResult process(final Context context, boolean simulate) {
ActionResult actionResult = new ActionResult();
try {
Authorizable authorizable = context.getCurrentAuthorizable();
actionResult.setAuthorizable(authorizable.getID());
LOGGER.info(String.format("Setting property %s for authorizable with id = %s", nameProperty,
authorizable.getID()));
final Value value = context.getValueFactory().createValue(valueProperty);
if (!simulate) {
authorizable.setProperty(nameProperty, value);
}
actionResult.logMessage(
"Property " + nameProperty + " for " + authorizable.getID() + " added vith value: "
+ valueProperty);
} catch (RepositoryException | ActionExecutionException e) {
actionResult.logError(MessagingUtils.createMessage(e));
}
return actionResult;
}
示例10: getItems
import javax.jcr.Value; //导入依赖的package包/类
private List<ContentMap> getItems(Node item, String nodeType, String workspace) {
final List<ContentMap> items = new ArrayList<ContentMap>(0);
try {
if (item != null) {
final Value[] values = item.getProperty(nodeType).getValues();
if (values != null) {
for (Value value : values) {
items.add(templatingFunctions.contentById(value.getString(), workspace));
}
}
}
} catch (RepositoryException e) {
LOGGER.error("Exception while getting items", e);
}
return items;
}
示例11: readJcrContent
import javax.jcr.Value; //导入依赖的package包/类
String readJcrContent(Session session) throws RepositoryException {
// get node directly
Node day1 = session.getNode("/content/adaptto/2013/day1");
// get first child node
Node firstTalk = day1.getNodes().nextNode();
// read property values
String title = firstTalk.getProperty("jcr:title").getString();
long duration = firstTalk.getProperty("durationMin").getLong();
// read multi-valued property
Value[] tagValues = firstTalk.getProperty("tags").getValues();
String[] tags = new String[tagValues.length];
for (int i=0; i<tagValues.length; i++) {
tags[i] = tagValues[i].getString();
}
return "First talk: " + title + " (" + duration + " min)\n"
+ "Tags: " + Arrays.toString(tags) + "\n"
+ "Path: " + firstTalk.getPath();
}
示例12: getBlogCategories
import javax.jcr.Value; //导入依赖的package包/类
/**
* Get categories for given blog node
*
* @param blog ContentMap of blog.
* @return List of category nodes
*/
public List<ContentMap> getBlogCategories(final ContentMap blog) {
final List<ContentMap> categories = new ArrayList<>(0);
try {
final Value[] values = blog.getJCRNode().getProperty(BlogsNodeTypes.Blog.PROPERTY_CATEGORIES).getValues();
if (values != null) {
for (Value value : values) {
categories.add(templatingFunctions.contentById(value.getString(), BlogRepositoryConstants.CATEGORY));
}
}
} catch (RepositoryException e) {
LOGGER.error("Exception while getting categories: {}", e.getMessage());
}
return categories;
}
示例13: adaptTo
import javax.jcr.Value; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
try {
return (type == String.class) ? (AdapterType)property.getString() :
(type == Boolean.class) ? (AdapterType)Boolean.valueOf(property.getBoolean()) :
(type == Long.class) ? (AdapterType)Long.valueOf(property.getLong()) :
(type == Double.class) ? (AdapterType)new Double(property.getDouble()) :
(type == BigDecimal.class) ? (AdapterType)property.getDecimal() :
(type == Calendar.class) ? (AdapterType)property.getDate() :
(type == Value.class) ? (AdapterType)property.getValue() :
(type == String[].class) ? (AdapterType)Values.convertValuesToStrings(property.getValues()) :
(type == Value[].class) ? (AdapterType)property.getValues() :
super.adaptTo(type);
}
catch (RepositoryException re) {
return super.adaptTo(type);
}
}
示例14: createValue
import javax.jcr.Value; //导入依赖的package包/类
@Override
public Value createValue(String value, int type) throws ValueFormatException {
switch (type) {
case PropertyType.STRING:
return createValue(value);
case PropertyType.LONG:
return createValue(Long.valueOf(value));
case PropertyType.DOUBLE:
return createValue(Double.valueOf(value));
case PropertyType.BOOLEAN:
return createValue(Boolean.valueOf(value));
case PropertyType.DECIMAL:
return createValue(new BigDecimal(value));
case PropertyType.DATE: // TODO: parse dates
case PropertyType.BINARY:
return createValue(createBinary(value));
default:
return null;
}
}
示例15: getStoragePolicy
import javax.jcr.Value; //导入依赖的package包/类
private Response getStoragePolicy(final String nodeType) throws RepositoryException {
LOGGER.debug("Get storage policy for: {}", nodeType);
Response.ResponseBuilder response;
final Node node =
getJcrTools().findOrCreateNode(session, FEDORA_STORAGE_POLICY_PATH, "test");
final Property prop = node.getProperty(nodeType);
if (null == prop) {
throw new PathNotFoundException("StoragePolicy not found: " + nodeType);
}
final Value[] values = prop.getValues();
if (values != null && values.length > 0) {
response = ok(values[0].getString());
} else {
throw new PathNotFoundException("StoragePolicy not found: " + nodeType);
}
return response.build();
}