I have created two custom node types, the nodes which is mixin can not be
retrieved , why?
public class SearchTest
{
private static String configFile = "e:\\jackrabbitHome\\repository.xml";
private static String localpath = "e:\\jackrabbitHome";
public static void main(String[] args) throws Exception
{
Repository repository = getRepository(configFile, localpath);
Session session = repository.login(new
SimpleCredentials("admin","admin".toCharArray()));
Tools.registerNamespaces(session);
Tools.RegisterCustomNodeTypes(session.getWorkspace(), "test.cnd");
Node root = session.getRootNode();
Node file1 = root.addNode("first", "ocm:file1");
setNode(file1);
Node file2 = root.addNode("second", "ocm:file2");
setNode(file2);
session.save();
Query q =
session.getWorkspace().getQueryManager().createQuery("//element(*, ocm:file1)",
Query.XPATH);
QueryResult result = q.execute();
if (result.getNodes().hasNext())
{
System.out.println("Nodes ocm:file1 Found! ");//can be found
} else
{
System.out.println("Nodes ocm:file1 not exist");
}
q = session.getWorkspace().getQueryManager().createQuery("//element(*,
ocm:file2)", Query.XPATH);
result = q.execute();
if (result.getNodes().hasNext())
{
System.out.println("Nodes ocm:file2 Found! ");
} else
{
System.out.println("Nodes ocm:file2 not exist");//cannot be found!
}
}
private static void setNode(Node node)
{
try
{
node.setProperty("jcr:encoding", "iso-8859-1");
node.setProperty("jcr:mimeType", "text/plain");
node.setProperty("jcr:lastModified", Calendar.getInstance());
node.setProperty("jcr:data", new FileInputStream("test.cnd"));
} catch (Exception e)
{
e.printStackTrace();
}
}
private synchronized static Repository getRepository(String configfile,
String localpath) throws RepositoryException
{
Repository repo = RepositoryImpl.create(RepositoryConfig.create(new
InputSource(configfile), localpath));
return repo;
}
}
test.cnd:
<'jcr'='http://www.jcp.org/jcr/1.0'>
<'sv'='http://www.jcp.org/jcr/sv/1.0'>
<'xs'='http://www.w3.org/2001/XMLSchema'>
<'xml'='http://www.w3.org/XML/1998/namespace'>
<'nt'='http://www.jcp.org/jcr/nt/1.0'>
<'fn'='http://www.w3.org/2005/xpath-functions'>
<'ocm'='http://jackrabbit.apache.org/ocm'>
<'mix'='http://www.jcp.org/jcr/mix/1.0'>
<'rep'='internal'>
[ocm:file1] > nt:resource
[ocm:file2] > nt:resource mix
___________________________________________________________
雅虎邮箱,您的终生邮箱!
http://cn.mail.yahoo.com/