use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class DefinitionUtil method createQNodeTypeDefinition.
static QNodeTypeDefinition createQNodeTypeDefinition(Element ntdElement, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
QNodeTypeDefinitionBuilder builder = new QNodeTypeDefinitionBuilder();
// NOTE: the server should send the namespace-mappings as addition ns-defininitions
try {
if (ntdElement.hasAttribute(NAME_ATTRIBUTE)) {
builder.setName(resolver.getQName(ntdElement.getAttribute(NAME_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(PRIMARYITEMNAME_ATTRIBUTE)) {
builder.setPrimaryItemName(resolver.getQName(ntdElement.getAttribute(PRIMARYITEMNAME_ATTRIBUTE)));
}
Element child = DomUtil.getChildElement(ntdElement, SUPERTYPES_ELEMENT, null);
if (child != null) {
ElementIterator stIter = DomUtil.getChildren(child, SUPERTYPE_ELEMENT, null);
List<Name> qNames = new ArrayList<Name>();
while (stIter.hasNext()) {
Name st = resolver.getQName(DomUtil.getTextTrim(stIter.nextElement()));
qNames.add(st);
}
builder.setSupertypes(qNames.toArray(new Name[qNames.size()]));
}
if (ntdElement.hasAttribute(ISMIXIN_ATTRIBUTE)) {
builder.setMixin(Boolean.valueOf(ntdElement.getAttribute(ISMIXIN_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)) {
builder.setOrderableChildNodes(Boolean.valueOf(ntdElement.getAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(ISABSTRACT_ATTRIBUTE)) {
builder.setAbstract(Boolean.valueOf(ntdElement.getAttribute(ISABSTRACT_ATTRIBUTE)));
}
if (ntdElement.hasAttribute(ISQUERYABLE_ATTRIBUTE)) {
builder.setQueryable(Boolean.valueOf(ntdElement.getAttribute(ISQUERYABLE_ATTRIBUTE)));
}
// nodeDefinitions
ElementIterator it = DomUtil.getChildren(ntdElement, CHILDNODEDEFINITION_ELEMENT, null);
List<QNodeDefinition> nds = new ArrayList<QNodeDefinition>();
while (it.hasNext()) {
nds.add(createQNodeDefinition(builder.getName(), it.nextElement(), resolver));
}
builder.setChildNodeDefs(nds.toArray(new QNodeDefinition[nds.size()]));
// propertyDefinitions
it = DomUtil.getChildren(ntdElement, PROPERTYDEFINITION_ELEMENT, null);
List<QPropertyDefinition> pds = new ArrayList<QPropertyDefinition>();
while (it.hasNext()) {
pds.add(createQPropertyDefinition(builder.getName(), it.nextElement(), resolver, qValueFactory));
}
builder.setPropertyDefs(pds.toArray(new QPropertyDefinition[pds.size()]));
} catch (NameException e) {
log.error(e.getMessage());
throw new RepositoryException(e);
}
return builder.build();
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class DefinitionUtil method createQNodeDefinition.
/**
*
* @param declaringNodeType
* @param ndefElement
* @param resolver
* @return
* @throws RepositoryException
*/
static QNodeDefinition createQNodeDefinition(Name declaringNodeType, Element ndefElement, NamePathResolver resolver) throws RepositoryException {
QNodeDefinitionBuilder builder = new QNodeDefinitionBuilder();
buildQItemDefinition(declaringNodeType, ndefElement, resolver, builder);
// NOTE: the server should send the namespace-mappings as addition ns-defininitions
try {
if (ndefElement.hasAttribute(DEFAULTPRIMARYTYPE_ATTRIBUTE)) {
Name defaultPrimaryType = resolver.getQName(ndefElement.getAttribute(DEFAULTPRIMARYTYPE_ATTRIBUTE));
builder.setDefaultPrimaryType(defaultPrimaryType);
}
Element reqPrimaryTypes = DomUtil.getChildElement(ndefElement, REQUIREDPRIMARYTYPES_ELEMENT, null);
if (reqPrimaryTypes != null) {
ElementIterator it = DomUtil.getChildren(reqPrimaryTypes, REQUIREDPRIMARYTYPE_ELEMENT, null);
while (it.hasNext()) {
builder.addRequiredPrimaryType(resolver.getQName(DomUtil.getTextTrim(it.nextElement())));
}
} else {
builder.addRequiredPrimaryType(NameConstants.NT_BASE);
}
if (ndefElement.hasAttribute(SAMENAMESIBLINGS_ATTRIBUTE)) {
builder.setAllowsSameNameSiblings(Boolean.valueOf(ndefElement.getAttribute(SAMENAMESIBLINGS_ATTRIBUTE)));
}
} catch (NameException e) {
throw new RepositoryException(e);
}
return builder.build();
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class IdFactoryImpl method createPropertyId.
/**
* Creates a <code>PropertyId</code> for the given <code>property</code>.
*
* @param property the JCR Property.
* @param resolver
* @return the <code>PropertyId</code> for <code>property</code>.
* @throws RepositoryException if an error occurs while reading from
* <code>property</code>.
*/
public PropertyId createPropertyId(Property property, NamePathResolver resolver) throws RepositoryException {
Node parent = property.getParent();
NodeId nodeId = createNodeId(parent);
String jcrName = property.getName();
Name name;
try {
name = resolver.getQName(jcrName);
} catch (NameException e) {
throw new RepositoryException(e.getMessage(), e);
}
return createPropertyId(nodeId, name);
}
use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.
the class RepositoryServiceImpl method getNodeInfo.
/**
* {@inheritDoc}
*/
public NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws ItemNotFoundException, RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
Node node = getNode(nodeId, sInfo);
try {
return new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver());
} catch (NameException e) {
throw new RepositoryException(e);
}
}
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, Name[] nodetypeNames) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>();
for (Name nodetypeName : nodetypeNames) {
try {
String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeName);
NodeType nt = ntMgr.getNodeType(ntName);
defs.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
// in addition pack all supertypes into the return value
NodeType[] supertypes = nt.getSupertypes();
for (NodeType supertype : supertypes) {
defs.add(new QNodeTypeDefinitionImpl(supertype, sInfo.getNamePathResolver(), getQValueFactory()));
}
} catch (NameException e) {
throw new RepositoryException(e);
}
}
return defs.iterator();
}
Aggregations