001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.common.web.template;
009:
010: //base classes
011: import java.util.ArrayList;
012: import java.util.HashMap;
013:
014: //project specific classes
015: import org.jfolder.common.UnexpectedSystemException;
016: import org.jfolder.common.utils.misc.CommonSeparators;
017: import org.jfolder.common.utils.misc.MiscHelper;
018: import org.jfolder.common.utils.xml.XMLHelper;
019:
020: //other classes
021:
022: public class RcthConstraintBuilder {
023:
024: //
025: private String targetConstraint = null;
026: private int targetIndex = 0;
027: private boolean deleteAction = false;
028: private boolean insertAction = false;
029: private boolean replaceAction = false;
030: private String ctNamespace = null;
031: private String ctName = null;
032: private String text = null;
033:
034: //
035: private RcthConstraintBuilder(String inTargetConstraint,
036: int inTargetIndex, boolean inDeleteAction,
037: boolean inInsertAction, boolean inReplaceAction,
038: String inCtNamespace, String inCtName, String inText) {
039: //
040: this .targetConstraint = inTargetConstraint;
041: this .targetIndex = inTargetIndex;
042: this .deleteAction = inDeleteAction;
043: this .insertAction = inInsertAction;
044: this .replaceAction = inReplaceAction;
045: this .ctNamespace = inCtNamespace;
046: this .ctName = inCtName;
047: this .text = inText;
048: }
049:
050: //
051: public final static RcthConstraintBuilder newInstance(
052: String inTargetConstraint, int inTargetIndex,
053: boolean inDeleteAction, boolean inInsertAction,
054: boolean inReplaceAction, String inCtNamespace,
055: String inCtName, String inText) {
056:
057: RcthConstraintBuilder outValue = null;
058:
059: outValue = new RcthConstraintBuilder(inTargetConstraint,
060: inTargetIndex, inDeleteAction, inInsertAction,
061: inReplaceAction, inCtNamespace, inCtName, inText);
062:
063: return outValue;
064: }
065:
066: //
067: public String getTargetConstraint() {
068: return this .targetConstraint;
069: }
070:
071: public int getTargetIndex() {
072: return this .targetIndex;
073: }
074:
075: public int getLastStudioTargetIndex() {
076:
077: int outValue = 0;
078:
079: if (isInsertAction()) {
080: outValue = this .targetIndex - 1;
081: } else {
082: outValue = this .targetIndex;
083: }
084:
085: return outValue;
086: }
087:
088: public boolean isDeleteAction() {
089: return this .deleteAction;
090: }
091:
092: public boolean isInsertAction() {
093: return this .insertAction;
094: }
095:
096: public boolean isReplaceAction() {
097: return this .replaceAction;
098: }
099:
100: public String getCtNamespace() {
101: return this .ctNamespace;
102: }
103:
104: public String getCtName() {
105: return this .ctName;
106: }
107:
108: public String getText() {
109: return this .text;
110: }
111:
112: //
113: public SubmitActionContext generateSubmitActionContext(
114: String inFromPage, String inHandle, String inAliasHandle) {
115: //
116: SubmitActionContext outValue = SubmitActionContext.newInstance(
117: inFromPage, inHandle, inAliasHandle);
118: //
119: //
120: String primaryAction = null;
121: //
122: //
123: if (isInsertAction()) {
124: primaryAction = ConsoleTemplateContext
125: .singleQuotes(SubmitActionParameters.ADD);
126: } else if (isReplaceAction()) {
127: primaryAction = ConsoleTemplateContext
128: .singleQuotes(SubmitActionParameters.REPLACE);
129: } else if (isDeleteAction()) {
130: primaryAction = ConsoleTemplateContext
131: .singleQuotes(SubmitActionParameters.DELETE);
132: } else {
133: throw UnexpectedSystemException.unknownState();
134: }
135: //
136: //
137: if (isInsertAction() || isReplaceAction()) {
138: //
139: //
140: if (this .ctName != null) {
141: //
142: //
143: outValue.addAction(ConsoleParameterContext.FIRST_INPUT,
144: primaryAction);
145: outValue
146: .addAction(
147: ConsoleParameterContext.SECOND_INPUT,
148: ConsoleTemplateContext
149: .singleQuotes(SubmitActionParameters.CONCEPT_TAG));
150: //
151: outValue.addParameter(
152: ConsoleParameterContext.FIRST_INPUT,
153: ConsoleTemplateContext
154: .singleQuotes(this .targetConstraint));
155: outValue.addParameter(
156: ConsoleParameterContext.SECOND_INPUT,
157: ConsoleTemplateContext
158: .singleQuotes(this .targetIndex + ""));
159: if (this .ctNamespace != null) {
160: outValue.addParameter(
161: ConsoleParameterContext.THIRD_INPUT,
162: ConsoleTemplateContext
163: .singleQuotes(this .ctNamespace));
164: } else {
165: outValue.addParameter(
166: ConsoleParameterContext.THIRD_INPUT,
167: ConsoleTemplateContext.singleQuotes(""));
168: }
169: outValue.addParameter(
170: ConsoleParameterContext.FOURTH_INPUT,
171: ConsoleTemplateContext
172: .singleQuotes(this .ctName));
173: } else if (this .text != null) {
174: //
175: outValue.addAction(ConsoleParameterContext.FIRST_INPUT,
176: primaryAction);
177: outValue
178: .addAction(
179: ConsoleParameterContext.SECOND_INPUT,
180: ConsoleTemplateContext
181: .singleQuotes(SubmitActionParameters.TEXT));
182: //
183: outValue.addParameter(
184: ConsoleParameterContext.FIRST_INPUT,
185: ConsoleTemplateContext
186: .singleQuotes(this .targetConstraint));
187: outValue.addParameter(
188: ConsoleParameterContext.SECOND_INPUT,
189: ConsoleTemplateContext
190: .singleQuotes(this .targetIndex + ""));
191: outValue.addParameter(
192: ConsoleParameterContext.THIRD_INPUT,
193: ConsoleTemplateContext.singleQuotes(XMLHelper
194: .fromStringToJSCData(this .text)));
195: } else {
196: //
197: outValue.addAction(ConsoleParameterContext.FIRST_INPUT,
198: primaryAction);
199: outValue
200: .addAction(
201: ConsoleParameterContext.SECOND_INPUT,
202: ConsoleTemplateContext
203: .singleQuotes(SubmitActionParameters.COMPOUND));
204: //
205: outValue.addParameter(
206: ConsoleParameterContext.FIRST_INPUT,
207: ConsoleTemplateContext
208: .singleQuotes(this .targetConstraint));
209: outValue.addParameter(
210: ConsoleParameterContext.SECOND_INPUT,
211: ConsoleTemplateContext
212: .singleQuotes(this .targetIndex + ""));
213: }
214: } else if (isDeleteAction()) {
215: //
216: //
217: outValue.addAction(ConsoleParameterContext.FIRST_INPUT,
218: primaryAction);
219: //
220: outValue.addParameter(ConsoleParameterContext.FIRST_INPUT,
221: ConsoleTemplateContext
222: .singleQuotes(this .targetConstraint));
223: outValue.addParameter(ConsoleParameterContext.SECOND_INPUT,
224: ConsoleTemplateContext
225: .singleQuotes(this .targetIndex + ""));
226: } else {
227: throw UnexpectedSystemException.unknownState();
228: }
229: //
230: //
231: return outValue;
232: }
233: //
234: //
235: //
236: //
237: //
238: //
239: //
240: //
241: //
242: //
243: //
244: }
|