001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.config;
017:
018: import java.io.File;
019:
020: import org.columba.core.config.DefaultXmlConfig;
021:
022: public class FolderXmlConfig extends DefaultXmlConfig {
023: //private File file;
024: public FolderXmlConfig(File file) {
025: super (file);
026: }
027:
028: /*
029: // create uid list from all accounts
030: protected void getUids(Vector v, AdapterNode parent) {
031:
032: int childCount = parent.getChildCount();
033:
034: if (childCount > 0) {
035: for (int i = 0; i < childCount; i++) {
036:
037: AdapterNode child = parent.getChild(i);
038:
039: getUids(v, child);
040:
041: //System.out.println("name: "+ child.getName() );
042:
043: if (child.getName().equals("folder")) {
044: AdapterNode uidNode = child.getChild("uid");
045:
046: Integer j = new Integer(uidNode.getValue());
047:
048: v.add(j);
049: }
050:
051: }
052: }
053: }
054: */
055: /*
056: // find a free uid for a new account
057: protected String createUid() {
058: Vector v = new Vector();
059:
060: AdapterNode rootNode = new AdapterNode(getDocument());
061: AdapterNode treeNode = rootNode.getChild(0);
062:
063: getUids(v, treeNode);
064:
065: int result = -1;
066: boolean hit;
067: boolean exit = false;
068:
069: while (exit == false) {
070: hit = false;
071: result++;
072: for (int i = 0; i < v.size(); i++) {
073: Integer j = (Integer) v.get(i);
074:
075: if (j.intValue() == result) {
076: hit = true;
077: }
078: }
079: if (hit == false)
080: exit = true;
081: }
082:
083: Integer newUid = new Integer(result);
084:
085: return newUid.toString();
086: }
087: */
088: /*
089: public AdapterNode addVirtualFolderNode( AdapterNode parentNode,
090: int uid,
091: String name,
092: String headerItem,
093: String pattern )
094: {
095: Element parentElement = createElementNode("folder");
096:
097: Element childElement = createTextElementNode("name",name);
098: addElement( parentElement, childElement );
099: childElement = createTextElementNode("accessrights","user");
100: addElement( parentElement, childElement );
101: childElement = createTextElementNode("messagefolder", "true");
102: addElement( parentElement, childElement );
103: childElement = createTextElementNode("subfolder","false");
104: addElement( parentElement, childElement );
105: childElement = createTextElementNode("add", "false");
106: addElement( parentElement, childElement );
107: childElement = createTextElementNode("remove", "true");
108: addElement( parentElement, childElement );
109: childElement = createTextElementNode("uid", createUid() );
110: addElement( parentElement, childElement );
111:
112:
113: childElement = createTextElementNode("type","virtual");
114: addElement( parentElement, childElement );
115:
116: Element searchElement = createElementNode("search");
117:
118: childElement = createTextElementNode("include","false");
119:
120: addElement( searchElement, childElement );
121:
122: Integer newUid = new Integer(uid);
123:
124: Element treePathNode = createTextElementNode("uid", newUid.toString() );
125:
126:
127: addElement( searchElement, treePathNode );
128:
129:
130:
131:
132: // create filter
133:
134: Element filterParent = createElementNode("filter");
135:
136: Element child = createElementNode("filterrule");
137:
138: Element subChild = createElementNode( "filtercriteria" );
139:
140: Element subNode = createTextElementNode("headeritem", headerItem);
141: addElement( subChild, subNode );
142: subNode = createTextElementNode("criteria", "contains" );
143: addElement( subChild, subNode );
144: subNode = createTextElementNode("pattern", pattern );
145: addElement( subChild, subNode );
146:
147: addElement( child, subChild );
148:
149: subNode = createTextElementNode("condition", "matchall" );
150: addElement( child, subNode );
151:
152: addElement( filterParent, child );
153:
154: addElement( searchElement, filterParent );
155:
156: addElement( parentElement, searchElement );
157:
158:
159: AdapterNode childNode=null;
160:
161: if ( parentNode == null )
162: {
163: AdapterNode node = getRootNode();
164: childNode = node.addElement( parentElement );
165:
166: System.out.println("parent node == null ");
167: System.out.println("childnode: "+ childNode );
168:
169: }
170: else
171: childNode = parentNode.addElement( parentElement );
172:
173: return childNode;
174:
175:
176: }
177: */
178: /*
179: public AdapterNode addFolderNode(
180: AdapterNode parentNode,
181: String name,
182: String access,
183: String messagefolder,
184: String type,
185: String subfolder,
186: String add,
187: String remove,
188: Integer uid) {
189: Element parentElement = createElementNode("folder");
190:
191:
192: Element childElement = createTextElementNode("name", name);
193: addElement(parentElement, childElement);
194: childElement = createTextElementNode("accessrights", access);
195: addElement(parentElement, childElement);
196: childElement = createTextElementNode("messagefolder", messagefolder);
197: addElement(parentElement, childElement);
198: childElement = createTextElementNode("subfolder", subfolder);
199: addElement(parentElement, childElement);
200: childElement = createTextElementNode("add", add);
201: addElement(parentElement, childElement);
202: childElement = createTextElementNode("remove", remove);
203: addElement(parentElement, childElement);
204: childElement = createTextElementNode("uid", createUid());
205: addElement(parentElement, childElement);
206:
207: if (type.equals("columba")) {
208: childElement = createTextElementNode("type", type);
209: addElement(parentElement, childElement);
210: } else if (type.equals("virtual")) {
211: childElement = createTextElementNode("type", type);
212: addElement(parentElement, childElement);
213:
214: Element searchElement = createElementNode("search");
215:
216: childElement = createTextElementNode("include", "false");
217:
218: addElement(searchElement, childElement);
219:
220: Element treePathNode = createTextElementNode("uid", "101");
221:
222:
223:
224: addElement(searchElement, treePathNode);
225:
226: // create filter
227:
228: Element filterParent = createElementNode("filter");
229:
230: Element child = createElementNode("filterrule");
231:
232: Element subChild = createElementNode("filtercriteria");
233:
234: Element subNode = createTextElementNode("headeritem", "Subject");
235: addElement(subChild, subNode);
236: subNode = createTextElementNode("criteria", "contains");
237: addElement(subChild, subNode);
238:
239:
240: subNode = createTextElementNode("pattern", "pattern");
241: addElement(subChild, subNode);
242: subNode = createTextElementNode("type", "Subject");
243: addElement(subChild, subNode);
244:
245: addElement(child, subChild);
246:
247: subNode = createTextElementNode("condition", "matchall");
248: addElement(child, subNode);
249:
250: addElement(filterParent, child);
251:
252: addElement(searchElement, filterParent);
253:
254: addElement(parentElement, searchElement);
255:
256: } else if (type.equals("outbox")) {
257: childElement = createTextElementNode("type", type);
258: addElement(parentElement, childElement);
259:
260: } else if ((type.equals("imap")) || (type.equals("imaproot"))) {
261: childElement = createTextElementNode("type", type);
262: addElement(parentElement, childElement);
263:
264: String uidString = (uid).toString();
265:
266: childElement = createTextElementNode("accountuid", uidString);
267: addElement(parentElement, childElement);
268: }
269:
270: AdapterNode childNode = null;
271:
272: if (parentNode == null) {
273: AdapterNode node = getRootNode();
274: childNode = node.addElement(parentElement);
275:
276: System.out.println("parent node == null ");
277: System.out.println("childnode: " + childNode);
278:
279: } else
280: childNode = parentNode.addElement(parentElement);
281:
282: return childNode;
283: }
284: */
285: /*
286: public FolderItem getFolderItem(AdapterNode node) {
287: if (node != null) {
288: if (node.getName().equals("folder")) {
289: FolderItem folderItem = new FolderItem(getDocument());
290:
291: folderItem.setNameNode(node.getChild("name"));
292:
293: //System.out.println("folder found: "+ node.getChild("name").getValue() );
294: folderItem.setAccessRightsNode(node.getChild("accessrights"));
295: folderItem.setMessageFolderNode(node.getChild("messagefolder"));
296: folderItem.setTypeNode(node.getChild("type"));
297: folderItem.setSubfolderNode(node.getChild("subfolder"));
298: folderItem.setAddNode(node.getChild("add"));
299: folderItem.setRemoveNode(node.getChild("remove"));
300: folderItem.setUidNode(node.getChild("uid"));
301:
302: String type = node.getChild("type").getValue();
303:
304: if ((type.equals("imap")) || (type.equals("imaproot")))
305: folderItem.setAccountUidNode(node.getChild("accountuid"));
306:
307: AdapterNode filterNode = node.getChild("filterlist");
308: if (filterNode != null) {
309: folderItem.setFilterListNode(filterNode);
310:
311:
312: } else {
313: AdapterNode searchNode = node.getChild("search");
314: if (searchNode != null) {
315: //System.out.println("search node found");
316:
317: folderItem.setSearchNode(searchNode);
318: }
319:
320: }
321:
322: return folderItem;
323: }
324:
325: }
326:
327: return null;
328: }
329: */
330: /*
331: public AdapterNode addEmptyFilterCriteria(AdapterNode filterRuleNode) {
332: Element child = createElementNode("filtercriteria");
333:
334: Element subNode = createTextElementNode("headeritem", "Subject");
335: addElement(child, subNode);
336: subNode = createTextElementNode("criteria", "contains");
337: addElement(child, subNode);
338: subNode = createTextElementNode("pattern", "pattern");
339: addElement(child, subNode);
340: subNode = createTextElementNode("type", "Subject");
341: addElement(child, subNode);
342:
343:
344: filterRuleNode.domNode.appendChild(child);
345:
346: return new AdapterNode(child);
347: }
348: */
349: /*
350: public AdapterNode addEmptyFilterAction(AdapterNode filterActionNode) {
351: Element actionNode = createElementNode("action");
352:
353: Element nameNode = createTextElementNode("name", "move");
354: addElement(actionNode, nameNode);
355:
356: Element uidNode = createTextElementNode("uid", "101");
357: addElement(actionNode, uidNode);
358:
359: filterActionNode.domNode.appendChild(actionNode);
360:
361: return new AdapterNode(actionNode);
362: }
363:
364: public AdapterNode addEmptyFilterNode(AdapterNode folderNode) {
365:
366: Element parent = createElementNode("filter");
367:
368: Element child = createTextElementNode("enabled", "true");
369: addElement(parent, child);
370: child = createTextElementNode("description", "new filter");
371: addElement(parent, child);
372:
373: addElement(parent, child);
374:
375: // create filterrule-node
376: child = createElementNode("filterrule");
377:
378: Element subChild = createElementNode("filtercriteria");
379:
380: Element subNode = createTextElementNode("headeritem", "Subject");
381: addElement(subChild, subNode);
382: subNode = createTextElementNode("criteria", "contains");
383: addElement(subChild, subNode);
384: subNode = createTextElementNode("pattern", "pattern");
385: addElement(subChild, subNode);
386: subNode = createTextElementNode("type", "Subject");
387: addElement(subChild, subNode);
388:
389: addElement(child, subChild);
390:
391: subNode = createTextElementNode("condition", "matchall");
392: addElement(child, subNode);
393:
394: addElement(parent, child);
395:
396: // create actionlist-node
397: Element actionNode = createElementNode("actionlist");
398:
399: Element subActionNode = createElementNode("action");
400:
401: Element nameNode = createTextElementNode("name", "move");
402: addElement(subActionNode, nameNode);
403: Element uidNode = createTextElementNode("uid", "101");
404: addElement(subActionNode, uidNode);
405:
406: addElement(actionNode, subActionNode);
407:
408: addElement(parent, actionNode);
409:
410: AdapterNode filterListNode = folderNode.getChild("filterlist");
411:
412: if (filterListNode == null) {
413: Element listNode = createElementNode("filterlist");
414:
415: addElement(listNode, parent);
416:
417: Node node = folderNode.domNode.appendChild(listNode);
418:
419: AdapterNode result = new AdapterNode(parent);
420:
421: return result;
422: } else {
423:
424: Node node = filterListNode.domNode.appendChild(parent);
425: AdapterNode result = new AdapterNode(node);
426:
427: return result;
428: }
429:
430: }
431: */
432: }
|