Search in sources :

Example 96 with Name

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;
}
Also used : Query(javax.jcr.query.Query) Name(org.apache.jackrabbit.spi.Name)

Example 97 with Name

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");
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) AssertionFailedError(junit.framework.AssertionFailedError) Name(org.apache.jackrabbit.spi.Name)

Example 98 with Name

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]);
}
Also used : QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) Name(org.apache.jackrabbit.spi.Name)

Example 99 with Name

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);
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) SAXException(org.xml.sax.SAXException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException)

Example 100 with Name

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.");
    }
}
Also used : EffectiveNodeType(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType) ArrayList(java.util.ArrayList) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) Name(org.apache.jackrabbit.spi.Name)

Aggregations

Name (org.apache.jackrabbit.spi.Name)382 RepositoryException (javax.jcr.RepositoryException)101 ArrayList (java.util.ArrayList)57 QValue (org.apache.jackrabbit.spi.QValue)42 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)39 HashSet (java.util.HashSet)38 Path (org.apache.jackrabbit.spi.Path)38 NodeId (org.apache.jackrabbit.core.id.NodeId)37 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)33 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)32 NodeId (org.apache.jackrabbit.spi.NodeId)32 PropertyId (org.apache.jackrabbit.core.id.PropertyId)29 HashMap (java.util.HashMap)28 NamespaceException (javax.jcr.NamespaceException)28 NodeState (org.apache.jackrabbit.core.state.NodeState)28 Value (javax.jcr.Value)25 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)25 InternalValue (org.apache.jackrabbit.core.value.InternalValue)23 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)22 PropertyState (org.apache.jackrabbit.core.state.PropertyState)22