PageRenderTime 163ms CodeModel.GetById 158ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/ModeCatalogHandler.java

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