{
//already resolved
return node;
}
Node includeNode;
if (node.getNodeId() != scalar)
{
nodeHandler.onCustomTagError(INCLUDE_TAG, node, "Include cannot be non-scalar");
return mockInclude(node);
}
ScalarNode scalarNode = (ScalarNode) node;
String resourceName = contextPath.resolveAbsolutePath(scalarNode.getValue());
InputStream inputStream = resourceLoader.fetchResource(resourceName);
if (inputStream == null)
{
nodeHandler.onCustomTagError(INCLUDE_TAG, node, "Include cannot be resolved " + resourceName);
return mockInclude(node);
}
else if (resourceName.endsWith(".raml") || resourceName.endsWith(".yaml") || resourceName.endsWith(".yml"))
{
Yaml yamlParser = new Yaml();
includeNode = yamlParser.compose(new InputStreamReader(inputStream));
}
else //scalar value
{
//String newValue = IOUtils.toString(inputStream);
String newValue = StreamUtils.toString(inputStream);
includeNode = new IncludeScalarNode(resourceName, newValue, scalarNode);
}
if (includeNode == null)
{
nodeHandler.onCustomTagError(INCLUDE_TAG, node, "Include file is empty " + resourceName);
return mockInclude(node);
}
//retag node with included resource info
String markInfo = node.getStartMark().getLine() + SEPARATOR + node.getStartMark().getColumn()
+ SEPARATOR + node.getEndMark().getColumn();
includeNode.setTag(new Tag(INCLUDE_APPLIED_TAG + resourceName + SEPARATOR + markInfo));
return includeNode;
}