11-29-2005 10:15 PM
11-30-2005 01:34 AM
Hello,
I have an existing CMS. I would like to use Alfresco's implementation of JSR-170 to be the back-end store. Can you point me to the most straight-forward code-sample with which I can "instantiate/initialize" the JCR back-end (I guess through some sort of factory)? In the meantime, I will try to find out by going through the code.
Thanks,
Hanan
public byte[] retrieveContent(String pContentMoniker)
throws RetrievalFailureException
{
/* define locals */
byte[] vRetContentBytes = null;
Repository vInstJcrRepository = null;
String vInstUsername = null;
String vInstPassword = null;
TransactionProvider vInstTransactionProvider = null;
Session vSession = null;
Credentials vCredentials = null;
UserTransaction vTransaction = null;
Node vContentNode = null;
Property vContentProperty = null;
Value vContentPropertyValue = null;
int vByteCount = 0;
/* initialize */
vInstJcrRepository = getJavaContentRepository();
vInstTransactionProvider = getTransactionProvider();
vInstUsername = getUsername();
vInstPassword = getPassword();
try
{
vCredentials = new SimpleCredentials(vInstUsername, vInstPassword.toCharArray());
vSession = vInstJcrRepository.login(vCredentials);
if(vInstTransactionProvider!=null)
{
vTransaction = vInstTransactionProvider.provideUserTransaction();
vTransaction.begin();
}
vContentNode = vSession.getNodeByUUID(pContentMoniker);
if(vContentNode!=null)
{
vContentProperty = vContentNode.getProperty("cm:content");
vContentPropertyValue = vContentProperty.getValue();
vByteCount = vContentPropertyValue.getStream().available();
vRetContentBytes = new byte[vByteCount];
vContentPropertyValue.getStream().read(vRetContentBytes);
}
}
catch(Exception eRepositoryFailure)
{
System.out.println("repository failure ["+eRepositoryFailure+"]");
try{ if(vTransaction!=null){ vTransaction.rollback(); } }catch(Exception eMuted){}
}
finally
{
try{ if(vTransaction!=null){ vTransaction.commit(); } }catch(Exception eMuted){}
}
return vRetContentBytes;
};
11-30-2005 03:28 AM
Hello,
I have an existing CMS. I would like to use Alfresco's implementation of JSR-170 to be the back-end store. Can you point me to the most straight-forward code-sample with which I can "instantiate/initialize" the JCR back-end (I guess through some sort of factory)? In the meantime, I will try to find out by going through the code.
Thanks,
Hanan
Is your application already expecting to consume a jcr repository? At the moment alfresco only supports level I of the JCR spec (read only is the easiest way to describe it.) They are working on level II at the moment.
How are you planning to run the repository? In the same jvm? rebuild the app on top of a jcr implementation? pick up a jcr reference from JNDI?
just curious.
The best example is the simple example located in the alfresco jcr project located in the eamples folder in the alfresco source distribution.
In case you dont want to get that… here is a fragment for reading a document:
public byte[] retrieveContent(String pContentMoniker)
throws RetrievalFailureException
{
/* define locals */
byte[] vRetContentBytes = null;
Repository vInstJcrRepository = null;
String vInstUsername = null;
String vInstPassword = null;
TransactionProvider vInstTransactionProvider = null;
Session vSession = null;
Credentials vCredentials = null;
UserTransaction vTransaction = null;
Node vContentNode = null;
Property vContentProperty = null;
Value vContentPropertyValue = null;
int vByteCount = 0;
/* initialize */
vInstJcrRepository = getJavaContentRepository();
vInstTransactionProvider = getTransactionProvider();
vInstUsername = getUsername();
vInstPassword = getPassword();
try
{
vCredentials = new SimpleCredentials(vInstUsername, vInstPassword.toCharArray());
vSession = vInstJcrRepository.login(vCredentials);
if(vInstTransactionProvider!=null)
{
vTransaction = vInstTransactionProvider.provideUserTransaction();
vTransaction.begin();
}
vContentNode = vSession.getNodeByUUID(pContentMoniker);
if(vContentNode!=null)
{
vContentProperty = vContentNode.getProperty("cm:content");
vContentPropertyValue = vContentProperty.getValue();
vByteCount = vContentPropertyValue.getStream().available();
vRetContentBytes = new byte[vByteCount];
vContentPropertyValue.getStream().read(vRetContentBytes);
}
}
catch(Exception eRepositoryFailure)
{
System.out.println("repository failure ["+eRepositoryFailure+"]");
try{ if(vTransaction!=null){ vTransaction.rollback(); } }catch(Exception eMuted){}
}
finally
{
try{ if(vTransaction!=null){ vTransaction.commit(); } }catch(Exception eMuted){}
}
return vRetContentBytes;
};
Initializing the repository (in the case of the example: the value behind getJavaContentRepository()) is a matter of implementation. Like I said before you can do it any number of a hundred different way.
The easiest is to build right on top of alfresco by including alfrescos jars and spring configuration in you app. In this case you would just wire the jcr interface to your consuming classes with spring.
This approach is not so hot unless you are looking to embed alfresco or unless you just want to play.
An alternative approach is to load alfresco in one context, register the alfresco jcr repository implemenation bean in JNDI and load you app up in a different context looking to JNDI for a repository.
In addition to that you can put any number of remote mechanisms between your application and the real deal so to speak. RMI will work well if you are geographically close and have no firewalls to deal with. Web services works as well if you have to talk on port 80. Both will incurr a performance penalty.
Hope this helps
11-30-2005 04:03 AM
11-30-2005 04:59 AM
HiHi Andy,
I may be missing the point here …. and you may want the JCR170 API….
Could you use the WebDAV interface to the repository instead?
It sounds like you may be able to reuse your existing wrapper.
Regards
Andy
11-30-2005 05:38 AM
11-30-2005 07:09 AM
There are three public Alfresco API's:
- Web Services (remote access)
- Java Services (local access, full implementation as used by our own Web Client)
- JCR (standards based, level 1 now, level 2 in development)
For information on the Java Service API take a look at http://www.alfresco.org/mediawiki/index.php/Alfresco_Content_Management_Java_API
11-30-2005 08:30 AM
Superb. This cut down my research time. Frankly, haven't had much uninterrupted time to work on this. Tomorrow first thing, I will try these out, following the examples in the WIKI link you provided.
The Web Services seems intriguing. Is it well tested? At least more than the WebDAV (in which there were a few bugs)?
Thanks so much for your quick response, wish I could pay part of your salary.
HananThere are three public Alfresco API's:
- Web Services (remote access)
- Java Services (local access, full implementation as used by our own Web Client)
- JCR (standards based, level 1 now, level 2 in development)
For information on the Java Service API take a look at http://www.alfresco.org/mediawiki/index.php/Alfresco_Content_Management_Java_API
12-01-2005 10:53 PM
There are three public Alfresco API's:
- Web Services (remote access)
- Java Services (local access, full implementation as used by our own Web Client)
- JCR (standards based, level 1 now, level 2 in development)
For information on the Java Service API take a look at http://www.alfresco.org/mediawiki/index.php/Alfresco_Content_Management_Java_API
12-02-2005 05:09 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.