KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > forte > node > XMLCDataLoader


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Lisa Reese
21  *
22  */

23
24 package org.enhydra.kelp.forte.node;
25
26 import java.io.IOException JavaDoc;
27 import java.util.Vector JavaDoc;
28
29 import org.openide.actions.*;
30 import org.openide.filesystems.FileObject;
31 import org.openide.filesystems.FileUtil;
32 import org.openide.loaders.*;
33 import org.openide.util.NbBundle;
34 import org.openide.util.actions.SystemAction;
35
36 import java.util.Enumeration JavaDoc;
37 import java.io.*;
38
39 /** Recognizes some set of files in the Repository as belonging together.
40  *
41  * @author rees0234
42  */

43 public class XMLCDataLoader extends MultiFileLoader {
44
45     static final long serialVersionUID = -5042424699146221934L;
46
47     public static final String JavaDoc PROP_XMLC_EXTENSIONS = "xmlc.extensions";
48
49
50     public XMLCDataLoader ()
51     {
52         this (XMLCDataObject.class);
53     }
54
55     public XMLCDataLoader (Class JavaDoc recognizedObject)
56     {
57          super (recognizedObject);
58     }
59
60     protected void initialize () {
61
62         setDisplayName (NbBundle.getMessage (XMLCDataLoader.class, "LBL_XMLCloader"));
63
64         setActions (new SystemAction[] {
65                         SystemAction.get (ViewAction.class),
66                         SystemAction.get (OpenAction.class),
67                         SystemAction.get (FileSystemAction.class),
68                         null,
69 // SystemAction.get (CompileAction.class),
70
// SystemAction.get (EnhydraAction.class),
71
// null,
72
SystemAction.get (CutAction.class),
73                         SystemAction.get (CopyAction.class),
74                         SystemAction.get (PasteAction.class),
75                         null,
76                         SystemAction.get (DeleteAction.class),
77                         SystemAction.get (RenameAction.class),
78                         null,
79                         SystemAction.get (SaveAsTemplateAction.class),
80 // null,
81
// SystemAction.get (ToolsAction.class),
82
SystemAction.get (PropertiesAction.class),
83                     });
84
85         super.initialize();
86
87     }
88
89     protected FileObject findPrimaryFile (FileObject fo) {
90         // This can of course be much more sophisticated.
91
Enumeration JavaDoc extSet = getExtensions().extensions();
92         while (extSet.hasMoreElements())
93         {
94             String JavaDoc ext = (String JavaDoc)extSet.nextElement();
95             if (fo.hasExt (ext))
96                 return fo;
97         }
98 // else if (fo.hasExt (SECONDARY_EXT))
99
// return FileUtil.findBrother (fo, MAIN_EXT);
100
// else
101
return null;
102     }
103
104     protected MultiDataObject createMultiObject (FileObject primaryFile)
105     throws DataObjectExistsException, IOException JavaDoc {
106         return new XMLCDataObject (primaryFile, this);
107     }
108
109     protected MultiDataObject.Entry createPrimaryEntry (MultiDataObject obj, FileObject primaryFile) {
110         // Entry for the important file: by default, is preserved during all operations.
111
return new FileEntry (obj, primaryFile);
112     }
113
114     /** @return The list of extensions this loader recognizes
115     *
116     */

117     public ExtensionList getExtensions () {
118         ExtensionList extensions = null;
119         ForteProject project = new ForteProject();
120         if (project != null){
121             String JavaDoc exts[] = project.getDocTypes();
122         if (exts != null) {
123                 //yuk - I don't like this.
124
extensions = new ExtensionList();
125                 for (int i = 0; i < exts.length; i++)
126                     extensions.addExtension(exts[i]);
127             putProperty(PROP_XMLC_EXTENSIONS, extensions, false);
128             }
129         }
130         else
131             extensions = (ExtensionList)getProperty(PROP_XMLC_EXTENSIONS);
132         return extensions;
133     }
134
135     /** Sets the extension list for this data loader.
136     * @param ext new list of extensions.
137     */

138     public void setExtensions(ExtensionList ext) {
139         putProperty(PROP_XMLC_EXTENSIONS, ext, true);
140         ForteProject project = new ForteProject();
141         if (project != null){
142             Vector JavaDoc v = new Vector JavaDoc();
143             Enumeration JavaDoc e = ext.extensions();
144             while (e.hasMoreElements())
145                 v.add(e.nextElement());
146             String JavaDoc exts[] = new String JavaDoc[0];
147             exts = (String JavaDoc[])v.toArray(exts);
148             project.setDocTypes(exts);
149         }
150     }
151
152     protected MultiDataObject.Entry createSecondaryEntry (MultiDataObject obj, FileObject secondaryFile) {
153         secondaryFile.setImportant (false);
154         return new FileEntry.Numb (obj, secondaryFile); // discard whenever needed
155
}
156
157 }
158
Popular Tags