use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.
the class TestAll method testOrderedNodeType.
/** Test for the <code>hasOrderableChildNodes</code> node type attribute. */
public void testOrderedNodeType() {
QNodeTypeDefinition def = getNodeType("orderedNodeType");
assertEquals("orderedNodeType hasOrderableChildNodes", true, def.hasOrderableChildNodes());
}
use of org.apache.jackrabbit.spi.QNodeTypeDefinition 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.QNodeTypeDefinition 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.QNodeTypeDefinition in project jackrabbit by apache.
the class NodeTypeManagerImpl method registerNodeTypes.
/**
* Registers the node types defined in the given input stream depending
* on the content type specified for the stream. This will also register
* any namespaces identified in the input stream if they have not already
* been registered.
*
* @param in node type XML stream
* @param contentType type of the input stream
* @param reregisterExisting flag indicating whether node types should be
* reregistered if they already exist
* @return registered node types
* @throws IOException if the input stream could not be read or parsed
* @throws RepositoryException if the node types are invalid or another
* repository error occurs
*/
public NodeType[] registerNodeTypes(InputStream in, String contentType, boolean reregisterExisting) throws IOException, RepositoryException {
// make sure the editing session is allowed to register node types.
context.getAccessManager().checkRepositoryPermission(Permission.NODE_TYPE_DEF_MNGMT);
try {
Map<String, String> namespaceMap = new HashMap<String, String>();
List<QNodeTypeDefinition> nodeTypeDefs = new ArrayList<QNodeTypeDefinition>();
if (contentType.equalsIgnoreCase(TEXT_XML) || contentType.equalsIgnoreCase(APPLICATION_XML)) {
try {
NodeTypeReader ntr = new NodeTypeReader(in);
Properties namespaces = ntr.getNamespaces();
if (namespaces != null) {
Enumeration<?> prefixes = namespaces.propertyNames();
while (prefixes.hasMoreElements()) {
String prefix = (String) prefixes.nextElement();
String uri = namespaces.getProperty(prefix);
namespaceMap.put(prefix, uri);
}
}
QNodeTypeDefinition[] defs = ntr.getNodeTypeDefs();
nodeTypeDefs.addAll(Arrays.asList(defs));
} catch (NameException e) {
throw new RepositoryException("Illegal JCR name", e);
}
} else if (contentType.equalsIgnoreCase(TEXT_X_JCR_CND)) {
try {
NamespaceMapping mapping = new NamespaceMapping(context.getSessionImpl());
CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping> reader = new CompactNodeTypeDefReader<QNodeTypeDefinition, NamespaceMapping>(new InputStreamReader(in), "cnd input stream", mapping, new QDefinitionBuilderFactory());
namespaceMap.putAll(mapping.getPrefixToURIMapping());
for (QNodeTypeDefinition ntDef : reader.getNodeTypeDefinitions()) {
nodeTypeDefs.add(ntDef);
}
} catch (ParseException e) {
IOException e2 = new IOException(e.getMessage());
e2.initCause(e);
throw e2;
}
} else {
throw new UnsupportedRepositoryOperationException("Unsupported content type: " + contentType);
}
new NamespaceHelper(context.getSessionImpl()).registerNamespaces(namespaceMap);
if (reregisterExisting) {
NodeTypeRegistry registry = context.getNodeTypeRegistry();
// split the node types into new and already registered node types.
// this way we can register new node types together with already
// registered node types which make circular dependencies possible
List<QNodeTypeDefinition> newNodeTypeDefs = new ArrayList<QNodeTypeDefinition>();
List<QNodeTypeDefinition> registeredNodeTypeDefs = new ArrayList<QNodeTypeDefinition>();
for (QNodeTypeDefinition nodeTypeDef : nodeTypeDefs) {
if (registry.isRegistered(nodeTypeDef.getName())) {
registeredNodeTypeDefs.add(nodeTypeDef);
} else {
newNodeTypeDefs.add(nodeTypeDef);
}
}
ArrayList<NodeType> nodeTypes = new ArrayList<NodeType>();
// register new node types
nodeTypes.addAll(registerNodeTypes(newNodeTypeDefs));
// re-register already existing node types
for (QNodeTypeDefinition nodeTypeDef : registeredNodeTypeDefs) {
registry.reregisterNodeType(nodeTypeDef);
nodeTypes.add(getNodeType(nodeTypeDef.getName()));
}
return nodeTypes.toArray(new NodeType[nodeTypes.size()]);
} else {
Collection<NodeType> types = registerNodeTypes(nodeTypeDefs);
return types.toArray(new NodeType[types.size()]);
}
} catch (InvalidNodeTypeDefException e) {
throw new RepositoryException("Invalid node type definition", e);
}
}
use of org.apache.jackrabbit.spi.QNodeTypeDefinition in project jackrabbit by apache.
the class NodeTypeRegistry method internalRegister.
/**
* Same as {@link #internalRegister(java.util.Collection, boolean)} except for the
* additional <code>lenient</code> parameter which governs whether
* validation can be lenient (e.g. for built-in node types) or has to be
* strict (such as in the case of custom node types). This differentiation
* is unfortunately required as there are e.g. properties defined in built-in
* node types which are auto-created but don't have a fixed default value
* that can be exposed in a property definition because it is
* system-generated (such as jcr:primaryType in nt:base).
*/
private void internalRegister(Collection<QNodeTypeDefinition> ntDefs, boolean external, boolean lenient) throws InvalidNodeTypeDefException, RepositoryException {
// need a list/collection that can be modified
List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>(ntDefs);
// map of node type names and node type definitions
Map<Name, QNodeTypeDefinition> tmpNTDefCache = new HashMap<Name, QNodeTypeDefinition>(registeredNTDefs);
// and do some preliminary checks
for (QNodeTypeDefinition ntd : defs) {
Name name = ntd.getName();
if (!external && name != null && tmpNTDefCache.containsKey(name)) {
String msg = name + " already exists locally";
log.debug(msg);
throw new InvalidNodeTypeDefException(msg);
}
// add definition to temporary cache
tmpNTDefCache.put(ntd.getName(), ntd);
}
// check if all node type defs have proper nt:base subtyping
for (int i = 0; i < defs.size(); i++) {
QNodeTypeDefinition ntd = defs.get(i);
QNodeTypeDefinition mod = checkNtBaseSubtyping(ntd, tmpNTDefCache);
if (mod != ntd) {
// check fixed subtyping
// -> update cache and list of defs
tmpNTDefCache.put(mod.getName(), mod);
defs.set(i, mod);
}
}
// create working copies of current ent & ntd caches:
// cache of pre-built aggregations of node types
EffectiveNodeTypeCache tmpENTCache = (EffectiveNodeTypeCache) entCache.clone();
for (QNodeTypeDefinition ntd : defs) {
EffectiveNodeType ent = validateNodeTypeDef(ntd, tmpENTCache, tmpNTDefCache, nsReg, lenient);
// store new effective node type instance
tmpENTCache.put(ent);
}
// be valid
for (QNodeTypeDefinition ntd : defs) {
registeredNTDefs.put(ntd.getName(), ntd);
}
// finally add newly created effective node types to entCache
entCache = tmpENTCache;
}
Aggregations