1 17 package org.alfresco.jcr.example; 18 19 import javax.jcr.Node; 20 import javax.jcr.NodeIterator; 21 import javax.jcr.Property; 22 import javax.jcr.PropertyIterator; 23 import javax.jcr.Repository; 24 import javax.jcr.Session; 25 import javax.jcr.SimpleCredentials; 26 27 import org.springframework.context.ApplicationContext; 28 import org.springframework.context.support.ClassPathXmlApplicationContext; 29 30 31 32 38 public class SimpleExample 39 { 40 41 public static void main(String [] args) 42 throws Exception 43 { 44 ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/jcr-context.xml"); 46 47 Repository repository = (Repository)context.getBean("JCR.Repository"); 49 50 Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray())); 54 55 try 56 { 57 Node root = session.getRootNode(); 59 Node companyHome = root.getNode("app:company_home"); 60 61 NodeIterator iterator = companyHome.getNodes(); 63 while(iterator.hasNext()) 64 { 65 Node child = iterator.nextNode(); 66 System.out.println(child.getName()); 67 68 PropertyIterator propIterator = child.getProperties(); 69 while(propIterator.hasNext()) 70 { 71 Property prop = propIterator.nextProperty(); 72 if (!prop.getDefinition().isMultiple()) 73 { 74 System.out.println(" " + prop.getName() + " = " + prop.getString()); 75 } 76 } 77 } 78 } 79 finally 80 { 81 session.logout(); 82 System.exit(0); 83 } 84 85 } 86 87 } 88 | Popular Tags |