[DOXIA-532] added ssi macro

git-svn-id: https://svn.apache.org/repos/asf/maven/doxia/doxia/trunk@1728197 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroRequest.java b/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroRequest.java
index 9ff1a8f..3ab7242 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroRequest.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroRequest.java
@@ -117,4 +117,9 @@
     {
         return (Parser) getParameter( PARAM_PARSER );
     }
+
+    public static boolean isInternalParameter( String name )
+    {
+        return PARAM_PARSER.equals( name ) || PARAM_SOURCE_CONTENT.equals( name );
+    }
 }
diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/macro/SsiMacro.java b/doxia-core/src/main/java/org/apache/maven/doxia/macro/SsiMacro.java
new file mode 100644
index 0000000..d06bd06
--- /dev/null
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/macro/SsiMacro.java
@@ -0,0 +1,69 @@
+package org.apache.maven.doxia.macro;
+
+/*
+ * 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.util.Map;
+import org.apache.maven.doxia.sink.Sink;
+import org.codehaus.plexus.component.annotations.Component;
+
+/**
+ * Server-Side Include directive, to insert a SSI into the output.
+ * Required parameter is <code>function</code> to define SSI function, then
+ * additional parameters are completely free.
+ * @since 1.7
+ */
+@Component( role = Macro.class, hint = "ssi" )
+public class SsiMacro
+    extends AbstractMacro
+{
+    private static final String PARAM_FUNCTION = "function";
+
+    private boolean isInternalParameter( String name )
+    {
+        return PARAM_FUNCTION.equals( name ) || MacroRequest.isInternalParameter( name );
+    }
+    /** {@inheritDoc} */
+    public void execute( Sink sink, MacroRequest request )
+        throws MacroExecutionException
+    {
+        String function = (String) request.getParameter( PARAM_FUNCTION );
+
+        required( PARAM_FUNCTION, function );
+
+        StringBuilder buff = new StringBuilder();
+        buff.append( '#' );
+        buff.append( function );
+
+        for ( Map.Entry<String, Object> entry : request.getParameters().entrySet() )
+        {
+            if ( !isInternalParameter( entry.getKey() ) )
+            {
+                buff.append( ' ' );
+                buff.append( entry.getKey() );
+                buff.append( "=\"" );
+                buff.append( entry.getValue() );
+                buff.append( '"' );
+            }
+        }
+
+        buff.append( ' ' );
+        sink.comment( buff.toString() );
+    }
+}
diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/macro/SsiMacroTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/macro/SsiMacroTest.java
new file mode 100644
index 0000000..e30bf92
--- /dev/null
+++ b/doxia-core/src/test/java/org/apache/maven/doxia/macro/SsiMacroTest.java
@@ -0,0 +1,65 @@
+package org.apache.maven.doxia.macro;
+
+/*
+ * 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;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.maven.doxia.parser.XhtmlBaseParser;
+import org.apache.maven.doxia.sink.impl.SinkEventElement;
+import org.apache.maven.doxia.sink.impl.SinkEventTestingSink;
+
+import junit.framework.TestCase;
+
+public class SsiMacroTest
+    extends TestCase
+{
+
+    /**
+     * Test of execute method, of class SwfMacro.
+     *
+     * @throws MacroExecutionException if a macro fails during testing.
+     */
+    public void testExecute()
+        throws MacroExecutionException
+    {
+
+        Map<String, Object> macroParameters = new HashMap<String, Object>();
+        macroParameters.put( "function", "include" );
+        macroParameters.put( "file", "include-file.html" );
+
+        MacroRequest request = new MacroRequest( "source", new XhtmlBaseParser(), macroParameters, new File( "." ) );
+        SsiMacro macro = new SsiMacro();
+
+        SinkEventTestingSink sink = new SinkEventTestingSink();
+        macro.execute( sink, request );
+
+        Iterator<SinkEventElement> it = sink.getEventList().iterator();
+        SinkEventElement event = it.next();
+
+        assertEquals( "comment", event.getName() );
+        String comment = (String) event.getArgs()[0];
+        assertEquals( "#include file=\"include-file.html\" ", comment );
+        assertFalse( it.hasNext() );
+    }
+}