You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2016/02/02 20:52:10 UTC
svn commit: r1728197 - in /maven/doxia/doxia/trunk/doxia-core/src:
main/java/org/apache/maven/doxia/macro/MacroRequest.java
main/java/org/apache/maven/doxia/macro/SsiMacro.java
test/java/org/apache/maven/doxia/macro/SsiMacroTest.java
Author: hboutemy
Date: Tue Feb 2 19:52:10 2016
New Revision: 1728197
URL: http://svn.apache.org/viewvc?rev=1728197&view=rev
Log:
[DOXIA-532] added ssi macro
Added:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/SsiMacro.java (with props)
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/SsiMacroTest.java (with props)
Modified:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroRequest.java
Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroRequest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroRequest.java?rev=1728197&r1=1728196&r2=1728197&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroRequest.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/MacroRequest.java Tue Feb 2 19:52:10 2016
@@ -117,4 +117,9 @@ public class MacroRequest
{
return (Parser) getParameter( PARAM_PARSER );
}
+
+ public static boolean isInternalParameter( String name )
+ {
+ return PARAM_PARSER.equals( name ) || PARAM_SOURCE_CONTENT.equals( name );
+ }
}
Added: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/SsiMacro.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/SsiMacro.java?rev=1728197&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/SsiMacro.java (added)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/SsiMacro.java Tue Feb 2 19:52:10 2016
@@ -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() );
+ }
+}
Propchange: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/SsiMacro.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/SsiMacroTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/SsiMacroTest.java?rev=1728197&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/SsiMacroTest.java (added)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/SsiMacroTest.java Tue Feb 2 19:52:10 2016
@@ -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() );
+ }
+}
Propchange: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/SsiMacroTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain