View Javadoc
1   package org.apache.maven.doxia.macro;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Map;
23  import org.apache.maven.doxia.sink.Sink;
24  import org.codehaus.plexus.component.annotations.Component;
25  
26  /**
27   * Server-Side Include directive, to insert a SSI into the output.
28   * Required parameter is <code>function</code> to define SSI function, then
29   * additional parameters are completely free.
30   * @since 1.7
31   */
32  @Component( role = Macro.class, hint = "ssi" )
33  public class SsiMacro
34      extends AbstractMacro
35  {
36      private static final String PARAM_FUNCTION = "function";
37  
38      private boolean isInternalParameter( String name )
39      {
40          return PARAM_FUNCTION.equals( name ) || MacroRequest.isInternalParameter( name );
41      }
42      /** {@inheritDoc} */
43      public void execute( Sink sink, MacroRequest request )
44          throws MacroExecutionException
45      {
46          String function = (String) request.getParameter( PARAM_FUNCTION );
47  
48          required( PARAM_FUNCTION, function );
49  
50          StringBuilder buff = new StringBuilder();
51          buff.append( '#' );
52          buff.append( function );
53  
54          for ( Map.Entry<String, Object> entry : request.getParameters().entrySet() )
55          {
56              if ( !isInternalParameter( entry.getKey() ) )
57              {
58                  buff.append( ' ' );
59                  buff.append( entry.getKey() );
60                  buff.append( "=\"" );
61                  buff.append( entry.getValue() );
62                  buff.append( '"' );
63              }
64          }
65  
66          buff.append( ' ' );
67          sink.comment( buff.toString() );
68      }
69  }