KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > markup > elem > PatternFilterElement


1 /*
2  * $Id: PatternFilterElement.java,v 1.1.1.1 2004/06/16 01:43:40 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.jdnc.markup.elem;
9
10 import java.util.Map JavaDoc;
11
12 import java.util.regex.Pattern JavaDoc;
13
14 import org.w3c.dom.Element JavaDoc;
15 import org.jdesktop.swing.decorator.*;
16
17 import net.openmarkup.ElementType;
18 import net.openmarkup.AttributeHandler;
19
20 import org.jdesktop.jdnc.markup.Attributes;
21 import org.jdesktop.jdnc.markup.Namespace;
22
23 import org.jdesktop.jdnc.markup.attr.Decoder;
24 import org.jdesktop.jdnc.markup.attr.NullAttribute;
25
26 /**
27  *
28  * @author Ramesh Gupta
29  */

30 public class PatternFilterElement extends FilterElement {
31
32     public PatternFilterElement(Element JavaDoc element, ElementType elementType) {
33         super(element, elementType);
34     }
35
36     protected Object JavaDoc instantiate() {
37         return new PatternFilter(null, 0, getColumnIndex());
38     }
39
40     protected void applyAttributesAfter() {
41         super.applyAttributesAfter();
42         applyExpressionAttribute(); // combo attribute
43
}
44
45     // XXX this is almost identical to PatternHighlighterElement.applyExpressionAttribute.
46
// Perhaps there could be some consolidation?
47
private void applyExpressionAttribute() {
48         // Identical to PatternHighlighterElement.applyExpressionAttribute
49
if (object != null) {
50             /** @todo deprecate Attributes.MATCH here and in PatternHighlighter */
51             // processes both Attributes.EXPRESSION and Attributes.MATCH
52
String JavaDoc expression = getAttributeNSOptional(Namespace.JDNC, Attributes.EXPRESSION);
53             if (expression.length() > 0) {
54                 try {
55                     int matchFlags = Decoder.decodePatternMatchFlags(
56                         getAttributeNSOptional(Namespace.JDNC, Attributes.MATCH));
57                     ( (PatternMatcher) object).setPattern(
58                         Pattern.compile(expression, matchFlags));
59                 }
60                 catch (Exception JavaDoc ex) {
61             logException("Bad regular expression \"" + expression +
62                  "\" or match flags", ex);
63                 }
64             }
65         }
66     }
67
68     protected Map JavaDoc registerAttributeHandlers() {
69         Map JavaDoc handlerMap = super.registerAttributeHandlers();
70         if (handlerMap != null) {
71         // Register null appliers. These attributes are handled elsewhere
72
handlerMap.put(Namespace.JDNC + ":" + Attributes.ID,
73                            NullAttribute.idHandler);
74             handlerMap.put(Namespace.JDNC + ":" + Attributes.EXPRESSION,
75                            exprHandler);
76             handlerMap.put(Namespace.JDNC + ":" + Attributes.MATCH,
77                            matchHandler);
78         }
79         return handlerMap;
80     }
81
82     private static final AttributeHandler exprHandler =
83         new AttributeHandler(Namespace.JDNC, Attributes.EXPRESSION, NullAttribute.nullApplier);
84
85     private static final AttributeHandler matchHandler =
86         new AttributeHandler(Namespace.JDNC, Attributes.EXPRESSION, NullAttribute.nullApplier);
87
88 }
89
Popular Tags