use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.
the class MockPropertyDefGenerator method getSimplePropertyDef.
public PropertyDefinition getSimplePropertyDef(String name) {
PropertyDefinition propertyDef = mock(PropertyDefinition.class);
when(propertyDef.getOnParentVersion()).thenReturn(OnParentVersionAction.COPY);
when(propertyDef.getName()).thenReturn(name);
return propertyDef;
}
use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.
the class MockPropertyDefGenerator method getEqualPropertyDefinitions.
@SuppressWarnings("deprecation")
public PropertyDefinition[] getEqualPropertyDefinitions() throws ValueFormatException, RepositoryException {
Value defaultValue1 = mock(Value.class);
when(defaultValue1.getType()).thenReturn(PropertyType.BINARY);
when(defaultValue1.getStream()).thenReturn(new ByteArrayInputStream("A content".getBytes()));
Value defaultValue2 = mock(Value.class);
when(defaultValue2.getType()).thenReturn(PropertyType.BINARY);
when(defaultValue2.getStream()).thenReturn(new ByteArrayInputStream("An other content".getBytes()));
PropertyDefinition binPropDef1 = this.getPropertyDef("binPropDef", PropertyType.BINARY, true, true, true, true, OnParentVersionAction.VERSION, new String[] { "[,1024]", "[,2048]" }, new Value[] { defaultValue1, defaultValue2 });
PropertyDefinition binPropDef2 = this.getPropertyDef("binPropDef", PropertyType.BINARY, true, true, true, true, OnParentVersionAction.VERSION, new String[] { "[,1024]", "[,512]" }, new Value[] { defaultValue1, defaultValue2 });
return new PropertyDefinition[] { binPropDef2, binPropDef1 };
}
use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.
the class MockPropertyDefGenerator method getCompletePropertyDev.
private PropertyDefinition getCompletePropertyDev(String name, Integer type, String[] valueConstraints, String defaultValueString) throws ValueFormatException, RepositoryException {
Value defaultValue = mock(Value.class);
when(defaultValue.getString()).thenReturn(defaultValueString);
PropertyDefinition propertyDef = getPropertyDef(name, type, valueConstraints, new Value[] { defaultValue });
return propertyDef;
}
use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.
the class JcrNode method getPropertyType.
public int getPropertyType(String propertyName) {
PropertyDefinition pd = getPropertyDefinition(propertyName);
if (pd != null) {
return pd.getRequiredType();
}
// otherwise use the SerializationManager to read the
// underlying vault file and derive the propertyType from there
GenericJcrRootFile u = properties.getUnderlying();
if (u == null) {
// no underlying properties file, that's not good
Activator.getDefault().getPluginLogger().warn("No underlying properties file, cannot derive propertyType (" + propertyName + ") for " + this);
return -1;
}
IFolder contentSyncRoot = ProjectUtil.getSyncDirectory(getProject());
IFile file = (IFile) u.file;
try (InputStream contents = file.getContents()) {
String resourceLocation = file.getFullPath().makeRelativeTo(contentSyncRoot.getFullPath()).toPortableString();
ResourceProxy resourceProxy = Activator.getDefault().getSerializationManager().readSerializationData(resourceLocation, contents);
// resourceProxy could be containing a full tree
// dive into the right position
String rawValue = properties.getValue(propertyName);
return PropertyTypeSupport.propertyTypeOfString(rawValue);
} catch (Exception e) {
Activator.getDefault().getPluginLogger().warn("Exception occurred during analyzing propertyType (" + propertyName + ") for " + this, e);
}
return -1;
}
use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.
the class JcrNode method getPropertyDefinition.
public PropertyDefinition getPropertyDefinition(String propertyName) {
NodeType nt0 = getNodeType();
if (nt0 == null) {
return null;
}
List<NodeType> nodeTypes = new LinkedList<>();
nodeTypes.add(nt0);
// add all supertypes
nodeTypes.addAll(Arrays.asList(nt0.getSupertypes()));
for (Iterator<NodeType> it = nodeTypes.iterator(); it.hasNext(); ) {
NodeType nt = it.next();
PropertyDefinition[] pds = nt.getPropertyDefinitions();
for (int i = 0; i < pds.length; i++) {
PropertyDefinition propertyDefinition = pds[i];
if (propertyDefinition.getName().equals(propertyName)) {
return propertyDefinition;
}
}
}
return null;
}
Aggregations