DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:applet

This is an old revision of the document!


Applet Plugin

Compatible with DokuWiki

Devel only

plugin A basic plugin for inserting Java applets in wiki pages.

Last updated on
2006-03-05
Provides
Syntax

The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.

Similar to netlogo

Tagged with !experimental, java

experimental

A basic plugin for inserting Java applets in wiki pages. Currently there is very little error checking so be extremely careful using the plugin. There is also no support for applet parameters i.e <param name=“yada” value=“yada”>. The limitations and assumptions are described in the code in detail. Feel free to improve and have fun.

-Stelios

Acknowledgments

The draw plugin author(s) for a clean example of how to hack up a simple wiki plugin.

Usage

<applet code=APPLET_CLASS archive=ARCHIVE_IN_NAMESPACE width=WIDTH_IN_PIXELS height=HEIGHT_IN_PIXELS>

Where

  • APPLET_CLASS: Is the class name of the applet. \

Version 2.0

Works on servers with higher security settings. (Uses the fetch.php mechanism). Make sure that you add a jar mime type for better results or make your jars into zips.

syntax.php

<?php
/**
 *  Applet Plugin  
 *
 *  @license    GPL 2 ( http://www.gnu.org/licenses/gpl.html )
 *  @author     Stylianos [at] Dritsas [dot] net    
 *
 *  Description:
 *  A very basic Java applet handling plugin.
 *
 *  Acknowledgments:
 *  The draw applet author(s) for a very readable plugin   
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 *  Applet Plugin 
 */
class syntax_plugin_applet extends DokuWiki_Syntax_Plugin {
 
  /**
   *  Plugin Info 
   */
  function getInfo( ) {
    return array(
      'author' => 'Stylianos Dritsas',
      'email'  => 'stylianos [at] dritsas [dot] net',
      'date'   => '2006-03-05',
      'name'   => 'applet',
      'desc'   => 'Java Applet Plugin',
      'url'    => 'http://www.dokuwiki.org/plugin:applet',
    );
  }
 
  /**
   *  Typology?
   */  
  function getType( ) { 
		return 'substition'; 
	}
 
  /**
   *  Sort Code? 
   */  
  function getSort( ) {
    return 316;
  }
 
  /**
   *  Pattern Matching? 
   */  
  function connectTo($mode) {       
    $this->Lexer->addSpecialPattern( '<applet.*?>', $mode, 'plugin_applet' ); 
  }
 
  /**
   *  Parsing
   *  1. Very rough parsing involved
   *  2. Applet parameters not included
   */    
  function handle( $match, $state, $pos, &$handler ) {
    preg_match( '/width=([0-9]+)/i',            substr( $match, 6, -1 ), $match_width   );
    preg_match( '/height=([0-9]+)/i',           substr( $match, 6, -1 ), $match_height  );
    preg_match( '/code=([a-zA-Z_0-9].+)/i',      substr( $match, 6, -1 ), $match_code    );
    preg_match( '/archive=([a-zA-Z_0-9:.]+)/i', substr( $match, 6, -1 ), $match_archive );
    return array( 
      $match_code[1], 
      $match_width[1], 
      $match_height[1], 
      $match_archive[1] 
    );
  }
 
  /**
   *  Rendering
   *  1. There is no error checking involved whatsoever
   *  2. Assuming that all applets come in a jar or zip archive
   *  3. The namespace to path conversion is highly ad-hoc-ish
   */  
  function render( $mode, &$renderer, $data ) {
    if($mode == 'xhtml'){
      list( $code, $width, $height, $archive ) = $data;
      //$archive = 'data/media/' . str_replace( ":", "/", $archive );
      $archive = DOKU_BASE . 'lib/exe/fetch.php?media=' . $archive;
      $renderer->doc .= "<applet code=\"$code\" " . 
                               "width=\"$width\" " .
                              "height=\"$height\" " .
                             "archive=\"$archive\"></applet>";   
      return true;
    } else {
      return false;
    }
  }   
}

Version 1.0

Works on servers with low security settings.

syntax.php

<?php
/**
 *  Applet Plugin  
 *
 *  @license    GPL 2 ( http://www.gnu.org/licenses/gpl.html )
 *  @author     Stylianos [at] Dritsas [dot] net    
 * 
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 *  Applet Plugin 
 */
class syntax_plugin_applet extends DokuWiki_Syntax_Plugin {
 
  /**
   *  Plugin Info 
   */
  function getInfo( ) {
    return array(
      'author' => 'Stylianos Dritsas',
      'email'  => 'stylianos [at] dritsas [dot] net',
      'date'   => '2006-03-05',
      'name'   => 'applet',
      'desc'   => 'Java Applet Plugin',
      'url'    => 'http://www.dokuwiki.org/plugin:applet',
    );
  }
 
  /**
   *  Typology?
   */  
  function getType( ) { 
		return 'substition'; 
	}
 
  /**
   *  Sort Code? 
   */  
  function getSort( ) {
    return 316;
  }
 
  /**
   *  Pattern Matching? 
   */  
  function connectTo($mode) {       
    $this->Lexer->addSpecialPattern( '<applet.*?>', $mode, 'plugin_applet' ); 
  }
 
  /**
   *  Parsing
   *  1. Very rough parsing involved
   *  2. Applet parameters not included
   */    
  function handle( $match, $state, $pos, &$handler ) {
    preg_match( '/width=([0-9]+)/i',            substr( $match, 6, -1 ), $match_width   );
    preg_match( '/height=([0-9]+)/i',           substr( $match, 6, -1 ), $match_height  );
    preg_match( '/code=([a-zA-Z_0-9].+)/i',      substr( $match, 6, -1 ), $match_code    );
    preg_match( '/archive=([a-zA-Z_0-9:.]+)/i', substr( $match, 6, -1 ), $match_archive );
    return array( 
      $match_code[1], 
      $match_width[1], 
      $match_height[1], 
      $match_archive[1] 
    );
  }
 
  /**
   *  Rendering
   *  1. There is no error checking involved whatsoever
   *  2. Assuming that all applets come in a jar or zip archive
   *  3. The namespace to path conversion is highly ad-hoc-ish
   */  
  function render( $mode, &$renderer, $data ) {
    if($mode == 'xhtml'){
      list( $code, $width, $height, $archive ) = $data;
      $archive = 'data/media/' . str_replace( ":", "/", $archive );
      $renderer->doc .= "<applet code=\"$code\" " . 
                               "width=\"$width\" " .
                              "height=\"$height\" " .
                             "archive=\"$archive\"></applet>";   
      return true;
    } else {
      return false;
    }
  }   
}
plugin/applet.1351371587.txt.gz · Last modified: 2012-10-27 22:59 by 46.184.150.63

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki