001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.filter.plugins;
019:
020: import org.columba.core.filter.AbstractFilter;
021: import org.columba.core.filter.FilterCriteria;
022: import org.columba.core.filter.IFilterCriteria;
023: import org.columba.core.folder.api.IFolder;
024: import org.columba.mail.folder.IMailbox;
025:
026: /**
027: * Search for a certain priority.
028: * <p>
029: * This can be for example "high", "log", "highest", "lowest"
030: *
031: * @author fdietz
032: */
033: public class PriorityFilter extends AbstractFilter {
034:
035: private String searchPattern;
036:
037: private int condition;
038:
039: /**
040: * Constructor for PriorityFilter.
041: */
042: public PriorityFilter() {
043: super ();
044: }
045:
046: /**
047: * Transform priority to integer value.
048: *
049: * @param pattern
050: * priority string
051: * @return integer representation of string
052: */
053: protected Integer transformPriority(String pattern) {
054: Integer searchPatternInt = new Integer(3);
055:
056: if (pattern.equalsIgnoreCase("Highest")) {
057: searchPatternInt = new Integer(1);
058: } else if (pattern.equalsIgnoreCase("High")) {
059: searchPatternInt = new Integer(2);
060: } else if (pattern.equalsIgnoreCase("Normal")) {
061: searchPatternInt = new Integer(3);
062: } else if (pattern.equalsIgnoreCase("Low")) {
063: searchPatternInt = new Integer(4);
064: } else if (pattern.equalsIgnoreCase("Lowest")) {
065: searchPatternInt = new Integer(5);
066: }
067:
068: //Integer priority = Integer.valueOf(pattern);
069: //return priority;
070: return searchPatternInt;
071: }
072:
073: /**
074: * @see org.columba.core.filter.AbstractFilter#process(java.lang.Object,
075: * org.columba.mail.folder.Folder, java.lang.Object,
076: * org.columba.api.command.IWorkerStatusController)
077: */
078: public boolean process(IFolder folder, Object uid) throws Exception {
079: boolean result = false;
080:
081: String s = (String) searchPattern;
082: Integer searchPatternInt = transformPriority(s);
083:
084: Integer priority = (Integer) ((IMailbox) folder).getAttribute(
085: uid, "columba.priority");
086:
087: if (priority == null) {
088: return false;
089: }
090:
091: switch (condition) {
092: case FilterCriteria.IS:
093:
094: if (priority.compareTo(searchPatternInt) == 0) {
095: result = true;
096: }
097:
098: break;
099:
100: case FilterCriteria.IS_NOT:
101:
102: if (priority.compareTo(searchPatternInt) != 0) {
103: result = true;
104: }
105:
106: break;
107: }
108:
109: return result;
110: }
111:
112: /**
113: *
114: * @see org.columba.core.filter.AbstractFilter#setUp(org.columba.mail.filter.FilterCriteria)
115: */
116: public void setUp(IFilterCriteria f) {
117:
118: // string to search
119: searchPattern = f.getPatternString();
120:
121: condition = f.getCriteria();
122: }
123: }
|