Jahia in English > When I deploy a...

0 (0 Good)
0 (0 Bad)

When I deploy a module to Jahia, I got an error message " zip file closed"

by  omglion »  2014/07/22 03:37

Hello, everybody,

Could anyone help me to solve the problem?

Here is the source codes (that is for reading datas from an external datasource like mysql):

package com.caii.modules.caiidbprovider;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;
import javax.jcr.ItemNotFoundException;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;

import net.sf.ehcache.CacheException;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;

import org.apache.commons.lang.StringUtils;
import org.jahia.modules.external.ExternalData;
import org.jahia.modules.external.ExternalDataSource;
import org.jahia.services.cache.ehcache.EhCacheProvider;

import com.caii.modules.caiidbprovider.dao.PersonDao;
import com.caii.modules.caiidbprovider.domain.Person;
import com.google.common.collect.Sets;

public class CaiiDataSource implements ExternalDataSource {
    
    private EhCacheProvider ehCacheProvider;
    private Ehcache cache;
    
    @Resource
    private PersonDao personDao;
    
    public CaiiDataSource() {
        super();
    }
    
    public void setCacheProvider(EhCacheProvider ehCacheProvider) {
        this.ehCacheProvider = ehCacheProvider;
    }
    
    public void start(){
        try {
            if(!ehCacheProvider.getCacheManager().cacheExists("caiidb-cache")){
                ehCacheProvider.getCacheManager().addCache("caiidb-cache");
            }
            cache = ehCacheProvider.getCacheManager().getCache("caiidb-cache");
            
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (CacheException e) {
            e.printStackTrace();  
        }
    }

    @Override
    public List<String> getChildren(String path) throws RepositoryException {
        return null;
    }

    @Override
    public ExternalData getItemByIdentifier(String identifier) throws ItemNotFoundException {
        try {
            if(identifier.equals("root")){
                return new ExternalData(identifier, "/", "jnt:contentFolder", new HashMap<String, String[]>());
            }
            
            if(identifier.equals("persons-folder")){
                final String s = StringUtils.substringBefore(identifier, "-folder");
                
                return new ExternalData(identifier, "/" + s, "jnt:contentFolder", new HashMap<String, String[]>());
            } else if (identifier.startsWith("personId-")) {
                String personId = StringUtils.substringAfter(identifier, "personId-");
                
                try {
                    Integer.parseInt(personId);
                } catch (NumberFormatException e) {
                    throw new ItemNotFoundException(identifier);
                }
                
                Person person = null;
                
                if (cache.get("personId-" + personId) != null) {
                    person = (Person) cache.get("personId-" + personId).getObjectValue();
                } else {
                    person = personDao.findPersonById(personId);
                    cache.put(new Element("personId-" + personId, person));
                }
                
                Map<String, String[]> properties = new HashMap<String, String[]>();
                
                if(person.getPersonId() != null){
                    properties.put("person_id", new String[]{person.getPersonId() + ""});
                }
                
                if(!StringUtils.isBlank(person.getName())){
                    properties.put("name", new String[]{person.getName()});
                }
                
                ExternalData externalData = new ExternalData(
                        identifier, "/persons/" + personId, "caiint:person", properties);
                
                return externalData;                
                
            }
            
        } catch (Exception e) {
            throw new ItemNotFoundException(e);
        }
        
        throw new ItemNotFoundException(identifier);
    }

    /**
     * the path of external data node is:
     *"/persons/123"
     *123 is id
     * */
    @Override
    public ExternalData getItemByPath(String path) throws PathNotFoundException {
        
        String[] splitPath = path.split("/");
        
        try {
            if (path.endsWith("j:acl")) {
                throw new PathNotFoundException(path);                
            }
            
            if (splitPath.length <= 1) {
                return getItemByIdentifier("root");
            } else if (splitPath[1].equals("persons")) {
                switch(splitPath.length){
                case 2:
                    return getItemByIdentifier("persons-folder");
                case 3:
                    return getItemByIdentifier("personId-" + splitPath[2]);                
                }                
            } 
            
        } catch (ItemNotFoundException e) {
            throw new PathNotFoundException(e);
        }
        
        throw new PathNotFoundException();
    }

    @Override
    public Set<String> getSupportedNodeTypes() {
        return Sets.newHashSet("jnt:contentFolder", "caiint:person");
    }

    @Override
    public boolean isSupportsHierarchicalIdentifiers() {
        return false;
    }

    @Override
    public boolean isSupportsUuid() {
        return false;
    }

    @Override
    public boolean itemExists(String path) {
        return false;
    }

}

And the Spring xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:osgi="http://www.eclipse.org/gemini/blueprint/schema/blueprint"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context" 
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.eclipse.org/gemini/blueprint/schema/blueprint http://www.eclipse.org/gemini/blueprint/schema/blueprint/gemini-blueprint.xsd
                        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
                        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
                        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">  
    
    <!-- 将OSGI服务转换成bean,以便调用 -->
    <osgi:reference id="ExternalProviderInitializerService" interface="org.jahia.modules.external.ExternalProviderInitializerService"/>
    <osgi:reference id="ehCacheProvider" interface="org.jahia.services.cache.ehcache.EhCacheProvider"/>
    
    <!-- 启动扫描 -->
    <context:component-scan base-package="com.caii.modules"/>
    
    <!--默认使用JDK动态代理,如果没有实现接口,自动用CGLIB动态代理-->
    <aop:aspectj-autoproxy/>
    
    <!-- DataSource 用于管理数据库的连接 -->
    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost/test?useUnicode=true&amp;characterEncoding=UTF-8" />
        <property name="username" value="root" />
        <property name="password" value="1234" />
    </bean>
    
    <!-- 事务管理器 -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
    <!-- 声明注解事务 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="caiiPU" />
        <property name="dataSource" ref="dataSource" />
    </bean>
    
    <!--Provider Definition 用于映射数据到JCR-->
    <bean id="caiiDBProvider" class="org.jahia.modules.external.ExternalContentStoreProvider" parent="AbstractJCRStoreProvider" >
        <property name="key" value="caiiDBProvider"/>
        <property name="mountPoint" value="/sites/caiisite/contents/caii-db-provider"/>
        <property name="externalProviderInitializerService" ref="ExternalProviderInitializerService"/>
        <property name="extendableTypes">
            <list>
                <value>nt:base</value>
            </list>
        </property>
        <property name="dataSource" ref="caiiDataSource"/>
    </bean>
    
    <!-- caii数据源,从DAO中读取数据,封装成ExternalData,再由Provider映射数据到JCR -->
    <bean name="caiiDataSource" class="com.caii.modules.caiidbprovider.CaiiDataSource" init-method="start">
        <property name="cacheProvider" ref="ehCacheProvider"/>
    </bean>
    
    
</beans>

 

Kindly regards

Lion

  • When I deploy a module to Jahia, I got an error message " zip file closed"
    2014/07/22 03:39

    omglion <p>Hello, everybody,</p> <p>Could anyone help me to solve the problem?</p> <p>Here is the source codes (that is for reading datas from an external datasource like mysql):</p> <p>package com.caii.modules.caiidbprovider;</p> <p>import java.util.HashMap;<br /> import java.util.List;<br /> import java.util.Map;<br /> import java.util.Set;</p> <p>import javax.annotation.Resource;<br /> import javax.jcr.ItemNotFoundException;<br /> import javax.jcr.PathNotFoundException;<br /> import javax.jcr.RepositoryException;</p> <p>import net.sf.ehcache.CacheException;<br /> import net.sf.ehcache.Ehcache;<br /> import net.sf.ehcache.Element;</p> <p>import org.apache.commons.lang.StringUtils;<br /> import org.jahia.modules.external.ExternalData;<br /> import org.jahia.modules.external.ExternalDataSource;<br /> import org.jahia.services.cache.ehcache.EhCacheProvider;</p> <p>import com.caii.modules.caiidbprovider.dao.PersonDao;<br /> import com.caii.modules.caiidbprovider.domain.Person;<br /> import com.google.common.collect.Sets;</p> <p>public class CaiiDataSource implements ExternalDataSource {<br /> &nbsp;&nbsp; &nbsp;<br /> &nbsp; &nbsp; private EhCacheProvider ehCacheProvider;<br /> &nbsp; &nbsp; private Ehcache cache;<br /> &nbsp; &nbsp;&nbsp;<br /> &nbsp; &nbsp; @Resource<br /> &nbsp; &nbsp; private PersonDao personDao;<br /> &nbsp; &nbsp;&nbsp;<br /> &nbsp;&nbsp; &nbsp;public CaiiDataSource() {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;super();<br /> &nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;public void setCacheProvider(EhCacheProvider ehCacheProvider) {<br /> &nbsp; &nbsp; &nbsp; &nbsp; this.ehCacheProvider = ehCacheProvider;<br /> &nbsp; &nbsp; }<br /> &nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;public void start(){<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(!ehCacheProvider.getCacheManager().cacheExists(&quot;caiidb-cache&quot;)){<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ehCacheProvider.getCacheManager().addCache(&quot;caiidb-cache&quot;);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;cache = ehCacheProvider.getCacheManager().getCache(&quot;caiidb-cache&quot;);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} catch (IllegalStateException e) {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;e.printStackTrace();<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} catch (CacheException e) {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace(); &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp;&nbsp; &nbsp;}</p> <p>&nbsp;&nbsp; &nbsp;@Override<br /> &nbsp;&nbsp; &nbsp;public List&lt;String&gt; getChildren(String path) throws RepositoryException {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return null;<br /> &nbsp;&nbsp; &nbsp;}</p> <p>&nbsp;&nbsp; &nbsp;@Override<br /> &nbsp;&nbsp; &nbsp;public ExternalData getItemByIdentifier(String identifier) throws ItemNotFoundException {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(identifier.equals(&quot;root&quot;)){<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return new ExternalData(identifier, &quot;/&quot;, &quot;jnt:contentFolder&quot;, new HashMap&lt;String, String[]&gt;());<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(identifier.equals(&quot;persons-folder&quot;)){<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;final String s = StringUtils.substringBefore(identifier, &quot;-folder&quot;);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return new ExternalData(identifier, &quot;/&quot; + s, &quot;jnt:contentFolder&quot;, new HashMap&lt;String, String[]&gt;());<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} else if (identifier.startsWith(&quot;personId-&quot;)) {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;String personId = StringUtils.substringAfter(identifier, &quot;personId-&quot;);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Integer.parseInt(personId);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} catch (NumberFormatException e) {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;throw new ItemNotFoundException(identifier);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Person person = null;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (cache.get(&quot;personId-&quot; + personId) != null) {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;person = (Person) cache.get(&quot;personId-&quot; + personId).getObjectValue();<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} else {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;person = personDao.findPersonById(personId);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;cache.put(new Element(&quot;personId-&quot; + personId, person));<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Map&lt;String, String[]&gt; properties = new HashMap&lt;String, String[]&gt;();<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(person.getPersonId() != null){<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;properties.put(&quot;person_id&quot;, new String[]{person.getPersonId() + &quot;&quot;});<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(!StringUtils.isBlank(person.getName())){<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;properties.put(&quot;name&quot;, new String[]{person.getName()});<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ExternalData externalData = new ExternalData(<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;identifier, &quot;/persons/&quot; + personId, &quot;caiint:person&quot;, properties);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return externalData;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} catch (Exception e) {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;throw new ItemNotFoundException(e);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;throw new ItemNotFoundException(identifier);<br /> &nbsp;&nbsp; &nbsp;}</p> <p>&nbsp;&nbsp; &nbsp;/**<br /> &nbsp;&nbsp; &nbsp; * the path of external data node is:<br /> &nbsp;&nbsp; &nbsp; *&quot;/persons/123&quot;<br /> &nbsp;&nbsp; &nbsp; *123 is id<br /> &nbsp;&nbsp; &nbsp; * */<br /> &nbsp;&nbsp; &nbsp;@Override<br /> &nbsp;&nbsp; &nbsp;public ExternalData getItemByPath(String path) throws PathNotFoundException {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;String[] splitPath = path.split(&quot;/&quot;);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (path.endsWith(&quot;j:acl&quot;)) {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;throw new PathNotFoundException(path);&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (splitPath.length &lt;= 1) {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return getItemByIdentifier(&quot;root&quot;);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} else if (splitPath[1].equals(&quot;persons&quot;)) {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;switch(splitPath.length){<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;case 2:<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return getItemByIdentifier(&quot;persons-folder&quot;);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;case 3:<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return getItemByIdentifier(&quot;personId-&quot; + splitPath[2]);&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}&nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} catch (ItemNotFoundException e) {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;throw new PathNotFoundException(e);<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;throw new PathNotFoundException();<br /> &nbsp;&nbsp; &nbsp;}</p> <p>&nbsp;&nbsp; &nbsp;@Override<br /> &nbsp;&nbsp; &nbsp;public Set&lt;String&gt; getSupportedNodeTypes() {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return Sets.newHashSet(&quot;jnt:contentFolder&quot;, &quot;caiint:person&quot;);<br /> &nbsp;&nbsp; &nbsp;}</p> <p>&nbsp;&nbsp; &nbsp;@Override<br /> &nbsp;&nbsp; &nbsp;public boolean isSupportsHierarchicalIdentifiers() {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br /> &nbsp;&nbsp; &nbsp;}</p> <p>&nbsp;&nbsp; &nbsp;@Override<br /> &nbsp;&nbsp; &nbsp;public boolean isSupportsUuid() {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br /> &nbsp;&nbsp; &nbsp;}</p> <p>&nbsp;&nbsp; &nbsp;@Override<br /> &nbsp;&nbsp; &nbsp;public boolean itemExists(String path) {<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br /> &nbsp;&nbsp; &nbsp;}</p> <p>}</p> <p>And the Spring xml file:</p> <p>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br /> &lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;xmlns:osgi=&quot;http://www.eclipse.org/gemini/blueprint/schema/blueprint&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;xmlns:context=&quot;http://www.springframework.org/schema/context&quot;&nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp;xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http://www.eclipse.org/gemini/blueprint/schema/blueprint http://www.eclipse.org/gemini/blueprint/schema/blueprint/gemini-blueprint.xsd<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd&quot;&gt; &nbsp;<br /> &nbsp; &nbsp;&nbsp;<br /> &nbsp; &nbsp; &lt;!-- 将OSGI服务转换成bean,以便调用 --&gt;<br /> &nbsp; &nbsp; &lt;osgi:reference id=&quot;ExternalProviderInitializerService&quot; interface=&quot;org.jahia.modules.external.ExternalProviderInitializerService&quot;/&gt;<br /> &nbsp; &nbsp; &lt;osgi:reference id=&quot;ehCacheProvider&quot; interface=&quot;org.jahia.services.cache.ehcache.EhCacheProvider&quot;/&gt;<br /> &nbsp; &nbsp;&nbsp;<br /> &nbsp; &nbsp; &lt;!-- 启动扫描 --&gt;<br /> &nbsp; &nbsp; &lt;context:component-scan base-package=&quot;com.caii.modules&quot;/&gt;<br /> &nbsp; &nbsp;&nbsp;<br /> &nbsp; &nbsp; &lt;!--默认使用JDK动态代理,如果没有实现接口,自动用CGLIB动态代理--&gt;<br /> &nbsp; &nbsp; &lt;aop:aspectj-autoproxy/&gt;<br /> &nbsp; &nbsp;&nbsp;<br /> &nbsp; &nbsp; &lt;!-- DataSource 用于管理数据库的连接 --&gt;<br /> &nbsp; &nbsp; &lt;bean id=&quot;dataSource&quot; class=&quot;org.apache.commons.dbcp2.BasicDataSource&quot; destroy-method=&quot;close&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot; /&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost/test?useUnicode=true&amp;amp;characterEncoding=UTF-8&quot; /&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;username&quot; value=&quot;root&quot; /&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;password&quot; value=&quot;1234&quot; /&gt;<br /> &nbsp; &nbsp; &lt;/bean&gt;<br /> &nbsp; &nbsp;&nbsp;<br /> &nbsp; &nbsp; &lt;!-- 事务管理器 --&gt;<br /> &nbsp; &nbsp; &lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;entityManagerFactory&quot; ref=&quot;entityManagerFactory&quot;/&gt;<br /> &nbsp; &nbsp; &lt;/bean&gt;<br /> &nbsp; &nbsp; &lt;!-- 声明注解事务 --&gt;<br /> &nbsp; &nbsp; &lt;tx:annotation-driven transaction-manager=&quot;transactionManager&quot;/&gt;</p> <p>&nbsp; &nbsp; &lt;bean id=&quot;entityManagerFactory&quot; class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;persistenceUnitName&quot; value=&quot;caiiPU&quot; /&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot; /&gt;<br /> &nbsp; &nbsp; &lt;/bean&gt;<br /> &nbsp; &nbsp;&nbsp;<br /> &nbsp; &nbsp; &lt;!--Provider Definition 用于映射数据到JCR--&gt;<br /> &nbsp; &nbsp; &lt;bean id=&quot;caiiDBProvider&quot; class=&quot;org.jahia.modules.external.ExternalContentStoreProvider&quot; parent=&quot;AbstractJCRStoreProvider&quot; &gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;key&quot; value=&quot;caiiDBProvider&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;mountPoint&quot; value=&quot;/sites/caiisite/contents/caii-db-provider&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;externalProviderInitializerService&quot; ref=&quot;ExternalProviderInitializerService&quot;/&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;extendableTypes&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;list&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;value&gt;nt:base&lt;/value&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/list&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;/property&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;property name=&quot;dataSource&quot; ref=&quot;caiiDataSource&quot;/&gt;<br /> &nbsp; &nbsp; &lt;/bean&gt;<br /> &nbsp; &nbsp;&nbsp;<br /> &nbsp; &nbsp; &lt;!-- caii数据源,从DAO中读取数据,封装成ExternalData,再由Provider映射数据到JCR --&gt;<br /> &nbsp; &nbsp; &lt;bean name=&quot;caiiDataSource&quot; class=&quot;com.caii.modules.caiidbprovider.CaiiDataSource&quot; init-method=&quot;start&quot;&gt;<br /> &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&lt;property name=&quot;cacheProvider&quot; ref=&quot;ehCacheProvider&quot;/&gt;<br /> &nbsp; &nbsp; &lt;/bean&gt;<br /> &nbsp; &nbsp;&nbsp;<br /> &nbsp; &nbsp;&nbsp;<br /> &lt;/beans&gt;</p> <p>&nbsp;</p> <p>Kindly regards</p> <p>Lion</p>

  • Number of messages  27
    Registration date Jul 22, 2014
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page