Search in sources :

Example 6 with NamePathResolver

use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.

the class RepositoryServiceImpl method getItemUri.

private String getItemUri(NodeId parentId, Name childName, SessionInfo sessionInfo) throws RepositoryException {
    String parentUri = uriResolver.getItemUri(parentId, sessionInfo.getWorkspaceName(), sessionInfo);
    NamePathResolver resolver = getNamePathResolver(sessionInfo);
    // JCR-2920: don't append '/' to a trailing '/'
    if (!parentUri.endsWith("/")) {
        parentUri += "/";
    }
    return parentUri + Text.escape(resolver.getJCRName(childName));
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver)

Example 7 with NamePathResolver

use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.

the class RepositoryServiceImpl method retrieveQNodeTypeDefinitions.

/**
     *
     * @param sessionInfo
     * @param reportDoc
     * @return
     * @throws RepositoryException
     */
private Iterator<QNodeTypeDefinition> retrieveQNodeTypeDefinitions(SessionInfo sessionInfo, Document reportDoc) throws RepositoryException {
    ElementIterator it = DomUtil.getChildren(reportDoc.getDocumentElement(), NodeTypeConstants.NODETYPE_ELEMENT, null);
    List<QNodeTypeDefinition> ntDefs = new ArrayList<QNodeTypeDefinition>();
    NamePathResolver resolver = getNamePathResolver(sessionInfo);
    while (it.hasNext()) {
        ntDefs.add(DefinitionUtil.createQNodeTypeDefinition(it.nextElement(), resolver, getQValueFactory()));
    }
    // refresh node type definitions map
    synchronized (nodeTypeDefinitions) {
        nodeTypeDefinitions.clear();
        for (Object ntDef : ntDefs) {
            QNodeTypeDefinition def = (QNodeTypeDefinition) ntDef;
            nodeTypeDefinitions.put(def.getName(), def);
        }
    }
    return ntDefs.iterator();
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) ArrayList(java.util.ArrayList)

Example 8 with NamePathResolver

use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.

the class Locked method with.

/**
     * Executes the method {@link #run} within the scope of a lock held on
     * <code>lockable</code>.
     *
     * @param lockable the node where the lock is obtained from.
     * @param isDeep   <code>true</code> if <code>lockable</code> will be locked
     *                 deep.
     * @param timeout  time in milliseconds to wait at most to aquire the lock.
     * @return the object returned by {@link #run} or {@link #TIMED_OUT} if the
     *         lock on <code>lockable</code> could not be aquired within the
     *         specified timeout.
     * @throws IllegalArgumentException if <code>timeout</code> is negative or
     *                                  <code>lockable</code> is not
     *                                  <i>mix:lockable</i>.
     * @throws RepositoryException      if {@link #run} throws an exception.
     * @throws UnsupportedRepositoryOperationException
     *                                  if this repository does not support
     *                                  locking.
     * @throws InterruptedException     if this thread is interrupted while
     *                                  waiting for the lock on node
     *                                  <code>lockable</code>.
     */
public Object with(Node lockable, boolean isDeep, long timeout) throws UnsupportedRepositoryOperationException, RepositoryException, InterruptedException {
    if (timeout < 0) {
        throw new IllegalArgumentException("timeout must be >= 0");
    }
    Session session = lockable.getSession();
    NamePathResolver resolver = new DefaultNamePathResolver(session);
    Lock lock;
    EventListener listener = null;
    try {
        // check whether the lockable can be locked at all
        if (!lockable.isNodeType(resolver.getJCRName(NameConstants.MIX_LOCKABLE))) {
            throw new IllegalArgumentException("Node is not lockable");
        }
        lock = tryLock(lockable, isDeep);
        if (lock != null) {
            return runAndUnlock(lock);
        }
        if (timeout == 0) {
            return TIMED_OUT;
        }
        long timelimit;
        if (timeout == Long.MAX_VALUE) {
            timelimit = Long.MAX_VALUE;
        } else {
            timelimit = System.currentTimeMillis() + timeout;
        }
        // node is locked by other session -> register event listener if possible
        if (isObservationSupported(session)) {
            ObservationManager om = session.getWorkspace().getObservationManager();
            listener = new EventListener() {

                public void onEvent(EventIterator events) {
                    synchronized (this) {
                        this.notify();
                    }
                }
            };
            om.addEventListener(listener, Event.PROPERTY_REMOVED, lockable.getPath(), false, null, null, true);
        }
        // the current thread when the lockable node is possibly unlocked
        for (; ; ) {
            synchronized (this) {
                lock = tryLock(lockable, isDeep);
                if (lock != null) {
                    return runAndUnlock(lock);
                } else {
                    // check timeout
                    if (System.currentTimeMillis() > timelimit) {
                        return TIMED_OUT;
                    }
                    if (listener != null) {
                        // event listener *should* wake us up, however
                        // there is a chance that removal of the lockOwner
                        // property is notified before the node is acutally
                        // unlocked. therefore we use a safety net to wait
                        // at most 1000 millis.
                        this.wait(Math.min(1000, timeout));
                    } else {
                        // repository does not support observation
                        // wait at most 50 millis then retry
                        this.wait(Math.min(50, timeout));
                    }
                }
            }
        }
    } catch (NameException e) {
        throw new RepositoryException(e);
    } finally {
        if (listener != null) {
            session.getWorkspace().getObservationManager().removeEventListener(listener);
        }
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) ObservationManager(javax.jcr.observation.ObservationManager) RepositoryException(javax.jcr.RepositoryException) EventListener(javax.jcr.observation.EventListener) EventIterator(javax.jcr.observation.EventIterator) Session(javax.jcr.Session) Lock(javax.jcr.lock.Lock)

Example 9 with NamePathResolver

use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.

the class CompactNodeTypeDefTest method testCompactNodeTypeDef.

public void testCompactNodeTypeDef() throws Exception {
    // Read in node type def from test file
    Reader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(TEST_FILE));
    CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping> cndReader = new CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping>(reader, TEST_FILE, new QDefinitionBuilderFactory());
    List<QNodeTypeDefinition> ntdList1 = cndReader.getNodeTypeDefinitions();
    NamespaceMapping nsm = cndReader.getNamespaceMapping();
    NamePathResolver resolver = new DefaultNamePathResolver(nsm);
    // Put imported node type def back into CND form with CND writer
    StringWriter sw = new StringWriter();
    CompactNodeTypeDefWriter.write(ntdList1, nsm, resolver, sw);
    // Rerun the reader on the product of the writer
    cndReader = new CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping>(new StringReader(sw.toString()), TEST_FILE, new QDefinitionBuilderFactory());
    List<QNodeTypeDefinition> ntdList2 = cndReader.getNodeTypeDefinitions();
    if (ntdList1.size() == 0 || ntdList1.size() != ntdList2.size()) {
        fail("Exported node type definition was not successfully read back in");
    } else {
        for (int k = 0; k < ntdList1.size(); k++) {
            QNodeTypeDefinition ntd1 = ntdList1.get(k);
            QNodeTypeDefinition ntd2 = ntdList2.get(k);
            NodeTypeDefDiff diff = NodeTypeDefDiff.create(ntd1, ntd2);
            if (diff.isModified() && !diff.isTrivial()) {
                fail("Exported node type definition was not successfully read back in. " + ntd2.getName() + "differs from original");
            }
        }
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) InputStreamReader(java.io.InputStreamReader) NamespaceMapping(org.apache.jackrabbit.spi.commons.namespace.NamespaceMapping) CompactNodeTypeDefReader(org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) StringWriter(java.io.StringWriter) QDefinitionBuilderFactory(org.apache.jackrabbit.spi.commons.nodetype.QDefinitionBuilderFactory) StringReader(java.io.StringReader) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) CompactNodeTypeDefReader(org.apache.jackrabbit.commons.cnd.CompactNodeTypeDefReader) NodeTypeDefDiff(org.apache.jackrabbit.spi.commons.nodetype.NodeTypeDefDiff)

Example 10 with NamePathResolver

use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.

the class NodeDefinitionTemplateImplTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    NamePathResolver resolver = new DefaultNamePathResolver(new DummyNamespaceResolver());
    tmpl = new NodeDefinitionTemplateImpl(resolver);
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) DummyNamespaceResolver(org.apache.jackrabbit.spi.commons.conversion.DummyNamespaceResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver)

Aggregations

NamePathResolver (org.apache.jackrabbit.spi.commons.conversion.NamePathResolver)27 DefaultNamePathResolver (org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver)13 RepositoryException (javax.jcr.RepositoryException)10 IOException (java.io.IOException)7 HttpResponse (org.apache.http.HttpResponse)7 DavException (org.apache.jackrabbit.webdav.DavException)7 Name (org.apache.jackrabbit.spi.Name)5 ArrayList (java.util.ArrayList)4 ItemNotFoundException (javax.jcr.ItemNotFoundException)4 HttpEntity (org.apache.http.HttpEntity)4 Path (org.apache.jackrabbit.spi.Path)4 QValue (org.apache.jackrabbit.spi.QValue)4 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)4 Value (javax.jcr.Value)3 Privilege (javax.jcr.security.Privilege)3 DummyNamespaceResolver (org.apache.jackrabbit.spi.commons.conversion.DummyNamespaceResolver)3 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 Session (javax.jcr.Session)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2