KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > api > VisualWebProperties


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.project.api;
21
22 import java.util.Map JavaDoc;
23 import java.util.HashMap JavaDoc;
24
25 import org.netbeans.api.project.ProjectManager;
26 import org.netbeans.api.project.Project;
27 import org.netbeans.spi.project.support.ant.AntProjectHelper;
28 import org.netbeans.spi.project.support.ant.EditableProperties;
29 import org.netbeans.modules.web.project.UpdateHelper;
30 import org.netbeans.modules.web.project.WebProject;
31 import org.openide.ErrorManager;
32
33 /**
34  * Class to set and get visual web properties.
35  *
36  * @author Po-Ting Wu
37  */

38 public class VisualWebProperties {
39     static final String JavaDoc[] CreatorProperties = {
40         "jsf.current.theme", // NOI18N
41
"jsf.pagebean.package", // NOI18N
42
"jsf.project.libraries.dir", // NOI18N
43
"jsf.startPage" // NOI18N
44
};
45
46     /**
47      * Creates a new instance of VisualWebProperties
48      */

49     public VisualWebProperties() {
50     }
51
52     /**
53      * Gets the Visual Web version
54      * @return the version, null if not exist
55      */

56     static public String JavaDoc getVersion(Project project) {
57         if (!(project instanceof WebProject)) {
58             return null;
59         }
60
61         UpdateHelper helper = ((WebProject) project).getUpdateHelper();
62         EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
63         return props.getProperty("creator"); // NOI18N
64
}
65
66     /**
67      * Sets the Visual Web version
68      * @param version the version.
69      */

70     static public void setVersion(Project project, String JavaDoc version) {
71         if (!(project instanceof WebProject)) {
72             return;
73         }
74
75         UpdateHelper helper = ((WebProject) project).getUpdateHelper();
76         EditableProperties props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);
77         props.setProperty("creator", version); // NOI18N
78
helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
79         try {
80             ProjectManager.getDefault().saveProject(project);
81         } catch (Exception JavaDoc e) {
82             ErrorManager.getDefault().notify(e);
83         }
84     }
85
86     /**
87      * Gets the Creator 2 project properties for migration.
88      * @return the project properties.
89      */

90     static public Map JavaDoc getCreatorProperties(Project project) {
91         HashMap JavaDoc result = new HashMap JavaDoc();
92
93         if (!(project instanceof WebProject)) {
94             return result;
95         }
96
97         UpdateHelper helper = ((WebProject) project).getUpdateHelper();
98         EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
99         for (int i = 0; i < CreatorProperties.length; i++) {
100             String JavaDoc value = (String JavaDoc) props.getProperty(CreatorProperties[i]);
101             if (value != null) {
102                 result.put(CreatorProperties[i], value);
103             }
104         }
105
106         return result;
107     }
108 }
109
Popular Tags