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