Peter Donald wrote:
 >
 > Hi,
 >
 > Okay I got bored and didn't wait for your patch ;)


??!
I've send you the patch (see the attachement) a week ago...



-- 
Al
--- Begin Message ---
 > >  > > <config-include location="cfgs/subconf1.xml"/>
 > >  > > <config-include location="cfgs/subconf2.xml"/>

 > > Well... maybe, I could do the task ?

 > That would be fantastic! ;)

here is the file (using the last cvs update 1.13)
seek the comment

// deal with <config-include location="path"/> element


I've tested this code with the Jabber server, and it works pretty well.


 > Yould also need to make sure blocks are not named "config-include" in the
 > phoenix.tools.validator package and all should be good.

???
Are you talking about the SarVerifier in
org.apache.avalon.phoenix.tools.verifier package?

Cheers,

--
Al
/* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.framework.configuration; import java.util.ArrayList; import java.io.File; import java.io.IOException; import org.xml.sax.Attributes; import org.xml.sax.ErrorHandler; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; /** * A SAXConfigurationHandler helps build Configurations out of sax events. * * @author Federico Barbieri * @author Peter Donald */ public class SAXConfigurationHandler extends DefaultHandler implements ErrorHandler { private final static String CONFIG_INCLUDE_ELEMENT = "config-include"; private final static String CONFIG_INCLUDE_LOCATION_ATTR = "location"; private final ArrayList m_elements = new ArrayList(); private Configuration m_configuration; private Locator m_locator; public Configuration getConfiguration() { return m_configuration; } public void clear() { m_elements.clear(); m_locator = null; } public void setDocumentLocator( final Locator locator ) { m_locator = locator; } public void characters( final char[] ch, int start, int end ) throws SAXException { String value = (new String( ch, start, end )).trim(); if( value.equals( "" ) ) { return; } final DefaultConfiguration configuration = (DefaultConfiguration)m_elements.get( m_elements.size() - 1 ); if( 0 != configuration.getChildCount() ) { throw new SAXException( "Not allowed to define mixed content in the " + "element " + configuration.getName() + " at " + configuration.getLocation() ); } value = configuration.getValue( "" ) + value; configuration.setValue( value ); } public void endElement( final String namespaceURI, final String localName, final String rawName ) throws SAXException { final int location = m_elements.size() - 1; final Object object = m_elements.remove( location ); // deal with element if( rawName != null && rawName.equals( CONFIG_INCLUDE_ELEMENT ) && location > 0 ) { DefaultConfiguration configuration = (DefaultConfiguration)object; DefaultConfiguration parent = (DefaultConfiguration)m_elements.get( location - 1 ); try { String configLocation = configuration.getAttribute( CONFIG_INCLUDE_LOCATION_ATTR ); String currentUri = m_locator.getSystemId(); if( configLocation != null && currentUri != null && currentUri.indexOf('/') > 0 ) { String uri = currentUri.substring( 0, currentUri.lastIndexOf('/') + 1 ) + configLocation; Configuration includeConfiguration = new DefaultConfigurationBuilder().build( uri ); parent.addChild( includeConfiguration ); parent.removeChild( configuration ); } } catch (ConfigurationException ce) { ce.printStackTrace(); throw new SAXException( ce.getMessage() ); } catch (IOException ioe) { ioe.printStackTrace(); throw new SAXException( ioe.getMessage() ); } } // end deal with element else if( 0 == location ) { m_configuration = (Configuration)object; } } protected DefaultConfiguration createConfiguration( final String localName, final String location ) { return new DefaultConfiguration( localName, location ); } public void startElement( final String namespaceURI, final String localName, final String rawName, final Attributes attributes ) throws SAXException { final DefaultConfiguration configuration = createConfiguration( rawName, getLocationString() ); final int size = m_elements.size() - 1; if( size > -1 ) { final DefaultConfiguration parent = (DefaultConfiguration)m_elements.get( size ); if( null != parent.getValue( null ) ) { throw new SAXException( "Not allowed to define mixed content in the " + "element " + parent.getName() + " at " + parent.getLocation() ); } parent.addChild( configuration ); } m_elements.add( configuration ); final int attributesSize = attributes.getLength(); for( int i = 0; i < attributesSize; i++ ) { final String name = attributes.getQName( i ); final String value = attributes.getValue( i ); configuration.setAttribute( name, value ); } } /** * This just throws an exception on a parse error. */ public void error( final SAXParseException exception ) throws SAXException { throw exception; } /** * This just throws an exception on a parse error. */ public void warning( final SAXParseException exception ) throws SAXException { throw exception; } /** * This just throws an exception on a parse error. */ public void fatalError( final SAXParseException exception ) throws SAXException { throw exception; } protected String getLocationString() { if( null == m_locator ) { return "Unknown"; } else { return m_locator.getSystemId() + ":" + m_locator.getLineNumber() + ":" + m_locator.getColumnNumber(); } } } --- End Message ---
--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to