use of com.dexels.navajo.document.navascript.tags.CheckTag in project navajo by Dexels.
the class NS3ToNSXML method parseValidations.
private ValidationsTag parseValidations(NS3Compatible parent, XMLElement xe) {
ValidationsTag vt = new ValidationsTag(myNavascript);
vt.addParent(parent);
Vector<XMLElement> children = xe.getChildren();
CheckTag ct = null;
for (XMLElement child : children) {
String name = child.getName();
String content = (child.getContent() != null && !"".equals(child.getContent()) ? child.getContent() : null);
if (name.equals("Checks")) {
return parseValidations(parent, child);
}
if (name.equals("Check")) {
ct = new CheckTag(myNavascript);
vt.addCheck(ct);
parseCheckAttributes(ct, child);
}
}
return vt;
}
use of com.dexels.navajo.document.navascript.tags.CheckTag in project navajo by Dexels.
the class NavascriptSaxHandler method startElement.
@Override
public final void startElement(String tag, Map<String, String> h) throws Exception {
if (tag.equals(Tags.NAVASCRIPT) || tag.equals("tsl")) {
currentDocument = new NavascriptTag();
currentDocument.setAuthor(h.get("author"));
currentDocument.setNotes(h.get("notes"));
currentDocument.setId(h.get("id"));
currentNode.push(currentDocument);
return;
}
BaseNode currentParent = currentNode.lastElement();
if (tag.equals(Tags.FINALLY)) {
FinallyTag ft = new FinallyTag(currentDocument);
currentDocument.addFinally(ft);
currentNode.push(ft);
}
if (tag.equals(Tags.METHODS)) {
MethodsTag mt = new MethodsTag(currentDocument);
currentDocument.addMethods(mt);
currentNode.push(mt);
currentMethods = mt;
}
if (tag.equals(Tags.METHOD)) {
MethodTag m = new MethodTag(currentDocument);
m.setScriptName(h.get("name"));
if (currentMethods == null) {
logger.error("Missing methods tag for this method " + h.get("name"));
return;
}
currentNode.push(m);
currentMethods.addMethod(m);
}
if (tag.equals(Tags.DEFINES)) {
DefinesTag dt = new DefinesTag(currentDocument);
currentDocument.addDefines(dt);
currentNode.push(dt);
currentDefines = dt;
}
if (tag.equals(Tags.DEFINE)) {
DefineTag dt = new DefineTag(currentDocument);
String name = h.get("name");
dt.setName(name);
if (currentDefines != null) {
currentDefines.addDefine(dt);
}
currentNode.push(dt);
}
if (tag.equals(Tags.DEBUG)) {
DebugTag dt = new DebugTag(currentDocument, h.get("value"));
dt.setCondition(h.get("condition"));
if (currentParent instanceof MapTag && currentMap.size() > 0) {
currentMap.lastElement().addDebug(dt);
} else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
currentMessage.lastElement().addDebug(dt);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).add(dt);
} else if (currentParent instanceof FinallyTag) {
((FinallyTag) currentParent).add(dt);
} else if (currentParent instanceof SynchronizedTag) {
((SynchronizedTag) currentParent).add(dt);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).addDebug(dt);
} else if (currentParent instanceof NavascriptTag) {
currentDocument.addDebug(dt);
} else {
throw new Exception("Did not expect debug tag under this parent: " + currentParent.getTagName());
}
currentNode.push(dt);
return;
}
if (tag.equals(Tags.LOG)) {
LogTag dt = new LogTag(currentDocument, h.get("value"));
dt.setCondition(h.get("condition"));
if (currentParent instanceof MapTag && currentMap.size() > 0) {
currentMap.lastElement().addDebug(dt);
} else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
currentMessage.lastElement().addDebug(dt);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).add(dt);
} else if (currentParent instanceof FinallyTag) {
((FinallyTag) currentParent).add(dt);
} else if (currentParent instanceof SynchronizedTag) {
((SynchronizedTag) currentParent).add(dt);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).addDebug(dt);
} else if (currentParent instanceof NavascriptTag) {
currentDocument.addDebug(dt);
} else {
throw new Exception("Did not expect log tag under this parent: " + currentParent.getTagName());
}
currentNode.push(dt);
return;
}
if (tag.equals(Tags.INCLUDE)) {
IncludeTag it = new IncludeTag(currentDocument, (h.get("script")));
it.setCondition(h.get("condition"));
if (currentParent instanceof MapTag && currentMap.size() > 0) {
currentMap.lastElement().addInclude(it);
} else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
currentMessage.lastElement().addInclude(it);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).add(it);
} else if (currentParent instanceof FinallyTag) {
((FinallyTag) currentParent).add(it);
} else if (currentParent instanceof SynchronizedTag) {
((SynchronizedTag) currentParent).add(it);
} else if (currentParent instanceof NavascriptTag) {
currentDocument.addInclude(it);
} else {
}
currentNode.push(it);
return;
}
if (tag.equals(Tags.VALIDATIONS)) {
if (!(currentParent instanceof NavascriptTag)) {
throw new Exception("Validation tags can only be specified as top level tags");
}
validationsBlock = currentDocument.addValidations();
currentNode.push(validationsBlock);
return;
}
if (tag.equals(Tags.OPTION)) {
String name = h.get(Attributes.NAME);
String value = h.get(Attributes.VALUE);
String selected = h.get(Attributes.SELECTED);
boolean bSel = (selected != null ? selected.equals("1") : false);
if (currentParent instanceof PropertyTag) {
SelectionTag st = ((PropertyTag) currentParent).addSelection(name, value, bSel);
currentNode.push(st);
} else {
throw new Exception("Option tags are only allowed after a property tag.");
}
return;
}
if (tag.equals(Tags.CHECK)) {
String code = h.get("code");
String desc = h.get(Attributes.DESCRIPTION);
String condition = h.get(Attributes.CONDITION);
if (validationsBlock != null) {
CheckTag ct = validationsBlock.addCheck(code, desc, condition);
currentNode.push(ct);
} else {
throw new Exception("Check tags can only be found under validations tag.");
}
return;
}
if (tag.equals(Tags.BREAK)) {
BreakTag bt = new BreakTag(currentDocument, h.get(Attributes.CONDITION), h.get("conditionId"), h.get("conditionDescription"));
if (currentParent instanceof MapTag && currentMap.size() > 0) {
currentMap.lastElement().addBreak(bt);
} else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
currentMessage.lastElement().addBreak(bt);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).add(bt);
} else if (currentParent instanceof FinallyTag) {
((FinallyTag) currentParent).add(bt);
} else if (currentParent instanceof SynchronizedTag) {
((SynchronizedTag) currentParent).add(bt);
} else if (currentParent instanceof NavascriptTag) {
currentDocument.addBreak(bt);
} else {
throw new Exception("Did not expect break tag under this parent: " + currentParent.getTagName());
}
currentNode.push(bt);
return;
}
if (tag.equals(Tags.SYNCHRONIZED)) {
SynchronizedTag st = new SynchronizedTag(currentDocument);
st.setContext(h.get(Attributes.CONTEXT));
st.setKey(h.get(Attributes.KEY));
st.setTimeout(h.get(Attributes.TIMEOUT));
st.setBreakOnNoLock(h.get(Attributes.BREAKON_NOLOCK));
if (currentParent instanceof MapTag && currentMap.size() > 0) {
currentMap.lastElement().addSynchronized(st);
} else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
currentMessage.lastElement().addSynchronized(st);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).addSynchronized(st);
} else if (currentParent instanceof FinallyTag) {
((FinallyTag) currentParent).add(st);
} else if (currentParent instanceof NavascriptTag) {
((NavascriptTag) currentParent).addSynchronized(st);
} else {
throw new Exception("Did not excpect synchronized tag under this parent: " + currentParent.getTagName());
}
currentNode.push(st);
}
if (tag.equals(Tags.BLOCK)) {
BlockTag bt = new BlockTag(currentDocument);
bt.setCondition(h.get(Attributes.CONDITION));
if (currentParent instanceof MapTag && currentMap.size() > 0) {
currentMap.lastElement().addBlock(bt);
} else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
currentMessage.lastElement().addBlock(bt);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).addBlock(bt);
} else if (currentParent instanceof FinallyTag) {
((FinallyTag) currentParent).add(bt);
} else if (currentParent instanceof NavascriptTag) {
((NavascriptTag) currentParent).addBlock(bt);
} else if (currentParent instanceof SynchronizedTag) {
((SynchronizedTag) currentParent).add(bt);
} else {
throw new Exception("Did not expect block tag under this parent: " + currentParent.getTagName());
}
currentNode.push(bt);
return;
}
if (tag.equals(Tags.MESSAGE) || tag.equals(Tags.ANTIMESSAGE)) {
MessageTag mt = new MessageTag(currentDocument, h.get(Attributes.NAME), h.get(Attributes.TYPE));
mt.setCondition(h.get(Attributes.CONDITION));
mt.setOrderBy(h.get(Attributes.ORDERBY));
boolean isAntiMsg = tag.equals(Tags.ANTIMESSAGE);
mt.setAntiMessage(isAntiMsg);
if (h.get("mode") != null) {
// postfix mode to prevent ignore message. Strip character later
mt.setMode(h.get("mode") + "_");
}
if (currentParent instanceof MapTag && currentMap.size() > 0) {
currentMap.lastElement().addMessage(mt);
} else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
currentMessage.lastElement().addMessage(mt);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).add(mt);
} else if (currentParent instanceof FinallyTag) {
((FinallyTag) currentParent).add(mt);
} else if (currentParent instanceof SynchronizedTag) {
((SynchronizedTag) currentParent).add(mt);
} else if (currentParent instanceof NavascriptTag) {
currentDocument.addMessage(mt);
} else {
throw new Exception("Did not expect message tag under this parent: " + currentParent.getTagName());
}
currentMessage.push(mt);
currentNode.push(mt);
return;
}
if (tag.equals(Tags.MAP)) {
String object = h.get(Attributes.OBJECT);
String ref = h.get(Attributes.REF);
String condition = h.get(Attributes.CONDITION);
MapTag mt = null;
if (object != null) {
mt = new MapTag(currentDocument, object, h.get(Attributes.CONDITION), true);
} else {
// map ref on message
mt = new MapTag(currentDocument, ref, h.get(Attributes.FILTER), (currentMap.size() > 0 ? currentMap.lastElement() : null), true);
if (ref.startsWith("[")) {
mt.setMappedMessage(true);
}
}
mt.setCondition(condition);
if (currentParent instanceof PropertyTag) {
// selection property.
((PropertyTag) currentParent).addMap(mt);
} else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
currentMessage.lastElement().addMap(mt);
} else if (currentParent instanceof MapTag && currentMap.size() > 0) {
currentMap.lastElement().addMap(mt);
} else if (currentParent instanceof FieldTag && currentField.size() > 0) {
currentField.lastElement().addMap(mt);
} else if (currentParent instanceof ParamTag) {
((ParamTag) currentParent).addMap(mt);
((ParamTag) currentParent).setType("array");
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).add(mt);
} else if (currentParent instanceof FinallyTag) {
((FinallyTag) currentParent).add(mt);
} else if (currentParent instanceof SynchronizedTag) {
((SynchronizedTag) currentParent).add(mt);
} else if (currentParent instanceof NavascriptTag) {
currentDocument.addMap(mt);
} else {
throw new Exception("Did not expect map tag under this parent: " + currentParent.getTagName());
}
currentMap.push(mt);
currentNode.push(mt);
return;
}
if (tag.equals(Tags.FIELD)) {
String name = h.get(Attributes.NAME);
FieldTag ft = new FieldTag(currentMap.lastElement(), null, name, true);
// FIELD CAN ALSO BE UNDER MESSAGE!!!
if (currentParent instanceof MessageTag) {
currentMessage.lastElement().addField(ft);
} else if (currentParent instanceof MapTag) {
currentMap.lastElement().addField(ft);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).add(ft);
} else {
throw new Exception("Field tags can only be found under message or map tags.");
}
currentField.push(ft);
currentNode.push(ft);
}
if (tag.startsWith(Tags.MAP + ".")) {
// map.navajo
String name = tag.split("\\.")[1].trim();
MapTag mt = new MapTag(currentDocument, name, h.get(Attributes.CONDITION));
Map<String, String> attributeMap = new HashMap<>();
for (String key : h.keySet()) {
attributeMap.put(key, h.get(key));
}
mt.addAttributes(attributeMap);
if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
currentMessage.lastElement().addMap(mt);
} else if (currentParent instanceof MapTag && currentMap != null) {
currentMap.lastElement().addMap(mt);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).add(mt);
} else if (currentParent instanceof FinallyTag) {
((FinallyTag) currentParent).add(mt);
} else if (currentParent instanceof SynchronizedTag) {
((SynchronizedTag) currentParent).add(mt);
} else if (currentParent instanceof NavascriptTag) {
currentDocument.addMap(mt);
} else {
StringBuffer sb = new StringBuffer();
sb.append("Did not expect map[" + name + "] tag under this parent: " + currentParent.getTagName() + ", currentMessage: " + currentMessage.size());
if (currentParent instanceof MessageTag) {
sb.append("\nParent is a message with name: " + ((MessageTag) currentParent).getName());
}
throw new Exception(sb.toString());
}
currentMap.push(mt);
currentNode.push(mt);
return;
}
if (tag.equals(Tags.VALUE)) {
String condition = h.get(Attributes.CONDITION);
ValueTag vt = new ValueTag(currentDocument);
vt.setCondition(condition);
if (currentParent instanceof FieldTag) {
// This FieldTag will be a normal "setter" field.
ExpressionTag et = new ExpressionTag(currentDocument);
et.addValueTag(vt);
((FieldTag) currentParent).setOldSkool(true);
((FieldTag) currentParent).setSetter(true);
((FieldTag) currentParent).addExpression(et);
} else {
((ExpressionTag) currentParent).addValueTag(vt);
}
currentNode.push(vt);
}
if (tag.equals(Tags.EXPRESSION)) {
String condition = h.get(Attributes.CONDITION);
String value = h.get(Attributes.VALUE);
ExpressionTag et = new ExpressionTag(currentDocument, condition, value);
if (currentParent instanceof PropertyTag) {
((PropertyTag) currentParent).addExpression(et);
} else if (currentParent instanceof FieldTag) {
((FieldTag) currentParent).addExpression(et);
} else if (currentParent instanceof ParamTag) {
((ParamTag) currentParent).addExpression(et);
} else if (currentParent instanceof MapTag) {
// Oops. this cannot happen. Should have been a FieldTag. Fix this.
MapTag fixThis = currentMap.pop();
currentNode.pop();
FieldTag ft = new FieldTag(currentMap.lastElement(), null, fixThis.getRefAttribute());
currentNode.push(ft);
currentField.push(ft);
currentMessage.lastElement().removeMap(fixThis);
currentMessage.lastElement().addField(ft);
ft.addExpression(et);
} else {
throw new Exception("Expression tags can only be found under following tags: property, field, param");
}
currentNode.push(et);
return;
}
if (tag.equals(Tags.PARAM)) {
ParamTag pt = new ParamTag(currentDocument, h.get(Attributes.CONDITION), h.get(Attributes.NAME));
String mode = h.get(Attributes.MODE);
String value = h.get(Attributes.VALUE);
pt.setType(h.get(Attributes.TYPE));
if (value != null && !"".equals(value)) {
// String Constant as value.
ExpressionTag et = new ExpressionTag(currentDocument);
et.setConstant(value);
pt.addExpression(et);
}
pt.setMode(mode);
if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
currentMessage.lastElement().addParam(pt);
} else if (currentParent instanceof MapTag && currentMap != null) {
currentMap.lastElement().addParam(pt);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).add(pt);
} else if (currentParent instanceof FinallyTag) {
((FinallyTag) currentParent).add(pt);
} else if (currentParent instanceof SynchronizedTag) {
((SynchronizedTag) currentParent).add(pt);
} else if (currentParent instanceof NavascriptTag) {
currentDocument.addParam(pt);
} else if (currentParent instanceof ParamTag) {
((ParamTag) currentParent).addParam(pt);
} else {
throw new Exception("Did not expect param tag under this parent: " + currentParent.getTagName());
}
currentNode.push(pt);
}
if (tag.equals(Tags.PROPERTY)) {
String name = h.get(Attributes.NAME);
String val = h.get(Attributes.VALUE);
String type = h.get(Attributes.TYPE);
String direction = h.get(Attributes.DIRECTION);
String description = h.get(Attributes.DESCRIPTION);
String length = h.get(Attributes.LENGTH);
String cardinality = h.get(Attributes.CARDINALITY);
String condition = h.get(Attributes.CONDITION);
int iLen = (length != null ? Integer.parseInt(length) : 0);
PropertyTag pt = new PropertyTag(currentDocument, name, type, val, iLen, description, direction);
pt.setCondition(condition);
if (cardinality != null) {
pt.setCardinality(cardinality);
}
if (val != null) {
// Dit kan NOG strakker. Niet alle types hoeven geunescaped worder
Hashtable<String, String> h2 = new Hashtable<String, String>(h);
val = BaseNode.XMLUnescape(val);
h2.put(Attributes.VALUE, val);
}
if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
currentMessage.lastElement().addProperty(pt);
} else if (currentParent instanceof MapTag && currentMap != null) {
currentMap.lastElement().addProperty(pt);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).add(pt);
} else {
throw new Exception("Property tags can only be found under a message, map or block tag.");
}
currentNode.push(pt);
return;
}
if (currentMap.size() > 0 && tag.startsWith(currentMap.lastElement().getAdapterName() + ".")) {
// navajomap.callwebservice
String fieldName = tag.split("\\.")[1];
String adapterName = tag.split("\\.")[0];
boolean isField = mapChecker.isField(adapterName, fieldName);
if (currentParent instanceof MessageTag && isField && h.get(Attributes.VALUE) == null) {
// Mapped field if it is a getter (no value field specified and no expression under the tag)
// map ref on message
MapTag mt = new MapTag(currentDocument, fieldName, h.get(Attributes.FILTER), currentMap.lastElement(), false);
Map<String, String> attributeMap = new HashMap<>();
for (String key : h.keySet()) {
attributeMap.put(key, h.get(key));
}
mt.addAttributes(attributeMap);
currentMessage.lastElement().addMap(mt);
currentMap.push(mt);
currentNode.push(mt);
} else if (currentParent instanceof PropertyTag) {
// selection property
MapTag mt = new MapTag(currentDocument, fieldName, h.get(Attributes.FILTER), currentMap.lastElement(), false);
Map<String, String> attributeMap = new HashMap<>();
for (String key : h.keySet()) {
attributeMap.put(key, h.get(key));
}
mt.addAttributes(attributeMap);
((PropertyTag) currentParent).addMap(mt);
currentMap.push(mt);
currentNode.push(mt);
} else if (currentParent instanceof ParamTag) {
// mapped param
MapTag mt = new MapTag(currentDocument, fieldName, h.get(Attributes.FILTER), currentMap.lastElement(), false);
Map<String, String> attributeMap = new HashMap<>();
for (String key : h.keySet()) {
attributeMap.put(key, h.get(key));
}
mt.addAttributes(attributeMap);
((ParamTag) currentParent).addMap(mt);
((ParamTag) currentParent).setType("array");
currentMap.push(mt);
currentNode.push(mt);
} else {
// Normal field
FieldTag ft = new FieldTag(currentMap.lastElement(), null, fieldName);
Map<String, String> attributeMap = new HashMap<>();
for (String key : h.keySet()) {
attributeMap.put(key, h.get(key));
}
ft.setAddAttributes(attributeMap);
// TODO: Get all attributes of this tag and set them in field (navascript field can have any attribute value!
if (h.get(Attributes.VALUE) != null) {
ExpressionTag et = new ExpressionTag(currentDocument, h.get(Attributes.CONDITION), h.get(Attributes.VALUE));
ft.addExpression(et);
}
if (currentParent instanceof MessageTag) {
((MessageTag) currentParent).addField(ft);
} else if (currentParent instanceof BlockTag) {
((BlockTag) currentParent).add(ft);
} else if (currentParent instanceof FinallyTag) {
((FinallyTag) currentParent).add(ft);
} else if (currentParent instanceof MapTag) {
((MapTag) currentParent).addField(ft);
} else {
throw new Exception("Cannot place tag " + tag + " (setter/operation) under this tag: " + currentParent);
}
currentField.push(ft);
currentNode.push(ft);
}
}
}
Aggregations