use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class QueryImpl method storeAsNode.
/**
* @see Query#storeAsNode(String)
*/
public Node storeAsNode(String absPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException {
NamePathResolver resolver = mgrProvider.getNamePathResolver();
try {
Path p = resolver.getQPath(absPath).getNormalizedPath();
if (!p.isAbsolute()) {
throw new RepositoryException(absPath + " is not an absolute path");
}
String jcrParent = resolver.getJCRPath(p.getAncestor(1));
if (!session.itemExists(jcrParent)) {
throw new PathNotFoundException(jcrParent);
}
String relPath = resolver.getJCRPath(p).substring(1);
String ntName = resolver.getJCRName(NameConstants.NT_QUERY);
Node queryNode = session.getRootNode().addNode(relPath, ntName);
// set properties
queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE), getLanguage());
queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT), getStatement());
node = queryNode;
return node;
} catch (NameException e) {
throw new RepositoryException(e.getMessage(), e);
}
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class AccessControlManagerImpl method getUniqueNodeName.
// copied from jackrabbit-core ACLEditor
/**
* Create a unique valid name for the Permission nodes to be save.
*
* @param node a name for the child is resolved
* @param name if missing the {@link #DEFAULT_ACE_NAME} is taken
* @return the name
* @throws RepositoryException if an error occurs
*/
private Name getUniqueNodeName(NodeState node, String name) throws RepositoryException {
try {
NameParser.checkFormat(name);
} catch (NameException e) {
log.debug("Invalid path name for Permission: " + name + ".");
}
int i = 0;
String check = name;
Name n = npResolver.getQName(check);
while (node.hasChildNodeEntry(n, 1)) {
check = name + i;
n = npResolver.getQName(check);
i++;
}
return n;
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class RepositoryServiceImpl method getQNodeTypeDefinitions.
/**
* {@inheritDoc}
*/
public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
List<QNodeTypeDefinition> nodeTypes = new ArrayList<QNodeTypeDefinition>();
try {
for (NodeTypeIterator it = ntMgr.getAllNodeTypes(); it.hasNext(); ) {
NodeType nt = it.nextNodeType();
nodeTypes.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
}
} catch (NameException e) {
throw new RepositoryException(e);
}
return nodeTypes.iterator();
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class RepositoryServiceImpl method getChildInfos.
/**
* {@inheritDoc}
*/
public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws ItemNotFoundException, RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
NodeIterator children = getNode(parentId, sInfo).getNodes();
List<ChildInfo> childInfos = new ArrayList<ChildInfo>();
try {
while (children.hasNext()) {
childInfos.add(new ChildInfoImpl(children.nextNode(), sInfo.getNamePathResolver()));
}
} catch (NameException e) {
throw new RepositoryException(e);
}
return childInfos.iterator();
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class RepositoryServiceImpl method getItemInfos.
/**
* {@inheritDoc}
*/
public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, ItemId itemId) throws ItemNotFoundException, RepositoryException {
if (!itemId.denotesNode()) {
PropertyId propertyId = (PropertyId) itemId;
PropertyInfo propertyInfo = getPropertyInfo(sessionInfo, propertyId);
return Iterators.singleton(propertyInfo);
} else {
NodeId nodeId = (NodeId) itemId;
final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
Node node = getNode(nodeId, sInfo);
Name ntName = null;
try {
ntName = sInfo.getNamePathResolver().getQName(node.getProperty(JcrConstants.JCR_PRIMARYTYPE).getString());
} catch (NameException e) {
// ignore. should never occur
}
int depth = batchReadConfig.getDepth(ntName);
if (depth == BatchReadConfig.DEPTH_DEFAULT) {
NodeInfo info;
try {
info = new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver());
} catch (NameException e) {
throw new RepositoryException(e);
}
return Collections.singletonList(info).iterator();
} else {
final List<ItemInfo> itemInfos = new ArrayList<ItemInfo>();
ItemVisitor visitor = new TraversingItemVisitor(false, depth) {
@Override
protected void entering(Property property, int i) throws RepositoryException {
try {
itemInfos.add(new PropertyInfoImpl(property, idFactory, sInfo.getNamePathResolver(), getQValueFactory()));
} catch (NameException e) {
throw new RepositoryException(e);
}
}
@Override
protected void entering(Node node, int i) throws RepositoryException {
try {
itemInfos.add(new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver()));
} catch (NameException e) {
throw new RepositoryException(e);
}
}
@Override
protected void leaving(Property property, int i) {
// nothing to do
}
@Override
protected void leaving(Node node, int i) {
// nothing to do
}
};
visitor.visit(node);
return itemInfos.iterator();
}
}
}
Aggregations