[jdom-interest] Element.addContent won't accept String in Collection

Jason Hunter jhunter at servlets.com
Tue Nov 14 17:30:27 PST 2006


You're right, a String should be suitable to add there.  If you'd like 
to add it, I think the way to do so is to check if it's a String and if 
so wrap it with a Text instance before proceeding.  That lets the class 
continue to hold a Content[].  I'll add it.

-jh-

Syloke Soong wrote:
> JDOM javadoc says,
> 
> [javadoc]
> Element addContent(java.util.Collection collection) 
> Appends all children in the given collection to the end of the content
> list.
> 
> Element addContent(int index, java.util.Collection c) 
> Inserts the content in a collection into the content list at the given
> index.
> 
> Element addContent(java.lang.String str) 
> This adds text content to this element.
> [/javadoc]
> 
> Since you could add individual String, I presumed no harm would come my
> way if String objects are included in the collection argument.
> 
> But no, I had a Vector with a String object and addContent(collection)
> rejected the vector due to ...
> 
> org.jdom.IllegalAddException: Class java.lang.String is of unrecognized
> type and cannot be added
> 	org.jdom.ContentList.add(ContentList.java:142)
> 	org.jdom.ContentList.addAll(ContentList.java:292)
> 	org.jdom.ContentList.clearAndSet(ContentList.java:338)
> 	org.jdom.Element.setContent(Element.java:742)
> 
> 
> Hrrrmmmmpppphhhhhhhh .... !
> 
> This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender immediately. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Even though this company takes every precaution to ensure this email is virus-free, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
> Protedyne Corporation, 1000 Day Hill Rd, Windsor, CT 06095, USA,                                                                  
> www.protedyne.com
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> 


More information about the jdom-interest mailing list