01: /*
02: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
03: *
04: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
05: *
06: * The contents of this file are subject to the terms of either the GNU
07: * General Public License Version 2 only ("GPL") or the Common
08: * Development and Distribution License("CDDL") (collectively, the
09: * "License"). You may not use this file except in compliance with the
10: * License. You can obtain a copy of the License at
11: * http://www.netbeans.org/cddl-gplv2.html
12: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13: * specific language governing permissions and limitations under the
14: * License. When distributing the software, include this License Header
15: * Notice in each file and include the License file at
16: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17: * particular file as subject to the "Classpath" exception as provided
18: * by Sun in the GPL Version 2 section of the License file that
19: * accompanied this code. If applicable, add the following below the
20: * License Header, with the fields enclosed by brackets [] replaced by
21: * your own identifying information:
22: * "Portions Copyrighted [year] [name of copyright owner]"
23: *
24: * Contributor(s):
25: *
26: * Portions Copyrighted 2007 Sun Microsystems, Inc.
27: */
28: package org.netbeans.modules.visualweb.insync;
29:
30: import java.io.IOException;
31: import org.netbeans.api.project.Project;
32: import org.netbeans.modules.web.api.webmodule.WebModule;
33: import org.netbeans.modules.web.jsf.JSFConfigDataObject;
34: import org.netbeans.modules.web.jsf.JSFConfigLoader;
35: import org.netbeans.modules.web.jsf.api.ConfigurationUtils;
36: import org.netbeans.modules.web.project.WebProject;
37: import org.openide.filesystems.FileObject;
38: import org.openide.filesystems.Repository;
39: import org.openide.loaders.DataLoader;
40: import org.openide.loaders.DataLoaderPool;
41: import org.openide.loaders.DataObject;
42:
43: /**
44: *
45: * @author jdeva
46: */
47: public class JSFConfigUtils {
48: private static JSFConfigLoader jsfConfigLoader = new JSFConfigLoader();
49:
50: public static void setUp(Project project) throws IOException {
51: assert (project instanceof WebProject);
52: WebModule webModule = ((WebProject) project).getAPIWebModule();
53: assert (webModule != null);
54: FileObject[] facesConfigFiles = ConfigurationUtils
55: .getFacesConfigFiles(webModule);
56: assert (facesConfigFiles.length == 1);
57:
58: FileObject facesConfigFile = facesConfigFiles[0];
59: assert (facesConfigFile != null);
60:
61: DataLoader dl = DataLoaderPool
62: .getPreferredLoader(facesConfigFile);
63:
64: if (dl == null || !(dl instanceof JSFConfigLoader)) {
65: if (jsfConfigLoader != null) {
66: DataLoaderPool.setPreferredLoader(facesConfigFile,
67: jsfConfigLoader);
68: }
69: }
70:
71: DataObject dataObj = DataObject.find(facesConfigFile);
72: assert (dataObj != null);
73: assert (dataObj instanceof JSFConfigDataObject);
74: registerXMLKit();
75: }
76:
77: private static void registerXMLKit() {
78: String[] path = new String[] { "Editors", "text", "x-jsf+xml" };
79: FileObject target = Repository.getDefault()
80: .getDefaultFileSystem().getRoot();
81: try {
82: for (int i = 0; i < path.length; i++) {
83: FileObject f = target.getFileObject(path[i]);
84: if (f == null) {
85: f = target.createFolder(path[i]);
86: }
87: target = f;
88: }
89: String name = "EditorKit.instance";
90: if (target.getFileObject(name) == null) {
91: FileObject f = target.createData(name);
92: f.setAttribute("instanceClass",
93: "org.netbeans.modules.xml.text.syntax.XMLKit");
94: }
95: } catch (IOException ioe) {
96: ioe.printStackTrace();
97: }
98: }
99: }
|