You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/09/15 21:29:00 UTC
svn commit: r289296 - in /beehive/trunk/netui/src: core/
core/org/apache/beehive/netui/core/urltemplates/schema/ core/schema/
pageflow/org/apache/beehive/netui/pageflow/internal/
util/org/apache/beehive/netui/util/xml/
Author: ekoneil
Date: Thu Sep 15 12:28:50 2005
New Revision: 289296
URL: http://svn.apache.org/viewcvs?rev=289296&view=rev
Log:
Remove the XMLBeans depdnecney from the URL templating infrastructure.
This is a contribution from Carlin Rogers.
BB: self
Test: NetUI BVT pass / urltemplates pass
Added:
beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urltemplates/schema/
beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urltemplates/schema/url-template-config.xsd
- copied unchanged from r289153, beehive/trunk/netui/src/core/schema/url-template-config/url-template-config.xsd
Removed:
beehive/trunk/netui/src/core/schema/
Modified:
beehive/trunk/netui/src/core/build.xml
beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
beehive/trunk/netui/src/util/org/apache/beehive/netui/util/xml/DomUtils.java
Modified: beehive/trunk/netui/src/core/build.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/core/build.xml?rev=289296&r1=289295&r2=289296&view=diff
==============================================================================
--- beehive/trunk/netui/src/core/build.xml (original)
+++ beehive/trunk/netui/src/core/build.xml Thu Sep 15 12:28:50 2005
@@ -9,7 +9,6 @@
<path id="module.classpath">
<path refid="servlet.dependency.path"/>
- <path refid="xbean.dependency.path"/>
<path refid="commons-codec.dependency.path"/>
<path refid="commons-logging.dependency.path"/>
<pathelement path="${classes.dir}/util"/>
@@ -22,14 +21,6 @@
<echo>module classpath: ${classpath}</echo>
<mkdir dir="${classes.dir}/${module.name}"/>
- <ant antfile="${netui.ant.dir}/xmlBean.xml">
- <property name="xsd.root.dir" value="${module.dir}/schema/"/>
- <property name="class.output.dir" value="${classes.dir}/${module.name}"/>
- <property name="xbean.inputs" value="${module.dir}/schema/**/*.xsd*"/>
- <!-- TODO: put in the right output classname -->
- <property name="xbean.output" value="${classes.dir}/${module.name}/org/apache/beehive/netui/core/urltemplates/schema/CHANGEME.class"/>
- </ant>
-
<javac srcdir="${module.dir}"
destdir="${classes.dir}/${module.name}"
classpathref="module.classpath"
@@ -43,8 +34,8 @@
<copy todir="${classes.dir}/${module.name}">
<fileset dir="${module.dir}" includes="**/*.properties"/>
+ <fileset dir="${module.dir}" includes="**/*.xsd"/>
</copy>
-
</target>
<target name="clean">
Modified: beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java?rev=289296&r1=289295&r2=289296&view=diff
==============================================================================
--- beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java (original)
+++ beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLTemplatesFactory.java Thu Sep 15 12:28:50 2005
@@ -20,19 +20,20 @@
import org.apache.beehive.netui.core.urltemplates.URLTemplate;
import org.apache.beehive.netui.core.urltemplates.URLTemplates;
import org.apache.beehive.netui.core.urltemplates.URLTemplatesFactory;
-import org.apache.beehive.netui.core.urltemplates.schema.UrlTemplateConfigDocument;
-import org.apache.beehive.netui.core.urltemplates.schema.UrlTemplateConfigDocument.UrlTemplateConfig;
-import org.apache.beehive.netui.core.urltemplates.schema.UrlTemplateDocument;
-import org.apache.beehive.netui.core.urltemplates.schema.UrlTemplateRefDocument;
-import org.apache.beehive.netui.core.urltemplates.schema.UrlTemplateRefGroupDocument;
import org.apache.beehive.netui.util.internal.InternalStringBuilder;
import org.apache.beehive.netui.util.logging.Logger;
-import org.apache.xmlbeans.XmlException;
+import org.apache.beehive.netui.util.xml.DomUtils;
-import javax.servlet.ServletContext;
import java.io.InputStream;
import java.io.IOException;
import java.util.HashMap;
+import java.util.List;
+import javax.servlet.ServletContext;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
/**
* Methods for configuring and retrieving the URLTemplate object.
@@ -41,6 +42,15 @@
{
private static final Logger _log = Logger.getInstance( DefaultURLTemplatesFactory.class );
+ // Constants for schema elements
+ private static final String KEY = "key";
+ private static final String NAME = "name";
+ private static final String TEMPLATE_NAME = "template-name";
+ private static final String URL_TEMPLATE = "url-template";
+ private static final String URL_TEMPLATE_REF = "url-template-ref";
+ private static final String URL_TEMPLATE_REF_GROUP = "url-template-ref-group";
+ private static final String VALUE = "value";
+
// The actual URL templates and template ref groups
private URLTemplates _urlTemplates;
@@ -103,6 +113,7 @@
*/
public void load( ServletContext servletContext )
{
+ _urlTemplates = new URLTemplates();
InputStream stream = null;
try
@@ -110,13 +121,17 @@
stream = servletContext.getResourceAsStream( _configFilePath );
if ( stream != null )
{
- _urlTemplates = getTemplatesFromConfig( stream );
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+ Document document = dBuilder.parse( stream );
+ Element root = document.getDocumentElement();
+
+ // Load the templates and template ref groups
+ loadTemplates( root );
+ loadTemplateRefGroups( root );
}
else
{
- // No descriptor
- _urlTemplates = new URLTemplates();
-
if ( _log.isInfoEnabled() )
{
String contextName = servletContext.getServletContextName();
@@ -125,26 +140,23 @@
{
message.append( contextName ).append( " - " );
}
-
+
message.append( "Running without URL template descriptor, " );
message.append( _configFilePath );
_log.info( message.toString() );
}
}
}
- catch ( XmlException xe )
+ catch ( SAXException se )
{
- // Bad descriptor
- _log.error( "Malformed URL template descriptor in " + _configFilePath, xe );
+ _log.error( "Problem parsing URL template descriptor in " + _configFilePath, se );
}
catch ( IOException ioe )
{
- // Bad descriptor
- _log.error( "Problem parsing URL template descriptor in " + _configFilePath, ioe );
+ _log.error( "Problem reading URL template descriptor file " + _configFilePath, ioe );
}
catch ( Exception e )
{
- // Bad descriptor
_log.error( "Problem loading URL template descriptor file " + _configFilePath, e );
}
finally
@@ -166,89 +178,80 @@
/**
* Loads the templates from a URL template config document.
*
- * @param stream the stream for the URL template config.
- * @return The URL templates found in the config document.
+ * @param parent
*/
- protected URLTemplates getTemplatesFromConfig( InputStream stream ) throws XmlException, IOException
+ private void loadTemplates( Element parent )
{
- URLTemplates urlTemplates = new URLTemplates();
-
- UrlTemplateConfig urlTemplateConfig = UrlTemplateConfigDocument.Factory.parse( stream ).getUrlTemplateConfig();
-
// Load templates
- UrlTemplateDocument.UrlTemplate[] templates = urlTemplateConfig.getUrlTemplateArray();
- for ( int i = 0; i < templates.length; i++ )
+ List templates = DomUtils.getChildElementsByName( parent, URL_TEMPLATE );
+ for ( int i = 0; i < templates.size(); i++ )
{
- String name = templates[i].getName();
- if ( name != null )
+ Element template = ( Element ) templates.get( i );
+ String name = getElementText( template, NAME );
+ if ( name == null )
{
- name = name.trim();
+ _log.error( "Malformed URL template descriptor in " + _configFilePath
+ + ". The url-template name is missing." );
+ continue;
}
- else
+
+ String value = getElementText( template, VALUE );
+ if ( value == null )
{
_log.error( "Malformed URL template descriptor in " + _configFilePath
- + ". The url-template name is missing." );
+ + ". The url-template value is missing for template " + name );
continue;
}
- String value = templates[i].getValue();
- if ( value != null )
+ if ( _log.isDebugEnabled() )
{
- value = value.trim();
- if ( _log.isDebugEnabled() )
- {
- _log.debug( "[URLTemplate] " + name + " = " + value );
- }
- URLTemplate urlTemplate = new URLTemplate( value );
- if ( urlTemplate.verify( _knownTokens, _requiredTokens ) )
- {
- urlTemplates.addTemplate( name, urlTemplate );
- }
+ _log.debug( "[URLTemplate] " + name + " = " + value );
}
- else
+
+ URLTemplate urlTemplate = new URLTemplate( value );
+ if ( urlTemplate.verify( _knownTokens, _requiredTokens ) )
{
- _log.error( "Malformed URL template descriptor in " + _configFilePath
- + ". The url-template value is missing." );
+ _urlTemplates.addTemplate( name, urlTemplate );
}
}
+ }
+ /**
+ * Loads the template reference groups from a URL template config document.
+ *
+ * @param parent
+ */
+ private void loadTemplateRefGroups( Element parent )
+ {
// Load template refs
- UrlTemplateRefGroupDocument.UrlTemplateRefGroup[] templateRefGroups = urlTemplateConfig.getUrlTemplateRefGroupArray();
- for ( int i = 0; i < templateRefGroups.length; i++ )
+ List templateRefGroups = DomUtils.getChildElementsByName( parent, URL_TEMPLATE_REF_GROUP );;
+ for ( int i = 0; i < templateRefGroups.size(); i++ )
{
- HashMap refGroup = new HashMap();
- String refGroupName = templateRefGroups[i].getName();
- if ( refGroupName != null )
- {
- refGroupName = refGroupName.trim();
- }
- else
+ Element refGroupElement = ( Element ) templateRefGroups.get( i );
+ String refGroupName = getElementText( refGroupElement, NAME );
+ if ( refGroupName == null )
{
_log.error( "Malformed URL template descriptor in " + _configFilePath
+ ". The url-template-ref-group name is missing." );
continue;
}
- UrlTemplateRefDocument.UrlTemplateRef[] templateRefs = templateRefGroups[i].getUrlTemplateRefArray();
- for ( int j = 0; j < templateRefs.length; j++ )
+ HashMap refGroup = new HashMap();
+ List templateRefs = DomUtils.getChildElementsByName( refGroupElement, URL_TEMPLATE_REF );;
+ for ( int j = 0; j < templateRefs.size(); j++ )
{
- String key = templateRefs[j].getKey();
-
- if ( key != null )
- {
- key = key.trim();
- }
- else
+ Element templateRefElement = ( Element ) templateRefs.get( j );
+ String key = getElementText( templateRefElement, KEY );
+ if ( key == null )
{
_log.error( "Malformed URL template descriptor in " + _configFilePath
- + ". The url-template-ref key is missing." );
+ + ". The url-template-ref key is missing in url-template-ref-group " + refGroupName );
continue;
}
- String name = templateRefs[j].getTemplateName();
+ String name = getElementText( templateRefElement, TEMPLATE_NAME );
if ( name != null )
{
- name = name.trim();
refGroup.put( key, name );
if ( _log.isDebugEnabled() )
{
@@ -258,16 +261,30 @@
else
{
_log.error( "Malformed URL template descriptor in " + _configFilePath
- + ". The url-template-ref template-name is missing." );
+ + ". The url-template-ref template-name is missing in url-template-ref-group " + refGroupName );
}
}
if ( refGroup.size() != 0 )
{
- urlTemplates.addTemplateRefGroup( refGroupName, refGroup );
+ _urlTemplates.addTemplateRefGroup( refGroupName, refGroup );
+ }
+ }
+ }
+
+ private String getElementText( Element parent, String elementName )
+ {
+ Element child = DomUtils.getChildElementByName( parent, elementName );
+ if ( child != null )
+ {
+ String text = DomUtils.getElementText( child );
+ if ( text != null )
+ {
+ text = text.trim();
+ return text.length() == 0 ? null : text;
}
}
- return urlTemplates;
+ return null;
}
}
Modified: beehive/trunk/netui/src/util/org/apache/beehive/netui/util/xml/DomUtils.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/xml/DomUtils.java?rev=289296&r1=289295&r2=289296&view=diff
==============================================================================
--- beehive/trunk/netui/src/util/org/apache/beehive/netui/util/xml/DomUtils.java (original)
+++ beehive/trunk/netui/src/util/org/apache/beehive/netui/util/xml/DomUtils.java Thu Sep 15 12:28:50 2005
@@ -1,13 +1,12 @@
/*
- * B E A S Y S T E M S
- * Copyright 2002-2004 BEA Systems, Inc.
+ * Copyright 2005 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.
@@ -28,7 +27,7 @@
import org.w3c.dom.Attr;
/**
- * <p>This class exists simply because DOM does so inconvenient to use.</p>
+ * <p>This class exists simply because DOM is so inconvenient to use.</p>
*/
public final class DomUtils {