use of org.apache.camel.Converter in project camel by apache.
the class ElasticsearchActionRequestConverter method toMultiSearchRequest.
@Converter
public static MultiSearchRequest toMultiSearchRequest(Object document, Exchange exchange) {
List<SearchRequest> items = (List<SearchRequest>) document;
MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
Iterator<SearchRequest> it = items.iterator();
while (it.hasNext()) {
SearchRequest item = it.next();
multiSearchRequest.add(item);
}
return multiSearchRequest;
}
use of org.apache.camel.Converter in project camel by apache.
the class DomConverter method toString.
@Converter
public String toString(NodeList nodeList, Exchange exchange) throws TransformerException {
// converting NodeList to String is more tricky
// sometimes the NodeList is a Node which we can then leverage
// the XML converter to turn into XML incl. tags
StringBuilder buffer = new StringBuilder();
// use XML converter at first since it preserves tag names
boolean found = false;
if (nodeList instanceof Node) {
Node node = (Node) nodeList;
String s = toString(node, exchange);
if (ObjectHelper.isNotEmpty(s)) {
found = true;
buffer.append(s);
}
} else {
// use XML converter at first since it preserves tag names
int size = nodeList.getLength();
for (int i = 0; i < size; i++) {
Node node = nodeList.item(i);
String s = toString(node, exchange);
if (ObjectHelper.isNotEmpty(s)) {
found = true;
buffer.append(s);
}
}
}
// used an xpath to select an attribute or text() or something
if (!found) {
append(buffer, nodeList);
}
return buffer.toString();
}
use of org.apache.camel.Converter in project camel by apache.
the class XmlConverter method toString.
/**
* Converts the given input Source into text
*/
@Converter
public String toString(Source source, Exchange exchange) throws TransformerException {
if (source == null) {
return null;
} else if (source instanceof StringSource) {
return ((StringSource) source).getText();
} else if (source instanceof BytesSource) {
return new String(((BytesSource) source).getData());
} else {
StringWriter buffer = new StringWriter();
if (exchange != null) {
// check the camelContext properties first
Properties properties = ObjectHelper.getCamelPropertiesWithPrefix(OUTPUT_PROPERTIES_PREFIX, exchange.getContext());
if (properties.size() > 0) {
toResult(source, new StreamResult(buffer), properties);
return buffer.toString();
}
}
// using the old way to deal with it
toResult(source, new StreamResult(buffer));
return buffer.toString();
}
}
use of org.apache.camel.Converter in project camel by apache.
the class XmlConverter method toDOMNodeFromStAX.
@Converter
public Node toDOMNodeFromStAX(StAXSource source) throws ParserConfigurationException, IOException, SAXException, TransformerException {
DOMResult result = new DOMResult();
toResult(source, result);
return result.getNode();
}
use of org.apache.camel.Converter in project camel by apache.
the class XmlConverter method toSAXSourceFromStAX.
@Converter
public SAXSource toSAXSourceFromStAX(StAXSource source, Exchange exchange) throws TransformerException {
String str = toString(source, exchange);
StringReader reader = new StringReader(str);
return new SAXSource(new InputSource(reader));
}
Aggregations