| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.phoenix.report; |
| 34 | | | |
| 35 | | | import java.io.IOException; |
| 36 | | | import java.io.InputStream; |
| 37 | | | import java.util.logging.Level; |
| 38 | | | import java.util.logging.Logger; |
| 39 | | | |
| 40 | | | import org.gjt.sp.jedit.Mode; |
| 41 | | | import org.gjt.sp.jedit.jEdit; |
| 42 | | | import org.gjt.sp.jedit.syntax.ModeProvider; |
| 43 | | | import org.gjt.sp.util.XMLUtilities; |
| 44 | | | import org.jcoderz.commons.util.IoUtil; |
| 45 | | | import org.xml.sax.Attributes; |
| 46 | | | import org.xml.sax.InputSource; |
| 47 | | | import org.xml.sax.helpers.DefaultHandler; |
| 48 | | | |
| 49 | | | |
| 50 | | | |
| 51 | | | |
| 52 | | | |
| 53 | | | |
| 54 | | | |
| 55 | | | <code></code> |
| 56 | | | |
| 57 | | | |
| 58 | | | |
| 59 | | | |
| 60 | | | |
| 61 | | | <code></code> |
| 62 | | | |
| 63 | | | |
| 64 | | | |
| 65 | | | {@link } |
| 66 | | | |
| 67 | | | @author |
| 68 | | | |
| 69 | | | public final class SyntaxModeCatalogHandler |
| 70 | | | extends DefaultHandler |
| 71 | | | { |
| 72 | 0 | | private static final String CLASSNAME |
| 73 | | | = SyntaxModeCatalogHandler.class.getName(); |
| 74 | 0 | | private static final Logger LOGGER = Logger.getLogger(CLASSNAME); |
| 75 | | | |
| 76 | | | |
| 77 | | | |
| 78 | | | |
| 79 | | | |
| 80 | | | private SyntaxModeCatalogHandler () |
| 81 | 0 | | { |
| 82 | | | |
| 83 | 0 | | } |
| 84 | | | |
| 85 | | | |
| 86 | | | |
| 87 | | | |
| 88 | | | public static void loadModes () |
| 89 | | | { |
| 90 | 0 | | final InputStream in |
| 91 | | | = jEdit.class.getResourceAsStream("/modes/catalog"); |
| 92 | | | try |
| 93 | | | { |
| 94 | 0 | | XMLUtilities.parseXML(in, new SyntaxModeCatalogHandler()); |
| 95 | | | } |
| 96 | 0 | | catch (IOException ex) |
| 97 | | | { |
| 98 | 0 | | LOGGER.log(Level.WARNING, "Failed to load modes catalog, " |
| 99 | | | + "no syntax highlighting will be available in the output.", |
| 100 | | | ex); |
| 101 | | | } |
| 102 | | | finally |
| 103 | | | { |
| 104 | 0 | | IoUtil.close(in); |
| 105 | 0 | | } |
| 106 | 0 | | } |
| 107 | | | |
| 108 | | | |
| 109 | | | |
| 110 | | | {@inheritDoc} |
| 111 | | | |
| 112 | | | public InputSource resolveEntity (String publicId, String systemId) |
| 113 | | | { |
| 114 | 0 | | return XMLUtilities.findEntity(systemId, "catalog.dtd", jEdit.class); |
| 115 | | | } |
| 116 | | | |
| 117 | | | |
| 118 | | | |
| 119 | | | |
| 120 | | | |
| 121 | | | {@inheritDoc} |
| 122 | | | |
| 123 | | | public void startElement (String uri, String localName, |
| 124 | | | String qName, Attributes attrs) |
| 125 | | | { |
| 126 | 0 | | if ("MODE".equals(qName)) |
| 127 | | | { |
| 128 | 0 | | final String modeName = attrs.getValue("NAME"); |
| 129 | 0 | | final String file = attrs.getValue("FILE"); |
| 130 | 0 | | if (file == null) |
| 131 | | | { |
| 132 | 0 | | LOGGER.log(Level.WARNING, "Mode '" + modeName |
| 133 | | | + "' doesn't have a FILE attribute"); |
| 134 | | | } |
| 135 | | | |
| 136 | 0 | | Mode mode = ModeProvider.instance.getMode(modeName); |
| 137 | 0 | | if (mode == null) |
| 138 | | | { |
| 139 | 0 | | mode = new Mode(modeName); |
| 140 | 0 | | ModeProvider.instance.addMode(mode); |
| 141 | | | } |
| 142 | | | |
| 143 | 0 | | mode.setProperty("file", "/modes/" + file); |
| 144 | | | |
| 145 | 0 | | final String filenameGlob = attrs.getValue("FILE_NAME_GLOB"); |
| 146 | 0 | | if (filenameGlob != null) |
| 147 | | | { |
| 148 | 0 | | mode.setProperty("filenameGlob", filenameGlob); |
| 149 | | | } |
| 150 | | | else |
| 151 | | | { |
| 152 | 0 | | mode.unsetProperty("filenameGlob"); |
| 153 | | | } |
| 154 | | | |
| 155 | 0 | | final String firstlineGlob = attrs.getValue("FIRST_LINE_GLOB"); |
| 156 | 0 | | if (firstlineGlob != null) |
| 157 | | | { |
| 158 | 0 | | mode.setProperty("firstlineGlob", firstlineGlob); |
| 159 | | | } |
| 160 | | | else |
| 161 | | | { |
| 162 | 0 | | mode.unsetProperty("firstlineGlob"); |
| 163 | | | } |
| 164 | | | |
| 165 | 0 | | mode.init(); |
| 166 | | | } |
| 167 | 0 | | } |
| 168 | | | } |