-- added fancybox 1.3.1 to project, initially for showing screenshots. See documentat...
[Bookkeeping.git] / src / com / interrupt / bookkeeping / cc / executor / VisitorApplyRemove.java
blob15f7ba706481bef07474d663dc87c4f9a0098054
1 package com.interrupt.bookkeeping.cc.executor;
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.StringTokenizer;
7 import org.apache.log4j.Logger;
9 import com.interrupt.bob.base.Bob;
10 import com.interrupt.bob.base.IBob;
11 import com.interrupt.bookkeeping.cc.ExpressionVisitor;
12 import com.interrupt.bookkeeping.cc.analysis.DepthFirstAdapter;
13 import com.interrupt.bookkeeping.cc.bkell.aauth.Aauthentication;
14 import com.interrupt.bookkeeping.cc.bkell.command.CreateCommand;
15 import com.interrupt.bookkeeping.cc.bkell.command.IOption;
16 import com.interrupt.bookkeeping.cc.bkell.command.IResult;
17 import com.interrupt.bookkeeping.cc.bkell.command.LoadCommand;
18 import com.interrupt.bookkeeping.cc.node.AIlist;
19 import com.interrupt.bookkeeping.cc.node.AIlistpart;
20 import com.interrupt.bookkeeping.cc.node.AOptsCommandInput;
21 import com.interrupt.bookkeeping.cc.node.AXmlCommandInput;
22 import com.interrupt.bookkeeping.cc.node.PCommandInput;
23 import com.interrupt.bookkeeping.cc.node.PIlistpart;
24 import com.interrupt.bookkeeping.users.IUser;
25 import com.interrupt.spittoon.Spittoon;
27 public class VisitorApplyRemove extends DepthFirstAdapter {
30 private Logger logger = Logger.getLogger(ExpressionVisitor.class);
32 private IBob removee = null;
33 private IUser user = null;
34 private Aauthentication aauthentication = null;
35 private Spittoon spittoon = null;
36 private String contextXPath = null;
39 private LoadCommand loadCommand = null;
40 private CreateCommand createCommand = null;
42 public IBob getRemovee() { return removee; }
43 public void setRemovee(IBob removee) { this.removee = removee; }
45 public IUser getUser() { return this.user; }
46 public void setUser(IUser user) { this.user = user; }
48 public LoadCommand getLoadCommand() { return loadCommand; }
49 public void setLoadCommand(LoadCommand loadCommand) { this.loadCommand = loadCommand; }
51 public CreateCommand getCreateCommand() { return createCommand; }
52 public void setCreateCommand(CreateCommand createCommand) { this.createCommand = createCommand; }
54 public Aauthentication getAauthentication() { return aauthentication; }
55 public void setAauthentication(Aauthentication aauthentication) { this.aauthentication = aauthentication; }
57 public Spittoon getSpittoon() { return spittoon; }
58 public void setSpittoon(Spittoon spittoon) { this.spittoon = spittoon; }
60 public String getContextXPath() { return contextXPath; }
61 public void setContextXPath(String contextXPath) { this.contextXPath = contextXPath; }
64 public void caseAIlist(AIlist node) {
66 inAIlist(node);
68 logger.debug("Remove - 2 / commandInput["+ node.getCommandInput() +"]");
71 //** get tag name
72 String commandString = node.getCommandInput().toString();
73 logger.debug("commandString["+ commandString +"]");
75 String tagName = commandString.substring(0, commandString.indexOf(" "));
76 logger.debug("tagName["+ tagName +"]");
79 if(node.getCommandInput() != null) {
81 node.getCommandInput().apply(this);
84 loadCommand = (com.interrupt.bookkeeping.cc.bkell.command.LoadCommand)
85 Bob.make( "com.interrupt.bookkeeping.cc.bkell.command.LoadCommand" );
86 createCommand = (com.interrupt.bookkeeping.cc.bkell.command.CreateCommand)
87 Bob.make( "com.interrupt.bookkeeping.cc.bkell.command.CreateCommand" );
89 createCommand.setAauthentication(aauthentication);
91 PCommandInput cinput = node.getCommandInput();
92 IResult result = null;
93 IBob resultBob = null;
94 if(cinput instanceof AXmlCommandInput) {
96 logger.debug("Remove - 3 / XML Command Input");
98 result = CreateHelper.execute(user, createCommand, (AXmlCommandInput)cinput);
99 resultBob = (IBob)result.allChildren().get(0);
100 removee.removeChild(resultBob);
102 else if(cinput instanceof AOptsCommandInput) {
104 logger.debug("Remove - 4 / Options Command Input");
106 result = CreateHelper.execute(user, createCommand, (AOptsCommandInput)cinput);
107 IOption option = (IOption)createCommand.getOptions().allOption().get(0);
109 String path = null;
110 if( removee.remove(createCommand.getToken().getName(), option.getName(), option.getValue()) ) { //** if we successfully remove the child in XML, then remove it from DB
113 spittoon.
114 this.getContextXPath()
115 /system[@id="main.system"]
116 /groups[@id="main.groups"]
117 /group[@id="seven.group"]
118 /bookkeeping[@id="main.bookkeeping"]
119 /journals[@id="main.journals"]
120 /journal[@id="generalledger"]
121 /entries[@id="main.entries"]
122 /entry.qwer
124 StringTokenizer tokenizer = new StringTokenizer(this.getContextXPath(), "/");
125 String ntoken = null;
126 String tagname = null;
127 String idname = null;
128 String pathFINAL = new String();
129 while(tokenizer.hasMoreTokens()) {
131 ntoken = tokenizer.nextToken();
132 logger.debug("each context token["+ ntoken +"]");
134 tagname = ntoken.substring( (ntoken.indexOf("/") + 1) , ntoken.indexOf("[") ); //** tagname
135 idname = ntoken.substring( (ntoken.indexOf("id") + 4) , (ntoken.lastIndexOf("]") - 1) ); //** idname
136 logger.debug("each tagname["+ tagname +"] > idname["+ idname +"]");
138 pathFINAL += "/" + tagname + "." + idname;
142 path = "/rootDir" + pathFINAL + "/" + tagName + "." + option.getValue();
143 logger.debug("DB XML > removing > context url["+ spittoon.getAauthDbUrl() +"] / path["+ path +"]");
144 spittoon.removeCollection(spittoon.getAauthDbUrl(), path);
152 List<PIlistpart> copy = new ArrayList<PIlistpart>(node.getIlistpart());
153 for(PIlistpart e : copy) {
154 e.apply(this);
157 outAIlist(node);
160 public void caseAIlistpart(AIlistpart node) {
162 inAIlistpart(node);
163 if(node.getListdelimiter() != null) {
164 node.getListdelimiter().apply(this);
166 if(node.getCommandInput() != null) {
169 node.getCommandInput().apply(this);
170 createCommand.setAauthentication(aauthentication);
172 loadCommand = (com.interrupt.bookkeeping.cc.bkell.command.LoadCommand)
173 Bob.make( "com.interrupt.bookkeeping.cc.bkell.command.LoadCommand" );
174 createCommand = (com.interrupt.bookkeeping.cc.bkell.command.CreateCommand)
175 Bob.make( "com.interrupt.bookkeeping.cc.bkell.command.CreateCommand" );
177 PCommandInput cinput = node.getCommandInput();
178 IResult result = null;
179 IBob resultBob = null;
180 if(cinput instanceof AXmlCommandInput) {
182 result = CreateHelper.execute(user,createCommand, (AXmlCommandInput)cinput);
183 resultBob = (IBob)result.allChildren().get(0);
184 removee.removeChild(resultBob);
186 else if(cinput instanceof AOptsCommandInput) {
188 result = CreateHelper.execute(user, createCommand, (AOptsCommandInput)cinput);
189 IOption option = (IOption)createCommand.getOptions().allOption().get(0);
191 removee.remove(createCommand.getToken().getName(), option.getName(), option.getValue());
196 outAIlistpart(node);