I'm ussing the Appache Jackrabbit JCA 2.7.5, the problem is that files .docx and .xlsx is not indexed.
My steps :
- Deploy the Jackrabbit JCA as
resource adapter
on glassfish
- create a
Connector Connection Pool
for the resource adapter
indicating the ConfigFile=path/to/the/repository.xml
and HomeDir=path/to/the //miss the repository.xml
- create a
Connector Resources
for the connector pool (the jndi)
- create web application
create class to get session from the connector ressources (code below)
import java.io.Serializable;
import java.net.MalformedURLException;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jcr.LoginException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@Stateless
public class OcmRepository implements Serializable {
public Repository repository;
public Session session;
public OcmRepository() {
}
public Session getSession(String log, String mdp) throws LoginException, RepositoryException, NamingException, MalformedURLException {
InitialContext initalContext = new InitialContext();
repository = (Repository) initalContext.lookup("jndi/jca");
session = repository.login(new SimpleCredentials(log, mdp.toCharArray()), null);
return session;
}
}
Create custom filetype
import javax.jcr.PropertyType;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.NodeTypeManager;
import javax.jcr.nodetype.NodeTypeTemplate;
import javax.jcr.nodetype.PropertyDefinitionTemplate;
/**
*
* @author nathan
*/
public class FileType {
public static void RegisterFileType(Session session) throws Exception {
NodeTypeManager nodeTypeManager = session.getWorkspace().getNodeTypeManager();
NodeTypeTemplate nodeType = nodeTypeManager.createNodeTypeTemplate();
nodeType.setName("FileType");
String[] str = {"nt:resource"};
nodeType.setDeclaredSuperTypeNames(str);
nodeType.setMixin(false);
nodeType.setQueryable(true);
PropertyDefinitionTemplate path = nodeTypeManager.createPropertyDefinitionTemplate();
path.setName("jcr:path");
path.setRequiredType(PropertyType.PATH);
path.setQueryOrderable(false);
path.setFullTextSearchable(false);
nodeType.getPropertyDefinitionTemplates().add(path);
PropertyDefinitionTemplate nom = nodeTypeManager.createPropertyDefinitionTemplate();
nom.setName("jcr:nom");
nom.setRequiredType(PropertyType.STRING);
nom.setQueryOrderable(true);
nom.setFullTextSearchable(true);
nodeType.getPropertyDefinitionTemplates().add(nom);
PropertyDefinitionTemplate description = nodeTypeManager.createPropertyDefinitionTemplate();
description.setName("jcr:description");
description.setRequiredType(PropertyType.STRING);
description.setQueryOrderable(true);
description.setFullTextSearchable(true);
nodeType.getPropertyDefinitionTemplates().add(description);
PropertyDefinitionTemplate motsCles = nodeTypeManager.createPropertyDefinitionTemplate();
motsCles.setName("jcr:motsCles");
motsCles.setRequiredType(PropertyType.STRING);
motsCles.setQueryOrderable(true);
motsCles.setFullTextSearchable(true);
nodeType.getPropertyDefinitionTemplates().add(motsCles);
PropertyDefinitionTemplate size = nodeTypeManager.createPropertyDefinitionTemplate();
size.setName("jcr:size");
size.setRequiredType(PropertyType.STRING);
size.setQueryOrderable(true);
size.setFullTextSearchable(false);
nodeType.getPropertyDefinitionTemplates().add(size);
PropertyDefinitionTemplate users = nodeTypeManager.createPropertyDefinitionTemplate();
users.setName("jcr:users");
users.setRequiredType(PropertyType.STRING);
users.setQueryOrderable(true);
users.setFullTextSearchable(false);
nodeType.getPropertyDefinitionTemplates().add(users);
PropertyDefinitionTemplate groupe = nodeTypeManager.createPropertyDefinitionTemplate();
groupe.setName("jcr:groupe");
groupe.setRequiredType(PropertyType.STRING);
groupe.setQueryOrderable(true);
groupe.setFullTextSearchable(false);
nodeType.getPropertyDefinitionTemplates().add(groupe);
NodeType newnodetype = nodeTypeManager.registerNodeType(nodeType, true);
session.save();
}
}
Create the abstract class for persistence
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.jcr.Session;
import org.apache.jackrabbit.ocm.query.Filter;
import org.apache.jackrabbit.ocm.query.impl.FilterImpl;
import org.apache.jackrabbit.ocm.query.impl.QueryImpl;
import org.apache.jackrabbit.ocm.query.Query;
import org.apache.jackrabbit.ocm.query.QueryManager;
import org.apache.jackrabbit.ocm.manager.ObjectContentManager;
import org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl;
import org.apache.jackrabbit.ocm.mapper.Mapper;
import org.apache.jackrabbit.ocm.mapper.impl.annotation.AnnotationMapperImpl;
import org.apache.jackrabbit.ocm.reflection.ReflectionUtils;
/**
*
* @author nathan
*/
public abstract class AbstractBean<T> {
private Class<T> entityClass;
private ObjectContentManager ocm;
private Mapper mapper;
public AbstractBean(Class<T> entityClass){
this.entityClass = entityClass;
}
/**
* Construct the Bean according to the extended class
* This will be also construct the ObjectContentManager nammed ocm with the default Mapper
* @param session javax.jcr.Session attached to the Bean
* @return The mapping class found for the desired java bean class
*/
public AbstractBean(Class<T> entityClass,Session session){
this.entityClass = entityClass;
ocm = new ObjectContentManagerImpl(session, this.getDefaultMapper());
}
/**
* @return ObjectContentManager of the Bean
*/
public ObjectContentManager getOcm() throws Exception{
return ocm;
}
/**
* Construct the Bean according to the extended class
* This will be also construct the ObjectContentManager nammed ocm with the param Mapper given
* @param session from "javax.jcr.Session" attached to the Bean
* @param map from "org.apache.jackrabbit.ocm.mapper.Mapper" which
* is the use to map entity between apllication and The repository
* @return ObjectContentManager of the Bean
*/
public ObjectContentManager getOcm(Session session, Mapper map) throws Exception{
return new ObjectContentManagerImpl(session, map);
}
public void setOcm(ObjectContentManager ocm) {
this.ocm = ocm;
}
private Mapper getDefaultMapper(){
ReflectionUtils.setClassLoader(com.ged.ocm.entity.Groupe.class.getClassLoader());
List<Class> classes = new ArrayList<Class>();
classes.add(com.ged.ocm.entity.Fichier.class);
classes.add(com.ged.ocm.entity.Dossier.class);
classes.add(com.ged.ocm.entity.Groupe.class);
classes.add(com.ged.ocm.entity.SimpleNode.class);
return new AnnotationMapperImpl(classes);
}
public Mapper getMapper() {
return mapper;
}
public void setMapper(Mapper mapper) {
this.mapper = mapper;
}
public void setLoader(Class classe){
ReflectionUtils.setClassLoader(classe.getClassLoader());
}
public void create(T entity) {
ocm.insert(entity);
ocm.save();
}
public void edit(T entity) {
ocm.update(entity);
ocm.save();
}
public void remove(T entity) {
ocm.remove(entity);
ocm.save();
}
public void refresh(){
ocm.refresh(true);
ocm.save();
}
public void copy(String orgPath, String destPath){
ocm.copy(orgPath, destPath);
ocm.save();
}
public void move(String orgPath, String destPath){
ocm.move(orgPath, destPath);
ocm.save();
}
public void removeByPath(String path) {
ocm.remove(path);
ocm.save();
}
public void removeAllByEqual(Map<String,String> filters){
QueryManager queryManager = ocm.getQueryManager();
Filter filter;
filter = queryManager.createFilter(entityClass);
for (String key : filters.keySet())filter.addEqualTo(key, filters.get(key));
Query query = queryManager.createQuery(filter);
ocm.remove(query);
ocm.save();
}
public void removeAllByEqual(String nodePath,Map<String,String> filters){
QueryManager queryManager = ocm.getQueryManager();
Filter filter;
filter = queryManager.createFilter(entityClass);
filter.setScope(nodePath);
for (String key : filters.keySet())filter.addEqualTo(key, filters.get(key));
Query query = queryManager.createQuery(filter);
ocm.remove(query);
ocm.save();
}
public boolean isPathExist(String path){
return ocm.objectExists(path);
}
public T findByPath(String path) {
try {
return (T)ocm.getObject(path);
} catch (Exception e) {
return null;
}
}
public T findOneByEqual(Map<String,String> filters){
QueryManager queryManager = ocm.getQueryManager();
Filter filter;
filter = queryManager.createFilter(entityClass);
for (String key : filters.keySet())filter.addEqualTo(key, filters.get(key));
Query query = queryManager.createQuery(filter);
List<T> results = (List<T>) ocm.getObjects(query);
T result = null;
try {
result = results.get(0);
} catch (Exception e) {
}
return result;
}
public List<T> findAllByEqual(Map<String,String> filters){
QueryManager queryManager = ocm.getQueryManager();
Filter filter;
filter = queryManager.createFilter(entityClass);
filter.setScope("//");
for (String key : filters.keySet())filter.addEqualTo(key, filters.get(key));
Query query = queryManager.createQuery(filter);
List<T> results = (List<T>) ocm.getObjects(query);
return results;
}
public List<T> findAllByLike(Map<String,String> filters){
QueryManager queryManager = ocm.getQueryManager();
Filter filter;
filter = queryManager.createFilter(entityClass);
filter.setScope("//");
for (String key : filters.keySet())filter.addLike(key, filters.get(key));
Query query = queryManager.createQuery(filter);
List<T> results = (List<T>) ocm.getObjects(query);
return results;
}
public List<T> findAllByLikeScoped(String scope,Map<String,String> filters){
QueryManager queryManager = ocm.getQueryManager();
Filter filter;
filter = queryManager.createFilter(e
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…