OSDN Git Service

9d39da1a705c2bfadd3aba3457e54b2750c36b25
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / filters / ContainsAttributeFilter.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.filters;\r
21 \r
22 import com.evernote.edam.type.Note;\r
23 \r
24 import cx.fbn.nevernote.filters.AttributeFilter;\r
25 \r
26 \r
27 public abstract class ContainsAttributeFilter extends AttributeFilter {\r
28         public ContainsAttributeFilter(String n) {\r
29                 super(n);\r
30         }\r
31         public abstract boolean checkContent(Note n);\r
32 \r
33         public static class Mime extends ContainsAttributeFilter {\r
34                 private String _mime;\r
35                 public Mime(String n, String m) {\r
36                         super(n);\r
37                         _mime = m; \r
38                 }\r
39                 public boolean checkContent(Note n) {\r
40                         for (int i=0; i<n.getResourcesSize(); i++) {\r
41                                 if (n.getResources().get(i).getMime().startsWith(_mime))\r
42                                         return true;\r
43                         }\r
44                         return false;\r
45                 }\r
46         }\r
47         public static class Attachment extends ContainsAttributeFilter {\r
48                 public Attachment(String n) {\r
49                         super(n);\r
50                 }\r
51                 public boolean checkContent(Note n) {\r
52                         for (int i=0; i<n.getResourcesSize(); i++) {\r
53                                 if (n.getResources().get(i).getAttributes() != null \r
54                                         && n.getResources().get(i).getAttributes().isAttachment())\r
55                                         return true;\r
56                         }\r
57                         return false;\r
58                 }\r
59         }\r
60         public static class Todo extends ContainsAttributeFilter {\r
61                 private boolean _checked;\r
62                 public Todo(String n, boolean checked) {\r
63                         super(n);\r
64                         _checked = checked;\r
65                 }\r
66                 public boolean checkContent(Note n) {\r
67                         String content = n.getContent();\r
68                         int pos = content.indexOf("<en-todo");\r
69                         for (; pos >=0 ; pos=content.indexOf("<en-todo", pos+1)) {\r
70                                 int endPos = content.indexOf("/>", pos);\r
71                                 String segment = content.substring(pos, endPos);\r
72                                 boolean currentState = false;\r
73                                 if (segment.indexOf("checked=\"true\"") > -1)\r
74                                         currentState = true;\r
75                                 if (currentState == _checked)\r
76                                         return true;\r
77                         }\r
78                         return false;\r
79                 }\r
80         }\r
81         public static class Content extends ContainsAttributeFilter {\r
82                 private String _text;\r
83                 public Content(String n, String text) {\r
84                         super(n);\r
85                         _text = text;\r
86                 }\r
87                 public boolean checkContent(Note n) {\r
88                         if (n.getContent().indexOf(_text) > -1)\r
89                          return true;\r
90                         else\r
91                          return false;\r
92                 }\r
93         }\r
94 }\r