use of javax.jcr.nodetype.NodeTypeIterator in project sling by apache.
the class NodeTypeConfigurationPrinter method printConfiguration.
/**
* {@inheritDoc}
*/
public void printConfiguration(PrintWriter pw, String mode) {
if (slingRepository != null) {
Session session = null;
try {
session = slingRepository.loginAdministrative(null);
NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
NodeTypeIterator it = ntm.getAllNodeTypes();
List<NodeType> sortedTypes = sortTypes(it);
for (NodeType nt : sortedTypes) {
pw.printf("[%s]", nt.getName());
printSuperTypes(pw, nt);
if (nt.hasOrderableChildNodes()) {
pw.print(" orderable");
}
if (nt.isMixin()) {
pw.print(" mixin");
}
linebreak(pw, mode);
for (PropertyDefinition prop : nt.getPropertyDefinitions()) {
if (prop.getDeclaringNodeType() == nt) {
startBold(pw, mode);
}
pw.printf("- %s", prop.getName());
printDefaultValues(pw, prop);
if (prop.getName().equals(nt.getPrimaryItemName())) {
pw.print(" primary");
}
if (prop.isMandatory()) {
pw.print(" mandatory");
}
if (prop.isAutoCreated()) {
pw.print(" autocreated");
}
if (prop.isProtected()) {
pw.print(" protected");
}
if (prop.isMultiple()) {
pw.print(" multiple");
}
pw.printf(" %s", OnParentVersionAction.nameFromValue(prop.getOnParentVersion()));
printConstraints(pw, prop);
if (prop.getDeclaringNodeType() == nt) {
stopBold(pw, mode);
}
linebreak(pw, mode);
}
for (NodeDefinition child : nt.getChildNodeDefinitions()) {
if (child.getDeclaringNodeType() == nt) {
startBold(pw, mode);
}
pw.printf("+ %s", child.getName());
printRequiredChildTypes(pw, child);
if (child.getDefaultPrimaryType() != null) {
pw.printf(" = %s", child.getDefaultPrimaryType().getName());
}
if (child.isMandatory()) {
pw.print(" mandatory");
}
if (child.isAutoCreated()) {
pw.print(" autocreated");
}
if (child.isProtected()) {
pw.print(" protected");
}
if (child.allowsSameNameSiblings()) {
pw.print(" multiple");
}
pw.printf(" %s", OnParentVersionAction.nameFromValue(child.getOnParentVersion()));
if (child.getDeclaringNodeType() == nt) {
stopBold(pw, mode);
}
linebreak(pw, mode);
}
linebreak(pw, mode);
}
} catch (RepositoryException e) {
pw.println("Unable to output namespace mappings.");
e.printStackTrace(pw);
} finally {
if (session != null) {
session.logout();
}
}
} else {
pw.println("SlingRepository is not available.");
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project sling by apache.
the class NodeTypesJSONServlet method doGet.
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json; charset=UTF-8");
PrintWriter writer = response.getWriter();
Resource resource = request.getResource();
Node currentNode = resource.adaptTo(Node.class);
try {
NodeTypeIterator nodeTypeIterator = currentNode.getSession().getWorkspace().getNodeTypeManager().getAllNodeTypes();
JSONObject nodeTypes = new JSONObject();
while (nodeTypeIterator.hasNext()) {
NodeType nodeType = nodeTypeIterator.nextNodeType();
if (nodeType.getName() != null) {
JSONNodeType jsonNodeType = new JSONNodeType(nodeType);
nodeTypes.put(nodeType.getName(), jsonNodeType.getJson());
}
}
writer.println(nodeTypes.toString(2));
writer.flush();
writer.close();
} catch (RepositoryException e) {
log.error("Could not generate the node types.", e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} catch (JSONException e) {
log.error("Could not generate the node types.", e);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class LuceneQueryFactory method create.
/**
* Creates a lucene query for the given QOM selector.
*
* @param selector the selector.
* @return a lucene query for the given selector.
* @throws RepositoryException if an error occurs while creating the query.
*/
public Query create(Selector selector) throws RepositoryException {
List<Term> terms = new ArrayList<Term>();
String name = selector.getNodeTypeName();
NodeTypeIterator allTypes = ntManager.getAllNodeTypes();
while (allTypes.hasNext()) {
NodeType nt = allTypes.nextNodeType();
if (nt.isNodeType(name)) {
terms.add(createNodeTypeTerm(nt));
}
}
if (terms.size() == 1) {
return new JackrabbitTermQuery(terms.get(0));
} else {
BooleanQuery b = new BooleanQuery();
for (Term term : terms) {
b.add(new JackrabbitTermQuery(term), SHOULD);
}
return b;
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class GQL method resolveChildNodeName.
/**
* Resolves the given node name. If the name has a prefix then the name
* is returned immediately as is. Otherwise the node type manager is
* searched for a node definition that defines a named child node with
* a local name that matches the provided <code>name</code>. If such a match
* is found the name of the node definition is returned.
*
* @param name the name of a node (optionally without a prefix).
* @return the resolved node name.
* @throws RepositoryException if an error occurs while reading from the
* node type manager.
*/
private String resolveChildNodeName(String name) throws RepositoryException {
if (isPrefixed(name)) {
return name;
}
if (childNodeNames == null) {
childNodeNames = new HashMap<String, String>();
NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
NodeTypeIterator it = ntMgr.getAllNodeTypes();
while (it.hasNext()) {
NodeType nt = it.nextNodeType();
NodeDefinition[] defs = nt.getDeclaredChildNodeDefinitions();
for (NodeDefinition def : defs) {
String cnn = def.getName();
if (!cnn.equals("*")) {
String localName = cnn;
int idx = cnn.indexOf(':');
if (idx != -1) {
localName = cnn.substring(idx + 1);
}
childNodeNames.put(localName, cnn);
}
}
}
}
String cnn = childNodeNames.get(name);
if (cnn != null) {
return cnn;
} else {
return name;
}
}
use of javax.jcr.nodetype.NodeTypeIterator in project jackrabbit by apache.
the class NodeMixinUtil method getNonExistingMixinName.
/**
* @return a string that is not the name of a mixin type
*/
public static String getNonExistingMixinName(Session session) throws RepositoryException {
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
NodeTypeIterator mixins = manager.getMixinNodeTypes();
StringBuffer s = new StringBuffer("X");
while (mixins.hasNext()) {
s.append(mixins.nextNodeType().getName());
}
return s.toString().replaceAll(":", "");
}
Aggregations