1 19 20 package org.gjt.sp.jedit; 21 22 import java.io.*; 23 24 import org.xml.sax.Attributes ; 25 import org.xml.sax.InputSource ; 26 import org.xml.sax.helpers.DefaultHandler ; 27 28 import org.gjt.sp.util.Log; 29 import org.gjt.sp.util.XMLUtilities; 30 31 class ModeCatalogHandler extends DefaultHandler 32 { 33 ModeCatalogHandler(String directory, boolean resource) 34 { 35 this.directory = directory; 36 this.resource = resource; 37 } 38 39 public InputSource resolveEntity(String publicId, String systemId) 40 { 41 return XMLUtilities.findEntity(systemId, "catalog.dtd", getClass()); 42 } 43 44 public void startElement(String uri, String localName, 45 String qName, Attributes attrs) 46 { 47 if (qName.equals("MODE")) 48 { 49 String modeName = attrs.getValue("NAME"); 50 51 String 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 filenameGlob = attrs.getValue("FILE_NAME_GLOB"); 60 String 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 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 directory; 92 private boolean resource; 93 94 } 95 96 | Popular Tags |