当前位置: 首页>>代码示例>>Java>>正文


Java Value类代码示例

本文整理汇总了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;
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:29,代码来源:ResourceUtils.java

示例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;
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:29,代码来源:ResourceUtils.java

示例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;
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:26,代码来源:PropertyUtils.java

示例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();
}
 
开发者ID:quatico-solutions,项目名称:aem-testing,代码行数:24,代码来源:MockValue.java

示例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"));
}
 
开发者ID:quatico-solutions,项目名称:aem-testing,代码行数:10,代码来源:MockNodeTest.java

示例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];
}
 
开发者ID:HS2-SOLUTIONS,项目名称:hs2-aem-commons,代码行数:19,代码来源:PropagatePropertyInheritanceCancelled.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:JcrGetNodeByIdTest.java

示例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;
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:23,代码来源:SetProperty.java

示例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;
}
 
开发者ID:tricode,项目名称:magnolia-news,代码行数:19,代码来源:NewsRenderableDefinition.java

示例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();
  }
 
开发者ID:adaptto,项目名称:2015-sling-rookie-session,代码行数:24,代码来源:JcrReadSample.java

示例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;
}
 
开发者ID:tricode,项目名称:magnolia-blog,代码行数:22,代码来源:BlogRenderableDefinition.java

示例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);
    }
}
 
开发者ID:TWCable,项目名称:jackalope,代码行数:20,代码来源:PropertyResourceImpl.java

示例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;
    }
}
 
开发者ID:TWCable,项目名称:jackalope,代码行数:21,代码来源:ValueFactoryImpl.java

示例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();
}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-storage-policy,代码行数:21,代码来源:FedoraStoragePolicy.java


注:本文中的javax.jcr.Value类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。