1 23 24 package com.sun.enterprise.tools.verifier.web; 25 26 import com.sun.enterprise.tools.verifier.Context; 27 import com.sun.enterprise.deployment.WebBundleDescriptor; 28 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 29 import com.sun.enterprise.deployment.util.ModuleDescriptor; 30 import com.sun.enterprise.util.io.FileUtils; 31 import java.io.File ; 32 import java.io.InputStream ; 33 import java.util.ArrayList ; 34 import java.util.List ; 35 import org.w3c.dom.Document ; 36 import org.xml.sax.InputSource ; 37 import javax.xml.parsers.DocumentBuilder ; 38 import javax.xml.parsers.DocumentBuilderFactory ; 39 import org.w3c.dom.NodeList ; 40 41 48 public class FacesConfigDescriptor { 49 50 private final String MANAGED_BEAN_CLASS = "managed-bean-class"; private final String facesConfigFileName = "WEB-INF/faces-config.xml"; 53 private Context context; 54 private Document facesConfigDocument; 55 56 public FacesConfigDescriptor(Context context, WebBundleDescriptor descriptor) { 57 try { 58 this.context = context; 59 readFacesConfigDocument(descriptor); 60 } catch(Exception ex) { 61 facesConfigDocument = null; 62 } 63 } 64 65 private void readFacesConfigDocument(WebBundleDescriptor webd) throws Exception { 66 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 67 factory.setValidating(false); 68 DocumentBuilder builder = factory.newDocumentBuilder(); 69 ModuleDescriptor moduleDesc = webd.getModuleDescriptor(); 70 String archBase = context.getAbstractArchive().getArchiveUri(); 71 String uri = null; 72 if(moduleDesc.isStandalone()){ 73 uri = archBase; 74 } else { 75 uri = archBase + File.separator + 76 FileUtils.makeFriendlyFileName(moduleDesc.getArchiveUri()); 77 } 78 FileArchive arch = new FileArchive(); 79 arch.open(uri); 80 InputStream is = arch.getEntry(facesConfigFileName); 81 InputSource source = new InputSource (is); 82 try { 83 facesConfigDocument = builder.parse(source); 84 } finally { 85 try{ 86 if(is != null) 87 is.close(); 88 } catch(Exception e) {} 89 } 90 } 91 92 public List <String > getManagedBeanClasses() { 93 if (facesConfigDocument == null) { 94 return new ArrayList <String >(); 95 } 96 NodeList nl = facesConfigDocument.getElementsByTagName(MANAGED_BEAN_CLASS); 97 List <String > classes = new ArrayList <String >(); 98 if (nl != null) { 99 int size = nl.getLength(); 100 for (int i = 0; i < size; i++) { 101 classes.add(nl.item(i).getFirstChild().getNodeValue().trim()); 102 } 103 } 104 return classes; 105 } 106 107 } 108 | Popular Tags |