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.gui;
\r
22 import java.util.ArrayList;
\r
24 import com.evernote.edam.type.Note;
\r
26 import cx.fbn.nevernote.filters.AttributeFilter;
\r
27 import cx.fbn.nevernote.sql.NoteTable;
\r
29 public class ContainsAttributeFilterTable {
\r
30 ArrayList<AttributeFilter> table;
\r
32 public ContainsAttributeFilterTable() {
\r
33 table = new ArrayList<AttributeFilter>();
\r
34 table.add(new AttributeFilter("Images"));
\r
35 table.add(new AttributeFilter("Audio"));
\r
36 table.add(new AttributeFilter("Ink"));
\r
37 table.add(new AttributeFilter("Encrypted Text"));
\r
38 table.add(new AttributeFilter("To-Do Items"));
\r
39 table.add(new AttributeFilter("Unfinished to-do items"));
\r
40 table.add(new AttributeFilter("Finished to-do items"));
\r
41 table.add(new AttributeFilter("Attachment"));
\r
42 table.add(new AttributeFilter("PDF"));
\r
50 public void reset() {
\r
51 for (int i=0; i<table.size(); i++)
\r
52 table.get(i).set(false);
\r
55 public void select(String name) {
\r
56 for (int i=0; i<table.size(); i++)
\r
57 if (table.get(i).getName().equalsIgnoreCase(name))
\r
58 table.get(i).set(true);
\r
62 return table.size();
\r
65 public boolean hasSelection() {
\r
66 for (int i=0; i<table.size(); i++) {
\r
67 if (table.get(i).isSet() == true)
\r
73 public boolean check(NoteTable sqlTable, Note n) {
\r
74 boolean result = true;
\r
76 for (int i=0; i<table.size(); i++) {
\r
77 if (table.get(i).isSet()) {
\r
78 n = sqlTable.getNote(n.getGuid(), true, true, false, false, false);
\r
79 if (table.get(i).getName().equalsIgnoreCase("images"))
\r
80 result = checkMime(n, "image/");
\r
81 if (table.get(i).getName().equalsIgnoreCase("audio"))
\r
82 result = checkMime(n, "audio/");
\r
83 if (table.get(i).getName().equalsIgnoreCase("ink"))
\r
84 result = checkMime(n, "application/vnd.evernote.ink");
\r
85 if (table.get(i).getName().equalsIgnoreCase("Attachment"))
\r
86 result = checkAttachment(n);
\r
87 if (table.get(i).getName().equalsIgnoreCase("pdf"))
\r
88 result = checkMime(n, "application/pdf");
\r
89 if (table.get(i).getName().equalsIgnoreCase("Encrypted Text"))
\r
90 result = checkText(n.getContent(), "<en-crypt");
\r
91 if (table.get(i).getName().equalsIgnoreCase("To-Do Items"))
\r
92 result = checkText(n.getContent(), "<en-todo");
\r
93 if (table.get(i).getName().equalsIgnoreCase("Unfinished to-do items"))
\r
94 result = checkTodo(n.getContent(), false);
\r
95 if (table.get(i).getName().equalsIgnoreCase("Finished to-do items"))
\r
96 result = checkTodo(n.getContent(), true);
\r
104 private boolean checkMime(Note n, String mime) {
\r
105 for (int i=0; i<n.getResourcesSize(); i++) {
\r
106 if (n.getResources().get(i).getMime().startsWith(mime))
\r
112 private boolean checkAttachment(Note n) {
\r
113 for (int i=0; i<n.getResourcesSize(); i++) {
\r
114 if (n.getResources().get(i).getAttributes() != null && n.getResources().get(i).getAttributes().isAttachment())
\r
120 private boolean checkTodo(String content, boolean checked) {
\r
121 int pos = content.indexOf("<en-todo");
\r
123 for (; pos >=0 ; pos=content.indexOf("<en-todo", pos+1)) {
\r
124 int endPos = content.indexOf("/>", pos);
\r
125 String segment = content.substring(pos, endPos);
\r
126 boolean currentState = false;
\r
127 if (segment.indexOf("checked=\"true\"") > -1)
\r
128 currentState = true;
\r
129 if (currentState == checked)
\r
138 private boolean checkText(String content, String text) {
\r
139 if (content.indexOf(text) > -1)
\r
144 // Get the name of a particular attribute check
\r
145 public String getName(int i) {
\r
146 return table.get(i).getName();
\r