KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > syntax > completion > JspCompletionItem


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.core.syntax.completion;
21
22
23 import java.awt.Graphics JavaDoc;
24 import java.io.IOException JavaDoc;
25 import javax.swing.text.*;
26 import java.awt.Color JavaDoc;
27 import java.awt.Component JavaDoc;
28 import java.io.ByteArrayOutputStream JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.net.MalformedURLException JavaDoc;
31 import java.net.URL JavaDoc;
32
33 import javax.servlet.jsp.tagext.*;
34
35 import org.netbeans.editor.*;
36 import org.netbeans.editor.Utilities;
37 import org.netbeans.editor.ext.ExtFormatter;
38 import org.netbeans.modules.editor.NbEditorUtilities;
39 import org.netbeans.modules.web.core.syntax.spi.AutoTagImporterProvider;
40 import org.openide.util.NbBundle;
41 import org.netbeans.modules.web.core.syntax.*;
42 import org.openide.filesystems.FileObject;
43 import org.openide.filesystems.Repository;
44 import org.openide.loaders.DataFolder;
45 import org.openide.loaders.FolderLookup;
46 import org.openide.util.Lookup;
47
48
49
50 /**
51  *
52  * @author Petr Jiricka, Petr Nejedly, Marek Fukala
53  */

54
55 /* ------------------------------------------------------------------------ */
56 /** An interface used as a generic value returned in CompletionQuery.Result
57  * as an data item
58  */

59 public class JspCompletionItem {
60     
61     private static final int DIRECTIVE_SORT_PRIORITY = 5;
62     private static final int DEFAULT_SORT_PRIORITY = 10;
63     
64     public static abstract class JspResultItem extends org.netbeans.modules.web.core.syntax.completion.ResultItem {
65         /** Contains a help for the item. It can be a url for a file.
66          */

67         protected String JavaDoc help;
68         protected String JavaDoc text;
69         private static ResultItemPaintComponent component = null;
70         
71         public JspResultItem( String JavaDoc text ) {
72             this.text = text;
73             help = null;
74         }
75         
76         public JspResultItem( String JavaDoc text, String JavaDoc help ) {
77             this( text );
78             this.help = help;
79         }
80         
81         public String JavaDoc getItemText() {
82             return text;
83         }
84         
85         protected Object JavaDoc getAssociatedObject() {
86             return text;
87         }
88         
89         public int getSortPriority() {
90             return DEFAULT_SORT_PRIORITY;
91         }
92         
93         public CharSequence JavaDoc getInsertPrefix() {
94             return getItemText();
95         }
96         
97         public Component JavaDoc getPaintComponent(boolean isSelected) {
98             if (component == null) {
99                 component = new ResultItemPaintComponent.StringPaintComponent();
100             }
101             component.setSelected(isSelected);
102             component.setString(text);
103             return component;
104         }
105         
106         /** Returns a url or null, if the help is not URL or the help is not defined.
107          */

108         public URL JavaDoc getHelpURL(){
109             if (help == null || help.equals(""))
110                 return null;
111             try{
112                 return new URL JavaDoc(help);
113             } catch (java.io.IOException JavaDoc e){
114             }
115             return null;
116         }
117         
118         /** Returns help for the item. It can be only url. If the item doesn't have a help
119          * than returns null. The class can overwrite this method and compounds the help realtime.
120          */

121         public String JavaDoc getHelp(){
122             return help;
123         }
124         
125         /** Returns whether the item has a help.
126          */

127         public boolean hasHelp(){
128             return (help != null && help.length() > 0);
129         }
130         
131         public void setHelp(String JavaDoc help){
132             this.help = help;
133         }
134         
135         protected boolean substituteText( JTextComponent c, int offset, int len, String JavaDoc fill, int moveBack) {
136             BaseDocument doc = (BaseDocument)c.getDocument();
137             try {
138                 doc.atomicLock();
139                 try {
140                     //test whether we are trying to insert sg. what is already present in the text
141
String JavaDoc currentText = doc.getText(offset, (doc.getLength() - offset) < fill.length() ? (doc.getLength() - offset) : fill.length()) ;
142                     if(!fill.substring(0, fill.length() - 1).equals(currentText)) {
143                         //remove common part
144
doc.remove( offset, len );
145                         doc.insertString( offset, fill, null);
146                     } else {
147                         c.setCaretPosition(c.getCaret().getDot() + fill.length() - len);
148                     }
149                     
150                     //format the inserted text
151
ExtFormatter f = (ExtFormatter)doc.getFormatter();
152                     int[] fmtBlk = f.getReformatBlock(c, fill);
153                     if (fmtBlk != null) {
154                         fmtBlk[0] = Utilities.getRowStart(doc, fmtBlk[0]);
155                         fmtBlk[1] = Utilities.getRowEnd(doc, fmtBlk[1]);
156                         f.reformat(doc, fmtBlk[0], fmtBlk[1], true);
157                     }
158                 } finally {
159                     doc.atomicUnlock();
160                 }
161                 if (moveBack != 0) {
162                     Caret caret = c.getCaret();
163                     int dot = caret.getDot();
164                     caret.setDot(dot - moveBack);
165                 }
166             } catch( BadLocationException exc ) {
167                 return false; //not sucessfull
168
} catch( IOException JavaDoc exc ) {
169                 return false; //not sucessfull
170
}
171             return true;
172         }
173         
174         public String JavaDoc getPaintText() {
175             return getItemText();
176         }
177         
178     }
179     
180     /** Item representing a JSP tag including its prefix. */
181     public static class PrefixTag extends JspResultItem {
182         
183         private TagInfo tagInfo;
184         private boolean isEmpty = false;
185         
186         private boolean hasAttributes = false;
187         
188         private static ResultItemPaintComponent.JspTagPaintComponent component = null;
189         private static ResultItemPaintComponent.JspTagPaintComponent componentEmpty = null;
190         
191         PrefixTag( String JavaDoc text ) {
192             super(text);
193         }
194         
195         PrefixTag(String JavaDoc prefix, TagInfo ti, SyntaxElement.Tag set) {
196             this(prefix + ":" + ti.getTagName()); // NOI18N
197
tagInfo = ti;
198             if ((tagInfo != null) &&
199                     (tagInfo.getBodyContent().equalsIgnoreCase(TagInfo.BODY_CONTENT_EMPTY)))
200                 isEmpty = true;
201             if (tagInfo != null)
202                 setHelp(tagInfo.getInfoString());
203             
204             //test whether this tag has some attributes
205
if (set != null) hasAttributes = !(set.getAttributes().size() == 0);
206         }
207         
208         PrefixTag(String JavaDoc prefix, TagInfo ti) {
209             this(prefix, ti, (SyntaxElement.Tag)null);
210         }
211         
212         public boolean hasHelp(){
213             return true;
214         }
215         
216         public TagInfo getTagInfo() {
217             return tagInfo;
218         }
219         
220         public String JavaDoc getHelp(){
221             URL JavaDoc url = super.getHelpURL();
222             if (url != null){
223                 String JavaDoc surl = url.toString();
224                 int first = surl.indexOf('#') + 1;
225                 String JavaDoc help = constructHelp(url);
226                 if (first > 0){
227                     int last = surl.lastIndexOf('#') + 1;
228                     String JavaDoc from = surl.substring( first , last - 1 );
229                     String JavaDoc to = surl.substring(last);
230                     first = help.indexOf(from);
231                     if (first > 0){
232                         first = first + from.length() + 2;
233                         if (first < help.length())
234                             help = help.substring(first);
235                     }
236                     last = help.indexOf(to);
237                     if (last > 0)
238                         help = help.substring(0, last);
239                     return help;
240                 }
241                 
242                 help = help.substring(help.indexOf("<h2>")); //NOI18N
243
help = help.substring(0, help.lastIndexOf("<h4>"));//NOI18N
244
return help;
245             }
246             return constructHelp(tagInfo);
247         }
248         
249         public Component JavaDoc getPaintComponent(boolean isSelected) {
250             ResultItemPaintComponent comp = (isEmpty ? componentEmpty : component);
251             
252             if (comp == null) {
253                 comp = new ResultItemPaintComponent.JspTagPaintComponent(isEmpty);
254             }
255             comp.setSelected(isSelected);
256             comp.setString(text);
257             return comp;
258         }
259         
260         public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) {
261             String JavaDoc suffix = isEmpty? "/>": ">"; // NOI18N
262

263             if(hasAttributes) suffix = "";
264             
265             if (!getItemText().startsWith("/")) { // NOI18N
266
if (!shift)
267                     return substituteText(c, offset, len, getItemText(), 0); // NOI18N
268

269                 boolean hasAttrs = true;
270                 if (tagInfo != null) {
271                     TagAttributeInfo[] tAttrs = tagInfo.getAttributes();
272                     hasAttrs = (tAttrs != null)? (tAttrs.length > 0): true;
273                 }
274                 if (hasAttrs)
275                     return substituteText(c, offset, len, getItemText() + ( hasAttributes ? "" : " ") + suffix , suffix.length()); // NOI18N
276
else
277                     return substituteText(c, offset, len, getItemText() + suffix, 0);
278             } else
279                 // closing tag
280
return substituteText(c, offset, len, getItemText().substring(1) + ">", 0); // NOI18N
281
}
282         
283         protected boolean substituteText( JTextComponent c, int offset, int len, String JavaDoc fill, int moveBack) {
284             BaseDocument doc = (BaseDocument)c.getDocument();
285             boolean value = false;
286             try {
287                 doc.atomicLock();
288                 value = super.substituteText(c, offset, len, fill, moveBack);
289                 FileObject f = Repository.getDefault().getDefaultFileSystem().
290                         findResource("Editors/" + NbEditorUtilities.getFileObject(c.getDocument()).getMIMEType()+"/AutoTagImportProviders");
291                 if (f != null){
292                     DataFolder folder = DataFolder.findFolder(f);
293                     FolderLookup l = new FolderLookup(folder);
294                     Lookup.Result result = l.getLookup().lookup(new Lookup.Template(AutoTagImporterProvider.class));
295                     if (result != null){
296                         for(Object JavaDoc instance : result.allInstances()){
297                             ((AutoTagImporterProvider)instance).importLibrary(c.getDocument(),
298                                     tagInfo.getTagLibrary().getPrefixString(), tagInfo.getTagLibrary().getURI());
299                         }
300                     }
301                 }
302             } finally {
303                 doc.atomicUnlock();
304             }
305             return value;
306         }
307     }
308     
309     /** Item representing a JSP tag (without prefix) or JSP directive. */
310     public abstract static class TagDirective extends JspResultItem {
311         
312         protected static ResultItemPaintComponent component = null;
313         
314         TagDirective( String JavaDoc text ) {
315             super(text);
316         }
317         
318         public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) {
319             return substituteText(c, offset, len, getItemText() + " ", 0); // NOI18N
320
}
321         
322         public boolean instantSubstitutionEnabled(JTextComponent c) {
323             return true;
324         }
325         
326         public Component JavaDoc getPaintComponent(boolean isSelected) {
327             if (component == null) {
328                 component = new ResultItemPaintComponent.JspTagPaintComponent(false);
329             }
330             component.setSelected(isSelected);
331             component.setString(text);
332             return component;
333         }
334         
335         
336     }
337     
338     /** Item representing a JSP tag (without prefix). */
339     public static class Tag extends JspResultItem {
340         
341         protected static ResultItemPaintComponent.JspTagPaintComponent component = null;
342         
343         private TagInfo ti = null;
344         
345         public Tag( String JavaDoc text ) {
346             super(text);
347         }
348         
349         public Tag( String JavaDoc text, TagInfo ti) {
350             this(text);
351             this.ti = ti;
352             if (ti != null)
353                 setHelp(ti.getInfoString());
354         }
355         
356         public boolean hasHelp(){
357             return true;
358         }
359         
360         public TagInfo getTagInfo() {
361             return ti;
362         }
363         
364         public String JavaDoc getHelp(){
365             URL JavaDoc url = super.getHelpURL();
366             if (url != null){
367                 String JavaDoc surl = url.toString();
368                 int first = surl.indexOf('#') + 1;
369                 String JavaDoc help = constructHelp(url);
370                 if (first > 0){
371                     int last = surl.lastIndexOf('#') + 1;
372                     String JavaDoc from = surl.substring( first , last - 1 );
373                     String JavaDoc to = surl.substring(last);
374                     first = help.indexOf(from);
375                     if (first > 0){
376                         first = first + from.length() + 2;
377                         if (first < help.length())
378                             help = help.substring(first);
379                     }
380                     last = help.indexOf(to);
381                     if (last > 0)
382                         help = help.substring(0, last);
383                     return help;
384                 }
385                 
386                 help = help.substring(help.indexOf("<h2>")); //NOI18N
387
help = help.substring(0, help.lastIndexOf("<h4>"));//NOI18N
388
return help;
389             }
390             return constructHelp(ti);
391         }
392         
393         public Component JavaDoc getPaintComponent(boolean isSelected) {
394             if (component == null) {
395                 component = new ResultItemPaintComponent.JspTagPaintComponent(false);
396             }
397             component.setSelected(isSelected);
398             component.setString(text);
399             return component;
400         }
401         
402         public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) {
403             if (!getItemText().startsWith("/")) // NOI18N
404
return substituteText(c, offset, len, getItemText() + " ", 0); // NOI18N
405
else
406                 return substituteText(c, offset, len, getItemText().substring(1) + ">", 0); // NOI18N
407
}
408         
409         public boolean substituteCommonText( JTextComponent c, int offset, int len, int subLen ) {
410             if (!getItemText().startsWith("/")) { // NOI18N
411
return substituteText(c, offset, len, getItemText().substring(subLen), 0); // NOI18N
412
} else {
413                 return substituteText(c, offset, len, getItemText().substring(1, subLen), 0); // NOI18N
414
}
415         }
416     }
417     
418     /** Item representing a JSP tag (without prefix). */
419     static class Directive extends TagDirective {
420         TagInfo tagInfo;
421         
422         Directive(String JavaDoc text){
423             super(text);
424             tagInfo = null;
425         }
426         
427         Directive(String JavaDoc text, TagInfo tagInfo ) {
428             super(text);
429             this.tagInfo = tagInfo;
430             if (tagInfo != null)
431                 setHelp(tagInfo.getInfoString());
432         }
433         
434         public int getSortPriority() {
435             return DIRECTIVE_SORT_PRIORITY;
436         }
437         
438         public String JavaDoc getHelp(){
439             if (getHelpURL() != null){
440                 String JavaDoc text = constructHelp(getHelpURL());
441                 if (text != null){
442                     text = text.substring(text.indexOf("<h2>")); //NOI18N
443
text = text.substring(0, text.lastIndexOf("<h4>"));//NOI18N
444
return text;
445                 }
446             }
447             return constructHelp(tagInfo);
448         }
449         
450         public TagInfo getTagInfo(){
451             return tagInfo;
452         }
453         
454         public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) {
455             return substituteText(c, offset, len, "%@ " + getItemText() + " %>", 3); // NOI18N
456
}
457         
458         public boolean substituteCommonText( JTextComponent c, int offset, int len, int subLen ) {
459             len = len - 2;
460             offset = offset + 2;
461             return super.substituteCommonText(c, offset, len, subLen);
462         }
463         
464         public Component JavaDoc getPaintComponent(boolean isSelected) {
465             if (component == null) {
466                 component = new ResultItemPaintComponent.JspDirectivePaintComponent();
467             }
468             component.setSelected(isSelected);
469             component.setString(getItemText());
470             return component;
471         }
472         
473     }
474     
475     /** Item representing an attribute of a JSP tag or directive. */
476     public static class Attribute extends JspResultItem {
477         private TagAttributeInfo tagAttributeInfo;
478         private boolean required;
479         
480         private static ResultItemPaintComponent.JspTagPaintComponent component = null;
481         private static ResultItemPaintComponent.JspTagPaintComponent componentRequired = null;
482         
483         Attribute( String JavaDoc text ) {
484             super(text);
485             tagAttributeInfo = null;
486             required = false;
487         }
488         
489         Attribute(TagAttributeInfo tai) {
490             super(tai.getName());
491             required = tai.isRequired();
492             tagAttributeInfo = tai;
493             if (tai.getTypeName() == null && tai.isFragment())
494                 setHelp("fragment"); // NOI!18N
495
else
496                 setHelp(tai.getTypeName());
497         }
498         
499         public Component JavaDoc getPaintComponent(boolean isSelected) {
500             ResultItemPaintComponent comp = (required ? componentRequired : component);
501             
502             if (comp == null) {
503                 comp = new ResultItemPaintComponent.AttributePaintComponent(required);
504             }
505             
506             comp.setSelected(isSelected);
507             comp.setString(getItemText());
508             return comp;
509         }
510         
511         public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) {
512             //always do the shift => jump into the attribute value between the quotation marks
513
return substituteText(c, offset, len, getItemText() + "=\"\"", 1); // NOI18N
514
}
515         
516         public String JavaDoc getHelp() {
517             URL JavaDoc url = super.getHelpURL();
518             if (url != null){
519                 String JavaDoc surl = url.toString();
520                 int first = surl.indexOf('#') + 1;
521                 int last = surl.lastIndexOf('#') + 1;
522                 String JavaDoc from;
523                 
524                 if (first < last){
525                     from = surl.substring( first , last - 1 );
526                 } else {
527                     from = surl.substring( first );
528                 }
529                 String JavaDoc text = constructHelp(getHelpURL());
530                 first = text.indexOf(from);
531                 if (first > 0){
532                     first = first + from.length() + 2;
533                     if (first < text.length())
534                         text = text.substring(first);
535                 }
536                 
537                 String JavaDoc to = surl.substring(last);
538                 last = text.indexOf(to);
539                 if (last > 0)
540                     text = text.substring(0, last);
541                 return text;
542             }
543             if (tagAttributeInfo != null){
544                 StringBuffer JavaDoc text = new StringBuffer JavaDoc();
545                 text.append("<table border=\"0\"><tr><td><b>Name:</b></td><td>"); //NOI18N
546
text.append(tagAttributeInfo.getName()); //NOI18N
547
text.append("</td></tr><tr><td><b>Required:</b></td><td>"); //NOI18N
548
text.append(tagAttributeInfo.isRequired()); //NOI18N
549
text.append("</td></tr><tr><td><b>Request-time:</b></td><td>"); //NOI18N
550
text.append(tagAttributeInfo.canBeRequestTime()); //NOI18N
551
text.append("</td></tr><tr><td><b>Fragment:</b></td><td>"); //NOI18N
552
text.append(tagAttributeInfo.isFragment()); //NOI18N
553
text.append("</td></tr></table>"); //NOI18N
554
return text.toString();
555             }
556             return super.getHelp();
557         }
558         
559         public URL JavaDoc getHelpURL(){
560             URL JavaDoc url = super.getHelpURL();
561             if (url != null){
562                 String JavaDoc surl = url.toString();
563                 int index = surl.lastIndexOf('#'); // NOI18N
564
if (index > 0)
565                     surl = surl.substring(0, index);
566                 try {
567                     url = new URL JavaDoc(surl);
568                 } catch (MalformedURLException JavaDoc e){
569                 }
570             }
571             return url;
572         }
573         
574     }
575     
576     /** Item representing a JSP attribute value. */
577     static class AttributeValue extends JspResultItem {
578         
579         AttributeValue( String JavaDoc text ) {
580             //super(text, Color.red);
581
super(text);
582         }
583         
584         public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) {
585             return substituteText(c, offset, len, getItemText(), 0);
586         }
587     }
588     
589     /** Item representing a File attribute */
590     public static class FileAttributeValue extends JspResultItem {
591         private javax.swing.ImageIcon JavaDoc icon;
592         private Color JavaDoc color;
593         
594         FileAttributeValue(String JavaDoc text, Color JavaDoc color){
595             this(text, color, null);
596         }
597         
598         FileAttributeValue(String JavaDoc text, Color JavaDoc color, javax.swing.ImageIcon JavaDoc icon){
599             super(text);
600             this.color = color;
601             this.icon = icon;
602         }
603         
604         public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) {
605             return substituteText(c, offset, len, getItemText(), 0);
606         }
607         
608         public Component JavaDoc getPaintComponent(final boolean isSelected) {
609             return new ResultItemPaintComponent() {
610                 public void draw(Graphics JavaDoc g) {
611                     drawIcon(g, FileAttributeValue.this.icon);
612                     drawString(g, text, FileAttributeValue.this.color);
613                 }
614                 
615                 public boolean isSelected() {
616                     return isSelected;
617                 }
618             };
619         }
620     }
621     
622     private static String JavaDoc constructHelp(URL JavaDoc url){
623         if (url == null )
624             return null;
625         try{
626             InputStream JavaDoc is = url.openStream();
627             byte buffer[] = new byte[1000];
628             ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
629             int count = 0;
630             do {
631                 count = is.read(buffer);
632                 if (count > 0) baos.write(buffer, 0, count);
633             } while (count > 0);
634             
635             is.close();
636             String JavaDoc text = baos.toString();
637             baos.close();
638             return text;
639         } catch (java.io.IOException JavaDoc e){
640             return null;
641         }
642     }
643     
644     private static String JavaDoc constructHelp(TagInfo tagInfo){
645         if (tagInfo == null) return null;
646         
647         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
648         sb.append("<h2>").append(getString("LBL_TagName")).append(" "); //NOI18N
649
sb.append(tagInfo.getTagName()).append("</h2>"); // NOI18N
650
String JavaDoc val = tagInfo.getDisplayName();
651         if (val != null) {
652             sb.append("<p>").append(getString("LBL_DisplayName")); //NOI18N
653
sb.append("<i>").append(val).append("</i>"); // NOI18N
654
}
655         val = tagInfo.getInfoString();
656         if (val != null)
657             sb.append("<hr>").append(val).append("<hr>"); // NOI18N
658

659         sb.append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"1\">");// NOI18N
660
sb.append("<tr bgcolor=\"#CCCCFF\"><td colspan=\"2\"><font size=\"+2\"><b>");// NOI18N
661
sb.append("Tag Information</b></font></td></tr>");// NOI18N
662
sb.append("<tr><td>Tag Class</td><td>");// NOI18N
663
if (tagInfo.getTagClassName() != null && !tagInfo.getClass().equals("") )
664             sb.append(tagInfo.getTagClassName());
665         else
666             sb.append("<i>None</i>");// NOI18N
667
sb.append("</td></tr><tr><td>Body Content</td><td>");// NOI18N
668
sb.append(tagInfo.getBodyContent());
669         sb.append("</td></tr><tr><td>Display Name</td><td>");// NOI18N
670
if (tagInfo.getDisplayName() != null && !tagInfo.getDisplayName().equals("")){
671             sb.append(tagInfo.getDisplayName());
672         } else
673             sb.append("<i>None</i>");// NOI18N
674
sb.append("</td></tr></table><br>");// NOI18N
675

676         sb.append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"1\">");// NOI18N
677
sb.append("<tr bgcolor=\"#CCCCFF\"><td colspan=\"3\"><font size=\"+2\"><b>Attributes</b></font></td></tr>");// NOI18N
678

679         TagAttributeInfo [] attrs = tagInfo.getAttributes();
680         if (attrs != null && attrs.length > 0){
681             sb.append("<tr><td><b>Name</b></td><td><b>Required</b></td><td><b>Request-time</b></td></tr>");// NOI18N
682
for (int i = 0; i < attrs.length; i++){
683                 sb.append("<tr><td>"); // NOI18N
684
sb.append(attrs[i].getName());
685                 sb.append("</td><td>"); // NOI18N
686
sb.append(attrs[i].isRequired());
687                 sb.append("</td><td>"); // NOI18N
688
sb.append(attrs[i].canBeRequestTime());
689                 sb.append("</td></tr>"); // NOI18N
690
}
691         } else {
692             sb.append("<tr><td colspan=\"3\"><i>No Attributes Defined.</i></td></tr>");// NOI18N
693
}
694         sb.append("</table><br>");// NOI18N
695
sb.append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"1\">");// NOI18N
696
sb.append("<tr bgcolor=\"#CCCCFF\"><td colspan=\"4\"><font size=\"+2\"><b>Variables</b></font></td></tr>");// NOI18N
697
TagVariableInfo [] variables = tagInfo.getTagVariableInfos();
698         if (variables != null && variables.length > 0){
699             sb.append("<tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Declare</b></td><td><b>Scope</b></td></tr>");// NOI18N
700
for (int i = 0; i < variables.length; i++){
701                 sb.append("<tr><td>"); // NOI18N
702
if (variables[i].getNameGiven() != null && !variables[i].getNameGiven().equals("")){// NOI18N
703
sb.append(variables[i].getNameGiven());
704                 } else {
705                     if(variables[i].getNameFromAttribute() != null && !variables[i].getNameFromAttribute().equals("")) // NOI18N
706
sb.append("<i>From attribute '").append(variables[i].getNameFromAttribute()).append("'</i>");// NOI18N
707
else
708                         sb.append("<i>Unknown</i>"); // NOI18N
709
}
710                 sb.append("</td><td><code>"); // NOI18N
711
if (variables[i].getClassName() == null || variables[i].getClassName().equals("") )
712                     sb.append("java.lang.String");// NOI18N
713
else
714                     sb.append(variables[i].getClassName());
715                 sb.append("</code></td></tr>"); // NOI18N
716
sb.append("</td><td>"); // NOI18N
717
sb.append(variables[i].getDeclare());
718                 sb.append("</td></tr>"); // NOI18N
719
sb.append("</td><td>"); // NOI18N
720
switch (variables[i].getScope()){
721                     case VariableInfo.AT_BEGIN:
722                         sb.append("AT_BEGIN"); break;// NOI18N
723
case VariableInfo.AT_END:
724                         sb.append("AT_END"); break;// NOI18N
725
default:
726                         sb.append("NESTED");// NOI18N
727
}
728                 sb.append("</td></tr>"); // NOI18N
729
}
730         } else {
731             sb.append("<tr><td colspan=\"4\"><i>No Variables Defined.</i></td></tr>");// NOI18N
732
}
733         sb.append("</table><br>");// NOI18N
734
return sb.toString();
735     }
736     
737     private static String JavaDoc getString(String JavaDoc key){
738         return NbBundle.getMessage(JspCompletionItem.class, key);
739     }
740     
741
742     // ------------------------ EL Items ------------------------------------------
743

744     public interface ELItem{};
745     
746     public static class ELImplicitObject extends JspResultItem implements ELItem {
747         
748         private static ResultItemPaintComponent.ELImplicitObjectPaintComponent paintComponent = null;
749         
750         int type;
751         
752         ELImplicitObject(String JavaDoc text, int type){
753             super(text);
754             this.type = type;
755         }
756         
757         public int getSortPriority() {
758             return 15;
759         }
760         
761         public Component JavaDoc getPaintComponent(boolean isSelected) {
762             if (paintComponent == null)
763                 paintComponent = new ResultItemPaintComponent.ELImplicitObjectPaintComponent();
764             paintComponent.setString(text);
765             paintComponent.setType(type);
766             return paintComponent;
767         }
768         
769         public String JavaDoc getItemText() {
770             String JavaDoc result = text;
771             if (type == org.netbeans.modules.web.core.syntax.completion.ELImplicitObjects.MAP_TYPE)
772                 result = result + "[]";
773             return result; //NOI18N
774
}
775         
776         public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) {
777             if (type == org.netbeans.modules.web.core.syntax.completion.ELImplicitObjects.MAP_TYPE)
778                 return substituteText(c, offset, len, getItemText(), 1);
779             else
780                 return substituteText(c, offset, len, getItemText(), 0);
781         }
782     }
783     
784     
785     public static class ELBean extends JspResultItem implements ELItem {
786         
787         private static ResultItemPaintComponent.ELBeanPaintComponent paintComponent = null;
788         
789         protected String JavaDoc type;
790         
791         public ELBean( String JavaDoc text, String JavaDoc type ) {
792             super(text);
793             if (type.lastIndexOf('.')> -1 )
794                 this.type = type.substring(type.lastIndexOf('.')+1);
795             else
796                 this.type = type;
797         }
798         
799         public int getSortPriority() {
800             return 10;
801         }
802         
803         public Component JavaDoc getPaintComponent(boolean isSelected) {
804             if (paintComponent == null)
805                 paintComponent = new ResultItemPaintComponent.ELBeanPaintComponent();
806             paintComponent.setString(text);
807             paintComponent.setTypeName(type);
808             return paintComponent;
809         }
810     }
811     
812     public static class ELProperty extends ELBean implements ELItem {
813         
814         private static ResultItemPaintComponent.ELPropertyPaintComponent paintComponent = null;
815         
816         public ELProperty( String JavaDoc text, String JavaDoc type ) {
817             super(text, type);
818         }
819         
820         public Component JavaDoc getPaintComponent(boolean isSelected) {
821             if (paintComponent == null)
822                 paintComponent = new ResultItemPaintComponent.ELPropertyPaintComponent();
823             paintComponent.setString(text);
824             paintComponent.setTypeName(type);
825             return paintComponent;
826         }
827     }
828     
829     public static class ELFunction extends ELBean implements ELItem {
830         
831         private static ResultItemPaintComponent.ELFunctionPaintComponent paintComponent = null;
832         
833         private String JavaDoc prefix;
834         private String JavaDoc parameters;
835         
836         
837         public ELFunction( String JavaDoc prefix, String JavaDoc name, String JavaDoc type, String JavaDoc parameters) {
838             super(name, type);
839             this.prefix = prefix;
840             this.parameters = parameters;
841         }
842         
843         public Component JavaDoc getPaintComponent(boolean isSelected) {
844             if (paintComponent == null)
845                 paintComponent = new ResultItemPaintComponent.ELFunctionPaintComponent();
846             paintComponent.setString(text);
847             paintComponent.setTypeName(type);
848             paintComponent.setPrefix(prefix);
849             paintComponent.setParameters(parameters);
850             return paintComponent;
851         }
852         
853         public int getSortPriority() {
854             return 12;
855         }
856         
857         public String JavaDoc getItemText() {
858             return prefix+":"+text+"()"; //NOI18N
859
}
860         
861         public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) {
862             return substituteText(c, offset, len, getItemText(), 1);
863         }
864     }
865     
866 }
867
Popular Tags