AnsweredAssumed Answered

[BUG, FYI] formatting in XML changes values

Question asked by stijndereede on Feb 28, 2008
Hi,

I think I've come across a bug in the reading of XML files, specifically in my case my module-context.xml file.
In my module, I want to define a new model, so I put:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>

   <bean id="cayman_dictionaryBootstrap"
      parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
      <property name="models">
         <list>
            <value>alfresco/module/cayman/model/caymanModel.xml</value>
         </list>
      </property>
   </bean>
</beans>

This works like expected, the model gets loaded when the AMP is inserted into the war.
However, I edit these XML files in Eclipse, and use the ctrl-shift-F function to auto-format my code. Eclipse then puts the value on it's own line, inserting a newline before and after the value:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>

   <bean id="cayman_dictionaryBootstrap"
      parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
      <property name="models">
         <list>
            <value>
               alfresco/module/cayman/model/caymanModel.xml
            </value>
         </list>
      </property>
   </bean>
</beans>

I would think this is OK, since XML is really a formatting independent way of storing data. I would expect that a trim() call is done on every value when parsing the XML. However, now Alfresco presents my with this error:

11:36:22,623 ERROR [org.springframework.web.context.ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cayman_dictionaryBootstrap' defined in file [D:\alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\module\cayman\module-context.xml]: Invocation of init method failed; nested exception is org.alfresco.service.cmr.dictionary.DictionaryException: Could not find bootstrap model
               alfresco/module/cayman/model/caymanModel.xml
            
Caused by: org.alfresco.service.cmr.dictionary.DictionaryException: Could not find bootstrap model
               alfresco/module/cayman/model/caymanModel.xml
            
   at org.alfresco.repo.dictionary.DictionaryBootstrap.initDictionary(DictionaryBootstrap.java:135)
(…)


I think a trim() call should be done on every value parsed from an XML file. Or at least a note about this should be made on the Wiki, since it took me quite some time to figure this out.

Stijn

Outcomes