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));
}
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();
}
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);
}
}
}
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");
}
}
}
}
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);
}
Aggregations