mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-19 09:37:50 -05:00
Brought up to date with the private repository (feea4c7)
This commit is contained in:
1 parent
1aa738d692
commit
1b1df1ae48
7925 files changed
+2617237
-20
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package org.osmf.captioning
|
||||
{
|
||||
import org.osmf.captioning.media.CaptioningProxyElement;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.media.MediaFactoryItem;
|
||||
import org.osmf.media.PluginInfo;
|
||||
import org.osmf.net.NetLoader;
|
||||
|
||||
public class CaptioningPluginInfo extends PluginInfo
|
||||
{
|
||||
|
||||
public static const CAPTIONING_METADATA_NAMESPACE:String = "http://www.osmf.org/captioning/1.0";
|
||||
|
||||
public static const CAPTIONING_METADATA_KEY_URI:String = "uri";
|
||||
|
||||
public static const CAPTIONING_TEMPORAL_METADATA_NAMESPACE:String = "http://www.osmf.org/temporal/captioning";
|
||||
|
||||
public function CaptioningPluginInfo()
|
||||
{
|
||||
var _loc3_:Vector.<MediaFactoryItem> = new Vector.<MediaFactoryItem>();
|
||||
var _loc2_:NetLoader = new NetLoader();
|
||||
var _loc1_:MediaFactoryItem = new MediaFactoryItem("org.osmf.captioning.CaptioningPluginInfo",_loc2_.canHandleResource,createCaptioningProxyElement,"proxy");
|
||||
_loc3_.push(_loc1_);
|
||||
super(_loc3_);
|
||||
}
|
||||
|
||||
private function createCaptioningProxyElement() : MediaElement
|
||||
{
|
||||
return new CaptioningProxyElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.osmf.captioning.loader
|
||||
{
|
||||
import org.osmf.captioning.model.CaptioningDocument;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
|
||||
public class CaptioningLoadTrait extends LoadTrait
|
||||
{
|
||||
|
||||
private var _document:CaptioningDocument;
|
||||
|
||||
public function CaptioningLoadTrait(param1:LoaderBase, param2:MediaResourceBase)
|
||||
{
|
||||
super(param1,param2);
|
||||
}
|
||||
|
||||
public function get document() : CaptioningDocument
|
||||
{
|
||||
return _document;
|
||||
}
|
||||
|
||||
public function set document(param1:CaptioningDocument) : void
|
||||
{
|
||||
_document = param1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package org.osmf.captioning.loader
|
||||
{
|
||||
import org.osmf.captioning.model.CaptioningDocument;
|
||||
import org.osmf.captioning.parsers.DFXPParser;
|
||||
import org.osmf.captioning.parsers.ICaptioningParser;
|
||||
import org.osmf.events.LoaderEvent;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.LoaderBase;
|
||||
import org.osmf.utils.HTTPLoadTrait;
|
||||
import org.osmf.utils.HTTPLoader;
|
||||
|
||||
public class CaptioningLoader extends LoaderBase
|
||||
{
|
||||
|
||||
private var httpLoader:HTTPLoader;
|
||||
|
||||
public function CaptioningLoader(param1:HTTPLoader = null)
|
||||
{
|
||||
super();
|
||||
this.httpLoader = param1 != null ? param1 : new HTTPLoader();
|
||||
}
|
||||
|
||||
override public function canHandleResource(param1:MediaResourceBase) : Boolean
|
||||
{
|
||||
return httpLoader.canHandleResource(param1);
|
||||
}
|
||||
|
||||
override protected function executeLoad(param1:LoadTrait) : void
|
||||
{
|
||||
var httpLoadTrait:HTTPLoadTrait;
|
||||
var loadTrait:LoadTrait = param1;
|
||||
var onHTTPLoaderStateChange:* = function(param1:LoaderEvent):void
|
||||
{
|
||||
var _loc2_:ICaptioningParser = null;
|
||||
var _loc3_:CaptioningDocument = null;
|
||||
if(param1.newState == "ready")
|
||||
{
|
||||
httpLoader.removeEventListener("loadStateChange",onHTTPLoaderStateChange);
|
||||
httpLoadTrait.removeEventListener("mediaError",onLoadError);
|
||||
_loc2_ = createCaptioningParser();
|
||||
try
|
||||
{
|
||||
_loc3_ = _loc2_.parse(httpLoadTrait.urlLoader.data.toString());
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
updateLoadTrait(loadTrait,"loadError");
|
||||
}
|
||||
CaptioningLoadTrait(loadTrait).document = _loc3_;
|
||||
updateLoadTrait(loadTrait,"ready");
|
||||
}
|
||||
else if(param1.newState == "loadError")
|
||||
{
|
||||
httpLoader.removeEventListener("loadStateChange",onHTTPLoaderStateChange);
|
||||
updateLoadTrait(loadTrait,param1.newState);
|
||||
}
|
||||
};
|
||||
var onLoadError:* = function(param1:MediaErrorEvent):void
|
||||
{
|
||||
httpLoadTrait.removeEventListener("mediaError",onLoadError);
|
||||
loadTrait.dispatchEvent(param1.clone());
|
||||
};
|
||||
updateLoadTrait(loadTrait,"loading");
|
||||
httpLoader.addEventListener("loadStateChange",onHTTPLoaderStateChange);
|
||||
httpLoadTrait = new HTTPLoadTrait(httpLoader,loadTrait.resource);
|
||||
httpLoadTrait.addEventListener("mediaError",onLoadError);
|
||||
httpLoader.load(httpLoadTrait);
|
||||
}
|
||||
|
||||
override protected function executeUnload(param1:LoadTrait) : void
|
||||
{
|
||||
updateLoadTrait(param1,"unloading");
|
||||
updateLoadTrait(param1,"uninitialized");
|
||||
}
|
||||
|
||||
protected function createCaptioningParser() : ICaptioningParser
|
||||
{
|
||||
return new DFXPParser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package org.osmf.captioning.media
|
||||
{
|
||||
import org.osmf.captioning.loader.CaptioningLoadTrait;
|
||||
import org.osmf.captioning.loader.CaptioningLoader;
|
||||
import org.osmf.captioning.model.Caption;
|
||||
import org.osmf.captioning.model.CaptioningDocument;
|
||||
import org.osmf.elements.ProxyElement;
|
||||
import org.osmf.events.LoadEvent;
|
||||
import org.osmf.events.MediaError;
|
||||
import org.osmf.events.MediaErrorEvent;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.media.MediaResourceBase;
|
||||
import org.osmf.media.URLResource;
|
||||
import org.osmf.metadata.Metadata;
|
||||
import org.osmf.metadata.TimelineMetadata;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
|
||||
public class CaptioningProxyElement extends ProxyElement
|
||||
{
|
||||
|
||||
public static const MEDIA_ERROR_INVALID_PROXIED_ELEMENT:int = 2201;
|
||||
|
||||
private static const ERROR_MISSING_CAPTION_METADATA:String = "Media Element is missing Captioning metadata";
|
||||
|
||||
private static const ERROR_MISSING_RESOURCE:String = "Media Element is missing a valid resource";
|
||||
|
||||
private var loadTrait:CaptioningLoadTrait;
|
||||
|
||||
private var _continueLoadOnFailure:Boolean;
|
||||
|
||||
public function CaptioningProxyElement(param1:MediaElement = null, param2:Boolean = true)
|
||||
{
|
||||
super(param1);
|
||||
_continueLoadOnFailure = param2;
|
||||
}
|
||||
|
||||
public function get continueLoadOnFailure() : Boolean
|
||||
{
|
||||
return _continueLoadOnFailure;
|
||||
}
|
||||
|
||||
override public function set proxiedElement(param1:MediaElement) : void
|
||||
{
|
||||
var _loc3_:MediaElement = null;
|
||||
var _loc4_:MediaResourceBase = null;
|
||||
var _loc2_:Metadata = null;
|
||||
var _loc5_:String = null;
|
||||
super.proxiedElement = param1;
|
||||
if(param1 != null)
|
||||
{
|
||||
_loc3_ = super.proxiedElement;
|
||||
_loc4_ = _loc3_ && _loc3_.resource != null ? _loc3_.resource : resource;
|
||||
if(_loc4_ == null)
|
||||
{
|
||||
dispatchEvent(new MediaErrorEvent("mediaError",false,false,new MediaError(2201)));
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc2_ = _loc4_.getMetadataValue("http://www.osmf.org/captioning/1.0") as Metadata;
|
||||
if(_loc2_ == null)
|
||||
{
|
||||
if(!_continueLoadOnFailure)
|
||||
{
|
||||
dispatchEvent(new MediaErrorEvent("mediaError",false,false,new MediaError(2201)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc5_ = _loc2_.getValue("uri");
|
||||
if(_loc5_ != null)
|
||||
{
|
||||
loadTrait = new CaptioningLoadTrait(new CaptioningLoader(),new URLResource(_loc5_));
|
||||
loadTrait.addEventListener("loadStateChange",onLoadStateChange,false,99);
|
||||
addTrait("load",loadTrait);
|
||||
}
|
||||
else if(!_continueLoadOnFailure)
|
||||
{
|
||||
dispatchEvent(new MediaErrorEvent("mediaError",false,false,new MediaError(2201)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onLoadStateChange(param1:LoadEvent) : void
|
||||
{
|
||||
var _loc3_:CaptioningDocument = null;
|
||||
var _loc2_:MediaElement = null;
|
||||
var _loc6_:TimelineMetadata = null;
|
||||
var _loc4_:int = 0;
|
||||
var _loc5_:Caption = null;
|
||||
if(param1.loadState == "ready")
|
||||
{
|
||||
_loc3_ = loadTrait.document;
|
||||
if(_loc3_)
|
||||
{
|
||||
_loc2_ = super.proxiedElement;
|
||||
_loc6_ = proxiedElement.getMetadata("http://www.osmf.org/temporal/captioning") as TimelineMetadata;
|
||||
if(_loc6_ == null)
|
||||
{
|
||||
_loc6_ = new TimelineMetadata(proxiedElement);
|
||||
proxiedElement.addMetadata("http://www.osmf.org/temporal/captioning",_loc6_);
|
||||
}
|
||||
_loc4_ = 0;
|
||||
while(_loc4_ < _loc3_.numCaptions)
|
||||
{
|
||||
_loc5_ = _loc3_.getCaptionAt(_loc4_);
|
||||
_loc6_.addMarker(_loc5_);
|
||||
_loc4_++;
|
||||
}
|
||||
}
|
||||
cleanUp();
|
||||
}
|
||||
else if(param1.loadState == "loadError")
|
||||
{
|
||||
if(!_continueLoadOnFailure)
|
||||
{
|
||||
dispatchEvent(param1.clone());
|
||||
}
|
||||
else
|
||||
{
|
||||
cleanUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function cleanUp() : void
|
||||
{
|
||||
removeTrait("load");
|
||||
var _loc1_:LoadTrait = getTrait("load") as LoadTrait;
|
||||
if(_loc1_ != null && _loc1_.loadState == "uninitialized")
|
||||
{
|
||||
_loc1_.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.osmf.captioning.model
|
||||
{
|
||||
import flash.errors.IllegalOperationError;
|
||||
import org.osmf.metadata.TimelineMarker;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
public class Caption extends TimelineMarker
|
||||
{
|
||||
|
||||
private var _id:uint;
|
||||
|
||||
private var _captionText:String;
|
||||
|
||||
private var _formats:Vector.<CaptionFormat>;
|
||||
|
||||
public function Caption(param1:uint, param2:Number, param3:Number, param4:String)
|
||||
{
|
||||
var _loc5_:Number = param3 > 0 ? param3 - param2 : NaN;
|
||||
super(param2,_loc5_);
|
||||
_id = param1;
|
||||
_captionText = param4;
|
||||
}
|
||||
|
||||
public function addCaptionFormat(param1:CaptionFormat) : void
|
||||
{
|
||||
if(_formats == null)
|
||||
{
|
||||
_formats = new Vector.<CaptionFormat>();
|
||||
}
|
||||
_formats.push(param1);
|
||||
}
|
||||
|
||||
public function get numCaptionFormats() : int
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
if(_formats != null)
|
||||
{
|
||||
_loc1_ = int(_formats.length);
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
public function getCaptionFormatAt(param1:int) : CaptionFormat
|
||||
{
|
||||
if(_formats == null || param1 >= _formats.length || param1 < 0)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString("invalidParam"));
|
||||
}
|
||||
return _formats[param1];
|
||||
}
|
||||
|
||||
public function get text() : String
|
||||
{
|
||||
return _captionText;
|
||||
}
|
||||
|
||||
public function get clearText() : String
|
||||
{
|
||||
var _loc1_:String = "";
|
||||
if(_captionText != null && _captionText.length > 0)
|
||||
{
|
||||
_loc1_ = _captionText.replace(/<(.|\n)*?>/g,"");
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.osmf.captioning.model
|
||||
{
|
||||
public class CaptionFormat
|
||||
{
|
||||
|
||||
public static const UNDEFINED_INDEX:int = -1;
|
||||
|
||||
private static const MISSING_STYLE_ERROR_MSG:String = "CaptionStyle is required for CaptionFormat objects";
|
||||
|
||||
private var _startIndex:int;
|
||||
|
||||
private var _endIndex:int;
|
||||
|
||||
private var _style:CaptionStyle;
|
||||
|
||||
public function CaptionFormat(param1:CaptionStyle, param2:int = -1, param3:int = -1)
|
||||
{
|
||||
super();
|
||||
if(param1 == null)
|
||||
{
|
||||
throw new ArgumentError("CaptionStyle is required for CaptionFormat objects");
|
||||
}
|
||||
_startIndex = param2;
|
||||
_endIndex = param3;
|
||||
_style = param1;
|
||||
}
|
||||
|
||||
public function get startIndex() : int
|
||||
{
|
||||
return _startIndex;
|
||||
}
|
||||
|
||||
public function get endIndex() : int
|
||||
{
|
||||
return _endIndex;
|
||||
}
|
||||
|
||||
public function get style() : CaptionStyle
|
||||
{
|
||||
return _style;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package org.osmf.captioning.model
|
||||
{
|
||||
public class CaptionStyle
|
||||
{
|
||||
|
||||
private var _id:String;
|
||||
|
||||
private var _backgroundColor:Object;
|
||||
|
||||
private var _backgroundColorAlpha:Object;
|
||||
|
||||
private var _textColor:Object;
|
||||
|
||||
private var _textColorAlpha:Object;
|
||||
|
||||
private var _fontFamily:String;
|
||||
|
||||
private var _fontSize:int;
|
||||
|
||||
private var _fontStyle:String;
|
||||
|
||||
private var _fontWeight:String;
|
||||
|
||||
private var _textAlign:String;
|
||||
|
||||
private var _wrapOption:Boolean;
|
||||
|
||||
public function CaptionStyle(param1:String)
|
||||
{
|
||||
super();
|
||||
_id = param1;
|
||||
}
|
||||
|
||||
public function get id() : String
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public function get backgroundColor() : Object
|
||||
{
|
||||
return _backgroundColor;
|
||||
}
|
||||
|
||||
public function set backgroundColor(param1:Object) : void
|
||||
{
|
||||
_backgroundColor = param1;
|
||||
}
|
||||
|
||||
public function get backgroundColorAlpha() : Object
|
||||
{
|
||||
return _backgroundColorAlpha;
|
||||
}
|
||||
|
||||
public function set backgroundColorAlpha(param1:Object) : void
|
||||
{
|
||||
_backgroundColorAlpha = param1;
|
||||
}
|
||||
|
||||
public function get textColor() : Object
|
||||
{
|
||||
return _textColor;
|
||||
}
|
||||
|
||||
public function set textColor(param1:Object) : void
|
||||
{
|
||||
_textColor = param1;
|
||||
}
|
||||
|
||||
public function get textColorAlpha() : Object
|
||||
{
|
||||
return _textColorAlpha;
|
||||
}
|
||||
|
||||
public function set textColorAlpha(param1:Object) : void
|
||||
{
|
||||
_textColorAlpha = param1;
|
||||
}
|
||||
|
||||
public function get fontFamily() : String
|
||||
{
|
||||
return _fontFamily;
|
||||
}
|
||||
|
||||
public function set fontFamily(param1:String) : void
|
||||
{
|
||||
_fontFamily = param1;
|
||||
}
|
||||
|
||||
public function get fontSize() : int
|
||||
{
|
||||
return _fontSize;
|
||||
}
|
||||
|
||||
public function set fontSize(param1:int) : void
|
||||
{
|
||||
_fontSize = param1;
|
||||
}
|
||||
|
||||
public function get fontStyle() : String
|
||||
{
|
||||
return _fontStyle;
|
||||
}
|
||||
|
||||
public function set fontStyle(param1:String) : void
|
||||
{
|
||||
_fontStyle = param1;
|
||||
}
|
||||
|
||||
public function get fontWeight() : String
|
||||
{
|
||||
return _fontWeight;
|
||||
}
|
||||
|
||||
public function set fontWeight(param1:String) : void
|
||||
{
|
||||
_fontWeight = param1;
|
||||
}
|
||||
|
||||
public function get textAlign() : String
|
||||
{
|
||||
return _textAlign;
|
||||
}
|
||||
|
||||
public function set textAlign(param1:String) : void
|
||||
{
|
||||
_textAlign = param1;
|
||||
}
|
||||
|
||||
public function get wrapOption() : Boolean
|
||||
{
|
||||
return _wrapOption;
|
||||
}
|
||||
|
||||
public function set wrapOption(param1:Boolean) : void
|
||||
{
|
||||
_wrapOption = param1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package org.osmf.captioning.model
|
||||
{
|
||||
import flash.errors.IllegalOperationError;
|
||||
import org.osmf.utils.OSMFStrings;
|
||||
|
||||
public class CaptioningDocument
|
||||
{
|
||||
|
||||
private var _title:String;
|
||||
|
||||
private var _desc:String;
|
||||
|
||||
private var _copyright:String;
|
||||
|
||||
private var _captions:Vector.<Caption>;
|
||||
|
||||
private var _styles:Vector.<CaptionStyle>;
|
||||
|
||||
public function CaptioningDocument()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public function get title() : String
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
|
||||
public function set title(param1:String) : void
|
||||
{
|
||||
_title = param1;
|
||||
}
|
||||
|
||||
public function get description() : String
|
||||
{
|
||||
return _desc;
|
||||
}
|
||||
|
||||
public function set description(param1:String) : void
|
||||
{
|
||||
_desc = param1;
|
||||
}
|
||||
|
||||
public function get copyright() : String
|
||||
{
|
||||
return _copyright;
|
||||
}
|
||||
|
||||
public function set copyright(param1:String) : void
|
||||
{
|
||||
_copyright = param1;
|
||||
}
|
||||
|
||||
public function addStyle(param1:CaptionStyle) : void
|
||||
{
|
||||
if(_styles == null)
|
||||
{
|
||||
_styles = new Vector.<CaptionStyle>();
|
||||
}
|
||||
_styles.push(param1);
|
||||
}
|
||||
|
||||
public function get numStyles() : int
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
if(_styles != null)
|
||||
{
|
||||
_loc1_ = int(_styles.length);
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
public function getStyleAt(param1:int) : CaptionStyle
|
||||
{
|
||||
if(_styles == null || param1 >= _styles.length)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString("invalidParam"));
|
||||
}
|
||||
return _styles[param1];
|
||||
}
|
||||
|
||||
public function addCaption(param1:Caption) : void
|
||||
{
|
||||
if(_captions == null)
|
||||
{
|
||||
_captions = new Vector.<Caption>();
|
||||
}
|
||||
_captions.push(param1);
|
||||
}
|
||||
|
||||
public function get numCaptions() : int
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
if(_captions != null)
|
||||
{
|
||||
_loc1_ = int(_captions.length);
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
public function getCaptionAt(param1:int) : Caption
|
||||
{
|
||||
if(_captions == null || param1 >= _captions.length)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString("invalidParam"));
|
||||
}
|
||||
return _captions[param1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,507 @@
|
||||
package org.osmf.captioning.parsers
|
||||
{
|
||||
import flash.utils.Dictionary;
|
||||
import org.osmf.captioning.model.Caption;
|
||||
import org.osmf.captioning.model.CaptionFormat;
|
||||
import org.osmf.captioning.model.CaptionStyle;
|
||||
import org.osmf.captioning.model.CaptioningDocument;
|
||||
import org.osmf.utils.TimeUtil;
|
||||
|
||||
public class DFXPParser implements ICaptioningParser
|
||||
{
|
||||
|
||||
private var ns:Namespace;
|
||||
|
||||
private var ttm:Namespace;
|
||||
|
||||
private var tts:Namespace;
|
||||
|
||||
private var rootNamespace:Namespace;
|
||||
|
||||
private var namedColorMap:Dictionary;
|
||||
|
||||
public function DFXPParser()
|
||||
{
|
||||
super();
|
||||
namedColorMap = new Dictionary();
|
||||
namedColorMap["transparent"] = 0;
|
||||
namedColorMap["black"] = 0;
|
||||
namedColorMap["silver"] = 12632256;
|
||||
namedColorMap["gray"] = 8421504;
|
||||
namedColorMap["white"] = 16777215;
|
||||
namedColorMap["maroon"] = 8388608;
|
||||
namedColorMap["red"] = 16711680;
|
||||
namedColorMap["purple"] = 8388736;
|
||||
namedColorMap["fuchsia"] = 16711935;
|
||||
namedColorMap["magenta"] = 16711935;
|
||||
namedColorMap["green"] = 32768;
|
||||
namedColorMap["lime"] = 65280;
|
||||
namedColorMap["olive"] = 8421376;
|
||||
namedColorMap["yellow"] = 16776960;
|
||||
namedColorMap["navy"] = 128;
|
||||
namedColorMap["blue"] = 255;
|
||||
namedColorMap["teal"] = 32896;
|
||||
namedColorMap["aqua"] = 65535;
|
||||
namedColorMap["cyan"] = 65535;
|
||||
}
|
||||
|
||||
public function parse(param1:String) : CaptioningDocument
|
||||
{
|
||||
var _loc2_:XML = null;
|
||||
var _loc3_:CaptioningDocument = new CaptioningDocument();
|
||||
var _loc4_:Boolean = Boolean(XML.ignoreWhitespace);
|
||||
var _loc6_:Boolean = Boolean(XML.prettyPrinting);
|
||||
var _loc5_:String = param1.replace(/\s+$/,"");
|
||||
_loc5_ = _loc5_.replace(/>\s+</g,"><");
|
||||
XML.ignoreWhitespace = false;
|
||||
XML.prettyPrinting = false;
|
||||
try
|
||||
{
|
||||
_loc2_ = new XML(_loc5_);
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
debugLog("Unhandled exception in DFXPParser : " + e.message);
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
XML.ignoreWhitespace = _loc4_;
|
||||
XML.prettyPrinting = _loc6_;
|
||||
}
|
||||
rootNamespace = _loc2_.namespace();
|
||||
ns = _loc2_.namespace();
|
||||
ttm = _loc2_.namespace("ttm");
|
||||
tts = _loc2_.namespace("tts");
|
||||
try
|
||||
{
|
||||
parseHead(_loc3_,_loc2_);
|
||||
parseBody(_loc3_,_loc2_);
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
debugLog("Unhandled exception in DFXPParser : " + err.message);
|
||||
throw err;
|
||||
}
|
||||
return _loc3_;
|
||||
}
|
||||
|
||||
private function parseHead(param1:CaptioningDocument, param2:XML) : void
|
||||
{
|
||||
var _loc7_:XMLList = null;
|
||||
var _loc6_:* = 0;
|
||||
var _loc5_:XML = null;
|
||||
var _loc3_:CaptionStyle = null;
|
||||
try
|
||||
{
|
||||
param1.title = param2..ttm::title.text();
|
||||
param1.description = param2..ttm::desc.text();
|
||||
param1.copyright = param2..ttm::copyright.text();
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
if(err.errorID != 1080)
|
||||
{
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
var _loc4_:XMLList = param2..ns::styling;
|
||||
if(_loc4_.length())
|
||||
{
|
||||
_loc7_ = _loc4_.children();
|
||||
_loc6_ = 0;
|
||||
while(_loc6_ < _loc7_.length())
|
||||
{
|
||||
_loc5_ = _loc7_[_loc6_];
|
||||
_loc3_ = createStyleObject(_loc5_);
|
||||
param1.addStyle(_loc3_);
|
||||
_loc6_++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createStyleObject(param1:XML) : CaptionStyle
|
||||
{
|
||||
var _loc4_:Object = null;
|
||||
var _loc6_:String = param1.@id;
|
||||
var _loc2_:CaptionStyle = new CaptionStyle(_loc6_);
|
||||
var _loc3_:String = param1.tts::@backgroundColor;
|
||||
if(_loc3_ != "")
|
||||
{
|
||||
_loc4_ = parseColor(_loc3_);
|
||||
_loc2_.backgroundColor = _loc4_.color;
|
||||
_loc2_.backgroundColorAlpha = _loc4_.alpha;
|
||||
}
|
||||
_loc2_.textAlign = param1.tts::@textAlign;
|
||||
_loc3_ = param1.tts::@color;
|
||||
if(_loc3_ != "")
|
||||
{
|
||||
_loc4_ = parseColor(_loc3_);
|
||||
_loc2_.textColor = _loc4_.color;
|
||||
_loc2_.textColorAlpha = _loc4_.alpha;
|
||||
}
|
||||
_loc2_.fontFamily = parseFontFamily(param1.tts::@fontFamily);
|
||||
var _loc5_:String = parseFontSize(param1.tts::@fontSize);
|
||||
_loc2_.fontSize = parseInt(_loc5_);
|
||||
_loc2_.fontStyle = param1.tts::@fontStyle;
|
||||
_loc2_.fontWeight = param1.tts::@fontWeight;
|
||||
_loc2_.wrapOption = String(param1.tts::@wrapOption).toLowerCase() == "nowrap" ? false : true;
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
private function parseColor(param1:String) : Object
|
||||
{
|
||||
var _loc4_:Object = null;
|
||||
var _loc5_:Object = null;
|
||||
var _loc3_:RegExp = /^\s*#([\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f][\dA-Fa-f])([\dA-Fa-f][\dA-Fa-f])?\s*$/;
|
||||
var _loc2_:Array = param1.match(_loc3_);
|
||||
if(_loc2_ != null)
|
||||
{
|
||||
_loc4_ = parseInt(_loc2_[1],16);
|
||||
if(_loc2_.length == 3)
|
||||
{
|
||||
_loc5_ = parseInt(_loc2_[2]) / 255;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc3_ = /^\s*rgb(a)?\((\d+),(\d+),(\d+)(\)|(,(\d+)\)))\s*$/i;
|
||||
_loc2_ = param1.match(_loc3_);
|
||||
if(_loc2_ != null && _loc2_.length >= 5)
|
||||
{
|
||||
_loc4_ = (parseInt(_loc2_[2]) << 16) + (parseInt(_loc2_[3]) << 8) + parseInt(_loc2_[4]);
|
||||
if(_loc2_.length == 8 && _loc2_[7] != undefined)
|
||||
{
|
||||
_loc5_ = parseInt(_loc2_[7]) / 255;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc4_ = namedColorMap[param1.toLowerCase()];
|
||||
if(_loc4_ == null)
|
||||
{
|
||||
_loc4_ = parseInt(param1);
|
||||
if(isNaN(int(_loc4_)))
|
||||
{
|
||||
_loc4_ = null;
|
||||
debugLog("Invalid DFXP document: invalid color value of " + param1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
"color":_loc4_,
|
||||
"alpha":_loc5_
|
||||
};
|
||||
}
|
||||
|
||||
private function parseFontSize(param1:String) : String
|
||||
{
|
||||
var _loc8_:RegExp = null;
|
||||
var _loc4_:Object = null;
|
||||
var _loc7_:RegExp = null;
|
||||
var _loc2_:Object = null;
|
||||
if(!param1 || param1 == "")
|
||||
{
|
||||
return "";
|
||||
}
|
||||
var _loc3_:String = "";
|
||||
var _loc6_:RegExp = new RegExp(/^\s*\d+%.*$/);
|
||||
var _loc5_:Object = _loc6_.exec(param1);
|
||||
if(_loc5_)
|
||||
{
|
||||
debugLog("Invalid DFXP document: percentages are not supported for font size.");
|
||||
_loc3_ = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc8_ = new RegExp(/^\s*[\+\-]\d.*/);
|
||||
_loc4_ = _loc8_.exec(param1);
|
||||
if(_loc4_)
|
||||
{
|
||||
debugLog("Invalid DFXP document: increment values are not supported for font size.");
|
||||
_loc3_ = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc7_ = new RegExp(/^\s*(\d+).*$/);
|
||||
_loc2_ = _loc7_.exec(param1);
|
||||
if(_loc2_ && _loc2_[1] != undefined)
|
||||
{
|
||||
_loc3_ = _loc2_[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return _loc3_;
|
||||
}
|
||||
|
||||
private function parseFontFamily(param1:String) : String
|
||||
{
|
||||
var _loc2_:Object = null;
|
||||
if(!param1 || param1 == "")
|
||||
{
|
||||
return "";
|
||||
}
|
||||
var _loc3_:String = "";
|
||||
var _loc5_:RegExp = new RegExp(/^\s*([^,\s]+)\s*((,\s*([^,\s]+)\s*)*)$/);
|
||||
var _loc4_:Boolean = false;
|
||||
do
|
||||
{
|
||||
_loc2_ = _loc5_.exec(param1);
|
||||
if(!_loc2_)
|
||||
{
|
||||
_loc4_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_loc3_.length > 0)
|
||||
{
|
||||
_loc3_ += ",";
|
||||
}
|
||||
switch(_loc2_[1])
|
||||
{
|
||||
case "default":
|
||||
case "serif":
|
||||
case "proportionalSerif":
|
||||
_loc3_ += "_serif";
|
||||
break;
|
||||
case "monospace":
|
||||
case "monospaceSansSerif":
|
||||
case "monospaceSerif":
|
||||
_loc3_ += "_typewriter";
|
||||
break;
|
||||
case "sansSerif":
|
||||
case "proportionalSansSerif":
|
||||
_loc3_ += "_sans";
|
||||
break;
|
||||
default:
|
||||
_loc3_ += _loc2_[1];
|
||||
}
|
||||
if(_loc2_[2] != undefined && _loc2_[2] != "")
|
||||
{
|
||||
param1 = _loc2_[2].slice(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc4_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
while(!_loc4_);
|
||||
return _loc3_;
|
||||
}
|
||||
|
||||
private function parseBody(param1:CaptioningDocument, param2:XML) : void
|
||||
{
|
||||
var _loc3_:XMLList = null;
|
||||
var _loc4_:XMLList = null;
|
||||
var _loc5_:* = 0;
|
||||
var _loc7_:XML = null;
|
||||
var _loc6_:XMLList = param2..ns::body;
|
||||
if(_loc6_.length() <= 0)
|
||||
{
|
||||
debugLog("Invalid DFXP document: <body> tag is required.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc3_ = param2..ns::div;
|
||||
_loc4_ = _loc3_.length() ? _loc3_.children() : (_loc6_.length() ? _loc6_.children() : new XMLList());
|
||||
_loc5_ = 0;
|
||||
while(_loc5_ < _loc4_.length())
|
||||
{
|
||||
_loc7_ = _loc4_[_loc5_];
|
||||
if(rootNamespace == _loc7_.namespace())
|
||||
{
|
||||
parsePTag(param1,_loc7_,_loc5_);
|
||||
}
|
||||
else
|
||||
{
|
||||
debugLog("Ignoring this tag, foreign namespaces not supported: \"" + _loc7_ + "\"");
|
||||
}
|
||||
_loc5_++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function parsePTag(param1:CaptioningDocument, param2:XML, param3:uint) : void
|
||||
{
|
||||
var _loc10_:* = 0;
|
||||
var _loc22_:XML = null;
|
||||
var _loc20_:* = 0;
|
||||
var _loc11_:* = null;
|
||||
var _loc5_:Array = null;
|
||||
var _loc6_:* = 0;
|
||||
var _loc12_:CaptionFormat = null;
|
||||
var _loc17_:CaptionFormat = null;
|
||||
var _loc19_:String = param2.@begin;
|
||||
var _loc16_:String = param2.@end;
|
||||
var _loc4_:String = param2.@dur;
|
||||
if(_loc19_ == "")
|
||||
{
|
||||
_loc19_ = "0s";
|
||||
}
|
||||
var _loc9_:Number = TimeUtil.parseTime(_loc19_);
|
||||
var _loc13_:Number = 0;
|
||||
if(_loc16_ != "")
|
||||
{
|
||||
_loc13_ = TimeUtil.parseTime(_loc16_);
|
||||
}
|
||||
else if(_loc4_ != "")
|
||||
{
|
||||
_loc13_ = _loc9_ + TimeUtil.parseTime(_loc4_);
|
||||
}
|
||||
var _loc7_:Array = [];
|
||||
var _loc18_:String = new String("<p>");
|
||||
var _loc15_:XMLList = param2.children();
|
||||
_loc10_ = 0;
|
||||
while(_loc10_ < _loc15_.length())
|
||||
{
|
||||
switch((_loc22_ = _loc15_[_loc10_]).nodeKind())
|
||||
{
|
||||
case "text":
|
||||
_loc18_ += formatCCText(_loc22_.toString());
|
||||
break;
|
||||
case "element":
|
||||
switch(_loc22_.localName())
|
||||
{
|
||||
case "set":
|
||||
case "metadata":
|
||||
break;
|
||||
case "span":
|
||||
_loc20_ = uint(calcClearTextLength(_loc18_));
|
||||
_loc5_ = [];
|
||||
_loc18_ += parseSpanTag(param1,_loc22_,_loc5_);
|
||||
_loc6_ = uint(calcClearTextLength(_loc18_));
|
||||
for each(var _loc8_:CaptionStyle in _loc5_)
|
||||
{
|
||||
_loc12_ = new CaptionFormat(_loc8_,_loc20_,_loc6_);
|
||||
_loc7_.push(_loc12_);
|
||||
}
|
||||
break;
|
||||
case "br":
|
||||
_loc18_ += "<br />";
|
||||
break;
|
||||
default:
|
||||
_loc18_ += formatCCText(_loc22_.toString());
|
||||
}
|
||||
}
|
||||
_loc10_++;
|
||||
}
|
||||
_loc18_ += "</p>";
|
||||
var _loc21_:Caption = new Caption(param3,_loc9_,_loc13_,_loc18_);
|
||||
var _loc14_:CaptionStyle = parseStyleAttrib(param1,param2);
|
||||
if(_loc14_)
|
||||
{
|
||||
_loc17_ = new CaptionFormat(_loc14_);
|
||||
_loc21_.addCaptionFormat(_loc17_);
|
||||
}
|
||||
_loc10_ = 0;
|
||||
while(_loc10_ < _loc7_.length)
|
||||
{
|
||||
_loc21_.addCaptionFormat(_loc7_[_loc10_]);
|
||||
_loc10_++;
|
||||
}
|
||||
param1.addCaption(_loc21_);
|
||||
}
|
||||
|
||||
private function parseStyleAttrib(param1:CaptioningDocument, param2:XML) : CaptionStyle
|
||||
{
|
||||
var _loc7_:* = 0;
|
||||
var _loc8_:XMLList = null;
|
||||
var _loc5_:XML = null;
|
||||
var _loc4_:String = null;
|
||||
var _loc6_:String = param2.@style;
|
||||
var _loc3_:CaptionStyle = null;
|
||||
if(_loc6_ != "")
|
||||
{
|
||||
while(_loc7_ < param1.numStyles)
|
||||
{
|
||||
if(param1.getStyleAt(_loc7_).id == _loc6_)
|
||||
{
|
||||
_loc3_ = param1.getStyleAt(_loc7_);
|
||||
}
|
||||
_loc7_++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
_loc8_ = param2.tts::@*;
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
if(err.errorID != 1080)
|
||||
{
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
_loc7_ = 0;
|
||||
while(_loc8_ != null && _loc7_ < _loc8_.length())
|
||||
{
|
||||
_loc5_ = _loc8_[_loc7_];
|
||||
_loc4_ = _loc5_.localName();
|
||||
if(_loc4_ != "inherit")
|
||||
{
|
||||
_loc3_ = createStyleObject(param2);
|
||||
}
|
||||
_loc7_++;
|
||||
}
|
||||
}
|
||||
return _loc3_;
|
||||
}
|
||||
|
||||
private function parseSpanTag(param1:CaptioningDocument, param2:XML, param3:Array) : String
|
||||
{
|
||||
var _loc7_:* = 0;
|
||||
var _loc8_:XML = null;
|
||||
var _loc4_:CaptionStyle = parseStyleAttrib(param1,param2);
|
||||
if(_loc4_ != null)
|
||||
{
|
||||
param3.push(_loc4_);
|
||||
}
|
||||
var _loc6_:String = new String();
|
||||
var _loc5_:XMLList = param2.children();
|
||||
_loc7_ = 0;
|
||||
while(_loc7_ < _loc5_.length())
|
||||
{
|
||||
switch((_loc8_ = _loc5_[_loc7_]).nodeKind())
|
||||
{
|
||||
case "text":
|
||||
_loc6_ += formatCCText(_loc8_.toString());
|
||||
break;
|
||||
case "element":
|
||||
switch(_loc8_.localName())
|
||||
{
|
||||
case "set":
|
||||
case "metadata":
|
||||
break;
|
||||
case "br":
|
||||
_loc6_ += "<br/>";
|
||||
break;
|
||||
default:
|
||||
_loc6_ += _loc8_.toString();
|
||||
}
|
||||
}
|
||||
_loc7_++;
|
||||
}
|
||||
return _loc6_;
|
||||
}
|
||||
|
||||
private function formatCCText(param1:String) : String
|
||||
{
|
||||
return param1.replace(/\s+/g," ");
|
||||
}
|
||||
|
||||
private function calcClearTextLength(param1:String) : int
|
||||
{
|
||||
var _loc2_:String = param1.replace(/<(.|\n)*?>/g,"");
|
||||
return _loc2_.length;
|
||||
}
|
||||
|
||||
private function debugLog(param1:String) : void
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.osmf.captioning.parsers
|
||||
{
|
||||
import org.osmf.captioning.model.CaptioningDocument;
|
||||
|
||||
public interface ICaptioningParser
|
||||
{
|
||||
|
||||
function parse(param1:String) : CaptioningDocument;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user