1 19 package org.netbeans.modules.xml.text.syntax; 20 21 import java.awt.Color ; 22 import java.util.*; 23 24 import org.netbeans.editor.Settings; 25 import org.netbeans.editor.SettingsUtil; 26 import org.netbeans.editor.SettingsNames; 27 import org.netbeans.editor.Coloring; 28 import org.netbeans.editor.BaseKit; 29 import org.netbeans.editor.Acceptor; 30 import org.netbeans.editor.AcceptorFactory; 31 import org.netbeans.editor.TokenCategory; 32 import org.netbeans.editor.TokenContext; 33 import org.netbeans.editor.TokenContextPath; 34 import org.netbeans.modules.xml.text.api.XMLDefaultTokenContext; 35 36 41 public class XMLSettingsInitializer extends Settings.AbstractInitializer { 42 43 44 public static final String NAME = "xml-settings-initializer"; 46 public XMLSettingsInitializer() { 47 super(NAME); 48 } 49 50 public void updateSettingsMap (Class kitClass, Map settingsMap) { 51 if (kitClass == null) return; 53 54 if (kitClass == BaseKit.class) { 55 56 new XMLTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap); 57 58 new DTDTokenColoringInitializer().updateSettingsMap(kitClass, settingsMap); 59 } 60 61 62 63 64 if (kitClass == DTDKit.class) { 65 66 settingsMap.put (SettingsNames.ABBREV_MAP, getDTDAbbrevMap()); 68 69 SettingsUtil.updateListSetting (settingsMap, SettingsNames.TOKEN_CONTEXT_LIST, 70 new TokenContext[] { DTDTokenContext.context } 71 ); 72 73 } 74 75 76 77 if (kitClass == XMLKit.class) { 78 79 settingsMap.put(SettingsNames.CODE_FOLDING_ENABLE, Boolean.TRUE); 80 81 settingsMap.put (SettingsNames.ABBREV_MAP, getXMLAbbrevMap()); 83 84 SettingsUtil.updateListSetting (settingsMap, SettingsNames.TOKEN_CONTEXT_LIST, 85 new TokenContext[] { XMLDefaultTokenContext.context } 86 ); 87 88 settingsMap.put(SettingsNames.IDENTIFIER_ACCEPTOR, getXMLIdentifierAcceptor()); 89 } 90 91 92 93 if (kitClass == XMLKit.class || kitClass == DTDKit.class) { 94 settingsMap.put(SettingsNames.ABBREV_RESET_ACCEPTOR, 95 new Acceptor() { 96 public boolean accept(char ch) { 97 return AcceptorFactory.NON_JAVA_IDENTIFIER.accept(ch) && ch != '!' && ch != '?'; 98 } 99 } 100 ); 101 } 102 103 } 104 105 Map getXMLAbbrevMap() { 107 Map xmlAbbrevMap = new TreeMap(); 108 109 xmlAbbrevMap.put ("?xm", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); xmlAbbrevMap.put ("!do", "<!DOCTYPE "); xmlAbbrevMap.put ("!cd", "<![CDATA[|]]>"); xmlAbbrevMap.put ("!at", "<!ATTLIST |>"); xmlAbbrevMap.put ("!el", "<!ELEMENT |>"); xmlAbbrevMap.put ("!en", "<!ENTITY |>"); xmlAbbrevMap.put ("pu", "PUBLIC \"|\""); xmlAbbrevMap.put ("sy", "SYSTEM \"|\""); 118 return xmlAbbrevMap; 119 } 120 121 Map getDTDAbbrevMap() { 123 Map dtdAbbrevMap = new TreeMap(); 124 125 dtdAbbrevMap.put ("!at", "<!ATTLIST |>"); dtdAbbrevMap.put ("!el", "<!ELEMENT |>"); dtdAbbrevMap.put ("!en", "<!ENTITY |>"); dtdAbbrevMap.put ("!no", "<!NOTATION |>"); dtdAbbrevMap.put ("cd", "CDATA"); dtdAbbrevMap.put ("em", "EMPTY"); dtdAbbrevMap.put ("en", "ENTITY"); dtdAbbrevMap.put ("ens", "ENTITIES"); dtdAbbrevMap.put ("fi", "#FIXED"); dtdAbbrevMap.put ("im", "#IMPLIED"); dtdAbbrevMap.put ("nm", "NMTOKEN"); dtdAbbrevMap.put ("nms", "NMTOKENS"); dtdAbbrevMap.put ("nn", "NOTATION"); dtdAbbrevMap.put ("pc", "#PCDATA"); dtdAbbrevMap.put ("pu", "PUBLIC \"|\""); dtdAbbrevMap.put ("re", "#REQUIRED"); dtdAbbrevMap.put ("rf", "IDREF"); dtdAbbrevMap.put ("rfs", "IDREFS"); dtdAbbrevMap.put ("sy", "SYSTEM \"|\""); 145 return dtdAbbrevMap; 146 } 147 148 149 152 Acceptor getXMLIdentifierAcceptor() { 153 154 return new Acceptor() { 155 public boolean accept(char ch) { 156 switch (ch) { 157 case ' ': case '\t': case '\n': case '\r': case '>': case '<': case '&': case '\'': case '"': case '/': 159 case '\\': return false; 161 } 162 163 return true; 164 } 165 }; 166 } 167 168 169 170 static class XMLTokenColoringInitializer 171 extends SettingsUtil.TokenColoringInitializer { 172 173 public XMLTokenColoringInitializer() { 174 super(XMLDefaultTokenContext.context); 175 } 176 177 public Object getTokenColoring(TokenContextPath tokenContextPath, TokenCategory tokenIDOrCategory, boolean printingSet) { 178 return new Coloring (null, Color.BLACK, null); 180 } 181 } 182 183 184 static class DTDTokenColoringInitializer 185 extends SettingsUtil.TokenColoringInitializer { 186 187 public DTDTokenColoringInitializer() { 188 super(DTDTokenContext.context); 189 } 190 191 public Object getTokenColoring(TokenContextPath tokenContextPath, TokenCategory tokenIDOrCategory, boolean printingSet) { 192 return new Coloring (null, Color.BLACK, null); 194 } 195 } 196 197 } 198 | Popular Tags |