01: /*
02: * ModeCatalogHandler.java - XML handler for mode catalog files
03: * Copyright (C) 2000, 2001 Slava Pestov
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * as published by the Free Software Foundation; either version 2
08: * of the License, or any later version.
09: *
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: //{{{ Imports
23: import org.gjt.sp.jedit.syntax.ModeProvider;
24: import org.gjt.sp.util.Log;
25: import org.gjt.sp.util.XMLUtilities;
26: import org.xml.sax.Attributes;
27: import org.xml.sax.InputSource;
28: import org.xml.sax.helpers.DefaultHandler;
29:
30: //}}}
31:
32: /**
33: * @author Slava Pestov
34: */
35: class ModeCatalogHandler extends DefaultHandler {
36: //{{{ ModeCatalogHandler constructor
37: ModeCatalogHandler(String directory, boolean resource) {
38: this .directory = directory;
39: this .resource = resource;
40: } //}}}
41:
42: //{{{ resolveEntity() method
43: public InputSource resolveEntity(String publicId, String systemId) {
44: return XMLUtilities.findEntity(systemId, "catalog.dtd",
45: getClass());
46: } //}}}
47:
48: //{{{ startElement() method
49: public void startElement(String uri, String localName,
50: String qName, Attributes attrs) {
51: if (qName.equals("MODE")) {
52: String modeName = attrs.getValue("NAME");
53:
54: String file = attrs.getValue("FILE");
55: if (file == null) {
56: Log.log(Log.ERROR, this , directory + "catalog:"
57: + " mode " + modeName + " doesn't have"
58: + " a FILE attribute");
59: }
60:
61: String filenameGlob = attrs.getValue("FILE_NAME_GLOB");
62: String firstlineGlob = attrs.getValue("FIRST_LINE_GLOB");
63:
64: Mode mode = ModeProvider.instance.getMode(modeName);
65: if (mode == null) {
66: mode = instantiateMode(modeName);
67: ModeProvider.instance.addMode(mode);
68: }
69:
70: Object 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: protected Mode instantiateMode(String modeName) {
92: return new Mode(modeName);
93: }
94:
95: private String directory;
96: private boolean resource;
97:
98: }
|