Migration to maven almost complete. At least everything builds and works
[utils] / crawler / kiss / src / org / wamblee / crawler / kiss / main / ProgramConfigurationParser.java
diff --git a/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramConfigurationParser.java b/crawler/kiss/src/org/wamblee/crawler/kiss/main/ProgramConfigurationParser.java
deleted file mode 100644 (file)
index 8a5d5ac..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2005 the original author or authors.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.wamblee.crawler.kiss.main;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.dom4j.Attribute;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.Element;
-import org.dom4j.io.SAXReader;
-import org.wamblee.conditions.AndCondition;
-import org.wamblee.conditions.Condition;
-import org.wamblee.conditions.PropertyRegexCondition;
-import org.wamblee.crawler.kiss.guide.Program;
-
-/**
- * Parse the configuration of desired programs.
- */
-class ProgramConfigurationParser {
-    private static final int DEFAULT_PRIORITY = 1; 
-
-    // Configuration of interesting programs.
-
-    private static final String ELEM_PROGRAM = "program";
-    
-    private static final String ELEM_PRIORITY = "priority";
-
-    private static final String ELEM_PATTERN = "match";
-
-    private static final String ELEM_ACTION = "action";
-
-    private static final String ELEM_CATEGORY = "category";
-
-    private static final String ACTION_NOTIFY = "notify";
-
-    private List<ProgramFilter> _filters;
-
-    ProgramConfigurationParser() {
-        _filters = null;
-    }
-
-    /**
-     * Parses the condition used to match the desired programs.
-     * 
-     * @param aStream
-     *            Input stream to parse from.
-     * @return Condition.
-     */
-    void parse(InputStream aStream) {
-        List<ProgramFilter> filters = new ArrayList<ProgramFilter>();
-        try {
-            SAXReader reader = new SAXReader();
-            Document document = reader.read(aStream);
-
-            Element root = document.getRootElement();
-
-            for (Iterator i = root.elementIterator(ELEM_PROGRAM); i.hasNext();) {
-                Element program = (Element) i.next();
-
-                Element categoryElem = program.element(ELEM_CATEGORY);
-                String category = "";
-                if (categoryElem != null) {
-                    category = categoryElem.getText().trim();
-                }
-
-                Element actionElem = program.element(ELEM_ACTION);
-                int priority = DEFAULT_PRIORITY; 
-                String priorityString = program.elementTextTrim(ELEM_PRIORITY);
-                if ( priorityString != null ) { 
-                    priority = Integer.valueOf(priorityString);
-                }
-                ProgramAction action = new RecordProgramAction(priority);
-                if (actionElem != null) {
-                    if (actionElem.getText().equals(ACTION_NOTIFY)) {
-                        action = new InterestingProgramAction(category);
-                    }
-                }
-
-                List<Condition<Program>> regexConditions = new ArrayList<Condition<Program>>();
-                for (Iterator j = program.elementIterator(ELEM_PATTERN); j
-                        .hasNext();) {
-                    Element patternElem = (Element) j.next();
-                    String fieldName = "name";
-                    Attribute fieldAttribute = patternElem.attribute("field");
-                    if (fieldAttribute != null) {
-                        fieldName = fieldAttribute.getText();
-                    }
-                    String pattern = ".*(" + patternElem.getText() + ").*";
-                    regexConditions.add(new PropertyRegexCondition<Program>(
-                            fieldName, pattern, true));
-                }
-                Condition<Program> condition = new AndCondition<Program>(
-                        regexConditions);
-                filters.add(new ProgramFilter(condition, action));
-            }
-            _filters = filters;
-        } catch (DocumentException e) {
-            throw new RuntimeException("Error parsing program configuraiton", e);
-        }
-    }
-
-    /**
-     * Returns the list of program filters.
-     * 
-     * @return Filter list.
-     */
-    public List<ProgramFilter> getFilters() {
-        return _filters;
-    }
-}