Handling "V2-style attachments" in Java

I have an NSF file which was produced by an EMC product. The attachments to the documents are not embedded in the “Body” rich item text (verified by API call), but seem to fall into this “V2-style attachment” category (they are shown in the UI in a separate ruled section at the bottom).

I am able to retrieve the attachment using the document.getAttachment(filename) call, however this only works if you know the name of the filename.

I have seen plenty of Lotusscript examples, such as these: http://www-01.ibm.com/support/docview.wss?rs=0&uid=swg21104835, which assume you can do something like this:

Forall i In doc.Items

If i.type = Attachment Then

Set emb = doc.GetAttachment(i.values(0))

In Java, this does not work. Calling item.getValues() throws an exception:

NotesException: Unknown value type to convert

at lotus.domino.local.NotesBase.NPropGetVector(Native Method)

at lotus.domino.local.NotesBase.PropGetVector(Unknown Source)

at lotus.domino.local.Item.getValues(Unknown Source)

The only think which returned something useful was item.getValueString(). This seemed to return the filename at the start null terminated, followed by “a lot of junk”.

I could write a hack to get this out, but I am wondering am I missing something obvious? Is there a bug in getValues() not parsing this value correctly?

Thanks in advance for any advice.

Cheers,

David

Subject: Does this help?

http://www-01.ibm.com/support/docview.wss?uid=swg21423790

Subject: Unfortunately, the link is dead

This is what I get :

Our apologies…

The page you requested cannot be displayed

Subject: I have the same problem in 8.5.2

Seems to be a bug in 8.5.2. Here is a workaround class to get the attachment name from the $FILE items:

class Attachments {

private Document doc = null;



public Attachments(Document doc) {

	this.doc = doc;

}

public Vector getAttachmentNames() throws NotesException, IOException {

	Vector attachmentNames = new Vector();

    Item item = null;

    Enumeration itemsEnum = doc.getItems().elements();

    while (itemsEnum.hasMoreElements()) {

    	item = (Item) itemsEnum.nextElement();

    	if (item.getType() == Item.ATTACHMENT) {

    		attachmentNames.add(getAttachmentNameOf(item));

    	}

    }

    return attachmentNames;

}

public String getAttachmentNameOf(Item item) throws NotesException, IOException {

	return getAttachmentName(item.getValueString());

}

private String getAttachmentName(String attachmentName) throws IOException {

    StringReader reader = new StringReader(attachmentName);

    StringBuilder sb = new StringBuilder();

    int character;

    try {

        while (true) {

        	character = reader.read();

        	if (character == -1) {

        		throw new EOFException();

        	}

        	if (character == 0) {

        		break;

        	}

        	sb.append((char) character);

        }

    } catch (EOFException e) {

    }

    return sb.toString();

}

}