use of com.dexels.navajo.document.nanoimpl.XMLElement 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.nanoimpl.XMLElement in project navajo by Dexels.
the class BaseContextImpl method writeArticleMeta.
@Override
public void writeArticleMeta(String name, ObjectNode w, ObjectMapper mapper, boolean extended) throws APIException {
File in = resolveArticle(name);
try (FileReader fr = new FileReader(in)) {
ObjectNode article = mapper.createObjectNode();
w.set(name, article);
XMLElement x = new CaseSensitiveXMLElement();
x.parseFromReader(fr);
article.put("name", name);
interpretMeta(x, mapper, article, extended);
} catch (FileNotFoundException e) {
throw new APIException("Article " + name + " not found", e, APIErrorCode.ArticleNotFound);
} catch (XMLParseException e) {
throw new APIException("Article " + name + " is not valid XML", e, APIErrorCode.InternalError);
} catch (IOException e) {
throw new APIException("Autoclose on filereader failed", e, APIErrorCode.InternalError);
}
}
use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.
the class BaseContextImpl method interpretArticle.
@Override
public void interpretArticle(File article, ArticleRuntime ac) throws APIException, NoJSONOutputException {
XMLElement articleXml = new CaseSensitiveXMLElement();
Reader r = null;
try {
r = new FileReader(article);
articleXml.parseFromReader(r);
ac.execute(this);
} catch (IOException e) {
throw new APIException(e.getMessage(), e, APIErrorCode.InternalError);
} finally {
if (r != null) {
try {
r.close();
} catch (IOException e) {
logger.error("Error: ", e);
}
}
}
}
use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.
the class ServletArticleRuntimeImpl method resolveArgument.
@Override
public String resolveArgument(String name) throws APIException {
final String trimmedName = name.substring(1);
String res = request.getParameter(trimmedName);
if (res != null) {
return res;
}
XMLElement args = article.getElementByTagName("_arguments");
if (args == null) {
throw new APIException("Unspecified parameter reference: " + name + ". No argument data found.", null, APIErrorCode.InternalError);
}
List<XMLElement> lts = args.getChildren();
for (XMLElement xmlElement : lts) {
if (trimmedName.equals(xmlElement.getStringAttribute("name"))) {
boolean optional = xmlElement.getBooleanAttribute("optional", "true", "false", false);
if (!optional) {
// not optional + no value = fail
throw new APIException("Missing parameter not optional: " + trimmedName, null, APIErrorCode.MissingRequiredArgument);
}
return xmlElement.getStringAttribute("default");
}
}
throw new APIException("Unspecified parameter reference: " + name + ". No argument data found.", null, APIErrorCode.InternalError);
}
use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.
the class TslMetaDataHandler method addCalledBy.
/**
* @param xn
* @param element
*/
private void addCalledBy(XMLElement xn, String element) {
TreeSet<String> s = calledByScriptMap.get(element);
if (s == null) {
return;
}
for (Iterator<String> iter = s.iterator(); iter.hasNext(); ) {
String include = iter.next();
XMLElement xnincl = new CaseSensitiveXMLElement();
xnincl.setName("calledby");
xnincl.setAttribute("name", include);
xn.addChild(xnincl);
}
}
Aggregations