1 7 8 package org.jdesktop.jdnc.markup.elem; 9 10 import java.util.Map ; 11 12 import java.util.regex.Pattern ; 13 14 import org.w3c.dom.Element ; 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 30 public class PatternFilterElement extends FilterElement { 31 32 public PatternFilterElement(Element element, ElementType elementType) { 33 super(element, elementType); 34 } 35 36 protected Object instantiate() { 37 return new PatternFilter(null, 0, getColumnIndex()); 38 } 39 40 protected void applyAttributesAfter() { 41 super.applyAttributesAfter(); 42 applyExpressionAttribute(); } 44 45 private void applyExpressionAttribute() { 48 if (object != null) { 50 51 String 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 ex) { 61 logException("Bad regular expression \"" + expression + 62 "\" or match flags", ex); 63 } 64 } 65 } 66 } 67 68 protected Map registerAttributeHandlers() { 69 Map handlerMap = super.registerAttributeHandlers(); 70 if (handlerMap != null) { 71 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 |