use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class TMLSerializer method serializeMessage.
private final void serializeMessage(Message m, byte type, boolean hidePropertyName, OutputStream os) throws IOException {
os.write(serializeMessageTag(m.getName(), type));
for (Property p : m.getAllProperties()) {
serializeProperty(p, type, hidePropertyName, os);
}
int index = 0;
for (Message cm : m.getAllMessages()) {
byte childType = (cm.isArrayMessage() ? ARRAY_MESSAGE_CODE : m.isArrayMessage() ? ARRAY_MESSAGE_ELT_CODE : MESSAGE_CODE);
serializeMessage(cm, childType, (index > 0 && childType == ARRAY_MESSAGE_ELT_CODE), os);
index++;
}
os.write(MESSAGE_CLOSE_CODE);
}
use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class TMLSerializer method parseMessage.
private final Message parseMessage(InputStream is, Message parent, String msgType) throws IOException {
String name = "-";
if (!msgType.equals(Message.MSG_TYPE_ARRAY_ELEMENT)) {
// array message elements do not have a message name.
byte[] array = new byte[bytesToShort(is)];
is.read(array, 0, array.length);
name = new String(array);
}
Message m = NavajoFactory.getInstance().createMessage(myNavajo, name, msgType);
if (parent != null) {
parent.addMessage(m);
} else {
myNavajo.addMessage(m);
}
boolean endOfMessage = false;
int propertyIndex = 0;
while (!endOfMessage) {
//
byte tagType = (byte) is.read();
if (tagType == MESSAGE_CODE) {
// a submessage.
parseMessage(is, m, Message.MSG_TYPE_SIMPLE);
} else if (tagType == ARRAY_MESSAGE_CODE) {
arrayEltIndex = 0;
// an array message.
Message am = parseMessage(is, m, Message.MSG_TYPE_ARRAY);
fixPropertyNames(am);
} else if (tagType == ARRAY_MESSAGE_ELT_CODE) {
// an array message element.
parseMessage(is, m, Message.MSG_TYPE_ARRAY_ELEMENT);
arrayEltIndex++;
} else if (tagType == MESSAGE_CLOSE_CODE) {
propertyIndex = 0;
endOfMessage = true;
} else if (tagType == STRING_PROPERTY_CODE || tagType == LONG_STRING_PROPERTY_CODE) {
Property p = parseProperty(Property.STRING_PROPERTY, m.getType().equals(Message.MSG_TYPE_ARRAY_ELEMENT), propertyIndex, arrayEltIndex, is, (tagType == LONG_STRING_PROPERTY_CODE));
m.addProperty(p);
propertyIndex++;
} else if (tagType == DATE_PROPERTY_CODE) {
Property p = parseProperty(Property.DATE_PROPERTY, m.getType().equals(Message.MSG_TYPE_ARRAY_ELEMENT), propertyIndex, arrayEltIndex, is, false);
m.addProperty(p);
propertyIndex++;
} else if (tagType == BOOLEAN_PROPERTY_CODE) {
Property p = parseProperty(Property.BOOLEAN_PROPERTY, m.getType().equals(Message.MSG_TYPE_ARRAY_ELEMENT), propertyIndex, arrayEltIndex, is, false);
m.addProperty(p);
propertyIndex++;
} else if (tagType == INTEGER_PROPERTY_CODE) {
Property p = parseProperty(Property.INTEGER_PROPERTY, m.getType().equals(Message.MSG_TYPE_ARRAY_ELEMENT), propertyIndex, arrayEltIndex, is, false);
m.addProperty(p);
propertyIndex++;
} else if (tagType == FLOAT_PROPERTY_CODE) {
Property p = parseProperty(Property.FLOAT_PROPERTY, m.getType().equals(Message.MSG_TYPE_ARRAY_ELEMENT), propertyIndex, arrayEltIndex, is, false);
m.addProperty(p);
propertyIndex++;
} else if (tagType == BINARY_PROPERTY_CODE) {
Property p = parseProperty(Property.BINARY_PROPERTY, m.getType().equals(Message.MSG_TYPE_ARRAY_ELEMENT), propertyIndex, arrayEltIndex, is, true);
m.addProperty(p);
propertyIndex++;
}
}
return m;
}
use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class Switch method createTestNavajo.
@Override
protected Navajo createTestNavajo() throws Exception {
Navajo doc = NavajoFactory.getInstance().createNavajo();
Message array = NavajoFactory.getInstance().createMessage(doc, "Aap");
array.setType(Message.MSG_TYPE_ARRAY);
Message array1 = NavajoFactory.getInstance().createMessage(doc, "Aap");
array.addElement(array1);
doc.addMessage(array);
Property p = NavajoFactory.getInstance().createProperty(doc, "Noot", Property.INTEGER_PROPERTY, "10", 10, "", "in");
p.setValue(10);
array1.addProperty(p);
Message single = NavajoFactory.getInstance().createMessage(doc, "Single");
doc.addMessage(single);
Property p2 = NavajoFactory.getInstance().createProperty(doc, "Selectie", "1", "", "in");
p2.addSelection(NavajoFactory.getInstance().createSelection(doc, "key", "value", true));
single.addProperty(p2);
Property p3 = NavajoFactory.getInstance().createProperty(doc, "Vuur", Property.INTEGER_PROPERTY, "10", 10, "", "out");
p3.setValue(10);
single.addProperty(p3);
return doc;
}
use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class TableCommand method execute.
@Override
public JsonNode execute(ArticleRuntime runtime, ArticleContext context, Map<String, String> parameters, XMLElement element) throws APIException {
String service = parameters.get("service");
if (service == null) {
throw new APIException("No service parameter supplied for table. We need to know which navajo you want to use.", null, APIErrorCode.InternalError);
}
Navajo navajo = runtime.getNavajo(service);
if (navajo == null) {
throw new APIException("Navajo: " + service + " was not found in the current runtime.", null, APIErrorCode.InternalError);
}
String path = parameters.get("path");
if (path == null) {
throw new APIException("No path parameter supplied. Which message do you want to listen to.", null, APIErrorCode.InternalError);
}
Message message = navajo.getMessage(path);
if (message == null) {
throw new APIException("Message: " + path + " not found", null, APIErrorCode.InternalError);
}
runtime.setMimeType("application/json; charset=utf-8");
ArrayNode nodes = runtime.getObjectMapper().createArrayNode();
for (Message data : message.getElements()) {
ObjectNode node = runtime.getObjectMapper().createObjectNode();
for (XMLElement XMLElement : element.getChildren()) {
final String id = XMLElement.getStringAttribute("id");
final String type = XMLElement.getStringAttribute("type");
final String target = XMLElement.getStringAttribute("target");
if (target != null) {
// A target is a link, they do not have navajo value.
node.put(id, resolveTarget(target, runtime, data));
} else {
// We default back to the id for the propertyName if not explicit set.
final String propertyName = XMLElement.getStringAttribute("propertyName", id);
Property property = data.getProperty(propertyName);
APIValue.setValueOnNodeForType(node, id, type, property, runtime);
}
}
nodes.add(node);
}
return nodes;
}
use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class Access method setInDoc.
public void setInDoc(Navajo in) {
if (in == null) {
return;
}
this.inDoc = in;
if (in.getHeader() != null) {
// Check for parent access id header.
String s = in.getHeader().getHeaderAttribute("parentaccessid");
if (s != null && !s.equals("")) {
setParentAccessId(s);
}
}
// Check if __parms__ exists.
Message msg = inDoc.getMessage("__parms__");
if (msg == null) {
msg = NavajoFactory.getInstance().createMessage(inDoc, "__parms__");
try {
inDoc.addMessage(msg);
} catch (NavajoException e) {
logger.error("Error: ", e);
}
}
}
Aggregations