Sorry, the attachement wasn't there.
Antonio, It took a little while, but finaly found the time to create the castor patch. The patch is created against the cocoon 2.1 cvs version from 10 April 2004 about 19:30. Here it is! Kind regards, Erwin van de Noort Citeren Antonio Gallardo <[EMAIL PROTECTED]>: > Thanks for the report. > > Can you post a PATCH? > > Best Regards, > > Antonio Gallardo > > > ----- Einde doorgestuurd bericht -----
Index: src/blocks/scratchpad/java/org/apache/cocoon/transformation/CastorTransformer.java =================================================================== RCS file: /home/cvspublic/cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/transformation/CastorTransformer.java,v retrieving revision 1.7 diff -u -r1.7 CastorTransformer.java --- src/blocks/scratchpad/java/org/apache/cocoon/transformation/CastorTransformer.java 5 Mar 2004 10:07:26 -0000 1.7 +++ src/blocks/scratchpad/java/org/apache/cocoon/transformation/CastorTransformer.java 10 Apr 2004 17:29:38 -0000 @@ -1,18 +1,53 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be + used to endorse or promote products derived from this software without + prior written permission. For written permission, please contact + [EMAIL PROTECTED] + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation and was originally created by + Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache + Software Foundation, please see <http://www.apache.org/>. + +*/ package org.apache.cocoon.transformation; import org.apache.avalon.framework.configuration.Configurable; @@ -84,7 +119,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Thorsten Mauch</a> * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> * @author <a href="mailto:[EMAIL PROTECTED]">Michael Homeijer</a> - * @version CVS $Id: CastorTransformer.java,v 1.7 2004/03/05 10:07:26 bdelacretaz Exp $ + * @version CVS $Id: CastorTransformer.java,v 1.6 2003/10/24 08:49:49 cziegeler Exp $ */ public class CastorTransformer extends AbstractTransformer implements Configurable { private static final String CASTOR_URI = "http://apache.org/cocoon/castor/1.0"; @@ -103,7 +138,7 @@ /** The map of namespace prefixes. */ private Map prefixMap = new HashMap(); - + private Unmarshaller unmarshaller; private UnmarshalHandler unmarshalHandler; private ContentHandler unmarshalContentHandler; @@ -119,6 +154,25 @@ private boolean in_castor_element = false; + + // Static initializer: + static { + // Try to find out which XML parser to use: + // FIXME: This should be a Cocoon parser. + if (xmlParserFoundAndSet("org.apache.xerces.parsers.SAXParser")) { + // Xerces / XML4J + } else if (xmlParserFoundAndSet("org.apache.crimson.jaxp.SAXParserImpl")) { + // Crimson + } else if (xmlParserFoundAndSet("com.jclark.xml.sax.Driver")) { + // James Clark XP + } else if (xmlParserFoundAndSet("com.microstar.xml.SAXDriver")) { + // Aelfred + } else { + System.err.println("ERROR: No SAX XML parser found!"); + } + } + + public void configure(Configuration conf) throws ConfigurationException { this.defaultMappingName = conf.getChild(ATTRIB_MAPPING).getValue(); } @@ -143,18 +197,18 @@ } else if (unmarshalContentHandler != null) { // check if this marks the end of the unmarshalling if ((CASTOR_URI.equals(uri)) && (CMD_UNMARSHAL.equals(name))) { - + // End marshalling, remove prefixes Iterator itt = prefixMap.entrySet().iterator(); while ( itt.hasNext() ) { Map.Entry entry = (Map.Entry) itt.next(); unmarshalContentHandler.endPrefixMapping((String)entry.getKey()); } - + // end document unmarshalContentHandler.endDocument(); unmarshalContentHandler = null; - + // store the result of the unmarshaller Object root = unmarshalHandler.getObject(); this.storeBean(objectModel, beanName, beanScope, root); @@ -184,11 +238,11 @@ private void process (String command, Attributes attr) throws SAXException { if (command.equals(CMD_MARSHAL)) { - + String scope = attr.getValue(ATTRIB_SCOPE); String name = attr.getValue(ATTRIB_NAME); String mapping = attr.getValue(ATTRIB_MAPPING); - + if (name == null) { getLogger().error("Attribute to insert not set"); } else { @@ -197,25 +251,25 @@ } else if (command.equals(CMD_UNMARSHAL)) { beanScope = attr.getValue(ATTRIB_SCOPE); beanName = attr.getValue(ATTRIB_NAME); - + if (beanScope == null) { getLogger().error("Destination for unmarshalled bean not set"); return; } - + if (beanName == null) { getLogger().error("Name of unmarshalled bean not set"); return; } String mappingpath = attr.getValue(ATTRIB_MAPPING); - - + + // Create the unmarshaller unmarshaller = new Unmarshaller((Class) null); // Only set a mapping if one is specified if (mappingpath != null) { Mapping mapping; - + try { mapping = loadMapping(mappingpath); unmarshaller.setMapping(mapping); @@ -225,13 +279,13 @@ getLogger().error("Could not load mapping file " + mappingpath, e); } } - + // unmarshalCommand = null; /* if (commandclass != null) { try { unmarshalCommand = (CastorUnmarshalCommand)Class.forName(commandclass).newInstance(); unmarshalCommand.enableLogging(this.getLogger()); - + unmarshalCommand.pre(unmarshaller, xmlConsumer, objectModel, params); } catch (InstantiationException e) { getLogger().error("Could not instantiate class " + commandclass ,e); @@ -241,22 +295,22 @@ getLogger().error("Could not instantiate class " + commandclass ,e); } }*/ - + // Create the unmarshalhandler and wrap it with a SAX2 contentHandler unmarshalHandler = unmarshaller.createHandler(); - + try { unmarshalContentHandler = Unmarshaller.getContentHandler( unmarshalHandler); - + unmarshalContentHandler.startDocument(); - + Iterator itt = prefixMap.entrySet().iterator(); while ( itt.hasNext() ) { Map.Entry entry = (Map.Entry)itt.next(); unmarshalContentHandler.startPrefixMapping((String)entry.getKey(), (String)entry.getValue()); } - + } catch (SAXException e) { getLogger().error("Could not get contenthandler from unmarshaller", e); } @@ -305,37 +359,37 @@ */ private Object searchBean(Map objectModel, String name, String scope) { Request request = ObjectModelHelper.getRequest(objectModel); - + // search all maps for the given bean if ((scope == null) || SCOPE_SITEMAP.equals(scope)) { return objectModel.get(name); } - + if ((scope == null) || SCOPE_REQUEST.equals(scope)) { return request.getAttribute(name); } - + if ((scope == null) || SCOPE_SESSION.equals(scope)) { Session session = request.getSession(false); - + if (session != null) { return session.getAttribute(name); } } - + return null; } private void storeBean(Map objectModel, String name, String scope, Object bean) { Request request = ObjectModelHelper.getRequest(objectModel); - + if (SCOPE_SITEMAP.equals(scope)) { objectModel.put(name, bean); } else if (SCOPE_REQUEST.equals(scope)) { request.setAttribute(name, bean); } else if (SCOPE_SESSION.equals(scope)) { Session session = request.getSession(true); - + session.setAttribute(name, bean); } } @@ -365,4 +419,21 @@ return mapping; } } + + /** + * Code to specify the appropriate parser. + */ + private static boolean xmlParserFoundAndSet(String qualifiedName) { + try { + Class.forName(qualifiedName, false, Thread.currentThread().getContextClassLoader()); + } catch (ClassNotFoundException cnfe) { + return false; + } + + System.setProperty("org.xml.sax.parser", qualifiedName); + System.out.println("Using SAX XML parser: " + qualifiedName); + + return true; +} + } Index: src/blocks/scratchpad/samples/castor/sitemap.xmap =================================================================== RCS file: /home/cvspublic/cocoon-2.1/src/blocks/scratchpad/samples/castor/sitemap.xmap,v retrieving revision 1.5 diff -u -r1.5 sitemap.xmap --- src/blocks/scratchpad/samples/castor/sitemap.xmap 11 Mar 2004 16:25:49 -0000 1.5 +++ src/blocks/scratchpad/samples/castor/sitemap.xmap 10 Apr 2004 17:29:38 -0000 @@ -36,7 +36,7 @@ <map:act type="TestBeanAction"/> <map:generate src="test.xml"/> <map:transform type="castor"/> - <map:serialize/> + <map:serialize type="xml"/> </map:match> </map:pipeline> </map:pipelines> Index: src/blocks/scratchpad/samples/castor/test.xml =================================================================== RCS file: /home/cvspublic/cocoon-2.1/src/blocks/scratchpad/samples/castor/test.xml,v retrieving revision 1.2 diff -u -r1.2 test.xml --- src/blocks/scratchpad/samples/castor/test.xml 6 Mar 2004 02:26:08 -0000 1.2 +++ src/blocks/scratchpad/samples/castor/test.xml 10 Apr 2004 17:29:38 -0000 @@ -1,24 +1,9 @@ <?xml version="1.0"?> -<!-- - Copyright 1999-2004 The Apache Software Foundation - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<zoo xmlns:castor="http://castor.exolab.org/cocoontransfomer"> - <castor:InsertBean name="Mouse"/> - <castor:InsertBean name="Lion"/> - <castor:InsertBean name="Hamster" mapping="castor-mappings/test-mapping_de.xml"/> - <castor:InsertBean name="Wale"/> - <castor:InsertBean name="Elefant" scope="session"/> - <castor:InsertBean name="Elefant" scope="request"/> +<zoo xmlns:castor="http://apache.org/cocoon/castor/1.0"> + <castor:marshal name="Mouse"/> + <castor:marshal name="Lion"/> + <castor:marshal name="Hamster" mapping="castor-mappings/test-mapping_de.xml"/> + <castor:marshal name="Wale"/> + <castor:marshal name="Elefant" scope="session"/> + <castor:marshal name="Elefant" scope="request"/> </zoo>