PageRenderTime 35ms CodeModel.GetById 18ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/ModeCatalogHandler.java

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