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