2 * This file is part of NeverNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\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
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
20 package cx.fbn.nevernote.filters;
\r
22 import com.evernote.edam.type.Note;
\r
24 import cx.fbn.nevernote.filters.AttributeFilter;
\r
27 public abstract class ContainsAttributeFilter extends AttributeFilter {
\r
28 public ContainsAttributeFilter(String n) {
\r
31 public abstract boolean checkContent(Note n);
\r
33 public static class Mime extends ContainsAttributeFilter {
\r
34 private String _mime;
\r
35 public Mime(String n, String m) {
\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
47 public static class Attachment extends ContainsAttributeFilter {
\r
48 public Attachment(String n) {
\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
60 public static class Todo extends ContainsAttributeFilter {
\r
61 private boolean _checked;
\r
62 public Todo(String n, boolean checked) {
\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
81 public static class Content extends ContainsAttributeFilter {
\r
82 private String _text;
\r
83 public Content(String n, String text) {
\r
87 public boolean checkContent(Note n) {
\r
88 if (n.getContent().indexOf(_text) > -1)
\r