javax.jcr.Workspace Java Examples

The following examples show how to use javax.jcr.Workspace. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JackrabbitSessionFactory.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void registerNodeTypes() throws Exception {
    if (!ObjectUtils.isEmpty(nodeDefinitions)) {

        Session session = getBareSession();
        Workspace ws = session.getWorkspace();

        NodeTypeManagerImpl jackrabbitNodeTypeManager = (NodeTypeManagerImpl) ws.getNodeTypeManager();

        boolean debug = LOG.isDebugEnabled();
        for (int i = 0; i < nodeDefinitions.length; i++) {
            Resource resource = nodeDefinitions[i];
            if (debug) {
                LOG.debug("adding node type definitions from " + resource.getDescription());
            }
            try {
                //                    ws.getNodeTypeManager().registerNodeType(ntd, allowUpdate)
                jackrabbitNodeTypeManager.registerNodeTypes(resource.getInputStream(), contentType);
            } catch (RepositoryException ex) {
                LOG.error("Error registering nodetypes ", ex.getCause());
            }
        }
        session.logout();
    }
}
 
Example #2
Source File: JcrSessionFactory.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Hook for adding listeners to the newly returned session. We have to treat
 * exceptions manually and can't reply on the template.
 * 
 * @param session
 *            JCR session
 * @return the listened session
 * @throws javax.jcr.RepositoryException
 */
protected Session addListeners(Session session) throws RepositoryException {
	if (eventListeners != null && eventListeners.length > 0) {
		Workspace ws = session.getWorkspace();
		ObservationManager manager = ws.getObservationManager();

		LOG.debug("adding listeners "
				+ Arrays.asList(eventListeners).toString()
				+ " for session " + session);

		for (int i = 0; i < eventListeners.length; i++) {
			manager.addEventListener(eventListeners[i].getListener(),
					eventListeners[i].getEventTypes(),
					eventListeners[i].getAbsPath(),
					eventListeners[i].isDeep(),
					eventListeners[i].getUuid(),
					eventListeners[i].getNodeTypeName(),
					eventListeners[i].isNoLocal());
		}
	}
	return session;
}
 
Example #3
Source File: PurRepositoryTestingUtils.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@linkplain JcrCallback} for setting up ACL management in test repository
 * 
 * @return acl management callback
 */
static JcrCallback setAclManagementCallback() {
  return new JcrCallback() {
    @Override
    public Object doInJcr( Session session ) throws IOException, RepositoryException {
      PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants( session );
      Workspace workspace = session.getWorkspace();
      PrivilegeManager privilegeManager = ( (JackrabbitWorkspace) workspace ).getPrivilegeManager();
      try {
        privilegeManager.getPrivilege( pentahoJcrConstants.getPHO_ACLMANAGEMENT_PRIVILEGE() );
      } catch ( AccessControlException ace ) {
        privilegeManager.registerPrivilege( pentahoJcrConstants.getPHO_ACLMANAGEMENT_PRIVILEGE(), false,
            new String[0] );
      }
      session.save();
      return null;
    }
  };
}
 
Example #4
Source File: UIEERepositoryDirectoryIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void setAclManagement() {
  testJcrTemplate.execute( new JcrCallback() {
    @Override
    public Object doInJcr( Session session ) throws IOException, RepositoryException {
      PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants( session );
      Workspace workspace = session.getWorkspace();
      PrivilegeManager privilegeManager = ( (JackrabbitWorkspace) workspace ).getPrivilegeManager();
      try {
        privilegeManager.getPrivilege( pentahoJcrConstants.getPHO_ACLMANAGEMENT_PRIVILEGE() );
      } catch ( AccessControlException ace ) {
        privilegeManager.registerPrivilege( pentahoJcrConstants.getPHO_ACLMANAGEMENT_PRIVILEGE(), false,
            new String[0] );
      }
      session.save();
      return null;
    }
  } );
}
 
Example #5
Source File: CatalogDataResourceProviderManagerImpl.java    From commerce-cif-connector with Apache License 2.0 5 votes vote down vote up
/**
 * Find all existing virtual catalog data roots using all query defined in service configuration.
 *
 * @param resolver Resource resolver
 * @return all virtual catalog roots
 */
@SuppressWarnings("unchecked")
private List<Resource> findDataRoots(ResourceResolver resolver) {
    List<Resource> allResources = new ArrayList<>();
    for (String queryString : this.findAllQueries) {
        if (!StringUtils.contains(queryString, "|")) {
            throw new IllegalArgumentException("Query string does not contain query syntax seperated by '|': " + queryString);
        }
        String queryLanguage = StringUtils.substringBefore(queryString, "|");
        String query = StringUtils.substringAfter(queryString, "|");
        // data roots are JCR nodes, so we prefer JCR query because the resource resolver appears to be unreliable
        // when we are in the middle of registering/unregistering resource providers
        try {
            Session session = resolver.adaptTo(Session.class);
            Workspace workspace = session.getWorkspace();
            QueryManager qm = workspace.getQueryManager();
            Query jcrQuery = qm.createQuery(query, queryLanguage);
            QueryResult result = jcrQuery.execute();
            NodeIterator nodes = result.getNodes();
            while (nodes.hasNext()) {
                Node node = nodes.nextNode();
                Resource resource = resolver.getResource(node.getPath());
                if (resource != null) {
                    allResources.add(resource);
                }
            }
        } catch (RepositoryException x) {
            log.error("Error finding data roots", x);
        }
    }
    dataRoots = allResources;
    return allResources;
}
 
Example #6
Source File: SessionImpl.java    From jackalope with Apache License 2.0 5 votes vote down vote up
@Override
public Workspace getWorkspace() {
    if (workspace == null) {
        WorkspaceImpl workspaceImpl = new WorkspaceImpl();
        workspaceImpl.setSession(this);
        workspace = workspaceImpl;
    }
    return workspace;
}
 
Example #7
Source File: JackrabbitSessionWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public Workspace getWorkspace() {
    return new JackrabbitWorkspaceWrapper(this, (JackrabbitWorkspace) this.wrappedSession.getWorkspace());
}
 
Example #8
Source File: SessionWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public Workspace getWorkspace() {
    return new WorkspaceWrapper(this, this.wrappedSession.getWorkspace());
}
 
Example #9
Source File: JackrabbitPrivilegeInstaller.java    From jackrabbit-filevault with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Collection<Privilege> install(ProgressTracker tracker, PrivilegeDefinitions defs)
        throws IOException, RepositoryException {

    Workspace wsp = session.getWorkspace();
    if (!(wsp instanceof JackrabbitWorkspace)) {
        throw new RepositoryException("Unable to register privileges. No JackrabbitWorkspace.");
    }
    PrivilegeManager mgr = ((JackrabbitWorkspace) wsp).getPrivilegeManager();

    ProgressTrackerListener.Mode mode = null;
    if (tracker != null) {
        mode = tracker.setMode(ProgressTrackerListener.Mode.TEXT);
    }

    JcrNamespaceHelper nsHelper = new JcrNamespaceHelper(session, tracker);

    // register namespaces
    nsHelper.registerNamespaces(defs.getNamespaceMapping().getPrefixToURIMapping());

    // register node types
    List<Privilege> registeredPrivs = new LinkedList<Privilege>();
    for (PrivilegeDefinition def: defs.getDefinitions()) {
        String name = getJCRName(def.getName());
        Privilege priv = null;
        try {
            priv = mgr.getPrivilege(name);
        } catch (RepositoryException e) {
            // ignore, already registered
        }
        if (priv == null) {
            String[] aggregateNames = new String[def.getDeclaredAggregateNames().size()];
            int i=0;
            for (Name n: def.getDeclaredAggregateNames()) {
                aggregateNames[i++] = getJCRName(n);
            }
            registeredPrivs.add(mgr.registerPrivilege(name, def.isAbstract(), aggregateNames));
            track(tracker, "A", name);
        } else {
            track(tracker, "-", name);
        }
    }

    if (tracker != null) {
        tracker.setMode(mode);
    }
    return registeredPrivs;
}
 
Example #10
Source File: StorageUpdate0.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void createNodeTypes() throws RepositoryException {
   	Session session = SessionFactoryUtils.getSession(getTemplate().getSessionFactory(), false);
   	Workspace workspace = session.getWorkspace();
   	
   	LOG.info("Registering namespace 'next' -> http://nextreports.ro/jcr/2.0");
       NamespaceRegistry namespaceRegistry = workspace.getNamespaceRegistry();
       namespaceRegistry.registerNamespace("next", "http://nextreports.ro/jcr/2.0");

   	/*
       // check if the node type is registered already
	if (nodeTypeManager.hasNodeType(NEXT_REPORT_MIXIN)) {
		return;
	}
	*/

   	LOG.info("Creating node type mixin '" + StorageConstants.NEXT_REPORT_MIXIN + "'");
   	NodeTypeManagerImpl nodeTypeManager = (NodeTypeManagerImpl) workspace.getNodeTypeManager();
   	NodeTypeTemplate nodeTypeTemplate = nodeTypeManager.createNodeTypeTemplate();
   	nodeTypeTemplate.setName(StorageConstants.NEXT_REPORT_MIXIN);
   	nodeTypeTemplate.setMixin(true);
   	nodeTypeTemplate.setOrderableChildNodes(false);
   	nodeTypeTemplate.setPrimaryItemName("nt:unstructured");
   	nodeTypeTemplate.setDeclaredSuperTypeNames(new String[] { "mix:referenceable", "mix:versionable" });

   	/*
   	PropertyDefinitionTemplate propertyDefinitionTemplate = nodeTypeManager.createPropertyDefinitionTemplate();
   	propertyDefinitionTemplate.setName("*");
   	propertyDefinitionTemplate.setRequiredType(PropertyType.UNDEFINED);
   	propertyDefinitionTemplate.setAutoCreated(false);
   	propertyDefinitionTemplate.setMandatory(false);
   	propertyDefinitionTemplate.setOnParentVersion(OnParentVersionAction.COPY);
   	propertyDefinitionTemplate.setProtected(false);
   	propertyDefinitionTemplate.setMultiple(false);

   	nodeTypeTemplate.getPropertyDefinitionTemplates().add(propertyDefinitionTemplate);
   	*/

   	NodeDefinitionTemplate nodeDefinitionTemplate = nodeTypeManager.createNodeDefinitionTemplate();
   	nodeDefinitionTemplate.setName("runHistory");
   	nodeDefinitionTemplate.setDefaultPrimaryTypeName("nt:unstructured");
   	nodeDefinitionTemplate.setRequiredPrimaryTypeNames(new String[] { "nt:unstructured" });
   	nodeDefinitionTemplate.setAutoCreated(true);
   	nodeDefinitionTemplate.setMandatory(false);
   	nodeDefinitionTemplate.setOnParentVersion(OnParentVersionAction.IGNORE);
   	nodeDefinitionTemplate.setProtected(false);
   	nodeDefinitionTemplate.setSameNameSiblings(false);

   	nodeTypeTemplate.getNodeDefinitionTemplates().add(nodeDefinitionTemplate);

   	LOG.info("Registering node type mixin '" + StorageConstants.NEXT_REPORT_MIXIN + "'");
   	nodeTypeManager.registerNodeType(nodeTypeTemplate, true);

   	getTemplate().save();
}
 
Example #11
Source File: StorageUpdate13.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
	private void createNodeTemplates() throws RepositoryException {
		Session session = SessionFactoryUtils.getSession(getTemplate().getSessionFactory(), false);
    	Workspace workspace = session.getWorkspace();
    	    	
    	NodeTypeManagerImpl nodeTypeManager = (NodeTypeManagerImpl) workspace.getNodeTypeManager();
//    	nodeTypeManager.unregisterNodeType(StorageConstants.NEXT_REPORT_MIXIN);
    	    	
    	NodeTypeTemplate nodeTypeTemplate = nodeTypeManager.createNodeTypeTemplate();
    	nodeTypeTemplate.setName(StorageConstants.NEXT_REPORT_MIXIN);
    	nodeTypeTemplate.setMixin(true);
    	nodeTypeTemplate.setOrderableChildNodes(false);
    	nodeTypeTemplate.setPrimaryItemName("nt:unstructured");
    	nodeTypeTemplate.setDeclaredSuperTypeNames(new String[] { "mix:referenceable", "mix:versionable" });   
    	
    	NodeDefinitionTemplate nodeDefinitionTemplate = nodeTypeManager.createNodeDefinitionTemplate();
    	nodeDefinitionTemplate.setName("runHistory");
    	nodeDefinitionTemplate.setDefaultPrimaryTypeName("nt:unstructured");
    	nodeDefinitionTemplate.setRequiredPrimaryTypeNames(new String[] { "nt:unstructured" });
    	nodeDefinitionTemplate.setAutoCreated(true);
    	nodeDefinitionTemplate.setMandatory(false);
    	nodeDefinitionTemplate.setOnParentVersion(OnParentVersionAction.IGNORE);
    	nodeDefinitionTemplate.setProtected(false);
    	nodeDefinitionTemplate.setSameNameSiblings(false);

    	nodeTypeTemplate.getNodeDefinitionTemplates().add(nodeDefinitionTemplate);
    	    	
    	NodeDefinitionTemplate nodeDefinitionTemplate2 = nodeTypeManager.createNodeDefinitionTemplate();
    	nodeDefinitionTemplate2.setName("templates");
    	nodeDefinitionTemplate2.setDefaultPrimaryTypeName("nt:unstructured");
    	nodeDefinitionTemplate2.setRequiredPrimaryTypeNames(new String[] { "nt:unstructured" });
    	nodeDefinitionTemplate2.setAutoCreated(true);
    	nodeDefinitionTemplate2.setMandatory(false);
    	nodeDefinitionTemplate2.setOnParentVersion(OnParentVersionAction.IGNORE);
    	nodeDefinitionTemplate2.setProtected(false);
    	nodeDefinitionTemplate2.setSameNameSiblings(false);
    	
    	nodeTypeTemplate.getNodeDefinitionTemplates().add(nodeDefinitionTemplate2);

    	LOG.info("Registering node type mixin '" + StorageConstants.NEXT_REPORT_MIXIN + "'");
    	nodeTypeManager.registerNodeType(nodeTypeTemplate, true);
    	
    	// add templates node to all existing reports
    	String statement = 
				"/jcr:root" + ISO9075.encodePath(StorageConstants.REPORTS_ROOT) + 
				"//*[@className='ro.nextreports.server.domain.Report']";
		  
		QueryResult queryResult = getTemplate().query(statement);
		NodeIterator nodes = queryResult.getNodes();
		
		LOG.info("Create templates nodes : Found " + nodes.getSize() + " report nodes");
		while (nodes.hasNext()) {			
			Node node = nodes.nextNode();
			node.addNode("templates");
		}					

    	getTemplate().save();
	}