1 19 20 package org.netbeans.modules.web.core.syntax.completion; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import java.util.List ; 25 import java.util.ArrayList ; 26 import javax.swing.text.JTextComponent ; 27 28 import org.netbeans.editor.ext.CompletionQuery; 29 import org.openide.util.NbBundle; 30 import org.netbeans.modules.web.core.syntax.*; 31 32 37 public abstract class AttributeValueSupport extends Object { 38 39 private static Map supports; 40 41 public static void putSupport(AttributeValueSupport support) { 42 if (supports == null) 43 initialize(); 44 supports.put(support, support); 46 } 47 48 public static AttributeValueSupport getSupport(boolean tag, String longName, String attrName) { 49 if (supports == null) 50 initialize(); 51 AttributeValueSupport support = new AttributeValueSupport.Default (tag, longName, attrName); 52 return (AttributeValueSupport)supports.get(support); 53 } 54 55 private static void initialize() { 56 supports = new HashMap (); 57 putSupport(new AttrSupports.ScopeSupport(true, "jsp:useBean", "scope")); putSupport(new AttrSupports.ClassNameSupport(true, "jsp:useBean", "class")); putSupport(new AttrSupports.GetSetPropertyName(true, "jsp:getProperty", "name")); putSupport(new AttrSupports.GetSetPropertyName(true, "jsp:setProperty", "name")); putSupport(new AttrSupports.GetPropertyProperty()); 64 putSupport(new AttrSupports.SetPropertyProperty()); 65 putSupport(new AttrSupports.TaglibURI()); 67 putSupport(new AttrSupports.TaglibTagdir()); 68 putSupport(new AttrSupports.PackageListSupport(false, "page", "import")); putSupport(new AttrSupports.ClassNameSupport(false, "page", "extends")); putSupport(new AttrSupports.PageLanguage()); 72 putSupport(new AttrSupports.TrueFalseSupport(false, "page", "session")); putSupport(new AttrSupports.TrueFalseSupport(false, "page", "autoFlush")); putSupport(new AttrSupports.TrueFalseSupport(false, "page", "isThreadSafe")); putSupport(new AttrSupports.TrueFalseSupport(false, "page", "isErrorPage")); putSupport(new AttrSupports.FilenameSupport (false, "page", "errorPage")); putSupport(new AttrSupports.EncodingSupport(false, "page", "pageEncoding")); putSupport(new AttrSupports.TrueFalseSupport(false, "page", "isELIgnored")); putSupport(new AttrSupports.PackageListSupport(false, "tag", "import")); putSupport(new AttrSupports.EncodingSupport(false, "tag", "pageEncoding")); putSupport(new AttrSupports.TrueFalseSupport(false, "tag", "isELIgnored")); putSupport(new AttrSupports.FilenameSupport(false, "tag", "small-icon")); putSupport(new AttrSupports.FilenameSupport(false, "tag", "large-icon")); putSupport(new AttrSupports.TrueFalseSupport(false, "attribute", "required")); putSupport(new AttrSupports.TrueFalseSupport(false, "attribute", "fragment")); putSupport(new AttrSupports.TrueFalseSupport(false, "attribute", "rtexprvalue")); putSupport(new AttrSupports.TrueFalseSupport(false, "variable", "declare")); putSupport(new AttrSupports.VariableScopeSupport(false, "variable", "scope")); putSupport(new AttrSupports.ClassNameSupport(false, "variable", "variable-class")); putSupport(new AttrSupports.FilenameSupport (false, "include", "file")); putSupport(new AttrSupports.FilenameSupport (true, "jsp:directive.include", "file")); 97 putSupport(new AttrSupports.FilenameSupport (true, "jsp:include", "page")); putSupport(new AttrSupports.FilenameSupport (true, "jsp:forward", "page")); putSupport(new AttrSupports.TrueFalseSupport(true, "jsp:include", "flush")); 102 putSupport(new AttrSupports.ScopeSupport(true, "jsp:doBody", "scope")); 104 putSupport(new AttrSupports.ScopeSupport(true, "jsp:invoke", "scope")); 107 putSupport(new AttrSupports.PackageListSupport(true, "jsp:directive.page", "import")); putSupport(new AttrSupports.ClassNameSupport(true, "jsp:directive.page", "extends")); putSupport(new AttrSupports.TrueFalseSupport(true, "jsp:directive.page", "session")); putSupport(new AttrSupports.TrueFalseSupport(true, "jsp:directive.page", "autoFlush")); putSupport(new AttrSupports.TrueFalseSupport(true, "jsp:directive.page", "isThreadSafe")); putSupport(new AttrSupports.TrueFalseSupport(true, "jsp:directive.page", "isErrorPage")); putSupport(new AttrSupports.FilenameSupport (true, "jsp:directive.page", "errorPage")); putSupport(new AttrSupports.EncodingSupport(true, "jsp:directive.page", "pageEncoding")); putSupport(new AttrSupports.TrueFalseSupport(true, "jsp:directive.page", "isELIgnored")); 118 putSupport(new AttrSupports.YesNoTrueFalseSupport(true, "jsp:output", "omit-xml-declaration")); putSupport(new AttrSupports.RootVersionSupport(true, "jsp:root", "version")); putSupport(new AttrSupports.PluginTypeSupport(true, "jsp:plugin", "type")); putSupport(new AttrSupports.TrueFalseSupport(true, "jsp:attribute", "trim")); 123 } 124 125 protected boolean tag; 126 protected String longName; 127 protected String attrName; 128 129 134 public AttributeValueSupport(boolean tag, String longName, String attrName) { 135 this.tag = tag; 136 this.longName = longName; 137 this.attrName = attrName; 138 } 139 140 public boolean equals(Object obj) { 141 AttributeValueSupport sup2 = (AttributeValueSupport)obj; 142 return (tag == sup2.tag) && 143 (longName.equals(sup2.longName)) && 144 (attrName.equals(sup2.attrName)); 145 } 146 147 public int hashCode() { 148 return longName.hashCode() + attrName.hashCode(); 149 } 150 151 152 public abstract CompletionQuery.Result getResult(JTextComponent component, 153 int offset, JspSyntaxSupport sup, SyntaxElement.TagDirective item, 154 String valuePart); 155 156 160 public static class Default extends AttributeValueSupport { 161 162 167 public Default(boolean tag, String longName, String attrName) { 168 super(tag, longName, attrName); 169 } 170 171 172 protected String completionTitle() { 173 return NbBundle.getMessage (JSPKit.class, "CTL_JSP_Completion_Title"); 174 } 175 176 179 protected List createCompletionItems(int offset, JspSyntaxSupport sup, SyntaxElement.TagDirective item, String valuePart) { 180 List values = sup.filterList(possibleValues(sup, item), valuePart); 182 List items = new ArrayList (); 183 for (int i = 0; i < values.size(); i++) { 184 items.add(new JspCompletionItem.AttributeValue((String )values.get(i))); 185 } 186 return items; 187 } 188 189 192 protected List possibleValues(JspSyntaxSupport sup, SyntaxElement.TagDirective item) { 193 return new ArrayList (); 194 } 195 196 200 public CompletionQuery.Result getResult (JTextComponent component, int offset, 201 JspSyntaxSupport sup, SyntaxElement.TagDirective item, String valuePart) { 202 List items = createCompletionItems (offset, sup, item, valuePart); 203 int valuePartLength = valuePart.length (); 204 205 return new JspCompletionQuery.JspCompletionResult(component, completionTitle(), 206 items, offset - valuePartLength, valuePartLength, -1); 207 } 208 209 } 210 211 } | Popular Tags |