You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by he...@apache.org on 2006/12/27 21:24:59 UTC

svn commit: r490562 [2/2] - in /velocity/site/doxia-velocity-renderer: ./ config/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/doxia/ src/main/java/org/apache/doxia/velocity/ src/main/java/org/apac...

Added: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaLibraryLoader.java
URL: http://svn.apache.org/viewvc/velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaLibraryLoader.java?view=auto&rev=490562
==============================================================================
--- velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaLibraryLoader.java (added)
+++ velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaLibraryLoader.java Wed Dec 27 12:24:58 2006
@@ -0,0 +1,56 @@
+package org.apache.doxia.velocity.util;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+
+
+/**
+ * This is the Role definition for the Doxia Library Loader component.
+ *
+ * @author  <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
+ * @version  $Revision$
+ */
+public interface DoxiaLibraryLoader
+{
+    /** Plexus Role Definition */
+    String ROLE = DoxiaLibraryLoader.class.getName();
+
+    /**
+     * Sets the list of known library. This is called from the {@link org.apache.doxia.velocity.plugin.DoxiaVelocityRendererPlugin}.
+     *
+     * @param  knownLibraries  An Array of Strings with the names of libraries to load. Can be null.
+     */
+    void setKnownLibraries(String[] libraries);
+
+    /**
+     * Returns the list of known macro libraries.
+     *
+     * @return  An array of strings with the names of the known libraries or null if none are defined.
+     */
+    String[] getKnownLibraries();
+
+    /**
+     * Set the base directory for the maven site generation.
+     *
+     * @param  siteDirectory  A file object representing the site source directory.
+     */
+    void setSiteDirectory(File siteDirectory);
+}

Propchange: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaLibraryLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaLibraryLoader.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Added: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaResourceLoader.java
URL: http://svn.apache.org/viewvc/velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaResourceLoader.java?view=auto&rev=490562
==============================================================================
--- velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaResourceLoader.java (added)
+++ velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaResourceLoader.java Wed Dec 27 12:24:58 2006
@@ -0,0 +1,139 @@
+package org.apache.doxia.velocity.util;
+
+/*
+ * 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.
+ */
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.codehaus.plexus.logging.Logger;
+
+
+/**
+ * This loader reads the current template from a passed in {@link Reader} object and
+ * returns the template as an {@link InputStream} for Velocity to use.
+ *
+ * @author  <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
+ * @version  $Revision$
+ */
+public class DoxiaResourceLoader
+    extends AbstractDoxiaResourceLoader
+{
+
+    /** Plexus logging */
+    private final Logger logger;
+
+    /** The current reader to load the template from. */
+    private Reader templateReader = null;
+
+    /**
+     * Creates a new DoxiaResourceLoader object.
+     *
+     * @param  logger  A Plexus logger object.
+     */
+    public DoxiaResourceLoader(final Logger logger)
+    {
+        this.templateReader = null;
+        this.logger = logger;
+    }
+
+    /**
+     * Set the {@link Reader} object for the loader to use.
+     *
+     * @param  templateReader  A {@link Reader} object. Must not be null.
+     */
+    public void setTemplateReader(final Reader templateReader)
+    {
+        this.templateReader = templateReader;
+    }
+
+    /**
+     * Returns the template available from the {@link Reader} that has been set using {@link #setTemplateReader(Reader)}
+     * when the requested template name is the empty string. This allows Velocity to pull the current template out of
+     * the reader and process as a template.
+     *
+     * TODO: Teach Velocity to know about InputReaders. This method is a kludge at best.
+     *
+     * @param  templateName  The template to retrieve. This loader only reacts on the empty (&quot;&quot;) template name.
+     *
+     * @return  An {@link InputStream} representing the Template available from the Reader or null.
+     *
+
+     * @throws ResourceNotFoundException When this {@link org.apache.velocity.runtime.resource.loader.ResourceLoader}
+     *                                   should have been able to supply the template but encountered an error.
+     */
+    public InputStream getResourceStream(final String templateName)
+        throws ResourceNotFoundException
+    {
+        if ((templateReader == null) || StringUtils.isNotEmpty(templateName))
+        {
+            return null;
+        }
+
+        BufferedReader bufReader = new BufferedReader(templateReader);
+
+        StringBuffer template = new StringBuffer();
+
+        String buf = null;
+
+        try
+        {
+            while ((buf = bufReader.readLine()) != null)
+            {
+                template.append(buf).append("\n");
+            }
+        }
+        catch (IOException ioe)
+        {
+            throw new ResourceNotFoundException("While reading Template: ", ioe);
+        }
+        finally
+        {
+            if (bufReader != null)
+            {
+                try
+                {
+                    bufReader.close();
+                }
+                catch (IOException ioe2)
+                {
+                    logger.error("While closing Input Stream: ", ioe2);
+                }
+            }
+        }
+
+        try
+        {
+            // must match the input.encoding setting in the properties file!
+            byte[] templateBytes = template.toString().getBytes("UTF-8");
+
+            return new ByteArrayInputStream(templateBytes);
+        }
+        catch (UnsupportedEncodingException uee)
+        {
+            throw new ResourceNotFoundException("While encoding Template: ", uee);
+        }
+    }
+}

Propchange: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaResourceLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaResourceLoader.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Added: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaVelocityContextFactory.java
URL: http://svn.apache.org/viewvc/velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaVelocityContextFactory.java?view=auto&rev=490562
==============================================================================
--- velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaVelocityContextFactory.java (added)
+++ velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaVelocityContextFactory.java Wed Dec 27 12:24:58 2006
@@ -0,0 +1,58 @@
+package org.apache.doxia.velocity.util;
+
+/*
+ * 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.
+ */
+
+import org.apache.velocity.VelocityContext;
+
+
+/**
+ * This is the Role definition for the Doxia Velocity Context Factory component.
+ *
+ *
+ * @author  <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
+ * @version  $Revision$
+ */
+public interface DoxiaVelocityContextFactory
+{
+    /** Plexus Role Definition */
+    String ROLE = DoxiaVelocityContextFactory.class.getName();
+
+    /**
+     * Add a new Element to be used in the Velocity context.
+     *
+     * @param elementName The name of the element to use in the Velocity Context.
+     * @param elementValue The object to put in the Velocity Context.
+     */
+    void addContextElement(final String elementName, final Object elementValue);
+
+    /**
+     * Set a list of {@link VelocityTool} objects to use in the Velocity context.
+     *
+     * @param  tools  An array of {@link VelocityTool} objects to use. Can be null.
+     */
+    void setTools(VelocityTool[] tools);
+
+    /**
+     * Returns a configured {@link VelocityContext} object to use.
+     *
+     * @return  A {@link VelocityContext} object.
+     */
+    VelocityContext getVelocityContext();
+}

Propchange: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaVelocityContextFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/DoxiaVelocityContextFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Added: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/PlexusLogger.java
URL: http://svn.apache.org/viewvc/velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/PlexusLogger.java?view=auto&rev=490562
==============================================================================
--- velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/PlexusLogger.java (added)
+++ velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/PlexusLogger.java Wed Dec 27 12:24:58 2006
@@ -0,0 +1,169 @@
+package org.apache.doxia.velocity.util;
+
+/*
+ * 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.
+ */
+
+import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.log.LogChute;
+import org.codehaus.plexus.logging.Logger;
+
+/**
+ * An implementation of a {@link LogChute} to use with Velocity that logs into
+ * Plexus logging.
+ *
+ * @author  <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
+ * @version  $Revision$
+ */
+public class PlexusLogger
+    implements LogChute
+{
+
+    /** Plexus Logger Object */
+    private final Logger logger;
+
+    /**
+     * Creates a new PlexusLogger object.
+     *
+     * @param  logger  The Plexus {@link Logger} object to use.
+     */
+    public PlexusLogger(Logger logger)
+    {
+        this.logger = logger;
+    }
+
+    /**
+     * @see LogChute#init(RuntimeServices)
+     */
+    public void init(final RuntimeServices rsvc)
+        throws Exception
+    { }
+
+    /**
+     * @see LogChute#isLevelEnabled(int)
+     */
+    public boolean isLevelEnabled(final int logLevel)
+    {
+        switch (logLevel)
+        {
+            case LogChute.DEBUG_ID:
+            case LogChute.TRACE_ID:
+            {
+                return logger.isDebugEnabled();
+            }
+
+            case LogChute.ERROR_ID:
+            {
+                return logger.isErrorEnabled();
+            }
+
+            case LogChute.INFO_ID:
+            {
+                return logger.isInfoEnabled();
+            }
+
+            case LogChute.WARN_ID:
+            {
+                return logger.isWarnEnabled();
+            }
+
+            default:
+            {
+                return false;
+            }
+        }
+    }
+
+    /**
+     * @see LogChute#log(int, String)
+     */
+    public void log(final int logLevel, final String msg)
+    {
+        switch (logLevel)
+        {
+            case LogChute.DEBUG_ID:
+            case LogChute.TRACE_ID:
+            {
+                logger.debug(msg);
+                break;
+            }
+
+            case LogChute.ERROR_ID:
+            {
+                logger.error(msg);
+                break;
+            }
+
+            case LogChute.INFO_ID:
+            {
+                logger.info(msg);
+                break;
+            }
+
+            case LogChute.WARN_ID:
+            {
+                logger.warn(msg);
+                break;
+            }
+
+            default:
+            {
+                break; // do nothing
+            }
+        }
+    }
+
+    /**
+     * @see LogChute#log(int, String, Throwable)
+     */
+    public void log(final int logLevel, final String msg, final Throwable t)
+    {
+        switch (logLevel)
+        {
+            case LogChute.DEBUG_ID:
+            case LogChute.TRACE_ID:
+            {
+                logger.debug(msg, t);
+                break;
+            }
+
+            case LogChute.ERROR_ID:
+            {
+                logger.error(msg, t);
+                break;
+            }
+
+            case LogChute.INFO_ID:
+            {
+                logger.info(msg, t);
+                break;
+            }
+
+            case LogChute.WARN_ID:
+            {
+                logger.warn(msg, t);
+                break;
+            }
+
+            default:
+            {
+                break; // do nothing
+            }
+        }
+    }
+}

Propchange: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/PlexusLogger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/PlexusLogger.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Added: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/VelocityTool.java
URL: http://svn.apache.org/viewvc/velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/VelocityTool.java?view=auto&rev=490562
==============================================================================
--- velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/VelocityTool.java (added)
+++ velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/VelocityTool.java Wed Dec 27 12:24:58 2006
@@ -0,0 +1,104 @@
+package org.apache.doxia.velocity.util;
+
+/*
+ * 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.
+ */
+
+/**
+ * This is a wrapper object for a Class to be used as a Velocity Tool.
+ *
+ * @author  <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
+ * @version  $Revision$
+ */
+public class VelocityTool
+{
+
+    /** The name of the tool. Set by Plexus when reading the configuration from the POM. */
+    private String toolName;
+
+    /** The class name of the tool. Set by Plexus when reading the configuration from the POM. */
+    private String toolClass;
+
+    /** Instance Object for this tool. */
+    private Object instance = null;
+
+    /**
+     * Returns the tool class.
+     *
+     * @return  The tool class.
+     */
+    public String getToolClass()
+    {
+        return this.toolClass;
+    }
+
+    /**
+     * Sets the tool class.
+     *
+     * @param  toolClass  The new tool class to use. Should not be null.
+     */
+    public void setToolClass(String toolClass)
+    {
+        this.toolClass = toolClass;
+    }
+
+    /**
+     * Returns the tool name.
+     *
+     * @return  The tool name.
+     */
+    public String getToolName()
+    {
+        return this.toolName;
+    }
+
+    /**
+     * Sets the tool name to use.
+     *
+     * @param  toolName  The new tool name to use. Should not be null.
+     */
+    public void setToolName(String toolName)
+    {
+        this.toolName = toolName;
+    }
+
+    /**
+     * Returns  the instance object for this tool.
+     *
+     * @return An instance object of the configured tool to be used in a Velocity Context.
+     *         If an error occured while instantiating, this method returns a {@link String}
+     *         object containing the error message.
+     */
+    public Object getInstance()
+    {
+        if (instance == null)
+        {
+            try
+            {
+                Class klass = Class.forName(toolClass);
+                instance = klass.newInstance();
+            }
+            catch (Exception e)
+            {
+                instance = e.getMessage(); // Error: Put a String with the error message in the context.
+            }
+        }
+
+        return instance;
+    }
+}

Propchange: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/VelocityTool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/site/doxia-velocity-renderer/src/main/java/org/apache/doxia/velocity/util/VelocityTool.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Added: velocity/site/doxia-velocity-renderer/src/main/resources/org/apache/doxia/velocity/renderer/doxia-velocity-renderer.properties
URL: http://svn.apache.org/viewvc/velocity/site/doxia-velocity-renderer/src/main/resources/org/apache/doxia/velocity/renderer/doxia-velocity-renderer.properties?view=auto&rev=490562
==============================================================================
--- velocity/site/doxia-velocity-renderer/src/main/resources/org/apache/doxia/velocity/renderer/doxia-velocity-renderer.properties (added)
+++ velocity/site/doxia-velocity-renderer/src/main/resources/org/apache/doxia/velocity/renderer/doxia-velocity-renderer.properties Wed Dec 27 12:24:58 2006
@@ -0,0 +1,33 @@
+# 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.
+
+# The sequence here is important.
+# Our libraries should never hit the doxia-loader!
+resource.loader = doxia-library-loader, doxia-loader
+
+# Do not cache any of the loaders
+doxia-library-loader.resource.loader.cache = false
+doxia-library-loader.resource.loader.modificationCheckInterval = 0
+
+doxia-loader.resource.loader.cache = false
+doxia-loader.resource.loader.modificationCheckInterval = 0
+
+# This is the encoding that the resource loader delivers.
+input.encoding = UTF-8
+
+# Don't log any messages from macro generation.
+velocimacro.messages.on = false
\ No newline at end of file

Propchange: velocity/site/doxia-velocity-renderer/src/main/resources/org/apache/doxia/velocity/renderer/doxia-velocity-renderer.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/site/doxia-velocity-renderer/src/main/resources/org/apache/doxia/velocity/renderer/doxia-velocity-renderer.properties
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Added: velocity/site/doxia-velocity-renderer/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/velocity/site/doxia-velocity-renderer/src/site/apt/index.apt?view=auto&rev=490562
==============================================================================
--- velocity/site/doxia-velocity-renderer/src/site/apt/index.apt (added)
+++ velocity/site/doxia-velocity-renderer/src/site/apt/index.apt Wed Dec 27 12:24:58 2006
@@ -0,0 +1,12 @@
+ --------
+Doxia Velocity Renderer Module
+ --------
+
+Doxia Velocity Renderer Module
+
+ The Doxia Velocity Renderer Module is an extension for Apache
+ Maven. It allows you to generate Xdoc and Apt pages used for the Maven
+ site using Apache Velocity.
+
+ The module is available as a combined plugin/extension and must be
+ configured in your POM.