本文整理汇总了Java中javax.jcr.Workspace类的典型用法代码示例。如果您正苦于以下问题:Java Workspace类的具体用法?Java Workspace怎么用?Java Workspace使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Workspace类属于javax.jcr包,在下文中一共展示了Workspace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addListeners
import javax.jcr.Workspace; //导入依赖的package包/类
/**
* 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
*/
private Session addListeners(Session session) throws RepositoryException {
if (getRepository() == null) {
throw new IllegalArgumentException("repository is required");
}
if (eventListeners != null && eventListeners.length > 0) {
if (!supportsObservation(getRepository())) {
throw new IllegalArgumentException("repository " + getRepositoryInfo() + " does NOT support Observation; remove Listener definitions");
}
Workspace ws = session.getWorkspace();
ObservationManager manager = ws.getObservationManager();
for (EventListenerDefinition eventListener : eventListeners) {
manager.addEventListener(eventListener.getListener(), eventListener.getEventTypes(), eventListener.getAbsPath(), eventListener.isDeep(), eventListener.getUuid(), eventListener.getNodeTypeName(), eventListener.isNoLocal());
}
}
return session;
}
示例2: testJcrProducer
import javax.jcr.Workspace; //导入依赖的package包/类
@Test
public void testJcrProducer() throws Exception {
Exchange exchange = createExchangeWithBody("<hello>world!</hello>");
Exchange out = template.send("direct:a", exchange);
assertNotNull(out);
String uuid = out.getOut().getBody(String.class);
Session session = openSession(CUSTOM_WORKSPACE_NAME);
try {
Node node = session.getNodeByIdentifier(uuid);
Workspace workspace = session.getWorkspace();
assertEquals(CUSTOM_WORKSPACE_NAME, workspace.getName());
assertNotNull(node);
assertEquals("/home/test/node", node.getPath());
assertEquals("<hello>world!</hello>", node.getProperty("my.contents.property").getString());
} finally {
if (session != null && session.isLive()) {
session.logout();
}
}
}
示例3: registerNodeTypes
import javax.jcr.Workspace; //导入依赖的package包/类
@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();
}
}
示例4: addListeners
import javax.jcr.Workspace; //导入依赖的package包/类
/**
* 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;
}
示例5: removeVersion
import javax.jcr.Workspace; //导入依赖的package包/类
@Override
public void removeVersion(final FedoraSession session, final String absPath, final String label) {
final Session jcrSession = getJcrSession(session);
final Workspace workspace = jcrSession.getWorkspace();
try {
final Version v = getVersionForLabel(workspace, absPath, label);
if (v == null) {
throw new PathNotFoundException("Unknown version \"" + label + "\"!");
} else if (workspace.getVersionManager().getBaseVersion(absPath).equals(v) ) {
throw new VersionException("Cannot remove most recent version snapshot.");
} else {
// remove labels
final VersionHistory history = v.getContainingHistory();
final String[] versionLabels = history.getVersionLabels(v);
for ( final String versionLabel : versionLabels ) {
LOGGER.debug("Removing label: {}", versionLabel);
history.removeVersionLabel( versionLabel );
}
history.removeVersion( v.getName() );
}
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}
示例6: checkpoint
import javax.jcr.Workspace; //导入依赖的package包/类
private static String checkpoint(final Session session, final String absPath, final String label)
throws RepositoryException {
if (!validLabel(label)) {
throw new VersionException("Invalid label: " + label);
}
LOGGER.trace("Setting version checkpoint for {}", absPath);
final Workspace workspace = session.getWorkspace();
final VersionManager versionManager = workspace.getVersionManager();
final VersionHistory versionHistory = versionManager.getVersionHistory(absPath);
if (versionHistory.hasVersionLabel(label)) {
throw new LabelExistsVersionException("The specified label \"" + label
+ "\" is already assigned to another version of this resource!");
}
final Version v = versionManager.checkpoint(absPath);
if (v == null) {
return null;
}
versionHistory.addVersionLabel(v.getName(), label, false);
return v.getFrozenNode().getIdentifier();
}
示例7: testGetBaseVersion
import javax.jcr.Workspace; //导入依赖的package包/类
@Test
public void testGetBaseVersion() throws RepositoryException {
final Version mockVersion = mock(Version.class);
when(mockVersion.getName()).thenReturn("uuid");
final Workspace mockWorkspace = mock(Workspace.class);
when(mockSession.getWorkspace()).thenReturn(mockWorkspace);
final VersionManager mockVersionManager = mock(VersionManager.class);
when(mockWorkspace.getVersionManager()).thenReturn(mockVersionManager);
when(mockVersionManager.getBaseVersion(anyString())).thenReturn(
mockVersion);
testObj.getBaseVersion();
verify(mockVersionManager).getBaseVersion(anyString());
}
示例8: testGetVersionLabels
import javax.jcr.Workspace; //导入依赖的package包/类
@Test
public void testGetVersionLabels() throws RepositoryException {
when(mockNode.isNodeType(FROZEN_NODE)).thenReturn(true);
final VersionHistory mockVersionHistory = mock(VersionHistory.class);
final Version mockVersion = mock(Version.class);
when(mockVersion.getName()).thenReturn("uuid");
final Workspace mockWorkspace = mock(Workspace.class);
when(mockSession.getWorkspace()).thenReturn(mockWorkspace);
final VersionManager mockVersionManager = mock(VersionManager.class);
when(mockWorkspace.getVersionManager()).thenReturn(mockVersionManager);
final VersionIterator mockVersionIterator = mock(VersionIterator.class);
when(mockVersionHistory.getAllVersions()).thenReturn(mockVersionIterator);
when(mockVersionIterator.hasNext()).thenReturn(false);
when(mockVersionManager.getVersionHistory(anyString())).thenReturn(
mockVersionHistory);
testObj.getVersions();
verify(mockVersionManager).getVersionHistory(anyString());
}
示例9: getSessionMock
import javax.jcr.Workspace; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Session getSessionMock() throws RepositoryException {
final String[] mockPrefixes = {MOCK_PREFIX};
final Session mockSession = mock(Session.class);
final Workspace mockWorkspace = mock(Workspace.class);
final NamespaceRegistry mockNameReg = mock(NamespaceRegistry.class);
final NodeTypeManager mockNTM = mock(NodeTypeManager.class);
final NodeTypeIterator mockNTI = mock(NodeTypeIterator.class);
final NodeType mockNodeType = mock(NodeType.class);
when(mockSession.getWorkspace()).thenReturn(mockWorkspace);
when(mockWorkspace.getNamespaceRegistry()).thenReturn(mockNameReg);
when(mockNameReg.getPrefixes()).thenReturn(mockPrefixes);
when(mockNameReg.getURI(MOCK_PREFIX)).thenReturn(MOCK_URI_STRING);
when(mockWorkspace.getNodeTypeManager()).thenReturn(mockNTM);
when(mockNodeType.getName()).thenReturn("mockName");
when(mockNodeType.toString()).thenReturn("mockString");
when(mockNTM.getAllNodeTypes()).thenReturn(mockNTI);
when(mockNTI.hasNext()).thenReturn(true, false);
when(mockNTI.nextNodeType()).thenReturn(mockNodeType).thenThrow(
ArrayIndexOutOfBoundsException.class);
return mockSession;
}
示例10: setAclManagementCallback
import javax.jcr.Workspace; //导入依赖的package包/类
/**
* 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;
}
};
}
示例11: setAclManagement
import javax.jcr.Workspace; //导入依赖的package包/类
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;
}
} );
}
示例12: initialize
import javax.jcr.Workspace; //导入依赖的package包/类
static void initialize( Session session )
throws RepositoryException
{
// TODO: consider using namespaces for facets instead of the current approach:
// (if used, check if actually called by normal injection)
// for ( String facetId : metadataFacetFactories.keySet() )
// {
// session.getWorkspace().getNamespaceRegistry().registerNamespace( facetId, facetId );
// }
Workspace workspace = session.getWorkspace();
NamespaceRegistry registry = workspace.getNamespaceRegistry();
if ( !Arrays.asList( registry.getPrefixes() ).contains( "archiva" ) )
{
registry.registerNamespace( "archiva", "http://archiva.apache.org/jcr/" );
}
NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.NAMESPACE_NODE_TYPE );
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.PROJECT_NODE_TYPE );
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.PROJECT_VERSION_NODE_TYPE );
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.ARTIFACT_NODE_TYPE );
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.FACET_NODE_TYPE );
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.DEPENDENCY_NODE_TYPE );
}
示例13: setUp
import javax.jcr.Workspace; //导入依赖的package包/类
@Override
@Before
public void setUp()
throws Exception
{
super.setUp();
File confFile = new File( "src/test/repository.xml" );
File dir = new File( "target/jcr" );
FileUtils.deleteDirectory( dir );
assertTrue( confFile.exists() );
assertFalse( dir.exists() );
TransientRepository repository = new TransientRepository( confFile, dir );
session = repository.login( new SimpleCredentials( "username", "password".toCharArray() ) );
// TODO: perhaps have an archiva-jcr-utils module shared by these plugins that does this and can contain
// structure information
Workspace workspace = session.getWorkspace();
NamespaceRegistry registry = workspace.getNamespaceRegistry();
registry.registerNamespace( "archiva", "http://archiva.apache.org/jcr/" );
NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
registerMixinNodeType( nodeTypeManager, "archiva:namespace" );
registerMixinNodeType( nodeTypeManager, "archiva:project" );
registerMixinNodeType( nodeTypeManager, "archiva:projectVersion" );
registerMixinNodeType( nodeTypeManager, "archiva:artifact" );
registerMixinNodeType( nodeTypeManager, "archiva:facet" );
metadataRepository = mock( MetadataRepository.class );
when( metadataRepository.canObtainAccess( Session.class ) ).thenReturn( true );
when( metadataRepository.obtainAccess( Session.class ) ).thenReturn( session );
repositoryStatisticsManager = new DefaultRepositoryStatisticsManager();
}
示例14: setUp
import javax.jcr.Workspace; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
deleteDirectory(REPO_PATH);
super.setUp();
Session session = getRepository().login(new SimpleCredentials("user", "pass".toCharArray()));
Workspace workspace = session.getWorkspace();
workspace.createWorkspace(CUSTOM_WORKSPACE_NAME);
session.save();
session.logout();
}
示例15: executeMockQuery
import javax.jcr.Workspace; //导入依赖的package包/类
private void executeMockQuery(String workspace, String expectedQuery, List<Node> results) throws Exception {
Session mockSession = mock(Session.class);
Workspace mockWorkspace = mock(Workspace.class);
QueryManager mockQueryManager = mock(QueryManager.class);
Query mockQuery = mock(Query.class);
QueryResult mockQueryResult = mock(QueryResult.class);
doReturn(mockSession).when(mockWebContext).getJCRSession(workspace);
doReturn(mockWorkspace).when(mockSession).getWorkspace();
doReturn(mockQueryManager).when(mockWorkspace).getQueryManager();
doReturn(mockQuery).when(mockQueryManager).createQuery(expectedQuery, Query.JCR_SQL2);
doReturn(mockQueryResult).when(mockQuery).execute();
doReturn(new NodeIteratorAdapter(results)).when(mockQueryResult).getNodes();
}