diff options
| author | Jules Laplace <carbon@melanarchy.org> | 2013-08-02 17:14:26 -0500 |
|---|---|---|
| committer | Jules Laplace <carbon@melanarchy.org> | 2013-08-02 17:14:26 -0500 |
| commit | 79670053c7247d3a49b607960efd284e93f057e5 (patch) | |
| tree | 9617f6eefa38b2686ae409bf75cc27a340444eda /bPod/php/cybozuLab | |
| parent | c53827d5d044ae5ca7ebb27acb404b7a8988918e (diff) | |
install.pl
Diffstat (limited to 'bPod/php/cybozuLab')
| -rw-r--r-- | bPod/php/cybozuLab/rssParser/FetchingRss.as | 1 | ||||
| -rw-r--r-- | bPod/php/cybozuLab/rssParser/ParsingRss.as | 1 | ||||
| -rw-r--r-- | bPod/php/cybozuLab/rssParser/RssParserException.as | 1 | ||||
| -rw-r--r-- | bPod/php/cybozuLab/rssParser/Utils.as | 1 |
4 files changed, 4 insertions, 0 deletions
diff --git a/bPod/php/cybozuLab/rssParser/FetchingRss.as b/bPod/php/cybozuLab/rssParser/FetchingRss.as new file mode 100644 index 0000000..bca92c1 --- /dev/null +++ b/bPod/php/cybozuLab/rssParser/FetchingRss.as @@ -0,0 +1 @@ +/*
Action script 2.0 RSS parser package
Copyright (C) 2006 Cybozu Labs, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
class: com.cybozuLab.rssParser.FetchingRss
version: 0.1
modified: 31/Jan/2006
Fetching RSS2.0 feed and set Action Script 2.0 XML tree.
*/
import com.cybozuLab.rssParser.*;
class com.cybozuLab.rssParser.FetchingRss
{
private static var DEBUG:Boolean = false;
private var targetURL:String; //target rss feed URL
private var httpStatusCode:Number;
private var httpStatusType:String;
private var errorMessage:String;
private var rssXml:XML;
private var rssParser:ParsingRss;
private var calledParserFlag:Boolean;
/*
function: FetchingRss
constructor
*/
public function FetchingRss( url:String )
{
var thisObj:FetchingRss = this;
calledParserFlag = false;
if( url != undefined )
{
targetURL = url;
}
rssXml = new XML();
rssXml.ignoreWhite = true;
rssXml.onHTTPStatus = function( httpStatus:Number )
{
thisObj.FetchingRssOnHTTPStatus( httpStatus );
}
rssXml.onLoad = function( successFlag:Boolean )
{
thisObj.FetchingRssOnLoad( successFlag, thisObj.rssXml.status );
if( successFlag == true )
{
thisObj.calledParserFlag = true;
thisObj.rssParser = new ParsingRss( thisObj.rssXml );
}
thisObj.onLoad( successFlag, thisObj.errorMessage );
}
}
public function load( url:String ):Boolean
{
if( url != undefined )
{
targetURL = url;
}
if( targetURL == undefined )
{
errorMessage = "Setting Error : Called without source URL.";
return false;
}
calledParserFlag = false;
rssXml.load( targetURL );
return true;
}
public function onLoad( success:Boolean, errorMessage:String )
{
}
public function getTargetUrl():String
{
return targetURL;
}
public function getRssXml():XML
{
return rssXml;
}
public function getRssObject():Object
{
if( calledParserFlag )
{
return rssParser.getRssObject();
}
return new Object();
}
public function traceRssObject():Void
{
if( calledParserFlag )
{
Utils.traceObj( rssParser.getRssObject() );
}
}
public function getErrorMessage():String
{
return errorMessage;
}
/*
function: FetchingRssOnHTTPStatus
Classify an HTTP status code.
*/
private function FetchingRssOnHTTPStatus( httpStatus:Number )
{
httpStatusCode = httpStatus;
if( httpStatus < 100 )
{
httpStatusType = "flashError";
}
else if( httpStatus < 200 )
{
httpStatusType = "information";
}
else if( httpStatus < 300 )
{
httpStatusType = "successful";
}
else if( httpStatus < 400 )
{
httpStatusType = "redirection";
}
else if( httpStatus < 500 )
{
httpStatusType = "client error";
}
else if (httpStatus < 600 )
{
httpStatusType = "server error";
}
else
{
httpStatusType = "unknown";
}
if( DEBUG )
{
trace( "httpStatus : " + httpStatusCode );
trace( "httpStatusType : " + httpStatusType );
}
}
private function FetchingRssOnLoad( successFlag:Boolean, statusNum:Number )
{
var eMessage:String;
if( successFlag )
{
switch ( statusNum ) {
case 0 :
eMessage = "Parse was completed successfully.";
break;
case -2 :
eMessage = "A CDATA section was not properly terminated.";
break;
case -3 :
eMessage = "The XML declaration was not properly terminated.";
break;
case -4 :
eMessage = "The DOCTYPE declaration was not properly terminated.";
break;
case -5 :
eMessage = "A comment was not properly terminated.";
break;
case -6 :
eMessage = "An XML element was malformed.";
break;
case -7 :
eMessage = "Out of memory.";
break;
case -8 :
eMessage = "An attribute value was not properly terminated.";
break;
case -9 :
eMessage = "A start-tag was not matched with an end-tag.";
break;
case -10 :
eMessage = "An end-tag was encountered without a matching start-tag.";
break;
default :
eMessage = "An unknown error has occurred.";
break;
}
if( statusNum != 0 )
{
errorMessage = "Parsing Error : XML was loaded successfully, but was unable to be parsed. (Error : "+eMessage+")";
}
else
{
errorMessage = eMessage;
}
}
else
{
errorMessage = "Loading Error : Failed to load RSS feed. ( httpStatus : "+httpStatusCode+" - "+httpStatusType+")";
}
}
}
\ No newline at end of file diff --git a/bPod/php/cybozuLab/rssParser/ParsingRss.as b/bPod/php/cybozuLab/rssParser/ParsingRss.as new file mode 100644 index 0000000..bff2161 --- /dev/null +++ b/bPod/php/cybozuLab/rssParser/ParsingRss.as @@ -0,0 +1 @@ +/*
Action script 2.0 RSS parser package
Copyright (C) 2006 Cybozu Labs, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
class: com.cybozuLab.rssParser.ParsingRss
version: 0.1
Last-modified: 01/Feb/2006
Parsing RSS 2.0 feed for Action Script 2.0
*/
import com.cybozuLab.rssParser.*;
class com.cybozuLab.rssParser.ParsingRss
{
private static var DEBUG:Boolean = false;
private var targetRssXml:XMLNode; //rss feed XML Node tree
private var errorMessage:String;
private var parsedRssObj:Object;
private var parsedRssChannelObj:Object;
private var parsedRssItemObj:Array;
private var isInRssTag:Boolean;
private var isInChannelTag:Boolean;
private var isInItemTag:Boolean;
private var currentChannelNum:Number;
private var currentItemNum:Number;
private var channelStackArray:Array;
private var itemStackArray:Array;
private var nodeObjStack:Array;
/*
function: ParsingRss
constructor
*/
public function ParsingRss ( sourceData:XMLNode )
{
if( sourceData == undefined )
{
errorMessage = "Parsing Error : Called without source data.";
throw new RssParserException( errorMessage );
}
targetRssXml = sourceData;
isInRssTag = false;
isInChannelTag = false;
isInItemTag = false;
currentItemNum = 0;
channelStackArray = new Array();
itemStackArray = new Array();
parsedRssObj = new Object();
parsedRssChannelObj = new Object();
parsedRssItemObj = new Array();
parseRss( targetRssXml );
parsedRssObj["channel"] = parsedRssChannelObj;
parsedRssObj["channel"]["item"] = parsedRssItemObj;
}
public function getRssObject():Object
{
return parsedRssObj;
}
public function traceRssObject():Void
{
Utils.traceObj( parsedRssObj );
}
private function parseRss( currentNode:XMLNode ):Void
{
for ( var aNode:XMLNode = currentNode; aNode != null; aNode = aNode.nextSibling )
{
if( isInItemTag )
{
itemStackArray.unshift( aNode.nodeName );
}
else if( isInChannelTag )
{
channelStackArray.unshift( aNode.nodeName );
}
/*
Parse attributes.
*/
if( ! isInRssTag
&& aNode.nodeName.toLowerCase() == "rss"
&& Utils.countProperty( aNode.attributes ) >0 )
{
nodeObjStack = Array();
appendAttribute( parsedRssObj, aNode.attributes );
}
else if( isInItemTag
&& Utils.countProperty( aNode.attributes) >0 )
{
nodeObjStack = itemStackArray.slice( 0 );
appendAttribute( parsedRssItemObj[ currentItemNum ], aNode.attributes );
}
else if( isInChannelTag
&& Utils.countProperty( aNode.attributes ) >0 )
{
nodeObjStack = channelStackArray.slice( 0 );
appendAttribute( parsedRssChannelObj, aNode.attributes );
}
/*
Parse child node or data.
*/
if( ! isInRssTag
&& aNode.nodeName.toLowerCase() == "rss" )
{
isInRssTag = true;
parseRss(aNode.firstChild);
isInRssTag = false;
}
else if( ! isInChannelTag
&& aNode.nodeName.toLowerCase() == "channel" )
{
isInChannelTag = true;
parseRss(aNode.firstChild);
isInChannelTag = false;
currentChannelNum++;
}
else if( ! isInItemTag
&& channelStackArray.length == 1
&& aNode.nodeName.toLowerCase() == "item" )
{
isInItemTag = true;
parsedRssItemObj[ currentItemNum ] = new Object();
parseRss(aNode.firstChild);
isInItemTag = false;
currentItemNum++;
}
else if( aNode.firstChild.nodeType == 1 )
{
parseRss( aNode.firstChild );
}
else if( aNode.firstChild.nodeType == 3 )
{
if( isInItemTag )
{
nodeObjStack = itemStackArray.slice( 0 );
appendNodeValue( parsedRssItemObj[ currentItemNum ], aNode.firstChild.nodeValue );
}
else if( isInChannelTag )
{
nodeObjStack = channelStackArray.slice( 0 );
appendNodeValue( parsedRssChannelObj, aNode.firstChild.nodeValue );
}
else
{
trace("no rss value : "+ aNode.firstChild.nodeValue);
}
}
if( isInItemTag )
{
itemStackArray.shift( );
}
else if( isInChannelTag )
{
channelStackArray.shift( );
}
} // close for loop
} // close function
private function appendNodeValue( nodeObj:Object, nodeValue:String )
{
if( nodeObjStack.length > 0 )
{
var key = nodeObjStack.pop();
if( nodeObj[ key ] == undefined )
{
nodeObj[ key ] = new Object();
if( key != key.toLowerCase() )
{
nodeObj[ key.toLowerCase() ] = new Object();
}
}
appendNodeValue( nodeObj[ key ], nodeValue );
if( key != key.toLowerCase() )
{
appendNodeValue( nodeObj[ key.toLowerCase() ], nodeValue );
}
}
else
{
nodeObj["value"] = nodeValue;
}
}
private function appendAttribute( nodeObj:Object, attributes:Object )
{
if( nodeObjStack.length > 0 )
{
var key = nodeObjStack.pop();
if( nodeObj[ key ] == undefined )
{
nodeObj[ key ] = new Object();
if( key != key.toLowerCase() )
{
nodeObj[ key.toLowerCase() ] = new Object();
}
}
appendAttribute( nodeObj[ key ], attributes );
if( key != key.toLowerCase() )
{
appendAttribute( nodeObj[ key.toLowerCase() ], attributes );
}
}
else
{
nodeObj["attrs"] = attributes;
}
}
}
\ No newline at end of file diff --git a/bPod/php/cybozuLab/rssParser/RssParserException.as b/bPod/php/cybozuLab/rssParser/RssParserException.as new file mode 100644 index 0000000..6b8f9dc --- /dev/null +++ b/bPod/php/cybozuLab/rssParser/RssParserException.as @@ -0,0 +1 @@ +/*
Action script 2.0 RSS parser package
Copyright (C) 2006 Cybozu Labs, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
class: com.cybozuLab.rssParser.RssParserException
modified: 12/Jan/2006
Exception Class for RssParser package.
*/
class com.cybozuLab.rssParser.RssParserException extends Error
{
public function RssParserException( errMessage:String )
{
message = errMessage;
}
}
\ No newline at end of file diff --git a/bPod/php/cybozuLab/rssParser/Utils.as b/bPod/php/cybozuLab/rssParser/Utils.as new file mode 100644 index 0000000..ddfe31c --- /dev/null +++ b/bPod/php/cybozuLab/rssParser/Utils.as @@ -0,0 +1 @@ +/*
Action script 2.0 RSS parser package
Copyright (C) 2006 Cybozu Labs, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
class: com.cybozuLab.rssParser.Utils
modified: 20/Jan/2006
Utilities for RSS parser package.
*/
class com.cybozuLab.rssParser.Utils
{
private static var INTEND_SPACE_NUMBER:Number = 3;
static public function traceObj( targetObj:Object, hierarchyLevel:Number ):Void
{
if( hierarchyLevel == undefined )
{
hierarchyLevel = 0;
}
for( var prop in targetObj )
{
if( typeof( targetObj[prop] ) != "object" )
{
trace( makeIntendSpace( hierarchyLevel ) + prop + " : " + targetObj[prop] );
}
else
{
trace( makeIntendSpace( hierarchyLevel ) + prop );
hierarchyLevel++;
traceObj( targetObj[prop], hierarchyLevel );
hierarchyLevel--;
}
}
}
static public function objToString( targetObj:Object, hierarchyLevel:Number ):String
{
var resultStr:String = "";
if( hierarchyLevel == undefined )
{
hierarchyLevel = 0;
}
for( var prop in targetObj )
{
if( typeof( targetObj[prop] ) != "object" )
{
resultStr += makeIntendSpace( hierarchyLevel ) + prop + " : " + targetObj[prop] + "\n";
}
else
{
resultStr += makeIntendSpace( hierarchyLevel ) + prop + "\n";
hierarchyLevel++;
resultStr += objToString( targetObj[prop], hierarchyLevel );
hierarchyLevel--;
}
}
return resultStr;
}
static private function makeIntendSpace( hierarchyLevel:Number ):String
{
var resultString:String = "";
for( var i:Number=0; i < INTEND_SPACE_NUMBER * hierarchyLevel; i++ )
{
resultString += " ";
}
return resultString+"|-";
}
static public function countProperty( targetObj:Object ):Number
{
var i:Number = 0;
for( var prop in targetObj ) { i++; }
return i;
}
}
\ No newline at end of file |
