001: /**
002: * ResourcesListImpl.java
003: * Created on 24.03.2003, 18:30:31 Alex
004: * Package: net.sf.memoranda
005: *
006: * @author Alex V. Alishevskikh, alex@openmechanics.net
007: * Copyright (c) 2003 Memoranda Team. http://memoranda.sf.net
008: */package net.sf.memoranda;
009:
010: import java.util.Vector;
011: import java.io.File;
012:
013: import net.sf.memoranda.util.Util;
014: import nu.xom.Attribute;
015: import nu.xom.Document;
016: import nu.xom.Element;
017: import nu.xom.Elements;
018:
019: /**
020: *
021: */
022: /*$Id: ResourcesListImpl.java,v 1.5 2007/03/20 06:21:46 alexeya Exp $*/
023: public class ResourcesListImpl implements ResourcesList {
024:
025: private Project _project = null;
026: private Document _doc = null;
027: private Element _root = null;
028:
029: /**
030: * Constructor for TaskListImpl.
031: */
032: public ResourcesListImpl(Document doc, Project prj) {
033: _doc = doc;
034: _root = _doc.getRootElement();
035: _project = prj;
036: }
037:
038: public ResourcesListImpl(Project prj) {
039: _root = new Element("resources-list");
040: _doc = new Document(_root);
041: _project = prj;
042: }
043:
044: public Vector getAllResources() {
045: Vector v = new Vector();
046: Elements rs = _root.getChildElements("resource");
047: for (int i = 0; i < rs.size(); i++)
048: v.add(new Resource(rs.get(i).getAttribute("path")
049: .getValue(), rs.get(i).getAttribute(
050: "isInetShortcut") != null, rs.get(i).getAttribute(
051: "isProjectFile") != null));
052: return v;
053: }
054:
055: /**
056: * @see net.sf.memoranda.ResourcesList#getResource(java.lang.String)
057: */
058: public Resource getResource(String path) {
059: Elements rs = _root.getChildElements("resource");
060: for (int i = 0; i < rs.size(); i++)
061: if (rs.get(i).getAttribute("path").getValue().equals(path))
062: return new Resource(rs.get(i).getAttribute("path")
063: .getValue(), rs.get(i).getAttribute(
064: "isInetShortcut") != null, rs.get(i)
065: .getAttribute("isProjectFile") != null);
066: return null;
067: }
068:
069: /**
070: * @see net.sf.memoranda.ResourcesList#addResource(java.lang.String, java.lang.String)
071: */
072: /*public void addResource(String path, String taskId) {
073: Element el = new Element("resource");
074: el.addAttribute(new Attribute("id", Util.generateId()));
075: el.addAttribute(new Attribute("path", path));
076: if (taskId != null) el.addAttribute(new Attribute("taskId", taskId));
077: _root.appendChild(el);
078: }*/
079:
080: /**
081: * @see net.sf.memoranda.ResourcesList#addResource(java.lang.String, boolean)
082: */
083: public void addResource(String path, boolean isInternetShortcut,
084: boolean isProjectFile) {
085: Element el = new Element("resource");
086: el.addAttribute(new Attribute("id", Util.generateId()));
087: el.addAttribute(new Attribute("path", path));
088: if (isInternetShortcut)
089: el.addAttribute(new Attribute("isInetShortcut", "true"));
090: if (isProjectFile)
091: el.addAttribute(new Attribute("isProjectFile", "true"));
092: _root.appendChild(el);
093: }
094:
095: public void addResource(String path) {
096: addResource(path, false, false);
097: }
098:
099: /**
100: * @see net.sf.memoranda.ResourcesList#removeResource(java.lang.String)
101: */
102: public void removeResource(String path) {
103: Elements rs = _root.getChildElements("resource");
104: for (int i = 0; i < rs.size(); i++)
105: if (rs.get(i).getAttribute("path").getValue().equals(path)) {
106: if (getResource(path).isProjectFile()) {
107: File f = new File(path);
108: System.out.println("[DEBUG] Removing file " + path);
109: f.delete();
110: }
111: _root.removeChild(rs.get(i));
112: }
113: }
114:
115: /**
116: * @see net.sf.memoranda.ResourcesList#getAllResourcesCount()
117: */
118: public int getAllResourcesCount() {
119: return _root.getChildElements("resource").size();
120: }
121:
122: /**
123: * @see net.sf.memoranda.ResourcesList#getXMLContent()
124: */
125: public Document getXMLContent() {
126: return _doc;
127: }
128:
129: /**
130: * @see net.sf.memoranda.ResourcesList#getResourcesForTask(java.lang.String)
131: */
132: /*public Vector getResourcesForTask(String taskId) {
133: Vector v = new Vector();
134: Elements rs = _root.getChildElements("resource");
135: for (int i = 0; i < rs.size(); i++)
136: if (rs.get(i).getAttribute("taskId").getValue().equals(taskId))
137: v.add(rs.get(i).getAttribute("path").getValue());
138: return v;
139: }*/
140:
141: }
|