001package org.apache.maven.doxia.macro; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.doxia.sink.Sink; 023import org.codehaus.plexus.component.annotations.Component; 024import org.codehaus.plexus.util.StringUtils; 025 026/** 027 * Macro for embedding Flash (SWF) within Maven documentation. 028 * 029 * @author <a href="mailto:steve.motola@gmail.com">Steve Motola</a> 030 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a> 031 * @version $Id$ 032 */ 033@Component( role = Macro.class, hint = "swf" ) 034public class SwfMacro 035 extends AbstractMacro 036{ 037 /** {@inheritDoc} */ 038 public void execute( Sink sink, MacroRequest request ) 039 throws MacroExecutionException 040 { 041 // parameter defaults 042 String src = ""; 043 String id = "swf"; 044 String width = "400"; 045 String height = "400"; 046 String quality = "high"; 047 String menu = "false"; 048 String loop = "0"; 049 String play = "true"; 050 String version = "9,0,45,0"; 051 String allowScript = "sameDomain"; 052 053 // assign parameters 054 for ( String key : request.getParameters().keySet() ) 055 { 056 Object parameterObject = request.getParameter( key ); 057 if ( !( parameterObject instanceof String ) ) 058 { 059 continue; 060 } 061 String str = (String) parameterObject; 062 if ( key.equals( "src" ) ) 063 { 064 if ( StringUtils.isNotEmpty( str ) ) 065 { 066 src = str; 067 } 068 } 069 else if ( key.equals( "id" ) ) 070 { 071 if ( StringUtils.isNotEmpty( str ) ) 072 { 073 id = str; 074 } 075 } 076 else if ( key.equals( "width" ) ) 077 { 078 if ( StringUtils.isNotEmpty( str ) ) 079 { 080 width = str; 081 } 082 } 083 else if ( key.equals( "height" ) ) 084 { 085 if ( StringUtils.isNotEmpty( str ) ) 086 { 087 height = str; 088 } 089 } 090 else if ( key.equals( "quality" ) ) 091 { 092 if ( StringUtils.isNotEmpty( str ) ) 093 { 094 quality = str; 095 } 096 } 097 else if ( key.equals( "menu" ) ) 098 { 099 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}