use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.
the class DownloadDefaultBinaryValueServlet method findMatchingPropertyDef.
/**
* This method pulls the first matcher out of the list and iterates over the list of specified property definitions to find matches.
* Lets say this is a PropertyNameMatcher that has been initialized with the property name from the URL. Than it will match for every
* property definition who's name is equal to the one specified in the URL. The matched property definitions and the rest of the matchers
* will be provided for the next recursive call of the method to work through the other path elements until all matchers are processed or
* until only one property definition matches. In the first case null is returned and in the second case the identified property definition
* is returned.
* @param propertyDefinitions The list of property definitions.
* @param propertyMatcherList The list of matcher in the order of appearance of their type in the URL. A matcher checks if the
* content of a path element it was initialized with matches its corresponding value in the property definition.
* @return Returns the property definition that is identified by the URL or null if no property definition matches the values specified in the URL.
*/
private PropertyDefinition findMatchingPropertyDef(List<PropertyDefinition> propertyDefinitions, List<PropertyMatcher> propertyMatcherList) {
if (propertyMatcherList.size() > 0) {
// retrieve the matcher to be used for this iteration
PropertyMatcher propertyMatcher = propertyMatcherList.get(0);
// remove the matcher to make the next matcher available for the
// next iteration
propertyMatcherList.remove(0);
List<PropertyDefinition> matchedPropDefs = new LinkedList<PropertyDefinition>();
// try to match all property definitions with the top matcher
for (PropertyDefinition propertyDefinition : propertyDefinitions) {
if (propertyMatcher.match(propertyDefinition)) {
matchedPropDefs.add(propertyDefinition);
}
}
if (matchedPropDefs.size() == 1) {
return matchedPropDefs.get(0);
} else if (matchedPropDefs.size() > 1) {
return findMatchingPropertyDef(matchedPropDefs, propertyMatcherList);
}
}
return null;
}
use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.
the class NodeTypeGenerationTest method testCompleteNodeTypes.
@Test
public void testCompleteNodeTypes() throws JSONException, ServletException, IOException, ValueFormatException, IllegalStateException, RepositoryException {
NodeType nt1 = getSimpleNodeTypeWithName("testNodeType");
NodeType[] superTypes = { getSimpleNodeTypeWithName("superType1"), getSimpleNodeTypeWithName("superType2"), getSimpleNodeTypeWithName("superType3") };
NodeType nt2 = getSimpleNodeTypeWithName(null);
when(nt1.getDeclaredSupertypes()).thenReturn(superTypes);
when(nodeTypeIterator.nextNodeType()).thenReturn(nt1, nt2);
when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE);
NodeDefinition childNodeDef1 = getCompleteChildNodeDef("childNodeDef1");
NodeDefinition childNodeDef2 = getCompleteChildNodeDef("childNodeDef2");
NodeDefinition[] childNodeDefs = { childNodeDef1, childNodeDef2 };
when(nt1.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs);
String propertyName = "stringPropertyDef";
PropertyDefinition propertyDef = mock(PropertyDefinition.class);
when(propertyDef.getOnParentVersion()).thenReturn(OnParentVersionAction.VERSION);
when(propertyDef.getName()).thenReturn(propertyName);
when(propertyDef.getRequiredType()).thenReturn(PropertyType.STRING);
when(propertyDef.getValueConstraints()).thenReturn(new String[] { GenerationConstants.CONSTRAINT_STRING });
when(propertyDef.isMultiple()).thenReturn(Boolean.TRUE);
when(propertyDef.isProtected()).thenReturn(Boolean.TRUE);
Value defaultValue = mock(Value.class);
when(defaultValue.getType()).thenReturn(PropertyType.STRING);
when(defaultValue.getString()).thenReturn(GenerationConstants.DEFAULT_VALUE_STRING);
when(propertyDef.getDefaultValues()).thenReturn(new Value[] { defaultValue });
when(propertyDef.isAutoCreated()).thenReturn(Boolean.TRUE);
when(propertyDef.isMandatory()).thenReturn(Boolean.TRUE);
when(nt1.getDeclaredPropertyDefinitions()).thenReturn(new PropertyDefinition[] { propertyDef });
assertEqualsWithServletResult("testCompleteNodeTypes");
}
use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.
the class PropertyDefGenerationTest method testMultipleConstraints.
@Test
public void testMultipleConstraints() throws ValueFormatException, IllegalStateException, RepositoryException, JSONException, ServletException, IOException {
PropertyDefinition propertyDef = getPropertyGenerator().getPropertyDef("stringProp", PropertyType.STRING, new String[] { "banana", "apple" }, null);
NodeType ntWithChildNodeDefs = getSimpleNodeTypeWithName("ntWithPropertyDefs");
when(ntWithChildNodeDefs.getDeclaredPropertyDefinitions()).thenReturn(new PropertyDefinition[] { propertyDef });
when(nodeTypeIterator.nextNodeType()).thenReturn(ntWithChildNodeDefs);
when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE);
assertEqualsWithServletResult("testMultipleConstraints");
}
use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.
the class PropertyDefGenerationTest method testMultipleDefaultValues.
@Test
public void testMultipleDefaultValues() throws ValueFormatException, IllegalStateException, RepositoryException, JSONException, ServletException, IOException {
Value defaultValue1 = mock(Value.class);
when(defaultValue1.getString()).thenReturn(DEFAULT_VALUE_STRING);
Value defaultValue2 = mock(Value.class);
when(defaultValue2.getString()).thenReturn(DEFAULT_VALUE_STRING + "2");
PropertyDefinition propertyDef = getPropertyGenerator().getPropertyDef("stringProp", PropertyType.STRING, new String[] { CONSTRAINT_STRING }, new Value[] { defaultValue1, defaultValue2 });
NodeType ntWithChildNodeDefs = getSimpleNodeTypeWithName("ntWithPropertyDefs");
when(ntWithChildNodeDefs.getDeclaredPropertyDefinitions()).thenReturn(new PropertyDefinition[] { propertyDef });
when(nodeTypeIterator.nextNodeType()).thenReturn(ntWithChildNodeDefs);
when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE);
assertEqualsWithServletResult("testMultipleDefaultValues");
}
use of javax.jcr.nodetype.PropertyDefinition in project sling by apache.
the class DownloadDefaultBinaryValueTest method invokeServletWithEqualPropertyDefs.
private void invokeServletWithEqualPropertyDefs() throws NoSuchNodeTypeException, RepositoryException, ValueFormatException, ServletException, IOException {
NodeType nodeType = mock(NodeType.class);
when(ntManager.getNodeType("ns:ntName")).thenReturn(nodeType);
PropertyDefinition[] propDefs = propDefGenerator.getEqualPropertyDefinitions();
when(nodeType.getPropertyDefinitions()).thenReturn(propDefs);
DownloadDefaultBinaryValueServlet downloadServlet = new DownloadDefaultBinaryValueServlet();
downloadServlet.service(request, response);
}
Aggregations