maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r646314 - in /maven/doxia/doxia-tools/trunk/doxia-converter/src/main: java/org/apache/maven/doxia/DefaultConverter.java resources/META-INF/ resources/META-INF/plexus/ resources/META-INF/plexus/components.xml
Date Wed, 09 Apr 2008 12:50:10 GMT
Author: vsiveton
Date: Wed Apr  9 05:50:08 2008
New Revision: 646314

URL: http://svn.apache.org/viewvc?rev=646314&view=rev
Log:
o added Plexus container to handle macros

Added:
    maven/doxia/doxia-tools/trunk/doxia-converter/src/main/resources/META-INF/
    maven/doxia/doxia-tools/trunk/doxia-converter/src/main/resources/META-INF/plexus/
    maven/doxia/doxia-tools/trunk/doxia-converter/src/main/resources/META-INF/plexus/components.xml
  (with props)
Modified:
    maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java

Modified: maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java?rev=646314&r1=646313&r2=646314&view=diff
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java
(original)
+++ maven/doxia/doxia-tools/trunk/doxia-converter/src/main/java/org/apache/maven/doxia/DefaultConverter.java
Wed Apr  9 05:50:08 2008
@@ -25,8 +25,10 @@
 import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.commons.lang.ClassUtils;
 import org.apache.maven.doxia.logging.Log;
@@ -53,6 +55,12 @@
 import org.apache.maven.doxia.wrapper.InputReaderWrapper;
 import org.apache.maven.doxia.wrapper.OutputFileWrapper;
 import org.apache.maven.doxia.wrapper.OutputWriterWrapper;
+import org.codehaus.plexus.ContainerConfiguration;
+import org.codehaus.plexus.DefaultContainerConfiguration;
+import org.codehaus.plexus.DefaultPlexusContainer;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.PlexusContainerException;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.SelectorUtils;
@@ -158,52 +166,87 @@
     public void convert( InputFileWrapper input, OutputFileWrapper output )
         throws UnsupportedFormatException, ConverterException
     {
-        if ( input == null )
+        PlexusContainer plexus;
+        try
         {
-            throw new IllegalArgumentException( "input is required" );
+            plexus = startPlexusContainer();
         }
-        if ( output == null )
+        catch ( PlexusContainerException e )
         {
-            throw new IllegalArgumentException( "output is required" );
+            throw new ConverterException( "PlexusContainerException: " + e.getMessage(),
e );
         }
 
-        Parser parser = getParser( input.getFormat() );
-
-        if ( getLog().isDebugEnabled() )
+        if ( input == null )
         {
-            getLog().debug( "Parser used: " + parser.getClass().getName() );
+            throw new IllegalArgumentException( "input is required" );
         }
-
-        if ( input.getFile().isFile() )
+        if ( output == null )
         {
-            parse( input.getFile(), output, parser );
+            throw new IllegalArgumentException( "output is required" );
         }
-        else
+
+        try
         {
-            List files;
+            Parser parser;
             try
             {
-                files = FileUtils.getFiles( input.getFile(), "**/*." + input.getFormat(),
StringUtils.join( FileUtils
-                    .getDefaultExcludes(), ", " ) );
+                parser = getParser( plexus, input.getFormat() );
             }
-            catch ( IOException e )
+            catch ( ComponentLookupException e )
             {
-                throw new ConverterException( "IOException: " + e.getMessage(), e );
+                throw new ConverterException( "ComponentLookupException: " + e.getMessage(),
e );
             }
 
-            for ( Iterator it = files.iterator(); it.hasNext(); )
+            if ( getLog().isDebugEnabled() )
+            {
+                getLog().debug( "Parser used: " + parser.getClass().getName() );
+            }
+
+            if ( input.getFile().isFile() )
+            {
+                parse( input.getFile(), output, parser );
+            }
+            else
             {
-                File f = (File) it.next();
+                List files;
+                try
+                {
+                    files = FileUtils.getFiles( input.getFile(), "**/*." + input.getFormat(),
StringUtils
+                        .join( FileUtils.getDefaultExcludes(), ", " ) );
+                }
+                catch ( IOException e )
+                {
+                    throw new ConverterException( "IOException: " + e.getMessage(), e );
+                }
+
+                for ( Iterator it = files.iterator(); it.hasNext(); )
+                {
+                    File f = (File) it.next();
 
-                parse( f, output, parser );
+                    parse( f, output, parser );
+                }
             }
         }
+        finally
+        {
+            stopPlexusContainer( plexus );
+        }
     }
 
     /** {@inheritDoc} */
     public void convert( InputReaderWrapper input, OutputWriterWrapper output )
         throws UnsupportedFormatException, ConverterException
     {
+        PlexusContainer plexus;
+        try
+        {
+            plexus = startPlexusContainer();
+        }
+        catch ( PlexusContainerException e )
+        {
+            throw new ConverterException( "PlexusContainerException: " + e.getMessage(),
e );
+        }
+
         if ( input == null )
         {
             throw new IllegalArgumentException( "input is required" );
@@ -213,34 +256,49 @@
             throw new IllegalArgumentException( "output is required" );
         }
 
-        Parser parser = getParser( input.getFormat() );
-
-        if ( getLog().isDebugEnabled() )
+        try
         {
-            getLog().debug( "Parser used: " + parser.getClass().getName() );
-        }
+            Parser parser;
+            try
+            {
+                parser = getParser( plexus, input.getFormat() );
+            }
+            catch ( ComponentLookupException e )
+            {
+                throw new ConverterException( "ComponentLookupException: " + e.getMessage(),
e );
+            }
 
-        Sink sink = getSink( output.getFormat(), output.getWriter() );
+            if ( getLog().isDebugEnabled() )
+            {
+                getLog().debug( "Parser used: " + parser.getClass().getName() );
+            }
 
-        if ( getLog().isDebugEnabled() )
-        {
-            getLog().debug( "Sink used: " + sink.getClass().getName() );
-        }
+            Sink sink = getSink( output.getFormat(), output.getWriter() );
 
-        try
-        {
-            parser.parse( input.getReader(), sink );
-        }
-        catch ( ParseException e )
-        {
-            throw new ConverterException( "ParseException: " + e.getMessage(), e );
+            if ( getLog().isDebugEnabled() )
+            {
+                getLog().debug( "Sink used: " + sink.getClass().getName() );
+            }
+
+            try
+            {
+                parser.parse( input.getReader(), sink );
+            }
+            catch ( ParseException e )
+            {
+                throw new ConverterException( "ParseException: " + e.getMessage(), e );
+            }
+            finally
+            {
+                IOUtil.close( input.getReader() );
+                sink.flush();
+                sink.close();
+                IOUtil.close( output.getWriter() );
+            }
         }
         finally
         {
-            IOUtil.close( input.getReader() );
-            sink.flush();
-            sink.close();
-            IOUtil.close( output.getWriter() );
+            stopPlexusContainer( plexus );
         }
     }
 
@@ -269,42 +327,51 @@
     }
 
     /**
+     * @param plexus
      * @param format
      * @return an instance of <code>Parser</code> depending the format.
+     * @throws ComponentLookupException if any
      * @throws IllegalArgumentException if any
      */
-    private static Parser getParser( String format )
+    private static Parser getParser( PlexusContainer plexus, String format )
+        throws ComponentLookupException
     {
+        Parser parser = null;
         if ( format.equals( APT_PARSER ) )
         {
-            return new AptParser();
+            parser = (Parser) plexus.lookup( Parser.ROLE, "apt" );
         }
         else if ( format.equals( CONFLUENCE_PARSER ) )
         {
-            return new ConfluenceParser();
+            parser = (Parser) plexus.lookup( Parser.ROLE, "confluence" );
         }
         else if ( format.equals( DOCBOOK_PARSER ) )
         {
-            return new DocBookParser();
+            parser = (Parser) plexus.lookup( Parser.ROLE, "doc-book" );
         }
         else if ( format.equals( FML_PARSER ) )
         {
-            return new FmlParser();
+            parser = (Parser) plexus.lookup( Parser.ROLE, "fml" );
         }
         else if ( format.equals( TWIKI_PARSER ) )
         {
-            return new TWikiParser();
+            parser = (Parser) plexus.lookup( Parser.ROLE, "twiki" );
         }
         else if ( format.equals( XDOC_PARSER ) )
         {
-            return new XdocParser();
+            parser = (Parser) plexus.lookup( Parser.ROLE, "xdoc" );
         }
         else if ( format.equals( XHTML_PARSER ) )
         {
-            return new XhtmlParser();
+            parser = (Parser) plexus.lookup( Parser.ROLE, "xhtml" );
+        }
+
+        if ( parser == null )
+        {
+            throw new IllegalArgumentException( "Parser not found for: " + format );
         }
 
-        throw new IllegalArgumentException( "Parser not found for: " + format );
+        return parser;
     }
 
     /**
@@ -430,5 +497,32 @@
             sink.close();
             IOUtil.close( writer );
         }
+    }
+
+    /**
+     * @return a new Plexus Container instance
+     * @throws PlexusContainerException if any
+     */
+    private PlexusContainer startPlexusContainer()
+        throws PlexusContainerException
+    {
+        Map context = new HashMap();
+        context.put( "basedir", new File( "" ).getAbsolutePath() );
+
+        ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration();
+        containerConfiguration.setName( "Doxia" );
+        containerConfiguration.setContext( context );
+
+        return new DefaultPlexusContainer( containerConfiguration );
+    }
+
+    /**
+     * Stop the Plexus container.
+     *
+     * @param plexus the Plexus container instance.
+     */
+    private void stopPlexusContainer( PlexusContainer plexus )
+    {
+        plexus.dispose();
     }
 }

Added: maven/doxia/doxia-tools/trunk/doxia-converter/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-tools/trunk/doxia-converter/src/main/resources/META-INF/plexus/components.xml?rev=646314&view=auto
==============================================================================
--- maven/doxia/doxia-tools/trunk/doxia-converter/src/main/resources/META-INF/plexus/components.xml
(added)
+++ maven/doxia/doxia-tools/trunk/doxia-converter/src/main/resources/META-INF/plexus/components.xml
Wed Apr  9 05:50:08 2008
@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you 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.
+-->
+
+<component-set>
+  <!-- Doxia core -->
+  <components>
+    <component>
+      <role>org.apache.maven.doxia.macro.Macro</role>
+      <role-hint>echo</role-hint>
+      <implementation>org.apache.maven.doxia.macro.EchoMacro</implementation>
+      <description>A simple macro that prints out the key and value of some supplied
+      parameters.</description>
+    </component>
+    <component>
+      <role>org.apache.maven.doxia.macro.manager.MacroManager</role>
+      <implementation>org.apache.maven.doxia.macro.manager.DefaultMacroManager</implementation>
+      <description>Default implementation of &lt;code&gt;MacroManager&lt;/code&gt;</description>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.doxia.macro.Macro</role>
+          <field-name>macros</field-name>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.apache.maven.doxia.macro.Macro</role>
+      <role-hint>snippet</role-hint>
+      <implementation>org.apache.maven.doxia.macro.snippet.SnippetMacro</implementation>
+      <description>A macro that prints out the content of a file or a URL.</description>
+    </component>
+    <component>
+      <role>org.apache.maven.doxia.macro.Macro</role>
+      <role-hint>swf</role-hint>
+      <implementation>org.apache.maven.doxia.macro.SwfMacro</implementation>
+      <description>Macro for embedding Flash (SWF) within Maven documentation.</description>
+    </component>
+    <component>
+      <role>org.apache.maven.doxia.macro.Macro</role>
+      <role-hint>toc</role-hint>
+      <implementation>org.apache.maven.doxia.macro.toc.TocMacro</implementation>
+      <description>Macro to display a &lt;code&gt;Table Of Content&lt;/code&gt;
in a
+        given &lt;code&gt;Sink&lt;/code&gt;.</description>
+    </component>
+    <component>
+      <role>org.apache.maven.doxia.parser.manager.ParserManager</role>
+      <implementation>org.apache.maven.doxia.parser.manager.DefaultParserManager</implementation>
+      <description>Simple implementation of the
+        &lt;code&gt;ParserManager&lt;/code&gt; interface.</description>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.doxia.parser.Parser</role>
+          <field-name>parsers</field-name>
+        </requirement>
+      </requirements>
+    </component>
+
+    <!-- Doxia apt -->
+    <component>
+      <role>org.apache.maven.doxia.parser.Parser</role>
+      <role-hint>apt</role-hint>
+      <implementation>org.apache.maven.doxia.module.apt.AptParser</implementation>
+      <description>The APT parser.</description>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.doxia.macro.manager.MacroManager</role>
+          <field-name>macroManager</field-name>
+        </requirement>
+      </requirements>
+    </component>
+
+    <!-- Doxia confluence -->
+    <component>
+      <role>org.apache.maven.doxia.parser.Parser</role>
+      <role-hint>confluence</role-hint>
+      <implementation>org.apache.maven.doxia.module.confluence.ConfluenceParser</implementation>
+      <description>Parse the &lt;a href=&quot;http://www.</description>
+    </component>
+
+    <!-- Doxia docbook -->
+    <component>
+      <role>org.apache.maven.doxia.parser.Parser</role>
+      <role-hint>doc-book</role-hint>
+      <implementation>org.apache.maven.doxia.module.docbook.DocBookParser</implementation>
+      <description>Parse a &lt;code&gt;Docbook&lt;/code&gt; document
and emit events
+        into the specified doxia Sink.</description>
+    </component>
+
+    <!-- Doxia fml -->
+    <component>
+      <role>org.apache.maven.doxia.parser.Parser</role>
+      <role-hint>fml</role-hint>
+      <implementation>org.apache.maven.doxia.module.fml.FmlParser</implementation>
+      <description>Parse a fml model and emit events into the specified doxia Sink.</description>
+    </component>
+
+    <!-- Doxia twiki -->
+    <component>
+      <role>org.apache.maven.doxia.parser.Parser</role>
+      <role-hint>twiki</role-hint>
+      <implementation>org.apache.maven.doxia.module.twiki.TWikiParser</implementation>
+      <description>Parse the &lt;a href=&quot;http://twiki.</description>
+    </component>
+
+    <!-- Doxia xdoc -->
+    <component>
+      <role>org.apache.maven.doxia.parser.Parser</role>
+      <role-hint>xdoc</role-hint>
+      <implementation>org.apache.maven.doxia.module.xdoc.XdocParser</implementation>
+      <description>Parse an xdoc model and emit events into the specified doxia Sink.</description>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.doxia.macro.manager.MacroManager</role>
+          <field-name>macroManager</field-name>
+        </requirement>
+      </requirements>
+    </component>
+
+    <!-- Doxia xhtml -->
+    <component>
+      <role>org.apache.maven.doxia.parser.Parser</role>
+      <role-hint>xhtml</role-hint>
+      <implementation>org.apache.maven.doxia.module.xhtml.XhtmlParser</implementation>
+      <description>Parse an xhtml model and emit events into a Doxia Sink.</description>
+    </component>
+  </components>
+</component-set>

Propchange: maven/doxia/doxia-tools/trunk/doxia-converter/src/main/resources/META-INF/plexus/components.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/doxia-tools/trunk/doxia-converter/src/main/resources/META-INF/plexus/components.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message