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   *
31   * @since 1.7
32   */
33  @Component( role = Macro.class, hint = "ssi" )
34  public class SsiMacro
35      extends AbstractMacro
36  {
37      private static final String PARAM_FUNCTION = "function";
38  
39      private boolean isInternalParameter( String name )
40      {
41          return PARAM_FUNCTION.equals( name ) || MacroRequest.isInternalParameter( name );
42      }
43      /** {@inheritDoc} */
44      public void execute( Sink sink, MacroRequest request )
45          throws MacroExecutionException
46      {
47          String function = (String) request.getParameter( PARAM_FUNCTION );
48  
49          required( PARAM_FUNCTION, function );
50  
51          StringBuilder buff = new StringBuilder();
52          buff.append( '#' );
53          buff.append( function );
54  
55          for ( Map.Entry<String, Object> entry : request.getParameters().entrySet() )
56          {
57              if ( !isInternalParameter( entry.getKey() ) )
58              {
59                  buff.append( ' ' );
60                  buff.append( entry.getKey() );
61                  buff.append( "=\"" );
62                  buff.append( entry.getValue() );
63                  buff.append( '"' );
64              }
65          }
66  
67          buff.append( ' ' );
68          sink.comment( buff.toString() );
69      }
70  }