.getTag().equals(defaultTag)); ScalarEvent event = new ScalarEvent(tAlias, node.getTag().getValue(), tuple, scalarNode.getValue(), null, null, scalarNode.getStyle()); this.emitter.emit(event); break;
private ScalarNode cloneScalarNode(ScalarNode node, Map<String, String> parameters) { String value = node.getValue(); Matcher matcher = TEMPLATE_PARAMETER_PATTERN.matcher(value); StringBuffer sb = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(sb, ""); sb.append(resolveParameter(matcher.group(), parameters, node)); } matcher.appendTail(sb); return new ScalarNode(node.getTag(), sb.toString(), node.getStartMark(), node.getEndMark(), node.getStyle()); }
private ScalarNode cloneScalarNode(ScalarNode node, Map<String, String> parameters) { String value = node.getValue(); Matcher matcher = TEMPLATE_PARAMETER_PATTERN.matcher(value); StringBuffer sb = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(sb, ""); sb.append(resolveParameter(matcher.group(), parameters, node)); } matcher.appendTail(sb); return new ScalarNode(node.getTag(), sb.toString(), node.getStartMark(), node.getEndMark(), node.getStyle()); }
public IncludeScalarNode(String includeName, String value, ScalarNode node) { super(Tag.STR, value, node.getStartMark(), node.getEndMark(), node.getStyle()); this.includeName = includeName; }
public IncludeScalarNode(String includeName, String value, ScalarNode node) { super(Tag.STR, value, node.getStartMark(), node.getEndMark(), node.getStyle()); this.includeName = includeName; }
protected Node representMapping(Tag tag, Map<?, ?> mapping, Boolean flowStyle) { List<NodeTuple> value = new ArrayList<NodeTuple>(mapping.size()); MappingNode node = new MappingNode(tag, value, flowStyle); representedObjects.put(objectToRepresent, node); boolean bestStyle = true; for (Map.Entry<?, ?> entry : mapping.entrySet()) { Node nodeKey = representData(entry.getKey()); Node nodeValue = representData(entry.getValue()); if (!(nodeKey instanceof ScalarNode && ((ScalarNode) nodeKey).getStyle() == null)) { bestStyle = false; } if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) { bestStyle = false; } value.add(new NodeTuple(nodeKey, nodeValue)); } if (flowStyle == null) { if (defaultFlowStyle != FlowStyle.AUTO) { node.setFlowStyle(defaultFlowStyle.getStyleBoolean()); } else { node.setFlowStyle(bestStyle); } } return node; }
protected Node representMapping(Tag tag, Map<?, ?> mapping, Boolean flowStyle) { List<NodeTuple> value = new ArrayList<NodeTuple>(mapping.size()); MappingNode node = new MappingNode(tag, value, flowStyle); representedObjects.put(objectToRepresent, node); boolean bestStyle = true; for (Map.Entry<?, ?> entry : mapping.entrySet()) { Node nodeKey = representData(entry.getKey()); Node nodeValue = representData(entry.getValue()); if (!(nodeKey instanceof ScalarNode && ((ScalarNode) nodeKey).getStyle() == null)) { bestStyle = false; } if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) { bestStyle = false; } value.add(new NodeTuple(nodeKey, nodeValue)); } if (flowStyle == null) { if (defaultFlowStyle != FlowStyle.AUTO) { node.setFlowStyle(defaultFlowStyle.getStyleBoolean()); } else { node.setFlowStyle(bestStyle); } } return node; }
@Override public Node resolve(Node node, ResourceLoader resourceLoader, NodeHandler nodeHandler) { String className = ((ScalarNode) node).getValue(); try { Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className); JAXBContext context = JAXBContext.newInstance(clazz); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); context.generateSchema(new SchemaOutputResolver() { @Override public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException { StreamResult result = new StreamResult(baos); result.setSystemId("001"); return result; } }); String schema = baos.toString(); return new ScalarNode(Tag.STR, schema, node.getStartMark(), node.getEndMark(), ((ScalarNode) node).getStyle()); } catch (Exception e) { throw new YAMLException(e); } }
@Override public Node resolve(Node node, ResourceLoader resourceLoader, NodeHandler nodeHandler) { String className = ((ScalarNode) node).getValue(); try { Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className); ObjectMapper objectMapper = new ObjectMapper(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(clazz), visitor); JsonSchema jsonSchema = visitor.finalSchema(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); objectMapper.writeValue(baos, jsonSchema); String schema = baos.toString(); return new ScalarNode(Tag.STR, schema, node.getStartMark(), node.getEndMark(), ((ScalarNode) node).getStyle()); } catch (Exception e) { throw new YAMLException(e); } }
@Override public Node resolve(Node node, ResourceLoader resourceLoader, NodeHandler nodeHandler) { String className = ((ScalarNode) node).getValue(); try { Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className); JAXBContext context = JAXBContext.newInstance(clazz); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); context.generateSchema(new SchemaOutputResolver() { @Override public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException { StreamResult result = new StreamResult(baos); result.setSystemId("001"); return result; } }); String schema = baos.toString(); return new ScalarNode(Tag.STR, schema, node.getStartMark(), node.getEndMark(), ((ScalarNode) node).getStyle()); } catch (Exception e) { throw new YAMLException(e); } }
protected Node representSequence(Tag tag, Iterable<?> sequence, Boolean flowStyle) { int size = 10;// default for ArrayList if (sequence instanceof List<?>) { size = ((List<?>) sequence).size(); } List<Node> value = new ArrayList<Node>(size); SequenceNode node = new SequenceNode(tag, value, flowStyle); representedObjects.put(objectToRepresent, node); boolean bestStyle = true; for (Object item : sequence) { Node nodeItem = representData(item); if (!(nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null)) { bestStyle = false; } value.add(nodeItem); } if (flowStyle == null) { if (defaultFlowStyle != FlowStyle.AUTO) { node.setFlowStyle(defaultFlowStyle.getStyleBoolean()); } else { node.setFlowStyle(bestStyle); } } return node; }
protected Node representSequence(Tag tag, Iterable<?> sequence, Boolean flowStyle) { int size = 10;// default for ArrayList if (sequence instanceof List<?>) { size = ((List<?>) sequence).size(); } List<Node> value = new ArrayList<Node>(size); SequenceNode node = new SequenceNode(tag, value, flowStyle); representedObjects.put(objectToRepresent, node); boolean bestStyle = true; for (Object item : sequence) { Node nodeItem = representData(item); if (!(nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null)) { bestStyle = false; } value.add(nodeItem); } if (flowStyle == null) { if (defaultFlowStyle != FlowStyle.AUTO) { node.setFlowStyle(defaultFlowStyle.getStyleBoolean()); } else { node.setFlowStyle(bestStyle); } } return node; }
@Override public Node resolve(Node node, ResourceLoader resourceLoader, NodeHandler nodeHandler) { String className = ((ScalarNode) node).getValue(); try { Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.disableDefaultTyping(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(clazz), visitor); JsonSchema jsonSchema = visitor.finalSchema(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); objectMapper.writeValue(baos, jsonSchema); String schema = baos.toString(); return new ScalarNode(Tag.STR, schema, node.getStartMark(), node.getEndMark(), ((ScalarNode) node).getStyle()); } catch (Exception e) { throw new YAMLException(e); } }
@Override public void onScalar(ScalarNode node, TupleType tupleType) { if (schemaTuple != null && node instanceof IncludeResolver.IncludeScalarNode) { final String includeName = ((IncludeResolver.IncludeScalarNode) node).getIncludeName(); if (includeName.endsWith(".json")) { try { @SuppressWarnings("unchecked") final Map<String, Object> json = mapper.readValue(node.getValue(), Map.class); if (json.containsKey("$schema") && !json.containsKey("id")) { json.put("id", protocol + ":/" + includeName); super.onScalar(new ScalarNode(node.getTag(), node.isResolved(), mapper.writeValueAsString(json), node.getStartMark(), node.getEndMark(), node.getStyle()), tupleType); return; } } catch (IOException e) { log.warn("Line {}: Could not parse json file '{}' as schema. Relative $refs inside might not work: {}", node.getStartMark().getLine() + 1, includeName, e.getMessage()); } } } super.onScalar(node, tupleType); } }
@Override protected NodeTuple representJavaBeanProperty(Object bean, Property property, Object value, Tag customTag) { NodeTuple tuple = super.representJavaBeanProperty(bean, property, value, customTag); if (isNullValue(tuple) || isEmptySequence(tuple) || isEmptyMapping(tuple)) { return null; } if ("body".equals(property.getName())) { ScalarNode n = (ScalarNode) tuple.getValueNode(); if (n.getStyle() == PLAIN.getChar()) { return tuple; } else { return new NodeTuple(tuple.getKeyNode(), new ScalarNode(n.getTag(), n.getValue(), n .getStartMark(), n.getEndMark(), LITERAL.getChar())); } } return tuple; }
private Node resolveInclude(Node node, Tag tag) { if (node.getNodeId() == scalar && node.getTag().equals(INCLUDE_TAG)) { if (tag != null && tag.startsWith(INCLUDE_APPLIED_TAG)) { // for multiple levels of includes in the same template recalculate path using // parent include applied tag path ScalarNode scalarNode = (ScalarNode) node; String parentPath = includeResolver.getContextPath().resolveRelativePath(tag); String includePathRecalculated = ContextPath.getPartentPath(parentPath) + scalarNode.getValue(); node = new ScalarNode(scalarNode.getTag(), includePathRecalculated, node.getStartMark(), node.getEndMark(), scalarNode.getStyle()); } return includeResolver.resolve(node, resourceLoader, nodeNandler); } return node; }
.getTag().equals(defaultTag)); ScalarEvent event = new ScalarEvent(tAlias, node.getTag().getValue(), tuple, scalarNode.getValue(), null, null, scalarNode.getStyle()); this.emitter.emit(event); break;