Update of 
/var/cvs/speeltuin/ernst/tagfileparser/src/nl/vpro/tagfileparser/parser
In directory james.mmbase.org:/tmp/cvs-serv1313/src/nl/vpro/tagfileparser/parser

Modified Files:
        DirectiveParser.java RegexpParser.java 
Log Message:
work in progress


See also: 
http://cvs.mmbase.org/viewcvs/speeltuin/ernst/tagfileparser/src/nl/vpro/tagfileparser/parser


Index: DirectiveParser.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/tagfileparser/src/nl/vpro/tagfileparser/parser/DirectiveParser.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- DirectiveParser.java        9 Jul 2008 10:07:48 -0000       1.2
+++ DirectiveParser.java        15 Jul 2008 06:54:23 -0000      1.3
@@ -23,7 +23,7 @@
         *            the name of the directive you want to parse
         */
        public DirectiveParser(String directive) {
-               super("^[\\s]*<[EMAIL PROTECTED]" + directive, "%>[\\s]*$", 
false);
+               super("^[\\s]*<[EMAIL PROTECTED]" + fixDirective(directive), 
"%>[\\s]*$", false);
        }
 
        @Override
@@ -34,52 +34,41 @@
 
                // make one string for each attribute-value pair, assuming
                // that there might be whitespaces surrounding the equals 
operator
-               Pattern attPattern = Pattern
-                               .compile("[a-zA-Z0-9_\\-]+\\s*=\\s*\"[^\"]*\"");
+               Pattern attPattern = 
Pattern.compile("[a-zA-Z0-9_\\-]+\\s*=\\s*\"[^\"]*\"");
                Matcher attMatcher = attPattern.matcher(line);
                int start = 0;
 
                while (attMatcher.find(start)) {
-                       String attString = line.substring(attMatcher.start(), 
attMatcher
-                                       .end());
+                       String attString = line.substring(attMatcher.start(), 
attMatcher.end());
                        attributeFound(createAttribute(attString));
                        start = attMatcher.end();
                }
        }
 
        /**
-        * @param attributeString
-        * @return
-        * @throws IllegalAttributeException
-        *             when the give string could not be parsed to a name value
-        *             pair.
+        * Template method that will be called when the directive is found.
         */
-       private Attribute createAttribute(String attributeString) {
-               StringTokenizer tokenizer = new 
StringTokenizer(attributeString, "=",
-                               false);
-               if (tokenizer.countTokens() == 2) {
-                       String aName = tokenizer.nextToken().trim();
-                       String aValue = tokenizer.nextToken().trim();
-                       // trim the quotes from the attribute value;
-                       aValue = aValue.substring(1, aValue.length() - 1);
-                       return new Attribute(aName, aValue);
-               }
-               throw new IllegalAttributeException(
-                               "illegal string format for attribute and value: 
["
-                                               + attributeString + "]");
-       }
+       protected abstract void directiveFound();
+
+       /**
+        * Template method that will be called when an attribute is found.
+        * 
+        * @param name
+        * @param value
+        */
+       protected abstract void attributeFound(Attribute attribute);
 
        /**
+        * Remove the <%\@ and %> bits from the line
         * 
         * @param line
         */
-       String cleanup(String line) {
+       private final String cleanup(String line) {
                line = line.trim();
                if (line.startsWith("<%@")) {
                        line = line.substring(3, line.length());
                } else {
-                       throw new RuntimeException(
-                                       "Line did not start with expected 
'<%@'. [" + line + "]");
+                       throw new BasicTagParserException("Line did not start 
with expected '<%@'. [" + line + "]");
                }
                if (line.endsWith("%>")) {
                        line = line.substring(0, line.length() - 2);
@@ -89,17 +78,30 @@
        }
 
        /**
-        * Template method that will be called when the directive is found.
+        * @param attributeString
+        * @return
+        * @throws IllegalAttributeException
+        *             when the give string could not be parsed to a name value
+        *             pair.
         */
-       protected abstract void directiveFound();
+       private final Attribute createAttribute(String attributeString) {
+               StringTokenizer tokenizer = new 
StringTokenizer(attributeString, "=", false);
+               if (tokenizer.countTokens() == 2) {
+                       String aName = tokenizer.nextToken().trim();
+                       String aValue = tokenizer.nextToken().trim();
+                       // trim the quotes from the attribute value;
+                       aValue = aValue.substring(1, aValue.length() - 1);
+                       return new Attribute(aName, aValue);
+               }
+               throw new IllegalAttributeException("illegal string format for 
attribute and value: [" + attributeString + "]");
+       }
 
-       /**
-        * Template method that will be called when an attribute is found.
-        * 
-        * @param name
-        * @param value
-        */
-       protected abstract void attributeFound(Attribute attribute);
+       private static final String fixDirective(String directive) {
+               if (!directive.startsWith(" ")) {
+                       return directive + " ";
+               }
+               return directive;
+       }
 
        static class Attribute {
                private String name;
@@ -121,18 +123,19 @@
        }
 
        /**
-        * This interface is used to creat simple objects that can
-        * take the string value of an attribute, and convert it 
-        * into a valid object value and inject it into the directive model 
object.
+        * This interface is used to creat simple objects that can take the 
string
+        * value of an attribute, and convert it into a valid object value and
+        * inject it into the directive model object.
         * 
         * @author ebunders
         *
         */
        public interface PropertySetter {
                /**
-                * @param value some attribute string value. 
-                * @throws IllegalDirectiveException when the value can not be 
converted
-                * to a valid object.
+                * @param value
+                *            some attribute string value.
+                * @throws IllegalDirectiveException
+                *             when the value can not be converted to a valid 
object.
                 */
                public void setProperty(String value);
        }


Index: RegexpParser.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/tagfileparser/src/nl/vpro/tagfileparser/parser/RegexpParser.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- RegexpParser.java   9 Jul 2008 10:07:48 -0000       1.2
+++ RegexpParser.java   15 Jul 2008 06:54:23 -0000      1.3
@@ -1,7 +1,7 @@
 package nl.vpro.tagfileparser.parser;
 
 import java.util.Iterator;
-import java.util.logging.Logger;
+import org.apache.commons.logging.*;
 
 import nl.vpro.tagfileparser.model.TagInfo;
 import nl.vpro.util.StringUtil;
@@ -15,7 +15,7 @@
  */
 public abstract class RegexpParser implements ElementParser {
        
-       private final Logger log = 
Logger.getLogger(RegexpParser.class.getName()); 
+       private final Log log = 
LogFactory.getLog(RegexpParser.class.getName()); 
 
        private String startPattern;
        private String endPattern;
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to