KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > ModeCatalogHandler


1 /*
2  * ModeCatalogHandler.java - XML handler for mode catalog files
3  * Copyright (C) 2000, 2001 Slava Pestov
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */

19
20 package org.gjt.sp.jedit;
21
22 import java.io.*;
23
24 import org.xml.sax.Attributes JavaDoc;
25 import org.xml.sax.InputSource JavaDoc;
26 import org.xml.sax.helpers.DefaultHandler JavaDoc;
27
28 import org.gjt.sp.util.Log;
29 import org.gjt.sp.util.XMLUtilities;
30
31 class ModeCatalogHandler extends DefaultHandler JavaDoc
32 {
33     ModeCatalogHandler(String JavaDoc directory, boolean resource)
34     {
35         this.directory = directory;
36         this.resource = resource;
37     }
38
39     public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId)
40     {
41         return XMLUtilities.findEntity(systemId, "catalog.dtd", getClass());
42     }
43
44     public void startElement(String JavaDoc uri, String JavaDoc localName,
45                              String JavaDoc qName, Attributes JavaDoc attrs)
46     {
47         if (qName.equals("MODE"))
48         {
49             String JavaDoc modeName = attrs.getValue("NAME");
50
51             String JavaDoc file = attrs.getValue("FILE");
52             if(file == null)
53             {
54                 Log.log(Log.ERROR,this,directory + "catalog:"
55                     + " mode " + modeName + " doesn't have"
56                     + " a FILE attribute");
57             }
58
59             String JavaDoc filenameGlob = attrs.getValue("FILE_NAME_GLOB");
60             String JavaDoc firstlineGlob = attrs.getValue("FIRST_LINE_GLOB");
61
62
63             Mode mode = jEdit.getMode(modeName);
64             if(mode == null)
65             {
66                 mode = new Mode(modeName);
67                 jEdit.addMode(mode);
68             }
69
70             Object JavaDoc path;
71             if(resource)
72                 path = jEdit.class.getResource(directory + file);
73             else
74                 path = MiscUtilities.constructPath(directory,file);
75             mode.setProperty("file",path);
76
77             if(filenameGlob != null)
78                 mode.setProperty("filenameGlob",filenameGlob);
79             else
80                 mode.unsetProperty("filenameGlob");
81
82             if(firstlineGlob != null)
83                 mode.setProperty("firstlineGlob",firstlineGlob);
84             else
85                 mode.unsetProperty("firstlineGlob");
86
87             mode.init();
88         }
89     }
90
91     private String JavaDoc directory;
92     private boolean resource;
93
94 }
95
96
Popular Tags