本文整理汇总了Java中javax.jcr.Repository类的典型用法代码示例。如果您正苦于以下问题:Java Repository类的具体用法?Java Repository怎么用?Java Repository使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Repository类属于javax.jcr包,在下文中一共展示了Repository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildRepository
import javax.jcr.Repository; //导入依赖的package包/类
Repository buildRepository(final JackrabbitConfiguration configuration) {
try {
ManagedRepository managedRepository = null;
MetricRegistry metricRegistry = null;
final RepositoryConfig config = RepositoryConfig.install(new File(configuration.getRepositoryXml()),
new File(configuration.getHomeDir()));
repository = RepositoryImpl.create(config);
managedRepository = new ManagedRepositoryImpl(repository, metricRegistry);
// final RepositoryConfig config1 = getRepositoryConfig();
// LOGGER.info("Connecting to local repository at {}",
// config1.getHomeDir());
// Repository rep1 = RepositoryImpl.create(config1);
return managedRepository;
} catch (Exception e) {
throw new RuntimeException("Could not create repository.", e);
}
}
示例2: getFactoryInstance
import javax.jcr.Repository; //导入依赖的package包/类
@Override
public Repository getFactoryInstance() throws UnknownHostException {
String[] hostArray = this.getHost().split(",");
List<String> hostList = Arrays.asList(hostArray);
List<ServerAddress> serverList = new ArrayList<ServerAddress>();
for( String hostURL : hostList){
ServerAddress sa = new ServerAddress(hostURL);
serverList.add(sa);
}
MongoClient mc = new MongoClient(serverList);
DB db = mc.getDB("gravity");
DocumentNodeStore ns = new DocumentMK.Builder().
setMongoDB(db).getNodeStore();
return new Jcr(new Oak(ns))
.with(new RepositoryIndexInitializer())
.withAsyncIndexing()
.createRepository();
}
示例3: getRemoteRepository
import javax.jcr.Repository; //导入依赖的package包/类
private Repository getRemoteRepository(Map map) throws Exception {
RemoteRegistry remoteRegistry;
Registry registry; // an admin registry
try {
RemoteRegistryService remoteRegistryService = new RemoteRegistryService(
(String) map.get("registryURL"),
(String) map.get("userName"),
(String) map.get("password"));
if (regRepo == null) {
regRepo = new RegistryRepository(remoteRegistryService);
}
} catch (Exception e) {
throw new Exception("Unable to create realm service " + e.getMessage());
}
return regRepo;
}
示例4: getSessionProvider
import javax.jcr.Repository; //导入依赖的package包/类
/**
* @see org.springframework.extensions.jcr.SessionHolderProviderManager#getSessionProvider(Repository)
*/
public SessionHolderProvider getSessionProvider(Repository repository) {
// graceful fallback
if (repository == null)
return defaultProvider;
String key = repository.getDescriptor(Repository.REP_NAME_DESC);
List<SessionHolderProvider> providers = getProviders();
// search the provider
for (int i = 0; i < providers.size(); i++) {
SessionHolderProvider provider = providers.get(i);
if (provider.acceptsRepository(key)) {
if (LOG.isDebugEnabled())
LOG.debug("specific SessionHolderProvider found for repository " + key);
return provider;
}
}
// no provider found - return the default one
if (LOG.isDebugEnabled())
LOG.debug("no specific SessionHolderProvider found for repository " + key + "; using the default one");
return defaultProvider;
}
示例5: getRepositorySize
import javax.jcr.Repository; //导入依赖的package包/类
/**
* Calculate the total size of all the binary properties in the repository
*
* @return size in bytes
*/
@Override
public Long getRepositorySize() {
try {
LOGGER.debug("Calculating repository size from index");
final Repository repo = getJcrRepository(repository);
try (final Timer.Context context = objectSizeCalculationTimer.time()) {
// Differentiating between the local getRepositorySize and
// ServiceHelpers
return ServiceHelpers.getRepositorySize(repo);
}
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}
示例6: getRepositoryCount
import javax.jcr.Repository; //导入依赖的package包/类
/**
* @param repository the repository
* @return a double of the size of the fedora:datastream binary content
* @throws RepositoryException if repository exception occurred
*/
public static long getRepositoryCount(final Repository repository)
throws RepositoryException {
final Session session = repository.login();
try {
final QueryManager queryManager =
session.getWorkspace().getQueryManager();
final String querystring =
"SELECT [" + JCR_PATH + "] FROM ["
+ FEDORA_CONTAINER + "]";
final QueryResult queryResults =
queryManager.createQuery(querystring, JCR_SQL2).execute();
return queryResults.getRows().getSize();
} finally {
session.logout();
}
}
示例7: getRepositorySize
import javax.jcr.Repository; //导入依赖的package包/类
/**
* @param repository the repository
* @return a double of the size of the fedora:datastream binary content
* @throws RepositoryException if repository exception occurred
*/
public static long getRepositorySize(final Repository repository)
throws RepositoryException {
final Session session = repository.login();
try {
long sum = 0;
final QueryManager queryManager =
session.getWorkspace().getQueryManager();
final String querystring =
"SELECT [" + CONTENT_SIZE + "] FROM [" +
FEDORA_BINARY + "]";
final QueryResult queryResults =
queryManager.createQuery(querystring, JCR_SQL2).execute();
for (final RowIterator rows = queryResults.getRows(); rows.hasNext(); ) {
final Value value =
rows.nextRow().getValue(CONTENT_SIZE);
sum += value.getLong();
}
return sum;
} finally {
session.logout();
}
}
示例8: getJcrFromFixture
import javax.jcr.Repository; //导入依赖的package包/类
public Session getJcrFromFixture(InputStream fixture) {
Repository repository = null;
Session session = null;
try {
repository = MockJcr.newRepository();
session = repository.login();
Node rootNode = session.getRootNode();
Yaml parser = new Yaml();
List<Map<String, Object>> nodes = (ArrayList<Map<String, Object>>) parser.load(fixture);
for (Map object: nodes) {
NodeYaml node = new NodeYaml(
(String) object.get("path"),
(String) object.get("primaryType"),
(Map<String, Object>) object.getOrDefault("properties", emptyMap())
);
Node n = rootNode.addNode(node.path, node.primaryType);
for (Map.Entry<String, Object> entry : node.properties.entrySet()) {
if (entry.getValue() instanceof Boolean) {
n.setProperty(entry.getKey(), (Boolean) entry.getValue());
} else {
n.setProperty(entry.getKey(), entry.getValue().toString());
}
}
}
session.save();
} catch (RepositoryException e) {
throw new RuntimeException("Failed to set property on JCR node", e);
}
return session;
}
示例9: setUp
import javax.jcr.Repository; //导入依赖的package包/类
@Before
@Override
public void setUp()
throws Exception
{
super.setUp();
File directory = new File( "target/test-repositories" );
if ( directory.exists() )
{
FileUtils.deleteDirectory( directory );
}
Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories();
// TODO: probably don't need to use Spring for this
Repository repository = applicationContext.getBean( Repository.class );
jcrMetadataRepository = new JcrMetadataRepository( factories, repository );
try
{
Session session = jcrMetadataRepository.getJcrSession();
// set up namespaces, etc.
JcrMetadataRepository.initialize( session );
// removing content is faster than deleting and re-copying the files from target/jcr
session.getRootNode().getNode( "repositories" ).remove();
}
catch ( RepositoryException e )
{
// ignore
}
this.repository = jcrMetadataRepository;
}
示例10: get
import javax.jcr.Repository; //导入依赖的package包/类
@Override
public Session get() {
if (session == null || !session.isLive()) {
try {
Repository repository = JcrUtils.getRepository(properties.getIp() + "/crx/server");
SimpleCredentials credentials = new SimpleCredentials(properties.getLogin(),
properties.getPassword().toCharArray());
session = repository.login(credentials);
} catch (RepositoryException e) {
LOG.error("Can't connect with jcr repository", e);
}
}
return session;
}
示例11: doStart
import javax.jcr.Repository; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
super.doStart();
ObjectHelper.notEmpty(host, "host", this);
this.repository = getCamelContext().getRegistry().lookupByNameAndType(host, Repository.class);
if (repository == null) {
throw new RuntimeCamelException("No JCR repository defined under '" + host + "'");
}
if (username != null && password != null) {
this.credentials = new SimpleCredentials(username, password.toCharArray());
}
}
示例12: checkLogin
import javax.jcr.Repository; //导入依赖的package包/类
private boolean checkLogin(Repository repository) throws RepositoryException {
boolean loginSuccessful = true;
Credentials credentials = new SimpleCredentials(userId, userPassword.toCharArray());
try {
repository.login(credentials).logout();
} catch (LoginException e) {
loginSuccessful = false;
}
return loginSuccessful;
}
示例13: initSession
import javax.jcr.Repository; //导入依赖的package包/类
public static void initSession() {
Repository repository = null;
char[] password = applicationProperties.getProperty(REPOSITORY_PASSWORD).toCharArray();
try {
repository = JcrUtils.getRepository(applicationProperties.getProperty(REPOSITORY_URL));
session = repository.login(new SimpleCredentials(applicationProperties.getProperty(REPOSITORY_USERNAME), password), applicationProperties.getProperty(ROOT_WORKSPACE_ID));
} catch (Exception a_excp) {
a_excp.printStackTrace();
System.out.println("Not able to get Source webdav connection");
JOptionPane.showMessageDialog(null, a_excp.getMessage(), "Couldn't open webdav to: " + applicationProperties.getProperty(REPOSITORY_URL), JOptionPane.ERROR_MESSAGE);
session = null;
applicationProperties.clear();
}
}
示例14: SessionImpl
import javax.jcr.Repository; //导入依赖的package包/类
public SessionImpl(Repository repository) {
this.repository = repository;
try {
addItem(new NodeImpl(this, "/"));
}
catch (RepositoryException re) { /* can't happen */ }
save();
}
示例15: getRepositoryInfo
import javax.jcr.Repository; //导入依赖的package包/类
/**
* A toString representation of the Repository.
* @return
*/
private String getRepositoryInfo() {
if (getRepository() == null) {
return "<N/A>";
}
StringBuffer buffer = new StringBuffer();
buffer.append(getRepository().getDescriptor(Repository.REP_NAME_DESC));
buffer.append(" ");
buffer.append(getRepository().getDescriptor(Repository.REP_VERSION_DESC));
return buffer.toString();
}