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 org.apache.maven.doxia.sink.Sink;
23  import org.codehaus.plexus.component.annotations.Component;
24  import org.codehaus.plexus.util.StringUtils;
25  
26  /**
27   * Macro for embedding Flash (SWF) within Maven documentation.
28   *
29   * @author <a href="mailto:steve.motola@gmail.com">Steve Motola</a>
30   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
31   */
32  @Component( role = Macro.class, hint = "swf" )
33  public class SwfMacro
34      extends AbstractMacro
35  {
36      /** {@inheritDoc} */
37      public void execute( Sink sink, MacroRequest request )
38          throws MacroExecutionException
39      {
40          // parameter defaults
41          String src = "";
42          String id = "swf";
43          String width = "400";
44          String height = "400";
45          String quality = "high";
46          String menu = "false";
47          String loop = "0";
48          String play = "true";
49          String version = "9,0,45,0";
50          String allowScript = "sameDomain";
51  
52          // assign parameters
53          for ( String key : request.getParameters().keySet() )
54          {
55              Object parameterObject = request.getParameter( key );
56              if ( !( parameterObject instanceof String ) )
57              {
58                  continue;
59              }
60              String str = (String) parameterObject;
61              switch ( key )
62              {
63                  case "src":
64                      if ( StringUtils.isNotEmpty( str ) )
65                      {
66                          src = str;
67                      }
68                      break;
69                  case "id":
70                      if ( StringUtils.isNotEmpty( str ) )
71                      {
72                          id = str;
73                      }
74                      break;
75                  case "width":
76                      if ( StringUtils.isNotEmpty( str ) )
77                      {
78                          width = str;
79                      }
80                      break;
81                  case "height":
82                      if ( StringUtils.isNotEmpty( str ) )
83                      {
84                          height = str;
85                      }
86                      break;
87                  case "quality":
88                      if ( StringUtils.isNotEmpty( str ) )
89                      {
90                          quality = str;
91                      }
92                      break;
93                  case "menu":
94                      if ( StringUtils.isNotEmpty( str ) )
95                      {
96                          menu = str;
97                      }
98                      break;
99                  case "loop":
100                     if ( StringUtils.isNotEmpty( str ) )
101                     {
102                         loop = str;
103                     }
104                     break;
105                 case "play":
106                     if ( StringUtils.isNotEmpty( str ) )
107                     {
108                         play = str;
109                     }
110                     break;
111                 case "version":
112                     // enable version shorthand
113                     // TODO: put in other shorthand versions
114                     if ( str.equals( "6" ) )
115                     {
116                         version = "6,0,29,0";
117                     }
118                     else
119                     {
120                         if ( str.equals( "9" ) )
121                         {
122                             version = "9,0,45,0";
123                         }
124                         else
125                         {
126                             if ( StringUtils.isNotEmpty( str ) )
127                             {
128                                 version = str;
129                             }
130                         }
131                     }
132                     break;
133                 case "allowScript":
134                     if ( StringUtils.isNotEmpty( str ) )
135                     {
136                         allowScript = str;
137                     }
138                     break;
139                  default:
140                         // ignore all other
141             }
142         }
143 
144         StringBuilder content = new StringBuilder();
145         content.append( "<center>" ).append( EOL );
146         content.append( "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" " )
147             .append( "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" )
148             .append( version ).append( "\" width=\"" ).append( width ).append( "\" height=\"" ).append( height )
149             .append( "\" id=\"" ).append( id ).append( "\">" ).append( EOL );
150         content.append( "<param name=\"movie\" value=\"" ).append( src ).append( "\" />" ).append( EOL );
151         content.append( "<param name=\"quality\" value=\"" ).append( quality ).append( "\" />" ).append( EOL );
152         content.append( "<param name=\"menu\" value=\"" ).append( menu ).append( "\" />" ).append( EOL );
153         content.append( "<param name=\"loop\" value=\"" ).append( loop ).append( "\" />" ).append( EOL );
154         content.append( "<param name=\"play\" value=\"" ).append( play ).append( "\" />" ).append( EOL );
155         content.append( "<param name=\"allowScriptAccess\" value=\"" )
156             .append( allowScript ).append( "\" />" ).append( EOL );
157         content.append( "<embed src=\"" ).append( src ).append( "\" width=\"" ).append( width ).append( "\" height=\"" )
158             .append( height ).append( "\" loop=\"" ).append( loop ).append( "\" play=\"" ).append( play )
159             .append( "\" quality=\"" ).append( quality ).append( "\" allowScriptAccess=\"" ).append( allowScript )
160             .append( "\" " ).append( "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" " )
161             .append( "type=\"application/x-shockwave-flash\" menu=\"" ).append( menu ).append( "\">" ).append( EOL );
162         content.append( "</embed>" ).append( EOL );
163         content.append( "</object>" ).append( EOL );
164         content.append( "</center>" ).append( EOL );
165 
166         sink.rawText( content.toString() );
167     }
168 }