KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > css > CSSLoader


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 package org.netbeans.modules.css;
20
21 import java.io.IOException JavaDoc;
22 import java.util.*;
23 import java.text.*;
24
25 import org.openide.loaders.*;
26 import org.openide.filesystems.FileObject;
27 import org.openide.filesystems.FileUtil;
28 import org.openide.actions.*;
29 import org.openide.util.actions.SystemAction;
30 import org.openide.util.*;
31
32 import org.netbeans.modules.css.actions.*;
33
34 /** Data loader which recognizes CSS files.
35  * This class is final only for performance reasons,
36  * can be unfinaled if desired.
37  *
38  * @author Petr Kuzel
39  */

40 public final class CSSLoader extends UniFileLoader {
41
42     /** Serial Version UID */
43     private static final long serialVersionUID = -6638807099960633333L;
44
45     private static final String JavaDoc CSS_EXT = "css"; // NOI18N
46
private static final String JavaDoc CSS_MIME = "text/css"; // NOI18N
47

48     /** Creates new DTDLoader */
49     public CSSLoader() {
50         super("org.netbeans.modules.css.CSSObject");
51     }
52
53     /** Does initialization. Initializes display name,
54      * extension list and the actions. */

55     protected void initialize () {
56         super.initialize();
57         
58         ExtensionList ext = getExtensions();
59         ext.addExtension (CSS_EXT);
60         ext.addMimeType(CSS_MIME);
61         setExtensions(ext);
62     }
63
64     protected String JavaDoc actionsContext() {
65         return "Loaders/text/css/Actions/";
66     }
67     
68     /**
69      * Lazy init name.
70      */

71     protected String JavaDoc defaultDisplayName () {
72         return Util.THIS.getString ("PROP_CSSLoader_Name");
73     }
74     
75     /** Creates the right data object for given primary file.
76      * It is guaranteed that the provided file is realy primary file
77      * returned from the method findPrimaryFile.
78      *
79      * @param primaryFile the primary file
80      * @return the data object for this file
81      * @exception DataObjectExistsException if the primary file already has data object
82      */

83     protected MultiDataObject createMultiObject (FileObject primaryFile)
84             throws DataObjectExistsException, java.io.IOException JavaDoc {
85         return new CSSObject (primaryFile, this);
86     }
87     
88     /** Creates the right primary entry for given primary file.
89      *
90      * @param primaryFile primary file recognized by this loader
91      * @return primary entry for that file
92      */

93     protected MultiDataObject.Entry createPrimaryEntry (MultiDataObject obj, FileObject primaryFile) {
94         return new CSSFileEntry (obj, primaryFile);
95     }
96
97     /** This entry defines the format for replacing the text during
98      * instantiation the data object.
99      * //!!! encoding hanling such as XML does
100      */

101     public static class CSSFileEntry extends FileEntry.Format {
102
103         /** Serial Version UID */
104         private static final long serialVersionUID = 2833661760805697888L;
105         
106         /** Creates new MakefileFileEntry */
107         CSSFileEntry (MultiDataObject obj, FileObject file) {
108             super (obj, file);
109         }
110
111         /** Method to provide suitable format for substitution of lines.
112          *
113          * @param target the target folder of the installation
114          * @param n the name the file will have
115          * @param e the extension the file will have
116          * @return format to use for formating lines
117          */

118         protected java.text.Format JavaDoc createFormat (FileObject target, String JavaDoc n, String JavaDoc e) {
119             HashMap map = new HashMap();
120             Date now = new Date();
121
122             map.put ("NAME", n); // NOI18N
123
map.put ("DATE", DateFormat.getDateInstance (DateFormat.LONG).format (now)); // NOI18N
124
map.put ("TIME", DateFormat.getTimeInstance (DateFormat.SHORT).format (now)); // NOI18N
125
map.put ("USER", System.getProperty ("user.name")); // NOI18N
126

127             MapFormat format = new MapFormat (map);
128             format.setLeftBrace ("__"); // NOI18N
129
format.setRightBrace ("__"); // NOI18N
130
format.setExactMatch (false);
131             return format;
132         }
133     }
134
135 }
136
Popular Tags