use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class DefaultHandler method getContentNode.
/**
* Retrieves/creates the node that will be used to import properties and
* data. In case of a non-collection this includes and additional content node
* to be created beside the 'file' node.<br>
* Please note: If the jcr:content node already exists and contains child
* nodes, those will be removed in order to make sure, that the import
* really replaces the existing content of the file-node.
*
* @param context
* @param isCollection
* @return
* @throws RepositoryException
*/
protected Node getContentNode(ImportContext context, boolean isCollection) throws RepositoryException {
Node parentNode = (Node) context.getImportRoot();
String name = context.getSystemId();
if (parentNode.hasNode(name)) {
parentNode = parentNode.getNode(name);
} else {
String ntName = (isCollection) ? getCollectionNodeType() : getNodeType();
parentNode = parentNode.addNode(name, ntName);
}
Node contentNode = null;
if (isCollection) {
contentNode = parentNode;
} else {
if (parentNode.hasNode(JcrConstants.JCR_CONTENT)) {
contentNode = parentNode.getNode(JcrConstants.JCR_CONTENT);
// check if nodetype is compatible (might be update of an existing file)
if (contentNode.isNodeType(getContentNodeType()) || !forceCompatibleContentNodes()) {
// includes properties (DefaultHandler) and nodes (e.g. ZipHandler)
if (contentNode.hasNodes()) {
NodeIterator it = contentNode.getNodes();
while (it.hasNext()) {
it.nextNode().remove();
}
}
} else {
contentNode.remove();
contentNode = null;
}
}
if (contentNode == null) {
// when the underlying repository allows it to be used
if (parentNode.getPrimaryNodeType().canAddChildNode(JcrConstants.JCR_CONTENT, getContentNodeType())) {
contentNode = parentNode.addNode(JcrConstants.JCR_CONTENT, getContentNodeType());
} else {
contentNode = parentNode.addNode(JcrConstants.JCR_CONTENT);
}
}
}
return contentNode;
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class PropertyTypeTest method typeCheckChildren.
private void typeCheckChildren(Node parentNode) throws RepositoryException {
NodeIterator nodes = parentNode.getNodes();
while (nodes.hasNext()) {
Node node = nodes.nextNode();
PropertyIterator props = node.getProperties();
while (props.hasNext()) {
Property prop = props.nextProperty();
int reqType = prop.getDefinition().getRequiredType();
int type = PropertyType.UNDEFINED;
boolean isEmptyMultipleArray = false;
if (prop.getDefinition().isMultiple()) {
if (prop.getValues().length > 0) {
type = prop.getValues()[0].getType();
} else {
isEmptyMultipleArray = true;
}
} else {
type = prop.getValue().getType();
}
if (!isEmptyMultipleArray && reqType != PropertyType.UNDEFINED) {
assertFalse("The type of a property must not " + "be UNDEFINED", type == PropertyType.UNDEFINED);
assertEquals("The type of a property has to match " + "the type of the property definition.", type, reqType);
}
}
typeCheckChildren(node);
}
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class PropertyUtil method searchMultivalProp.
/**
* Helper method to find a multivalue property.
*
* @param node the node to start the search from.
* @return a multivalue property or null if not found any.
*/
public static Property searchMultivalProp(Node node) throws RepositoryException {
Property multiVal = null;
for (PropertyIterator props = node.getProperties(); props.hasNext(); ) {
Property property = props.nextProperty();
if (property.getDefinition().isMultiple()) {
multiVal = property;
break;
}
}
if (multiVal == null) {
for (NodeIterator nodes = node.getNodes(); nodes.hasNext(); ) {
Node n = nodes.nextNode();
multiVal = searchMultivalProp(n);
if (multiVal != null) {
break;
}
}
}
return multiVal;
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class PropertyUtil method searchMultivalProp.
/**
* Helper method to find a multivalue property of a given type.
*
* @param node the node to start the search from.
* @param type the property type.
* @return a multivalue property or null if not found any.
*/
public static Property searchMultivalProp(Node node, int type) throws RepositoryException {
Property multiVal = null;
for (PropertyIterator props = node.getProperties(); props.hasNext(); ) {
Property property = props.nextProperty();
if (property.getDefinition().isMultiple() && property.getType() == type) {
multiVal = property;
break;
}
}
if (multiVal == null) {
for (NodeIterator nodes = node.getNodes(); nodes.hasNext(); ) {
Node n = nodes.nextNode();
multiVal = searchMultivalProp(n, type);
if (multiVal != null) {
break;
}
}
}
return multiVal;
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class SelectorTest method testSelector.
public void testSelector() throws RepositoryException {
// make sure there's at least one node with this node type
testRootNode.addNode(nodeName1, testNodeType);
superuser.save();
QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), null, null, null);
forQOMandSQL2(qom, new Callable() {
public Object call(Query query) throws RepositoryException {
QueryResult result = query.execute();
String[] names = result.getSelectorNames();
assertNotNull(names);
assertEquals(1, names.length);
assertEquals("s", names[0]);
NodeIterator it = result.getNodes();
while (it.hasNext()) {
assertTrue("Wrong node type", it.nextNode().isNodeType(testNodeType));
}
return null;
}
});
}
Aggregations