Coverage Report - org.apache.maven.doxia.macro.SwfMacro
 
Classes in this File Line Coverage Branch Coverage Complexity
SwfMacro
93%
59/63
67%
31/46
24
 
 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 1151002 2011-07-26 07:17:54Z ltheussl $
 34  
  */
 35  4
 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  4
         String src = "";
 44  4
         String id = "swf";
 45  4
         String width = "400";
 46  4
         String height = "400";
 47  4
         String quality = "high";
 48  4
         String menu = "false";
 49  4
         String loop = "0";
 50  4
         String play = "true";
 51  4
         String version = "9,0,45,0";
 52  4
         String allowScript = "sameDomain";
 53  
 
 54  
         // assign parameters
 55  4
         for ( String key : request.getParameters().keySet() )
 56  
         {
 57  20
             String str = (String) request.getParameter( key );
 58  20
             if ( key.equals( "src" ) )
 59  
             {
 60  2
                 if ( StringUtils.isNotEmpty( str ) )
 61  
                 {
 62  2
                     src = str;
 63  
                 }
 64  
             }
 65  18
             else if ( key.equals( "id" ) )
 66  
             {
 67  2
                 if ( StringUtils.isNotEmpty( str ) )
 68  
                 {
 69  2
                     id = str;
 70  
                 }
 71  
             }
 72  16
             else if ( key.equals( "width" ) )
 73  
             {
 74  2
                 if ( StringUtils.isNotEmpty( str ) )
 75  
                 {
 76  2
                     width = str;
 77  
                 }
 78  
             }
 79  14
             else if ( key.equals( "height" ) )
 80  
             {
 81  2
                 if ( StringUtils.isNotEmpty( str ) )
 82  
                 {
 83  2
                     height = str;
 84  
                 }
 85  
             }
 86  12
             else if ( key.equals( "quality" ) )
 87  
             {
 88  2
                 if ( StringUtils.isNotEmpty( str ) )
 89  
                 {
 90  2
                     quality = str;
 91  
                 }
 92  
             }
 93  10
             else if ( key.equals( "menu" ) )
 94  
             {
 95  2
                 if ( StringUtils.isNotEmpty( str ) )
 96  
                 {
 97  2
                     menu = str;
 98  
                 }
 99  
             }
 100  8
             else if ( key.equals( "loop" ) )
 101  
             {
 102  2
                 if ( StringUtils.isNotEmpty( str ) )
 103  
                 {
 104  2
                     loop = str;
 105  
                 }
 106  
             }
 107  6
             else if ( key.equals( "play" ) )
 108  
             {
 109  2
                 if ( StringUtils.isNotEmpty( str ) )
 110  
                 {
 111  2
                     play = str;
 112  
                 }
 113  
             }
 114  4
             else if ( key.equals( "version" ) )
 115  
             {
 116  
                 // enable version shorthand
 117  
                 // TODO: put in other shorthand versions
 118  2
                 if ( str.equals( "6" ) )
 119  
                 {
 120  2
                     version = "6,0,29,0";
 121  
                 }
 122  
                 else
 123  
                 {
 124  0
                     if ( str.equals( "9" ) )
 125  
                     {
 126  0
                         version = "9,0,45,0";
 127  
                     }
 128  
                     else
 129  
                     {
 130  0
                         if ( StringUtils.isNotEmpty( str ) )
 131  
                         {
 132  0
                             version = str;
 133  
                         }
 134  
                     }
 135  
                 }
 136  
             }
 137  2
             else if ( key.equals( "allowScript" ) )
 138  
             {
 139  2
                 if ( StringUtils.isNotEmpty( str ) )
 140  
                 {
 141  2
                     allowScript = str;
 142  
                 }
 143  
             }
 144  20
         }
 145  
 
 146  4
         StringBuffer content = new StringBuffer();
 147  4
         content.append( "<center>" ).append( EOL );
 148  4
         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  4
         content.append( "<param name=\"movie\" value=\"" ).append( src ).append( "\" />" ).append( EOL );
 153  4
         content.append( "<param name=\"quality\" value=\"" ).append( quality ).append( "\" />" ).append( EOL );
 154  4
         content.append( "<param name=\"menu\" value=\"" ).append( menu ).append( "\" />" ).append( EOL );
 155  4
         content.append( "<param name=\"loop\" value=\"" ).append( loop ).append( "\" />" ).append( EOL );
 156  4
         content.append( "<param name=\"play\" value=\"" ).append( play ).append( "\" />" ).append( EOL );
 157  4
         content.append( "<param name=\"allowScriptAccess\" value=\"" )
 158  
             .append( allowScript ).append( "\" />" ).append( EOL );
 159  4
         content.append( "<embed src=\"" ).append( src ).append( "\" width=\"" ).append( width ).append( "\" height=\"" )
 160  
             .append( height ).append( "\" loop=\"" ).append( loop ).append( "\" play=\"" ).append( play )
 161  
             .append( "\" quality=\"" ).append( quality ).append( "\" allowScriptAccess=\"" ).append( allowScript )
 162  
             .append( "\" " ).append( "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" " )
 163  
             .append( "type=\"application/x-shockwave-flash\" menu=\"" ).append( menu ).append( "\">" ).append( EOL );
 164  4
         content.append( "</embed>" ).append( EOL );
 165  4
         content.append( "</object>" ).append( EOL );
 166  4
         content.append( "</center>" ).append( EOL );
 167  
 
 168  4
         sink.rawText( content.toString() );
 169  4
     }
 170  
 }