09-14-2006 03:23 PM
public class FirstJCRClient extends GenericPortlet
{
protected void doView(RenderRequest rRequest, RenderResponse rResponse)
throws PortletException, IOException, UnavailableException
{
// access the Alfresco JCR Repository (here it's via programmatic approach, but it could also be injected)
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:jcr-api-context.xml");
Repository repository = (Repository)context.getBean("JCR.Repository");
// login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
Session session = null;
try
{
session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
// first, access the company home
Node rootNode = session.getRootNode();
Node companyHome = rootNode.getNode("app:company_home/index.html");
rResponse.setContentType("text/html");
PrintWriter writer = rResponse.getWriter();
String content = companyHome.getProperty("cm:content").toString();
writer.write("Content:<P>");
writer.write(content);
writer.close();
session.save();
}
catch(RepositoryException re)
{
}
finally
{
session.logout();
System.exit(0);
}
}
09-15-2006 12:37 PM
<!– Expose the bean via RMI (http://www.springframework.org/docs/reference/remoting.html - JKT&JDP) –>
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<!– does not necessarily have to be the same name as the bean to be exported –>
<property name="serviceName" value="AlfrescoJcrRepository"/>
<property name="service" ref="JCR.Repository"/>
<property name="serviceInterface" value="javax.jcr.Repository"/>
<!– defaults to 1099 –>
<property name="registryPort" value="1199"/>
</bean>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:com/raf/portal/drippy/firstclient/context.xml
</param-value>
<description>Spring config file locations</description>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="repositoryUser" class="com.raf.portal.drippy.firstclient.RepositoryUser">
<property name="alfrescoJcrRepository" ref="alfrescoJcrRepositoryProxy"/>
</bean>
<bean id="alfrescoJcrRepositoryProxy" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://localhost:1199/AlfrescoJcrRepository"/>
<property name="serviceInterface" value="javax.jcr.Repository"/>
</bean>
</beans>
package com.raf.portal.drippy.firstclient;
import javax.jcr.Repository;
public class RepositoryUser {
private Repository alfrescoJcrRepository;
/**
* IoC setter
* @param alfrescoJcrRepository
*/
public void setAlfrescoJcrRepository(Repository alfrescoJcrRepository) {
this.alfrescoJcrRepository = alfrescoJcrRepository;
}
public Repository getAlfrescoJcrRepository() {
return alfrescoJcrRepository;
}
}
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package com.raf.portal.drippy;
import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import org.alfresco.jcr.api.JCRNodeRef;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import com.raf.foundation.log.Log;
import com.raf.portal.drippy.firstclient.RepositoryUser;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.UnavailableException;
import java.io.IOException;
import java.io.PrintWriter;
/**
* Simple client example demonstrating the use of the Alfresco JCR (JSR-170) API.
*
* The client creates a content node in the "Company Home" folder. The content
* may be viewed and operated on within the Alfresco Web Client. Note: the web client
* will need to be re-started after executing this sample to see the changes in
* effect.
*
* This client demonstrates the "Embedded Repository" deployment option as described
* in the Alfresco Respotiory Architecture docucment -
* http://wiki.alfresco.com/wiki/Alfresco_Repository_Architecture
*/
public class FirstJCRClient extends GenericPortlet
{
protected void doView(RenderRequest rRequest, RenderResponse rResponse)
throws PortletException, IOException, UnavailableException
{
// access the Alfresco JCR Repository (here it's via programmatic approach, but it could also be injected)
WebApplicationContext context = (WebApplicationContext)getPortletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
RepositoryUser user = (RepositoryUser)context.getBean("repositoryUser");
Repository repository = user.getAlfrescoJcrRepository();
// login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
Session session = null;
try
{
session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
// first, access the company home
Node rootNode = session.getRootNode();
Node companyHome = rootNode.getNode("app:company_home/index.html");
rResponse.setContentType("text/html");
PrintWriter writer = rResponse.getWriter();
String content = companyHome.getProperty("cm:content").toString();
writer.write("Content:<P>");
writer.write(content);
writer.close();
// save changes
session.save();
}
catch(Exception e)
{
Log.error(this,"Something bad happened: ",e);
}
}
09-15-2006 03:42 PM
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.