1 19 20 package org.netbeans.modules.web.jsf; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import org.netbeans.api.project.FileOwnerQuery; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.api.project.ProjectUtils; 28 import org.netbeans.api.project.SourceGroup; 29 import org.netbeans.api.project.Sources; 30 import org.netbeans.modules.j2ee.dd.api.common.InitParam; 31 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 32 import org.netbeans.modules.web.api.webmodule.WebModule; 33 import org.netbeans.modules.web.api.webmodule.WebProjectConstants; 34 import org.netbeans.modules.web.jsf.api.ConfigurationUtils; 35 import org.netbeans.modules.web.jsf.api.facesmodel.FacesConfig; 36 import org.netbeans.modules.web.jsf.api.facesmodel.NavigationRule; 37 import org.openide.ErrorManager; 38 import org.openide.filesystems.FileObject; 39 import org.openide.filesystems.FileUtil; 40 import org.netbeans.modules.j2ee.dd.api.web.DDProvider; 41 42 46 public class JSFConfigUtilities { 47 48 49 50 51 public static NavigationRule findNavigationRule(JSFConfigDataObject data, String fromView){ 52 NavigationRule navigationRule = null; 53 FacesConfig config = ConfigurationUtils.getConfigModel(data.getPrimaryFile(), true).getRootComponent(); 54 Collection <NavigationRule> rules = config.getNavigationRules(); 55 for (Iterator <NavigationRule> it = rules.iterator(); it.hasNext();) { 56 NavigationRule nRule = it.next(); 57 if (fromView.equals(nRule.getFromViewId())){ 58 navigationRule = nRule; 59 continue; 60 } 61 } 62 return navigationRule; 63 } 64 65 68 79 81 public static SourceGroup[] getDocBaseGroups(FileObject fileObject) throws java.io.IOException { 82 Project proj = FileOwnerQuery.getOwner(fileObject); 83 if (proj==null) return new SourceGroup[]{}; 84 Sources sources = ProjectUtils.getSources(proj); 85 return sources.getSourceGroups(WebProjectConstants.TYPE_DOC_ROOT); 86 } 87 88 public static String getResourcePath(SourceGroup[] groups,FileObject fileObject, char separator, boolean withExt) { 89 for (int i=0;i<groups.length;i++) { 90 FileObject root = groups[i].getRootFolder(); 91 if (FileUtil.isParentOf(root,fileObject)) { 92 String relativePath = FileUtil.getRelativePath(root,fileObject); 93 if (relativePath!=null) { 94 if (separator!='/') relativePath = relativePath.replace('/',separator); 95 if (!withExt) { 96 int index = relativePath.lastIndexOf((int)'.'); 97 if (index>0) relativePath = relativePath.substring(0,index); 98 } 99 return relativePath; 100 } else { 101 return ""; 102 } 103 } 104 } 105 return ""; 106 } 107 108 109 110 111 112 public static boolean validateXML(FileObject deploymentDesc){ 113 boolean value = false; if (deploymentDesc != null){ 115 try{ 116 WebApp webApp = DDProvider.getDefault().getDDRoot(deploymentDesc); 117 InitParam param = null; 118 if (webApp != null) 119 param = (InitParam)webApp.findBeanByName("InitParam", "ParamName", "com.sun.faces.validateXml"); if (param != null) 121 value = "true".equals(param.getParamValue().trim()); } catch (java.io.IOException e) { 123 ErrorManager.getDefault().notify(e); 124 } 125 } 126 return value; 127 } 128 129 public static boolean verifyObjects(FileObject deploymentDesc){ 130 boolean value = false; if (deploymentDesc != null){ 132 try{ 133 WebApp webApp = DDProvider.getDefault().getDDRoot(deploymentDesc); 134 InitParam param = null; 135 if (webApp != null) 136 param = (InitParam)webApp.findBeanByName("InitParam", "ParamName", "com.sun.faces.verifyObjects"); if (param != null) 138 value = "true".equals(param.getParamValue().trim()); 139 } catch (java.io.IOException e) { 140 ErrorManager.getDefault().notify(e); 141 } 142 } 143 return value; 144 } 145 146 149 public static String [] getConfigFiles(FileObject deploymentDesc){ 150 ArrayList <String > files = new ArrayList (); 151 String [] filesURI; 152 if (deploymentDesc != null){ 153 InitParam param = null; 154 try{ 155 WebApp webApp = DDProvider.getDefault().getDDRoot(deploymentDesc); 156 if (webApp != null) 157 param = (InitParam)webApp.findBeanByName("InitParam", "ParamName", "javax.faces.CONFIG_FILES"); } catch (java.io.IOException e) { 159 ErrorManager.getDefault().notify(e); 160 } 161 162 if (param != null){ 163 String value = param.getParamValue().trim(); 165 if (value != null){ 166 filesURI = value.split(","); 167 for (int i = 0; i < filesURI.length; i++) 168 files.add(filesURI[i].trim()); 169 } 170 } 171 WebModule webModule = WebModule.getWebModule(deploymentDesc); 173 FileObject baseDir = webModule.getDocumentBase(); 174 FileObject fileObject = baseDir.getFileObject("WEB-INF/faces-config.xml"); 175 if (fileObject != null) 176 files.add("WEB-INF/faces-config.xml"); 177 } 178 filesURI = new String [files.size()]; 179 return files.toArray(filesURI); 180 } 181 } 182 | Popular Tags |