本文整理汇总了Java中javax.jcr.Property.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java Property.setValue方法的具体用法?Java Property.setValue怎么用?Java Property.setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jcr.Property
的用法示例。
在下文中一共展示了Property.setValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: populateItem
import javax.jcr.Property; //导入方法依赖的package包/类
private void populateItem(InputStream inputStream, Node qrCodeNode, final String fileName) throws RepositoryException {
if (inputStream != null) {
try {
Property data = getPropertyOrNull(qrCodeNode, JCR_DATA);
Binary binary = ValueFactoryImpl.getInstance().createBinary(inputStream);
if (data == null) {
qrCodeNode.setProperty(JCR_DATA, binary);
} else {
data.setValue(binary);
}
setProperty(qrCodeNode, FileProperties.PROPERTY_FILENAME, fileName);
setProperty(qrCodeNode, FileProperties.PROPERTY_CONTENTTYPE, MIME_TYPE);
Calendar calValue = new GregorianCalendar(TimeZone.getDefault());
setProperty(qrCodeNode, FileProperties.PROPERTY_LASTMODIFIED, calValue);
} catch (RepositoryException re) {
LOGGER.error("Could not get Binary. Upload will not be performed", re);
}
}
}
示例2: removeNodeProperty
import javax.jcr.Property; //导入方法依赖的package包/类
/**
* Given a JCR node, property and value, remove the value (if it exists)
* from the property, and remove the
* property if no values remove
*
* @param node the JCR node
* @param propertyName a name of a JCR property (either pre-existing or
* otherwise)
* @param valueToRemove the JCR value to remove
* @throws RepositoryException if repository exception occurred
*/
public void removeNodeProperty(final Node node, final String propertyName, final Value valueToRemove)
throws RepositoryException {
LOGGER.debug("Request to remove {}", valueToRemove);
// if the property doesn't exist, we don't need to worry about it.
if (node.hasProperty(propertyName)) {
final Property property = node.getProperty(propertyName);
final String strValueToRemove = valueToRemove.getString();
final String strValueToRemoveWithoutStringType = removeStringTypes(strValueToRemove);
if (property.isMultiple()) {
final AtomicBoolean remove = new AtomicBoolean();
final Value[] newValues = stream(node.getProperty(propertyName).getValues()).filter(uncheck(v -> {
final String strVal = removeStringTypes(v.getString());
LOGGER.debug("v is '{}', valueToRemove is '{}'", v, strValueToRemove );
if (strVal.equals(strValueToRemoveWithoutStringType)) {
remove.set(true);
return false;
}
return true;
})).toArray(Value[]::new);
// we only need to update the property if we did anything.
if (remove.get()) {
if (newValues.length == 0) {
LOGGER.debug("Removing property '{}'", propertyName);
property.remove();
} else {
LOGGER.debug("Removing value '{}' from property '{}'", strValueToRemove, propertyName);
property.setValue(newValues);
}
} else {
LOGGER.debug("Value not removed from property name '{}' (value '{}')", propertyName,
strValueToRemove);
}
} else {
final String strPropVal = property.getValue().getString();
final String strPropValWithoutStringType = removeStringTypes(strPropVal);
LOGGER.debug("Removing string '{}'", strValueToRemove);
if (StringUtils.equals(strPropValWithoutStringType, strValueToRemoveWithoutStringType)) {
LOGGER.debug("single value: Removing value from property '{}'", propertyName);
property.remove();
} else {
LOGGER.debug("Value not removed from property name '{}' (property value: '{}';compare value: '{}')",
propertyName, strPropVal, strValueToRemove);
throw new RepositoryException("Property '" + propertyName + "': Unable to remove value '" +
StringUtils.substring(strValueToRemove, 0, 50) + "'");
}
}
}
}