mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-21 01: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,34 @@
|
||||
package org.osmf.captioning
|
||||
{
|
||||
import org.osmf.captioning.media.CaptioningProxyElement;
|
||||
import org.osmf.media.MediaElement;
|
||||
import org.osmf.media.MediaFactoryItem;
|
||||
import org.osmf.media.MediaFactoryItemType;
|
||||
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 _loc1_:Vector.<MediaFactoryItem> = new Vector.<MediaFactoryItem>();
|
||||
var _loc2_:NetLoader = new NetLoader();
|
||||
var _loc3_:MediaFactoryItem = new MediaFactoryItem("org.osmf.captioning.CaptioningPluginInfo",_loc2_.canHandleResource,this.createCaptioningProxyElement,MediaFactoryItemType.PROXY);
|
||||
_loc1_.push(_loc3_);
|
||||
super(_loc1_);
|
||||
}
|
||||
|
||||
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 this._document;
|
||||
}
|
||||
|
||||
public function set document(param1:CaptioningDocument) : void
|
||||
{
|
||||
this._document = param1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
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.LoadState;
|
||||
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 this.httpLoader.canHandleResource(param1);
|
||||
}
|
||||
|
||||
override protected function executeLoad(param1:LoadTrait) : void
|
||||
{
|
||||
var httpLoadTrait:HTTPLoadTrait = null;
|
||||
var onHTTPLoaderStateChange:Function = null;
|
||||
var onLoadError:Function = null;
|
||||
var loadTrait:LoadTrait = param1;
|
||||
onHTTPLoaderStateChange = function(param1:LoaderEvent):void
|
||||
{
|
||||
var parser:ICaptioningParser = null;
|
||||
var captioningDocument:CaptioningDocument = null;
|
||||
var event:LoaderEvent = param1;
|
||||
if(event.newState == LoadState.READY)
|
||||
{
|
||||
httpLoader.removeEventListener(LoaderEvent.LOAD_STATE_CHANGE,onHTTPLoaderStateChange);
|
||||
httpLoadTrait.removeEventListener(MediaErrorEvent.MEDIA_ERROR,onLoadError);
|
||||
parser = createCaptioningParser();
|
||||
try
|
||||
{
|
||||
captioningDocument = parser.parse(httpLoadTrait.urlLoader.data.toString());
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
updateLoadTrait(loadTrait,LoadState.LOAD_ERROR);
|
||||
}
|
||||
CaptioningLoadTrait(loadTrait).document = captioningDocument;
|
||||
updateLoadTrait(loadTrait,LoadState.READY);
|
||||
}
|
||||
else if(event.newState == LoadState.LOAD_ERROR)
|
||||
{
|
||||
httpLoader.removeEventListener(LoaderEvent.LOAD_STATE_CHANGE,onHTTPLoaderStateChange);
|
||||
updateLoadTrait(loadTrait,event.newState);
|
||||
}
|
||||
};
|
||||
onLoadError = function(param1:MediaErrorEvent):void
|
||||
{
|
||||
httpLoadTrait.removeEventListener(MediaErrorEvent.MEDIA_ERROR,onLoadError);
|
||||
loadTrait.dispatchEvent(param1.clone());
|
||||
};
|
||||
updateLoadTrait(loadTrait,LoadState.LOADING);
|
||||
this.httpLoader.addEventListener(LoaderEvent.LOAD_STATE_CHANGE,onHTTPLoaderStateChange);
|
||||
httpLoadTrait = new HTTPLoadTrait(this.httpLoader,loadTrait.resource);
|
||||
httpLoadTrait.addEventListener(MediaErrorEvent.MEDIA_ERROR,onLoadError);
|
||||
this.httpLoader.load(httpLoadTrait);
|
||||
}
|
||||
|
||||
override protected function executeUnload(param1:LoadTrait) : void
|
||||
{
|
||||
updateLoadTrait(param1,LoadState.UNLOADING);
|
||||
updateLoadTrait(param1,LoadState.UNINITIALIZED);
|
||||
}
|
||||
|
||||
protected function createCaptioningParser() : ICaptioningParser
|
||||
{
|
||||
return new DFXPParser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package org.osmf.captioning.media
|
||||
{
|
||||
import org.osmf.captioning.CaptioningPluginInfo;
|
||||
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.LoadState;
|
||||
import org.osmf.traits.LoadTrait;
|
||||
import org.osmf.traits.MediaTraitType;
|
||||
|
||||
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);
|
||||
this._continueLoadOnFailure = param2;
|
||||
}
|
||||
|
||||
public function get continueLoadOnFailure() : Boolean
|
||||
{
|
||||
return this._continueLoadOnFailure;
|
||||
}
|
||||
|
||||
override public function set proxiedElement(param1:MediaElement) : void
|
||||
{
|
||||
var _loc2_:MediaElement = null;
|
||||
var _loc3_:MediaResourceBase = null;
|
||||
var _loc4_:Metadata = null;
|
||||
var _loc5_:String = null;
|
||||
super.proxiedElement = param1;
|
||||
if(param1 != null)
|
||||
{
|
||||
_loc2_ = super.proxiedElement;
|
||||
_loc3_ = Boolean(_loc2_) && _loc2_.resource != null ? _loc2_.resource : resource;
|
||||
if(_loc3_ == null)
|
||||
{
|
||||
dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MEDIA_ERROR_INVALID_PROXIED_ELEMENT)));
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc4_ = _loc3_.getMetadataValue(CaptioningPluginInfo.CAPTIONING_METADATA_NAMESPACE) as Metadata;
|
||||
if(_loc4_ == null)
|
||||
{
|
||||
if(!this._continueLoadOnFailure)
|
||||
{
|
||||
dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MEDIA_ERROR_INVALID_PROXIED_ELEMENT)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc5_ = _loc4_.getValue(CaptioningPluginInfo.CAPTIONING_METADATA_KEY_URI);
|
||||
if(_loc5_ != null)
|
||||
{
|
||||
this.loadTrait = new CaptioningLoadTrait(new CaptioningLoader(),new URLResource(_loc5_));
|
||||
this.loadTrait.addEventListener(LoadEvent.LOAD_STATE_CHANGE,this.onLoadStateChange,false,99);
|
||||
addTrait(MediaTraitType.LOAD,this.loadTrait);
|
||||
}
|
||||
else if(!this._continueLoadOnFailure)
|
||||
{
|
||||
dispatchEvent(new MediaErrorEvent(MediaErrorEvent.MEDIA_ERROR,false,false,new MediaError(MEDIA_ERROR_INVALID_PROXIED_ELEMENT)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function onLoadStateChange(param1:LoadEvent) : void
|
||||
{
|
||||
var _loc2_:CaptioningDocument = null;
|
||||
var _loc3_:MediaElement = null;
|
||||
var _loc4_:TimelineMetadata = null;
|
||||
var _loc5_:int = 0;
|
||||
var _loc6_:Caption = null;
|
||||
if(param1.loadState == LoadState.READY)
|
||||
{
|
||||
_loc2_ = this.loadTrait.document;
|
||||
if(_loc2_)
|
||||
{
|
||||
_loc3_ = super.proxiedElement;
|
||||
_loc4_ = proxiedElement.getMetadata(CaptioningPluginInfo.CAPTIONING_TEMPORAL_METADATA_NAMESPACE) as TimelineMetadata;
|
||||
if(_loc4_ == null)
|
||||
{
|
||||
_loc4_ = new TimelineMetadata(proxiedElement);
|
||||
proxiedElement.addMetadata(CaptioningPluginInfo.CAPTIONING_TEMPORAL_METADATA_NAMESPACE,_loc4_);
|
||||
}
|
||||
_loc5_ = 0;
|
||||
while(_loc5_ < _loc2_.numCaptions)
|
||||
{
|
||||
_loc6_ = _loc2_.getCaptionAt(_loc5_);
|
||||
_loc4_.addMarker(_loc6_);
|
||||
_loc5_++;
|
||||
}
|
||||
}
|
||||
this.cleanUp();
|
||||
}
|
||||
else if(param1.loadState == LoadState.LOAD_ERROR)
|
||||
{
|
||||
if(!this._continueLoadOnFailure)
|
||||
{
|
||||
dispatchEvent(param1.clone());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cleanUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function cleanUp() : void
|
||||
{
|
||||
removeTrait(MediaTraitType.LOAD);
|
||||
var _loc1_:LoadTrait = getTrait(MediaTraitType.LOAD) as LoadTrait;
|
||||
if(_loc1_ != null && _loc1_.loadState == 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_);
|
||||
this._id = param1;
|
||||
this._captionText = param4;
|
||||
}
|
||||
|
||||
public function addCaptionFormat(param1:CaptionFormat) : void
|
||||
{
|
||||
if(this._formats == null)
|
||||
{
|
||||
this._formats = new Vector.<CaptionFormat>();
|
||||
}
|
||||
this._formats.push(param1);
|
||||
}
|
||||
|
||||
public function get numCaptionFormats() : int
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
if(this._formats != null)
|
||||
{
|
||||
_loc1_ = int(this._formats.length);
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
public function getCaptionFormatAt(param1:int) : CaptionFormat
|
||||
{
|
||||
if(this._formats == null || param1 >= this._formats.length || param1 < 0)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
return this._formats[param1];
|
||||
}
|
||||
|
||||
public function get text() : String
|
||||
{
|
||||
return this._captionText;
|
||||
}
|
||||
|
||||
public function get clearText() : String
|
||||
{
|
||||
var _loc1_:String = "";
|
||||
if(this._captionText != null && this._captionText.length > 0)
|
||||
{
|
||||
_loc1_ = this._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(MISSING_STYLE_ERROR_MSG);
|
||||
}
|
||||
this._startIndex = param2;
|
||||
this._endIndex = param3;
|
||||
this._style = param1;
|
||||
}
|
||||
|
||||
public function get startIndex() : int
|
||||
{
|
||||
return this._startIndex;
|
||||
}
|
||||
|
||||
public function get endIndex() : int
|
||||
{
|
||||
return this._endIndex;
|
||||
}
|
||||
|
||||
public function get style() : CaptionStyle
|
||||
{
|
||||
return this._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();
|
||||
this._id = param1;
|
||||
}
|
||||
|
||||
public function get id() : String
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public function get backgroundColor() : Object
|
||||
{
|
||||
return this._backgroundColor;
|
||||
}
|
||||
|
||||
public function set backgroundColor(param1:Object) : void
|
||||
{
|
||||
this._backgroundColor = param1;
|
||||
}
|
||||
|
||||
public function get backgroundColorAlpha() : Object
|
||||
{
|
||||
return this._backgroundColorAlpha;
|
||||
}
|
||||
|
||||
public function set backgroundColorAlpha(param1:Object) : void
|
||||
{
|
||||
this._backgroundColorAlpha = param1;
|
||||
}
|
||||
|
||||
public function get textColor() : Object
|
||||
{
|
||||
return this._textColor;
|
||||
}
|
||||
|
||||
public function set textColor(param1:Object) : void
|
||||
{
|
||||
this._textColor = param1;
|
||||
}
|
||||
|
||||
public function get textColorAlpha() : Object
|
||||
{
|
||||
return this._textColorAlpha;
|
||||
}
|
||||
|
||||
public function set textColorAlpha(param1:Object) : void
|
||||
{
|
||||
this._textColorAlpha = param1;
|
||||
}
|
||||
|
||||
public function get fontFamily() : String
|
||||
{
|
||||
return this._fontFamily;
|
||||
}
|
||||
|
||||
public function set fontFamily(param1:String) : void
|
||||
{
|
||||
this._fontFamily = param1;
|
||||
}
|
||||
|
||||
public function get fontSize() : int
|
||||
{
|
||||
return this._fontSize;
|
||||
}
|
||||
|
||||
public function set fontSize(param1:int) : void
|
||||
{
|
||||
this._fontSize = param1;
|
||||
}
|
||||
|
||||
public function get fontStyle() : String
|
||||
{
|
||||
return this._fontStyle;
|
||||
}
|
||||
|
||||
public function set fontStyle(param1:String) : void
|
||||
{
|
||||
this._fontStyle = param1;
|
||||
}
|
||||
|
||||
public function get fontWeight() : String
|
||||
{
|
||||
return this._fontWeight;
|
||||
}
|
||||
|
||||
public function set fontWeight(param1:String) : void
|
||||
{
|
||||
this._fontWeight = param1;
|
||||
}
|
||||
|
||||
public function get textAlign() : String
|
||||
{
|
||||
return this._textAlign;
|
||||
}
|
||||
|
||||
public function set textAlign(param1:String) : void
|
||||
{
|
||||
this._textAlign = param1;
|
||||
}
|
||||
|
||||
public function get wrapOption() : Boolean
|
||||
{
|
||||
return this._wrapOption;
|
||||
}
|
||||
|
||||
public function set wrapOption(param1:Boolean) : void
|
||||
{
|
||||
this._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 this._title;
|
||||
}
|
||||
|
||||
public function set title(param1:String) : void
|
||||
{
|
||||
this._title = param1;
|
||||
}
|
||||
|
||||
public function get description() : String
|
||||
{
|
||||
return this._desc;
|
||||
}
|
||||
|
||||
public function set description(param1:String) : void
|
||||
{
|
||||
this._desc = param1;
|
||||
}
|
||||
|
||||
public function get copyright() : String
|
||||
{
|
||||
return this._copyright;
|
||||
}
|
||||
|
||||
public function set copyright(param1:String) : void
|
||||
{
|
||||
this._copyright = param1;
|
||||
}
|
||||
|
||||
public function addStyle(param1:CaptionStyle) : void
|
||||
{
|
||||
if(this._styles == null)
|
||||
{
|
||||
this._styles = new Vector.<CaptionStyle>();
|
||||
}
|
||||
this._styles.push(param1);
|
||||
}
|
||||
|
||||
public function get numStyles() : int
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
if(this._styles != null)
|
||||
{
|
||||
_loc1_ = int(this._styles.length);
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
public function getStyleAt(param1:int) : CaptionStyle
|
||||
{
|
||||
if(this._styles == null || param1 >= this._styles.length)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
return this._styles[param1];
|
||||
}
|
||||
|
||||
public function addCaption(param1:Caption) : void
|
||||
{
|
||||
if(this._captions == null)
|
||||
{
|
||||
this._captions = new Vector.<Caption>();
|
||||
}
|
||||
this._captions.push(param1);
|
||||
}
|
||||
|
||||
public function get numCaptions() : int
|
||||
{
|
||||
var _loc1_:int = 0;
|
||||
if(this._captions != null)
|
||||
{
|
||||
_loc1_ = int(this._captions.length);
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
|
||||
public function getCaptionAt(param1:int) : Caption
|
||||
{
|
||||
if(this._captions == null || param1 >= this._captions.length)
|
||||
{
|
||||
throw new IllegalOperationError(OSMFStrings.getString(OSMFStrings.INVALID_PARAM));
|
||||
}
|
||||
return this._captions[param1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,515 @@
|
||||
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();
|
||||
this.namedColorMap = new Dictionary();
|
||||
this.namedColorMap["transparent"] = 0;
|
||||
this.namedColorMap["black"] = 0;
|
||||
this.namedColorMap["silver"] = 12632256;
|
||||
this.namedColorMap["gray"] = 8421504;
|
||||
this.namedColorMap["white"] = 16777215;
|
||||
this.namedColorMap["maroon"] = 8388608;
|
||||
this.namedColorMap["red"] = 16711680;
|
||||
this.namedColorMap["purple"] = 8388736;
|
||||
this.namedColorMap["fuchsia"] = 16711935;
|
||||
this.namedColorMap["magenta"] = 16711935;
|
||||
this.namedColorMap["green"] = 32768;
|
||||
this.namedColorMap["lime"] = 65280;
|
||||
this.namedColorMap["olive"] = 8421376;
|
||||
this.namedColorMap["yellow"] = 16776960;
|
||||
this.namedColorMap["navy"] = 128;
|
||||
this.namedColorMap["blue"] = 255;
|
||||
this.namedColorMap["teal"] = 32896;
|
||||
this.namedColorMap["aqua"] = 65535;
|
||||
this.namedColorMap["cyan"] = 65535;
|
||||
}
|
||||
|
||||
public function parse(param1:String) : CaptioningDocument
|
||||
{
|
||||
var xml:XML = null;
|
||||
var rawData:String = param1;
|
||||
var document:CaptioningDocument = new CaptioningDocument();
|
||||
var saveXMLIgnoreWhitespace:Boolean = Boolean(XML.ignoreWhitespace);
|
||||
var saveXMLPrettyPrinting:Boolean = Boolean(XML.prettyPrinting);
|
||||
var xmlStr:String = rawData.replace(/\s+$/,"");
|
||||
xmlStr = xmlStr.replace(/>\s+</g,"><");
|
||||
XML.ignoreWhitespace = false;
|
||||
XML.prettyPrinting = false;
|
||||
try
|
||||
{
|
||||
xml = new XML(xmlStr);
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
debugLog("Unhandled exception in DFXPParser : " + e.message);
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
XML.ignoreWhitespace = saveXMLIgnoreWhitespace;
|
||||
XML.prettyPrinting = saveXMLPrettyPrinting;
|
||||
}
|
||||
this.rootNamespace = xml.namespace();
|
||||
this.ns = xml.namespace();
|
||||
this.ttm = xml.namespace("ttm");
|
||||
this.tts = xml.namespace("tts");
|
||||
try
|
||||
{
|
||||
this.parseHead(document,xml);
|
||||
this.parseBody(document,xml);
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
debugLog("Unhandled exception in DFXPParser : " + err.message);
|
||||
throw err;
|
||||
}
|
||||
return document;
|
||||
}
|
||||
|
||||
private function parseHead(param1:CaptioningDocument, param2:XML) : void
|
||||
{
|
||||
var styling:XMLList;
|
||||
var styles:XMLList = null;
|
||||
var i:uint = 0;
|
||||
var styleNode:XML = null;
|
||||
var styleObj:CaptionStyle = null;
|
||||
var doc:CaptioningDocument = param1;
|
||||
var xml:XML = param2;
|
||||
try
|
||||
{
|
||||
doc.title = xml..this.ttm::title.text();
|
||||
doc.description = xml..this.ttm::desc.text();
|
||||
doc.copyright = xml..this.ttm::copyright.text();
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
if(err.errorID != 1080)
|
||||
{
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
styling = xml..this.ns::styling;
|
||||
if(styling.length())
|
||||
{
|
||||
styles = styling.children();
|
||||
i = 0;
|
||||
while(i < styles.length())
|
||||
{
|
||||
styleNode = styles[i];
|
||||
styleObj = this.createStyleObject(styleNode);
|
||||
doc.addStyle(styleObj);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createStyleObject(param1:XML) : CaptionStyle
|
||||
{
|
||||
var _loc4_:Object = null;
|
||||
var _loc2_:String = param1.@id;
|
||||
var _loc3_:CaptionStyle = new CaptionStyle(_loc2_);
|
||||
var _loc5_:String = param1.this.tts::@backgroundColor;
|
||||
if(_loc5_ != "")
|
||||
{
|
||||
_loc4_ = this.parseColor(_loc5_);
|
||||
_loc3_.backgroundColor = _loc4_.color;
|
||||
_loc3_.backgroundColorAlpha = _loc4_.alpha;
|
||||
}
|
||||
_loc3_.textAlign = param1.this.tts::@textAlign;
|
||||
_loc5_ = param1.this.tts::@color;
|
||||
if(_loc5_ != "")
|
||||
{
|
||||
_loc4_ = this.parseColor(_loc5_);
|
||||
_loc3_.textColor = _loc4_.color;
|
||||
_loc3_.textColorAlpha = _loc4_.alpha;
|
||||
}
|
||||
_loc3_.fontFamily = this.parseFontFamily(param1.this.tts::@fontFamily);
|
||||
var _loc6_:String = this.parseFontSize(param1.this.tts::@fontSize);
|
||||
_loc3_.fontSize = parseInt(_loc6_);
|
||||
_loc3_.fontStyle = param1.this.tts::@fontStyle;
|
||||
_loc3_.fontWeight = param1.this.tts::@fontWeight;
|
||||
_loc3_.wrapOption = String(param1.this.tts::@wrapOption).toLowerCase() == "nowrap" ? false : true;
|
||||
return _loc3_;
|
||||
}
|
||||
|
||||
private function parseColor(param1:String) : Object
|
||||
{
|
||||
var _loc2_:Object = null;
|
||||
var _loc3_:Object = null;
|
||||
var _loc4_: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 _loc5_:Array = param1.match(_loc4_);
|
||||
if(_loc5_ != null)
|
||||
{
|
||||
_loc2_ = parseInt(_loc5_[1],16);
|
||||
if(_loc5_.length == 3)
|
||||
{
|
||||
_loc3_ = Number(parseInt(_loc5_[2]) / 255);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc4_ = /^\s*rgb(a)?\((\d+),(\d+),(\d+)(\)|(,(\d+)\)))\s*$/i;
|
||||
_loc5_ = param1.match(_loc4_);
|
||||
if(_loc5_ != null && _loc5_.length >= 5)
|
||||
{
|
||||
_loc2_ = (parseInt(_loc5_[2]) << 16) + (parseInt(_loc5_[3]) << 8) + parseInt(_loc5_[4]);
|
||||
if(_loc5_.length == 8 && _loc5_[7] != undefined)
|
||||
{
|
||||
_loc3_ = Number(parseInt(_loc5_[7]) / 255);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc2_ = this.namedColorMap[param1.toLowerCase()];
|
||||
if(_loc2_ == null)
|
||||
{
|
||||
_loc2_ = parseInt(param1);
|
||||
if(isNaN(int(_loc2_)))
|
||||
{
|
||||
_loc2_ = null;
|
||||
this.debugLog("Invalid DFXP document: invalid color value of " + param1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
"color":_loc2_,
|
||||
"alpha":_loc3_
|
||||
};
|
||||
}
|
||||
|
||||
private function parseFontSize(param1:String) : String
|
||||
{
|
||||
var _loc5_:RegExp = null;
|
||||
var _loc6_:Object = null;
|
||||
var _loc7_:RegExp = null;
|
||||
var _loc8_:Object = null;
|
||||
if(!param1 || param1 == "")
|
||||
{
|
||||
return "";
|
||||
}
|
||||
var _loc2_:String = "";
|
||||
var _loc3_:RegExp = new RegExp(/^\s*\d+%.*$/);
|
||||
var _loc4_:Object = _loc3_.exec(param1);
|
||||
if(_loc4_)
|
||||
{
|
||||
this.debugLog("Invalid DFXP document: percentages are not supported for font size.");
|
||||
_loc2_ = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc5_ = new RegExp(/^\s*[\+\-]\d.*/);
|
||||
_loc6_ = _loc5_.exec(param1);
|
||||
if(_loc6_)
|
||||
{
|
||||
this.debugLog("Invalid DFXP document: increment values are not supported for font size.");
|
||||
_loc2_ = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc7_ = new RegExp(/^\s*(\d+).*$/);
|
||||
_loc8_ = _loc7_.exec(param1);
|
||||
if((Boolean(_loc8_)) && _loc8_[1] != undefined)
|
||||
{
|
||||
_loc2_ = _loc8_[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
private function parseFontFamily(param1:String) : String
|
||||
{
|
||||
var _loc5_:Object = null;
|
||||
if(!param1 || param1 == "")
|
||||
{
|
||||
return "";
|
||||
}
|
||||
var _loc2_:String = "";
|
||||
var _loc3_:RegExp = new RegExp(/^\s*([^,\s]+)\s*((,\s*([^,\s]+)\s*)*)$/);
|
||||
var _loc4_:Boolean = false;
|
||||
do
|
||||
{
|
||||
_loc5_ = _loc3_.exec(param1);
|
||||
if(!_loc5_)
|
||||
{
|
||||
_loc4_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_loc2_.length > 0)
|
||||
{
|
||||
_loc2_ += ",";
|
||||
}
|
||||
switch(_loc5_[1])
|
||||
{
|
||||
case "default":
|
||||
case "serif":
|
||||
case "proportionalSerif":
|
||||
_loc2_ += "_serif";
|
||||
break;
|
||||
case "monospace":
|
||||
case "monospaceSansSerif":
|
||||
case "monospaceSerif":
|
||||
_loc2_ += "_typewriter";
|
||||
break;
|
||||
case "sansSerif":
|
||||
case "proportionalSansSerif":
|
||||
_loc2_ += "_sans";
|
||||
break;
|
||||
default:
|
||||
_loc2_ += _loc5_[1];
|
||||
}
|
||||
if(_loc5_[2] != undefined && _loc5_[2] != "")
|
||||
{
|
||||
param1 = _loc5_[2].slice(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc4_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
while(!_loc4_);
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
private function parseBody(param1:CaptioningDocument, param2:XML) : void
|
||||
{
|
||||
var _loc4_:XMLList = null;
|
||||
var _loc5_:XMLList = null;
|
||||
var _loc6_:uint = 0;
|
||||
var _loc7_:XML = null;
|
||||
var _loc3_:XMLList = param2..this.ns::body;
|
||||
if(_loc3_.length() <= 0)
|
||||
{
|
||||
this.debugLog("Invalid DFXP document: <body> tag is required.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc4_ = param2..this.ns::div;
|
||||
_loc5_ = _loc4_.length() ? _loc4_.children() : (_loc3_.length() ? _loc3_.children() : new XMLList());
|
||||
_loc6_ = 0;
|
||||
while(_loc6_ < _loc5_.length())
|
||||
{
|
||||
_loc7_ = _loc5_[_loc6_];
|
||||
if(this.rootNamespace == _loc7_.namespace())
|
||||
{
|
||||
this.parsePTag(param1,_loc7_,_loc6_);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.debugLog("Ignoring this tag, foreign namespaces not supported: \"" + _loc7_ + "\"");
|
||||
}
|
||||
_loc6_++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function parsePTag(param1:CaptioningDocument, param2:XML, param3:uint) : void
|
||||
{
|
||||
var _loc10_:String = null;
|
||||
var _loc15_:XML = null;
|
||||
var _loc16_:uint = 0;
|
||||
var _loc17_:String = null;
|
||||
var _loc18_:Array = null;
|
||||
var _loc19_:uint = 0;
|
||||
var _loc20_:CaptionStyle = null;
|
||||
var _loc21_:CaptionFormat = null;
|
||||
var _loc22_:CaptionFormat = null;
|
||||
var _loc4_:String = param2.@begin;
|
||||
var _loc5_:String = param2.@end;
|
||||
var _loc6_:String = param2.@dur;
|
||||
if(_loc4_ == "")
|
||||
{
|
||||
_loc4_ = "0s";
|
||||
}
|
||||
var _loc7_:Number = TimeUtil.parseTime(_loc4_);
|
||||
var _loc8_:Number = 0;
|
||||
if(_loc5_ != "")
|
||||
{
|
||||
_loc8_ = TimeUtil.parseTime(_loc5_);
|
||||
}
|
||||
else if(_loc6_ != "")
|
||||
{
|
||||
_loc8_ = _loc7_ + TimeUtil.parseTime(_loc6_);
|
||||
}
|
||||
var _loc9_:Array = new Array();
|
||||
_loc10_ = new String("<p>");
|
||||
var _loc11_:XMLList = param2.children();
|
||||
var _loc12_:uint = 0;
|
||||
while(_loc12_ < _loc11_.length())
|
||||
{
|
||||
_loc15_ = _loc11_[_loc12_];
|
||||
switch(_loc15_.nodeKind())
|
||||
{
|
||||
case "text":
|
||||
_loc10_ += this.formatCCText(_loc15_.toString());
|
||||
break;
|
||||
case "element":
|
||||
switch(_loc15_.localName())
|
||||
{
|
||||
case "set":
|
||||
case "metadata":
|
||||
break;
|
||||
case "span":
|
||||
_loc16_ = uint(this.calcClearTextLength(_loc10_));
|
||||
_loc18_ = new Array();
|
||||
_loc10_ += this.parseSpanTag(param1,_loc15_,_loc18_);
|
||||
_loc19_ = uint(this.calcClearTextLength(_loc10_));
|
||||
for each(_loc20_ in _loc18_)
|
||||
{
|
||||
_loc21_ = new CaptionFormat(_loc20_,_loc16_,_loc19_);
|
||||
_loc9_.push(_loc21_);
|
||||
}
|
||||
break;
|
||||
case "br":
|
||||
_loc10_ += "<br />";
|
||||
break;
|
||||
default:
|
||||
_loc10_ += this.formatCCText(_loc15_.toString());
|
||||
}
|
||||
}
|
||||
_loc12_++;
|
||||
}
|
||||
_loc10_ += "</p>";
|
||||
var _loc13_:Caption = new Caption(param3,_loc7_,_loc8_,_loc10_);
|
||||
var _loc14_:CaptionStyle = this.parseStyleAttrib(param1,param2);
|
||||
if(_loc14_)
|
||||
{
|
||||
_loc22_ = new CaptionFormat(_loc14_);
|
||||
_loc13_.addCaptionFormat(_loc22_);
|
||||
}
|
||||
_loc12_ = 0;
|
||||
while(_loc12_ < _loc9_.length)
|
||||
{
|
||||
_loc13_.addCaptionFormat(_loc9_[_loc12_]);
|
||||
_loc12_++;
|
||||
}
|
||||
param1.addCaption(_loc13_);
|
||||
}
|
||||
|
||||
private function parseStyleAttrib(param1:CaptioningDocument, param2:XML) : CaptionStyle
|
||||
{
|
||||
var i:uint = 0;
|
||||
var attributes:XMLList = null;
|
||||
var attrib:XML = null;
|
||||
var localName:String = null;
|
||||
var doc:CaptioningDocument = param1;
|
||||
var node:XML = param2;
|
||||
var styleId:String = node.@style;
|
||||
var captionStyle:CaptionStyle = null;
|
||||
if(styleId != "")
|
||||
{
|
||||
while(i < doc.numStyles)
|
||||
{
|
||||
if(doc.getStyleAt(i).id == styleId)
|
||||
{
|
||||
captionStyle = doc.getStyleAt(i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
attributes = node.this.tts::@*;
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
if(err.errorID != 1080)
|
||||
{
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
while(attributes != null && i < attributes.length())
|
||||
{
|
||||
attrib = attributes[i];
|
||||
localName = attrib.localName();
|
||||
if(localName != "inherit")
|
||||
{
|
||||
captionStyle = this.createStyleObject(node);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return captionStyle;
|
||||
}
|
||||
|
||||
private function parseSpanTag(param1:CaptioningDocument, param2:XML, param3:Array) : String
|
||||
{
|
||||
var _loc8_:XML = null;
|
||||
var _loc4_:CaptionStyle = this.parseStyleAttrib(param1,param2);
|
||||
if(_loc4_ != null)
|
||||
{
|
||||
param3.push(_loc4_);
|
||||
}
|
||||
var _loc5_:String = new String();
|
||||
var _loc6_:XMLList = param2.children();
|
||||
var _loc7_:uint = 0;
|
||||
while(_loc7_ < _loc6_.length())
|
||||
{
|
||||
_loc8_ = _loc6_[_loc7_];
|
||||
switch(_loc8_.nodeKind())
|
||||
{
|
||||
case "text":
|
||||
_loc5_ += this.formatCCText(_loc8_.toString());
|
||||
break;
|
||||
case "element":
|
||||
switch(_loc8_.localName())
|
||||
{
|
||||
case "set":
|
||||
case "metadata":
|
||||
break;
|
||||
case "br":
|
||||
_loc5_ += "<br/>";
|
||||
break;
|
||||
default:
|
||||
_loc5_ += _loc8_.toString();
|
||||
}
|
||||
}
|
||||
_loc7_++;
|
||||
}
|
||||
return _loc5_;
|
||||
}
|
||||
|
||||
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