Announcement Announcement Module
Collapse
No announcement yet.
A simplified JackrabbitSessionFactory which suppoert JK 2.0 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • A simplified JackrabbitSessionFactory which suppoert JK 2.0

    Code:
    package org.springframework.extensions.jcr.jackrabbit;
    
    import java.io.InputStreamReader;
    
    import javax.jcr.Session;
    
    import org.apache.jackrabbit.commons.cnd.CndImporter;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.core.io.Resource;
    import org.springframework.extensions.jcr.JcrSessionFactory;
    import org.springframework.util.ObjectUtils;
    
    
    /**
     * Jackrabbit specific {@link JcrSessionFactory} which allows registration of node types in <a
     * href="http://jackrabbit.apache.org/node-types.html">Content node types</a> format.
     * @author Costin Leau
     * @author Sergio Bossa
     * @author Salvatore Incandela
     */
    public class JackrabbitSessionFactory2 extends JcrSessionFactory {
    
        private static final Logger log = LoggerFactory.getLogger(JackrabbitSessionFactory2.class);
    
        /**
         * Node definitions in CND format.
         */
        private Resource[] nodeDefinitions;
    
        //private String contentType = JackrabbitNodeTypeManager.TEXT_XML;
    
        /*
         * (non-Javadoc)
         * @see org.springframework.extensions.jcr.JcrSessionFactory#registerNodeTypes()
         */
    
        protected void registerNodeTypes() throws Exception {
            if (!ObjectUtils.isEmpty(nodeDefinitions)) {
                Session session = getBareSession();
                for (int i = 0; i < nodeDefinitions.length; i++) {
                    Resource resource = nodeDefinitions[i];
                    if(log.isDebugEnabled())
                    	log.debug("adding node type definitions from " + resource.getDescription());
                    CndImporter.registerNodeTypes(new InputStreamReader(resource.getInputStream()), session);
                }
    
                session.logout();
            }
        }
    
        /**
         * @param nodeDefinitions The nodeDefinitions to set.
         */
        public void setNodeDefinitions(Resource[] nodeDefinitions) {
            this.nodeDefinitions = nodeDefinitions;
        }
    
    }
Working...
X