If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
thibeact
Posts: 1
Registered: ‎04-03-2009
My Device: Not Specified

XML Attachment

Hi.

 

 Looking for a way to retireve an xml attachment then automatically process the xml document and display it. I am stuck on how to retreive the xml attachment into a inputstream.

Here is what I have so far:

 

 

import java.io.InputStream; import org.w3c.dom.Document; import net.rim.blackberry.api.mail.Folder; import net.rim.blackberry.api.mail.Message; import net.rim.blackberry.api.mail.Multipart; import net.rim.blackberry.api.mail.event.FolderEvent; import net.rim.device.api.notification.NotificationsManager; import net.rim.device.api.system.RuntimeStore; import net.rim.device.api.ui.component.Dialog; import net.rim.device.api.xml.parsers.DocumentBuilder; import net.rim.device.api.xml.parsers.DocumentBuilderFactory; public class test extends UiApplication implements FolderListener{ ... public void messagesAdded(FolderEvent e) { // Create a store to save the xml document into RuntimeStore store = RuntimeStore.getRuntimeStore(); long ATTACHMENT_ID = 0x227cdf69ca6b6ce8L; // ATTACHMENT_ID // get the message and folder it was added to Message msg = e.getMessage(); Folder messageFolder = msg.getFolder(); if (msg.getSubject().equalsIgnoreCase("XML TEST")) { Object content = msg.getContent(); if (content instanceof Multipart) { Multipart mp = (Multipart) content; for (int i = 0; i < mp.getCount(); i++) { try { // Build a document based on the XML file. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); // InputStream inputStream = // mp.getBodyPart(i).getInputStream(); Document document = builder.parse((InputStream) mp.getBodyPart(i).getContent()); store.put(ATTACHMENT_ID, document); } catch (Exception ex) { Dialog.alert("Error: " + ex.getMessage()); } } // delete the message messageFolder.deleteMessage(msg); NotificationsManager.triggerImmediateEvent(ShowXML.NOTIFICATION_ID, 0, this, null); } } } }

 

 

Please use plain text.
Administrator
MSohm
Posts: 14,362
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: XML Attachment

There are 2 approaches you can take to work with email attachments.  You can implement a content handler using JSR 172 for the content type of the attachment.  This provides the user with a Download Attachment menu option when they open the message.  Download Attachment downloads the attachment and then invokes your application to process it.

 

Alternatively you can use an AttachmentHandler as described here:

 

How to - Create a custom Attachment Handler on the BlackBerry device
Article Number: DB-00143

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800698/How_To_...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.