Source Code Cross Referenced for HasMailAttributeWithValue.java in  » Net » james-2.3.1 » org » apache » james » transport » matchers » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » james 2.3.1 » org.apache.james.transport.matchers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /****************************************************************
002:         * Licensed to the Apache Software Foundation (ASF) under one   *
003:         * or more contributor license agreements.  See the NOTICE file *
004:         * distributed with this work for additional information        *
005:         * regarding copyright ownership.  The ASF licenses this file   *
006:         * to you under the Apache License, Version 2.0 (the            *
007:         * "License"); you may not use this file except in compliance   *
008:         * with the License.  You may obtain a copy of the License at   *
009:         *                                                              *
010:         *   http://www.apache.org/licenses/LICENSE-2.0                 *
011:         *                                                              *
012:         * Unless required by applicable law or agreed to in writing,   *
013:         * software distributed under the License is distributed on an  *
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
015:         * KIND, either express or implied.  See the License for the    *
016:         * specific language governing permissions and limitations      *
017:         * under the License.                                           *
018:         ****************************************************************/package org.apache.james.transport.matchers;
019:
020:        import java.util.Collection;
021:
022:        import javax.mail.MessagingException;
023:
024:        import org.apache.mailet.GenericMatcher;
025:        import org.apache.mailet.Mail;
026:        import org.apache.mailet.MatcherConfig;
027:
028:        /**
029:         * <p>This Matcher determines if the mail contains the attribute specified in
030:         * the condition and if the value answered when the method toString() is 
031:         * invoked on the attribute is equal to the String value specified in the
032:         * condition. If both tests are true, all recipients are returned, else null.
033:         * </p>
034:         * 
035:         * <p>Notes:</p>
036:         * <p>The current matcher implementation expects a single String value to match
037:         * on. This matcher requires two values, the attribute name and attribute
038:         * value. This requires some implicit rules to govern how the single value
039:         * supplied to the matcher is parsed into two values.</p> 
040:         * <ul>
041:         * <li>In the match condition, the split between the attribute name and the
042:         * attribute value is made at the first comma. Attribute names that include
043:         * a comma will parse incorrectly and therefore are not supported by this
044:         * matcher.
045:         * </li>
046:         * <li>Leading and trailing spaces are removed from both the attribute name and
047:         * attribute value specified in the condition and the tested attribute value in
048:         * the mail prior to matching. Therefore, "abc" , " abc", "abc " and " abc " 
049:         * are considered equivalent.
050:         * </li>
051:         * <li>To test for an empty string, do not specify an attribute value after the
052:         * comma.
053:         * </li>
054:         * </ul>
055:         * 
056:         * <p>Sample configuration:</p>
057:         * <pre><code>
058:         * &lt;mailet match="HasMailAttributeWithValue=name, value" class=&quot;&lt;any-class&gt;&quot;&gt;
059:         * </code></pre>
060:         *
061:         * @version CVS $Revision: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $
062:         * @since 2.2.0
063:         **/
064:        public class HasMailAttributeWithValue extends GenericMatcher {
065:
066:            /**
067:             * The name of the attribute to match
068:             */
069:            private String fieldAttributeName;
070:
071:            /**
072:             * The value of the attribute to match
073:             */
074:            private String fieldAttributeValue;
075:
076:            /**
077:             * <p>Answers the recipients of the mail if the attribute is present,
078:             * and has a toString() value equal to the configured value.</p>
079:             * 
080:             * @see org.apache.mailet.Matcher#match(Mail)
081:             */
082:            public Collection match(Mail mail) throws MessagingException {
083:                Object attributeValue = mail.getAttribute(getAttributeName());
084:
085:                if (attributeValue != null
086:                        && attributeValue.toString().trim().equals(
087:                                getAttributeValue()))
088:                    return mail.getRecipients();
089:                return null;
090:            }
091:
092:            /**
093:             * Returns the attributeName.
094:             * @return String
095:             */
096:            protected String getAttributeName() {
097:                return fieldAttributeName;
098:            }
099:
100:            /**
101:             * Returns the attributeValue.
102:             * @return String
103:             */
104:            protected String getAttributeValue() {
105:                return fieldAttributeValue;
106:            }
107:
108:            /**
109:             * Sets the attributeName.
110:             * @param attributeName The attributeName to set
111:             */
112:            protected void setAttributeName(String attributeName) {
113:                fieldAttributeName = attributeName;
114:            }
115:
116:            /**
117:             * Sets the attributeValue.
118:             * @param attributeValue The attributeValue to set
119:             */
120:            protected void setAttributeValue(String attributeValue) {
121:                fieldAttributeValue = attributeValue;
122:            }
123:
124:            /**
125:             * @see org.apache.mailet.Matcher#init(MatcherConfig)
126:             */
127:            public void init(MatcherConfig config) throws MessagingException {
128:                super .init(config);
129:                String condition = config.getCondition().trim();
130:                int commaPosition = condition.indexOf(',');
131:
132:                if (-1 == commaPosition)
133:                    throw new MessagingException("Syntax Error. Missing ','.");
134:
135:                if (0 == commaPosition)
136:                    throw new MessagingException(
137:                            "Syntax Error. Missing attribute name.");
138:
139:                setAttributeName(condition.substring(0, commaPosition).trim());
140:                setAttributeValue(condition.substring(commaPosition + 1).trim());
141:            }
142:
143:            /**
144:             * Return a string describing this matcher.
145:             *
146:             * @return a string describing this matcher
147:             */
148:            public String getMatcherInfo() {
149:                return "Has Mail Attribute With Value Matcher";
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.