use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class IndexNodeResolver method buildQuery.
/**
*
* @param value
* @param relPath
* @param exact
* @param maxSize
* @return
* @throws RepositoryException
*/
private Query buildQuery(String value, Path relPath, boolean exact, long maxSize, String searchRoot) throws RepositoryException {
StringBuilder stmt = new StringBuilder("/jcr:root");
if (!"/".equals(searchRoot)) {
stmt.append(searchRoot);
}
String p = getNamePathResolver().getJCRPath(relPath.getAncestor(1));
stmt.append("//").append(p);
if (value != null) {
stmt.append("[");
Name prop = relPath.getName();
stmt.append((exact) ? "@" : "jcr:like(@");
String pName = getNamePathResolver().getJCRName(prop);
stmt.append(ISO9075.encode(pName));
if (exact) {
stmt.append("='");
stmt.append(value.replaceAll("'", "''"));
stmt.append("'");
} else {
stmt.append(",'%");
stmt.append(escapeForQuery(value));
stmt.append("%')");
}
stmt.append("]");
}
Query q = queryManager.createQuery(stmt.toString(), Query.XPATH);
q.setLimit(maxSize);
return q;
}
use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class TestAll method getChildNode.
/**
* Returns the named child node definition from the named node type
* definition. If either of the definitions do not exist, an assertion
* failure is generated.
*
* @param typeName node type name
* @param nodeName child node name
* @return child node definition
*/
private QNodeDefinition getChildNode(String typeName, String nodeName) {
Name name = FACTORY.create(TEST_NAMESPACE, nodeName);
QNodeTypeDefinition def = getNodeType(typeName);
QNodeDefinition[] defs = def.getChildNodeDefs();
for (int i = 0; i < defs.length; i++) {
if (name.equals(defs[i].getName())) {
return defs[i];
}
}
throw new AssertionFailedError("Child node " + nodeName + " does not exist");
}
use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class TestAll method testRequiredTypeNode.
/** Test for the <code>requiredPrimaryTypes</code> child node attributes. */
public void testRequiredTypeNode() {
QNodeDefinition def = getChildNode("childNodeType", "requiredTypeNode");
assertEquals("requiredTypeNode requiredPrimaryTypes", 2, def.getRequiredPrimaryTypes().length);
Name[] types = def.getRequiredPrimaryTypes();
Arrays.sort(types);
assertEquals("requiredTypeNode requiredPrimaryTypes[0]", FACTORY.create(Name.NS_NT_URI, "base"), types[0]);
assertEquals("requiredTypeNode requiredPrimaryTypes[1]", FACTORY.create(Name.NS_NT_URI, "unstructured"), types[1]);
}
use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class DocViewImportHandler method startElement.
//-------------------------------------------------------< ContentHandler >
/**
* {@inheritDoc}
* <p>
* See also {@link org.apache.jackrabbit.commons.xml.DocumentViewExporter#exportProperty(String, String, int, javax.jcr.Value[])}
* regarding special handling of multi-valued properties on export.
*/
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
// process buffered character data
processCharacters();
try {
String dcdLocalName = ISO9075.decode(localName);
Name nodeName = nameFactory.create(namespaceURI, dcdLocalName);
// properties
String uuid = null;
Name nodeTypeName = null;
Name[] mixinTypes = null;
List<Importer.PropInfo> props = new ArrayList<Importer.PropInfo>(atts.getLength());
for (int i = 0; i < atts.getLength(); i++) {
if (atts.getURI(i).equals(Name.NS_XMLNS_URI)) {
// see http://issues.apache.org/jira/browse/JCR-620#action_12448164
continue;
}
dcdLocalName = ISO9075.decode(atts.getLocalName(i));
Name propName = nameFactory.create(atts.getURI(i), dcdLocalName);
// attribute value
String attrValue = atts.getValue(i);
if (propName.equals(NameConstants.JCR_PRIMARYTYPE)) {
// jcr:primaryType
if (attrValue.length() > 0) {
try {
nodeTypeName = resolver.getQName(attrValue);
} catch (NameException ne) {
throw new SAXException("illegal jcr:primaryType value: " + attrValue, ne);
}
}
} else if (propName.equals(NameConstants.JCR_MIXINTYPES)) {
// jcr:mixinTypes
mixinTypes = parseNames(attrValue);
} else if (propName.equals(NameConstants.JCR_UUID)) {
// jcr:uuid
if (attrValue.length() > 0) {
uuid = attrValue;
}
} else {
// always assume single-valued property for the time being
// until a way of properly serializing/detecting multi-valued
// properties on re-import is found (see JCR-325);
// see also DocViewSAXEventGenerator#leavingProperties(Node, int)
// TODO: proper multi-value serialization support
Importer.TextValue[] propValues = new Importer.TextValue[1];
propValues[0] = new StringValue(attrValue);
props.add(new Importer.PropInfo(propName, PropertyType.UNDEFINED, propValues));
}
}
Importer.NodeInfo node = new Importer.NodeInfo(nodeName, nodeTypeName, mixinTypes, uuid);
// all information has been collected, now delegate to importer
importer.startNode(node, props, resolver);
// push current node data onto stack
stack.push(node);
} catch (RepositoryException re) {
throw new SAXException(re);
}
}
use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class SessionImporter method checkIncludesMixReferenceable.
/**
* Validate the given <code>NodeInfo</code>: make sure, that if a uuid is
* defined, the primary or the mixin types include mix:referenceable.
*
* @param nodeInfo
* @throws RepositoryException
*/
private void checkIncludesMixReferenceable(Importer.NodeInfo nodeInfo) throws RepositoryException {
List<Name> l = new ArrayList<Name>();
l.add(nodeInfo.getNodeTypeName());
Name[] mixinNames = nodeInfo.getMixinNames();
if (mixinNames != null && mixinNames.length > 0) {
l.addAll(Arrays.asList(nodeInfo.getMixinNames()));
}
if (l.contains(NameConstants.MIX_REFERENCEABLE)) {
// shortcut
return;
}
Name[] ntNames = l.toArray(new Name[l.size()]);
EffectiveNodeType ent = session.getEffectiveNodeTypeProvider().getEffectiveNodeType(ntNames);
if (!ent.includesNodeType(NameConstants.MIX_REFERENCEABLE)) {
throw new ConstraintViolationException("XML defines jcr:uuid without defining import node to be referenceable.");
}
}
Aggregations