Skip to main content

Create custom Metadata for a ContentAdvertisement

2 replies [Last post]
0vw3
Offline
Joined: 2007-11-18
Points: 0

Hi all!
I am developing a photo-sharing app on jxta. I would like to share image metadata through CMS service that i classify in two types:
1) Text metadata: Width, heigth, exposure time and other fields from EXIF
2) (A bit more difficult, perhaps, but with XML it shouldn't be any problem i think)
Embed the thumbnail of the image into the ContentAdvertisement's Metadata field.

I am using jxse-cms, and as far as i know, i should use the class ContentMetadataImpl.

I think this class it's some kind of parser for an structured document you must create before calling the constructor.
The constructor is as follows:

public ContentMetadataImpl(Element metadata)
throws IllegalArgumentException {
init(metadata);
value = (String) metadata.getValue();
}

init is a method inherited from ContentMetadataImpl's parent class, ContentMetadata. It initializes the fields name, location, etc..

The problem is that i don't know how to create the Element metadata arg for this constructor. I've been trying with StructuredDocument, but I didn't obtain any success.

How should I handle with StructuredDocument (or whatever) to make a suitable arg to that constructor?

Thank you very much.

Message was edited by: 0vw3

Message was edited by: 0vw3

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
0vw3
Offline
Joined: 2007-11-18
Points: 0

OK, I solved the first problem using ContentMetadataImpl and StructuredDocumentFactory:

StructuredDocument doc = StructuredDocumentFactory.newStructuredDocument(new MimeMediaType("text/xml"), ContentMetadata.EN_METADATA, res_value);
Element schemeEl = doc.createElement(ContentMetadata.EN_SCHEME); doc.appendChild(schemeEl);
schemeEl.appendChild(doc.createElement(ContentMetadata.EN_NAME, "Resolution"));
schemeEl.appendChild(doc.createElement(ContentMetadata.EN_LOCATION,null));
schemeEl.appendChild(doc.createElement(ContentMetadata.EN_CONTENT_TYPE, "text/plain"));

ContentMetadataImpl metadata1 = new ContentMetadataImpl(doc);

myCms.getContentManager().share(file, null, null,metadata);

Now I have to embed a thumbnail (A BufferedImage) into the advertisement. I should use LiteXMLMetadata and LiteXMLMetadataImpl since its value won't be a string.

The question is: How can I make a proper StructuredDocument to embed the image? When I call StructuredDocumentFactory.newStructuredDocument(new MimeMediaType("text/xml"), ContentMetadata.EN_METADATA, res_value); res_value must be an string so this method is not valid for my second target.
Any ideas?

Thanks

Message was edited by: 0vw3

0vw3
Offline
Joined: 2007-11-18
Points: 0

Ok, I've been working on this and seems like it's not possible to create a LiteXMLDocument with a non-string value. Here is the method:

public LiteXMLElement createElement(Object key, Object val) {
if (!(key instanceof String)) {
throw new ClassCastException(key.getClass().getName() + " not supported by createElement as key.");
}

if ((null != val) && !(val instanceof String)) {
throw new ClassCastException(val.getClass().getName() + " not supported by createElement as value.");
}

return createElement((String) key, (String) val);
}
Note this: if ((null != val) && !(val instanceof String))

But I don't understand why? When I go to LiteXMLMetadata source code i can find this:

/**
* Get the string representation of the metadata payload, or null if the
* metadata has no string representation.
*
* @return null because LiteXMLMetadata does not represent its metadata as
* a string.
*/
public String getValue() {
return null;
}

so...if LiteXMLMetadata does not represent its metadata as a string...why are you asked for a string in createElement method??? Is this a bug?

bondolo, if you are there, please help me!! :)

I've also tried to create an StructuredDocument by instanciating a ByteArrayMessageElement and calling to StructuredDocumentFactory.newStructuredDocument( byteArrayElement );
but this fails because I obtain an exception with the message: "key 'application/octet-stream' not registered" D'OH!
So seems that REALLY there's no way to create an structured document with non-string data inside of it???

Help!!! :(