use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.
the class JcrCellLabelProvider method update.
@Override
public void update(ViewerCell cell) {
int index = cell.getColumnIndex();
if (!isNewRow(cell)) {
if (canEdit(cell)) {
cell.setForeground(normalColor);
} else {
cell.setForeground(greyColor);
}
}
if (index == 0) {
updateName(cell);
return;
} else if (index == 1) {
final Object element = cell.getElement();
if (element instanceof NewRow) {
NewRow newRow = (NewRow) element;
int propertyType = newRow.getType();
String type = PropertyType.nameFromValue(propertyType);
cell.setText(type);
} else if (element instanceof IPropertyDescriptor) {
IPropertyDescriptor pd = (IPropertyDescriptor) element;
JcrNode jcrNode = (JcrNode) viewer.getInput();
Map.Entry me = (Entry) pd.getId();
final String propertyName = String.valueOf(me.getKey());
int propertyType = jcrNode.getPropertyType(propertyName);
if (propertyType <= -1 || propertyType == PropertyType.UNDEFINED) {
cell.setText("");
} else {
final JcrProperty property = jcrNode.getProperty(propertyName);
String type = PropertyType.nameFromValue(propertyType);
if (property != null && property.isMultiple()) {
type = type + "[]";
}
cell.setText(type);
}
} else {
cell.setText("");
}
return;
} else if (index == 2) {
updateValue(cell);
return;
} else {
final Object element = cell.getElement();
if (element instanceof NewRow) {
NewRow newRow = (NewRow) element;
cell.setText("");
} else if (element instanceof IPropertyDescriptor) {
IPropertyDescriptor pd = (IPropertyDescriptor) element;
JcrNode jcrNode = (JcrNode) viewer.getInput();
Map.Entry me = (Entry) pd.getId();
PropertyDefinition prd = jcrNode.getPropertyDefinition(String.valueOf(me.getKey()));
if (index == 3) {
// protected
if (prd != null) {
cell.setText(String.valueOf(prd.isProtected()));
} else {
cell.setText("false");
}
} else if (index == 4) {
// mandatory
if (prd != null) {
cell.setText(String.valueOf(prd.isMandatory()));
} else {
cell.setText("false");
}
} else if (index == 5) {
// multiple
if (prd != null) {
cell.setText(String.valueOf(prd.isMultiple()));
} else {
cell.setText(String.valueOf(jcrNode.getProperty(String.valueOf(me.getKey())).isMultiple()));
}
} else if (index == 6) {
// auto creatd
if (prd != null) {
cell.setText(String.valueOf(prd.isAutoCreated()));
} else {
cell.setText("false");
}
} else {
cell.setText("n/a");
return;
}
}
}
}
use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.
the class VltNodeTypeFactory method initPropertyDefinitions.
private void initPropertyDefinitions(VltNodeType nt) {
Map<String, VltPropertyDefinition> pds = new HashMap<>();
PropertyDefinition[] declaredPds = nt.getDeclaredPropertyDefinitions();
if (declaredPds != null) {
for (int i = 0; i < declaredPds.length; i++) {
PropertyDefinition pd = declaredPds[i];
pds.put(pd.getName(), (VltPropertyDefinition) pd);
}
}
NodeType[] superTypes = nt.getSupertypes();
if (superTypes != null) {
for (int i = 0; i < superTypes.length; i++) {
VltNodeType aSuperType = (VltNodeType) superTypes[i];
VltPropertyDefinition[] superTypePds = (VltPropertyDefinition[]) aSuperType.getPropertyDefinitions();
for (int j = 0; j < superTypePds.length; j++) {
VltPropertyDefinition pd = superTypePds[j];
VltPropertyDefinition existingPd = pds.get(pd.getName());
if (existingPd != null) {
// merge the two
existingPd.mergeFrom(pd);
} else {
pds.put(pd.getName(), pd);
}
}
}
}
nt.setPropertyDefinitions(pds.values().toArray(new VltPropertyDefinition[pds.size()]));
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class PropertyImpl method setValue.
/**
* Same as <code>{@link Property#setValue(String)}</code> except that
* this method takes a <code>Name</code> instead of a <code>String</code>
* value.
*
* @param name
* @throws ValueFormatException
* @throws VersionException
* @throws LockException
* @throws ConstraintViolationException
* @throws RepositoryException
*/
public void setValue(Name name) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
// check state of this instance
sanityCheck();
// check pre-conditions for setting property value
checkSetValue(false);
// check type according to definition of this property
final PropertyDefinition definition = data.getPropertyDefinition();
int reqType = definition.getRequiredType();
if (reqType == UNDEFINED) {
reqType = NAME;
}
if (name == null) {
internalSetValue(null, reqType);
return;
}
InternalValue internalValue;
if (reqType != NAME) {
// type conversion required
Value targetValue = ValueHelper.convert(ValueFormat.getJCRValue(InternalValue.create(name), sessionContext, getSession().getValueFactory()), reqType, getSession().getValueFactory());
internalValue = InternalValue.create(targetValue, sessionContext, sessionContext.getDataStore());
} else {
// no type conversion required
internalValue = InternalValue.create(name);
}
internalSetValue(new InternalValue[] { internalValue }, reqType);
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class CompactNodeTypeDefWriter method write.
/**
* Write one NodeTypeDefinition to this writer
*
* @param ntd node type definition
* @throws IOException if an I/O error occurs
*/
public void write(NodeTypeDefinition ntd) throws IOException {
writeName(ntd);
writeSupertypes(ntd);
writeOptions(ntd);
PropertyDefinition[] pdefs = ntd.getDeclaredPropertyDefinitions();
if (pdefs != null) {
for (PropertyDefinition pd : pdefs) {
writePropDef(pd);
}
}
NodeDefinition[] ndefs = ntd.getDeclaredChildNodeDefinitions();
if (ndefs != null) {
for (NodeDefinition nd : ndefs) {
writeNodeDef(nd);
}
}
out.write("\n\n");
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class CanSetPropertyBooleanTest method testConversionsMultiple.
/**
* Tests if NodeType.canSetProperty(String propertyName, Value[] values)
* returns true if all values and its types are convertible to
* BooleanValue.
*/
public void testConversionsMultiple() throws NotExecutableException, RepositoryException {
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.BOOLEAN, true, false, false, false);
if (propDef == null) {
throw new NotExecutableException("No multiple boolean property def that meets the " + "requirements of the test has been found");
}
NodeType nodeType = propDef.getDeclaringNodeType();
Value booleanValue = NodeTypeUtil.getValueOfType(session, PropertyType.BOOLEAN);
Value stringValue = NodeTypeUtil.getValueOfType(session, PropertyType.STRING);
Value[] stringValues = new Value[] { stringValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Boolean and values are of type StringValue", nodeType.canSetProperty(propDef.getName(), stringValues));
Value binaryValue = NodeTypeUtil.getValueOfType(session, PropertyType.BINARY);
Value[] binaryValues = new Value[] { binaryValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Boolean and values are of type BinaryValue", nodeType.canSetProperty(propDef.getName(), binaryValues));
Value dateValue = NodeTypeUtil.getValueOfType(session, PropertyType.DATE);
Value[] dateValues = new Value[] { booleanValue, dateValue };
assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Boolean and values are of type DateValue", nodeType.canSetProperty(propDef.getName(), dateValues));
Value doubleValue = NodeTypeUtil.getValueOfType(session, PropertyType.DOUBLE);
Value[] doubleValues = new Value[] { booleanValue, doubleValue };
assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Boolean and values are of type DoubleValue", nodeType.canSetProperty(propDef.getName(), doubleValues));
Value longValue = NodeTypeUtil.getValueOfType(session, PropertyType.LONG);
Value[] longValues = new Value[] { booleanValue, longValue };
assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Boolean and values are of type LongValue", nodeType.canSetProperty(propDef.getName(), longValues));
Value[] booleanValues = new Value[] { booleanValue };
assertTrue("canSetProperty(String propertyName, Value[] values) must return " + "true if the property is of type Boolean and values are of type BooleanValue", nodeType.canSetProperty(propDef.getName(), booleanValues));
Value nameValue = NodeTypeUtil.getValueOfType(session, PropertyType.NAME);
Value[] nameValues = new Value[] { booleanValue, nameValue };
assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Boolean and values are of type NameValue", nodeType.canSetProperty(propDef.getName(), nameValues));
Value pathValue = NodeTypeUtil.getValueOfType(session, PropertyType.PATH);
Value[] pathValues = new Value[] { booleanValue, pathValue };
assertFalse("canSetProperty(String propertyName, Value[] values) must return " + "false if the property is of type Boolean and values are of type PathValue", nodeType.canSetProperty(propDef.getName(), pathValues));
}
Aggregations