use of org.apache.camel.Converter in project camel by apache.
the class FlatpackConverter method toDocument.
@Converter
public static Document toDocument(DataSet dataSet) throws ParserConfigurationException {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
if (dataSet.getIndex() == -1) {
Element list = doc.createElement("Dataset");
dataSet.goTop();
while (dataSet.next()) {
list.appendChild(createDatasetRecord(dataSet, doc));
}
doc.appendChild(list);
} else {
doc.appendChild(createDatasetRecord(dataSet, doc));
}
return doc;
}
use of org.apache.camel.Converter in project camel by apache.
the class JcloudsPayloadConverter method toPayload.
@Converter
public static Payload toPayload(final StreamSourceCache cache, Exchange exchange) throws IOException {
long contentLength = ByteStreams.length(new InputSupplier<InputStream>() {
@Override
public InputStream getInput() throws IOException {
return cache.getInputStream();
}
});
cache.reset();
InputStreamPayload payload = new InputStreamPayload(cache.getInputStream());
payload.getContentMetadata().setContentLength(contentLength);
setContentMetadata(payload, exchange);
return payload;
}
use of org.apache.camel.Converter in project camel by apache.
the class SnmpConverters method toString.
/**
* Converts the given snmp pdu to a String body.
*
* @param pdu the snmp pdu
* @return the text content
*/
@Converter
public static String toString(PDU pdu) {
// the output buffer
StringBuilder sb = new StringBuilder();
// prepare the header
if (pdu.getType() == PDU.V1TRAP) {
sb.append("<" + SNMP_TAG + " messageType=\"v1\">");
} else {
sb.append(SNMP_TAG_OPEN);
}
// Extract SNMPv1 specific variables
if (pdu.getType() == PDU.V1TRAP) {
PDUv1 v1pdu = (PDUv1) pdu;
entryAppend(sb, "enterprise", v1pdu.getEnterprise().toString());
entryAppend(sb, "agent-addr", v1pdu.getAgentAddress().toString());
entryAppend(sb, "generic-trap", Integer.toString(v1pdu.getGenericTrap()));
entryAppend(sb, "specific-trap", Integer.toString(v1pdu.getSpecificTrap()));
entryAppend(sb, "time-stamp", Long.toString(v1pdu.getTimestamp()));
}
// now loop all variables of the response
for (Object o : pdu.getVariableBindings()) {
VariableBinding b = (VariableBinding) o;
sb.append(ENTRY_TAG_OPEN);
sb.append(OID_TAG_OPEN);
sb.append(b.getOid().toString());
sb.append(OID_TAG_CLOSE);
sb.append(VALUE_TAG_OPEN);
sb.append(StringHelper.xmlEncode(b.getVariable().toString()));
sb.append(VALUE_TAG_CLOSE);
sb.append(ENTRY_TAG_CLOSE);
}
// prepare the footer
sb.append(SNMP_TAG_CLOSE);
return sb.toString();
}
use of org.apache.camel.Converter in project camel by apache.
the class MyCxfCustomerConverter method cxfPayloadToString.
@Converter
public static String cxfPayloadToString(final CxfPayload<?> payload) {
XmlConverter converter = new XmlConverter();
StringBuilder buf = new StringBuilder();
for (Object element : payload.getBody()) {
String elementString = "";
try {
elementString = converter.toString((Element) element, null);
} catch (TransformerException e) {
elementString = element.toString();
}
buf.append(elementString);
}
return buf.toString();
}
use of org.apache.camel.Converter in project camel by apache.
the class MailConverters method toString.
/**
* Converts the given JavaMail multipart to a String body, where the content-type of the multipart
* must be text based (ie start with text). Can return null.
*/
@Converter
public static String toString(Multipart multipart) throws MessagingException, IOException {
int size = multipart.getCount();
for (int i = 0; i < size; i++) {
BodyPart part = multipart.getBodyPart(i);
Object content = part.getContent();
while (content instanceof MimeMultipart) {
if (multipart.getCount() < 1) {
break;
}
part = ((MimeMultipart) content).getBodyPart(0);
content = part.getContent();
}
if (part.getContentType().toLowerCase().startsWith("text")) {
return part.getContent().toString();
}
}
return null;
}
Aggregations