use of javax.jcr.nodetype.NodeTypeManager in project jackrabbit-oak by apache.
the class RepositoryUpgradeTest method verifyReplacedBuiltinNodeTypes.
@Test
public void verifyReplacedBuiltinNodeTypes() throws Exception {
Session session = createAdminSession();
try {
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
NodeType nt = manager.getNodeType(UserConstants.NT_REP_GROUP);
assertTrue("Migrated repository must have new nodetype definitions", nt.isNodeType(UserConstants.NT_REP_MEMBER_REFERENCES));
} finally {
session.logout();
}
}
use of javax.jcr.nodetype.NodeTypeManager in project sling by apache.
the class JCRSupportImpl method isFileNodeType.
public Boolean isFileNodeType(final ResourceResolver resolver, final String nodeType) {
final Session session = resolver.adaptTo(Session.class);
if (session != null) {
try {
final NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
final NodeType nt = ntMgr.getNodeType(nodeType);
return nt.isNodeType(JcrConstants.NT_FILE);
} catch (RepositoryException e) {
// assuming type not valid.
return null;
}
}
return false;
}
use of javax.jcr.nodetype.NodeTypeManager in project sling by apache.
the class DownloadDefaultBinaryValueServlet method doGet.
@SuppressWarnings("deprecation")
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/octet-stream; charset=UTF-8");
String requestURI = request.getRequestURI();
String[] idFields = requestURI.substring(1).split("/");
try {
NodeTypeManager nodeTypeManager = request.getResourceResolver().getResource("/").adaptTo(Node.class).getSession().getWorkspace().getNodeTypeManager();
NodeType nodeType = nodeTypeManager.getNodeType(idFields[0]);
PropertyDefinition[] propertyDefinitions = nodeType.getPropertyDefinitions();
List<PropertyDefinition> propertyDefinitionList = Arrays.asList(propertyDefinitions);
if (propertyDefinitionList != null) {
// Every matcher represents a path element in the URL and is initialized with its value.
// It will try to match the value of a path element with the corresponding property
// element of all property definitions from the node type in findMatchingPropertyDef().
PropertyMatcher[] propertyMatcher = new PropertyMatcher[] { new PropertyNameMatcher(idFields, 1), new RequiredPropertyTypeMatcher(idFields, 2), new AutoCreatedMatcher(idFields, 3), new MandatoryMatcher(idFields, 4), new ProtectedMatcher(idFields, 5), new MultipleMatcher(idFields, 6), new OnParentVersionMatcher(idFields, 7) };
PropertyDefinition propDef = findMatchingPropertyDef(propertyDefinitionList, new LinkedList<PropertyMatcher>(Arrays.asList(propertyMatcher)));
if (propDef != null) {
Value[] defaultValues = propDef.getDefaultValues();
if (defaultValues != null && defaultValues.length > 0) {
int startIndex = requestURI.lastIndexOf('/') + 1;
int endIndex = requestURI.indexOf("default_binary_value.bin") - 1;
int defaultValueIndex = 0;
if (endIndex - startIndex == 1) {
String indexString = requestURI.substring(startIndex, endIndex);
defaultValueIndex = Integer.parseInt(indexString);
}
try {
if (defaultValueIndex < defaultValues.length) {
Value defaultValue = defaultValues[defaultValueIndex];
InputStream stream = defaultValue.getStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream));
PrintWriter writer = response.getWriter();
String line = null;
while ((line = bufferedReader.readLine()) != null) {
writer.write(line);
}
writer.flush();
writer.close();
response.setStatus(HttpServletResponse.SC_OK);
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} catch (NumberFormatException nfe) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
} else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
} catch (RepositoryException e) {
log.error("Could not return the binary file.", e);
throw new ServletException(e);
}
}
Aggregations