001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.core.command.xml;
034:
035: import fr.loria.ecoo.so6.xml.exception.InvalidNodePath;
036: import fr.loria.ecoo.so6.xml.exception.ParseException;
037: import fr.loria.ecoo.so6.xml.node.TreeNode;
038: import fr.loria.ecoo.so6.xml.util.XmlUtil;
039:
040: import org.libresource.so6.core.WsConnection;
041: import org.libresource.so6.core.engine.DBType;
042:
043: import java.io.File;
044: import java.io.IOException;
045: import java.io.Writer;
046:
047: /**
048: * @author smack
049: */
050: public class DeleteNode extends UpdateXmlFile {
051: private TreeNode nodeToDelete;
052:
053: public DeleteNode(long ticket, String path, String wsName,
054: long time, String nodePath, TreeNode nodeToDelete) {
055: super (ticket, path, wsName, time, false, null);
056: this .nodePath = nodePath;
057: this .nodeToDelete = nodeToDelete;
058: }
059:
060: public DeleteNode(String path, WsConnection ws, String nodePath,
061: TreeNode nodeToDelete) {
062: super (path, ws);
063: this .nodePath = nodePath;
064: this .nodeToDelete = nodeToDelete;
065: }
066:
067: public void execute(String dir, DBType dbt) throws IOException,
068: InvalidNodePath, ParseException {
069: File f = new File(dir + File.separator + path);
070:
071: if (!f.exists()) {
072: throw new IOException("File does not exist :" + f);
073: }
074:
075: doTheJobOnFile(f.getAbsolutePath());
076: }
077:
078: public boolean equals(Object obj) {
079: if (obj instanceof DeleteNode) {
080: return path.equals(((DeleteNode) obj).path)
081: && nodePath.equals(((DeleteNode) obj).nodePath)
082: && ((DeleteNode) obj).nodeToDelete
083: .equalsContent(nodeToDelete);
084: } else {
085: return false;
086: }
087: }
088:
089: public void doTheJobOnFile(String xmlFilePath) throws IOException,
090: InvalidNodePath, ParseException {
091: XmlUtil.deleteNode(xmlFilePath, nodePath);
092: }
093:
094: public String toString() {
095: return "DeleteNode(" + nodePath + "," + nodeToDelete + ")";
096: }
097:
098: public void toXML(Writer osw) throws IOException {
099: super .toXML(osw);
100: osw.write("<treeNode>");
101: nodeToDelete.toBase64(osw);
102: osw.write("</treeNode>");
103: }
104: }
|