|
From: <rga...@us...> - 2002-11-10 15:18:37
|
Update of /cvsroot/csms/csms-core/src/java/org/fanfoot/scoring
In directory usw-pr-cvs1:/tmp/cvs-serv11840
Modified Files:
EventParser.java
Log Message:
Minor clarifications in comments
Index: EventParser.java
===================================================================
RCS file: /cvsroot/csms/csms-core/src/java/org/fanfoot/scoring/EventParser.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** EventParser.java 21 Oct 2002 22:19:31 -0000 1.4
--- EventParser.java 10 Nov 2002 15:18:34 -0000 1.5
***************
*** 64,73 ****
/** Holds value of property conf. */
private EventParserConfiguration conf;
- /** WHere to write log info */
- final Logger logger = Logger.getLogger("org.fanfoot.scoring");
/** The listeners to this parser */
private Vector listeners = new Vector();
/** The commentary document to parse */
private Document docCommentary = null;
--- 64,73 ----
/** Holds value of property conf. */
private EventParserConfiguration conf;
/** The listeners to this parser */
private Vector listeners = new Vector();
/** The commentary document to parse */
private Document docCommentary = null;
+ /** WHere to write log info */
+ final Logger logger = Logger.getLogger( "org.fanfoot.scoring" );
***************
*** 88,94 ****
*@throws EventParserConfigurationException
*/
! public EventParser(String strURL) throws EventParserConfigurationException {
super();
! conf = new EventParserConfiguration(strURL);
}
--- 88,94 ----
*@throws EventParserConfigurationException
*/
! public EventParser( String strURL ) throws EventParserConfigurationException {
super();
! conf = new EventParserConfiguration( strURL );
}
***************
*** 107,116 ****
* Exception
*/
! public Events parse(String strURL, String strType)
throws MalformedURLException, IOException,
EventParserConfigurationException {
! URL url = new URL(strURL);
! return parse(url, strType);
}
--- 107,116 ----
* Exception
*/
! public Events parse( String strURL, String strType )
throws MalformedURLException, IOException,
EventParserConfigurationException {
! URL url = new URL( strURL );
! return parse( url, strType );
}
***************
*** 128,134 ****
* Exception
*/
! public Events parse(File file, String strType) throws IOException,
EventParserConfigurationException {
! return parse(file.toURL(), strType);
}
--- 128,134 ----
* Exception
*/
! public Events parse( File file, String strType ) throws IOException,
EventParserConfigurationException {
! return parse( file.toURL(), strType );
}
***************
*** 147,173 ****
* Exception
*/
! public Events parse(URL url, String strType) throws MalformedURLException,
IOException,
EventParserConfigurationException {
! docCommentary = XMLUtils.loadTidiedHTML(url);
this.notifyRetrievedCommentary();
StringBuffer sbData = new StringBuffer();
! XMLUtils.appendAllText(docCommentary.getDocumentElement(), sbData);
String strData = sbData.toString();
! ArrayList patterns = conf.getPatternsForType(strType);
Events evtsResult = new Events();
! String strEventsUID = parseEventsUID(strData, strType);
! evtsResult.setUID(strEventsUID);
Events evtsCurrent;
EventPattern p;
! for(int i = 0; i < patterns.size(); i++) {
! p = (EventPattern) patterns.get(i);
! evtsCurrent = processEvents(p, strData);
! if(evtsCurrent != null) {
! evtsResult.addAll(evtsCurrent, this.conf);
}
}
--- 147,173 ----
* Exception
*/
! public Events parse( URL url, String strType ) throws MalformedURLException,
IOException,
EventParserConfigurationException {
! docCommentary = XMLUtils.loadTidiedHTML( url );
this.notifyRetrievedCommentary();
StringBuffer sbData = new StringBuffer();
! XMLUtils.appendAllText( docCommentary.getDocumentElement(), sbData );
String strData = sbData.toString();
! ArrayList patterns = conf.getPatternsForType( strType );
Events evtsResult = new Events();
! String strEventsUID = parseEventsUID( strData, strType );
! evtsResult.setUID( strEventsUID );
Events evtsCurrent;
EventPattern p;
! for ( int i = 0; i < patterns.size(); i++ ) {
! p = (EventPattern) patterns.get( i );
! evtsCurrent = processEvents( p, strData );
! if ( evtsCurrent != null ) {
! evtsResult.addAll( evtsCurrent, this.conf );
}
}
***************
*** 185,216 ****
*@return Events matched by the pattern
*/
! private Events processEvents(EventPattern p, String strData) {
Events evts = new Events();
! Matcher m = p.getRegexPattern().matcher(strData);
String strPartValue;
String strPartName;
! logger.finest("Looking for matches of type " + p.getType() + " (RE="
! + p.getRegexPattern().pattern() + ")");
! while(m.find()) {
! logger.fine("Matched event in: " + m.group());
! Event evt = new Event(p.getType());
// Extract the event parts and store them in the event object
! logger.finest("There are " + m.groupCount()
! + " groups in the match");
! for(int i = 1; i <= m.groupCount(); i++) {
! strPartValue = m.group(i).trim();
! strPartName = p.getPartName(i);
! evt.putPart(strPartName, strPartValue);
! logger.finest("Set " + strPartName + " to " + strPartValue
! + " (part #" + i + ")");
}
! logger.fine("Added event of type " + p.getType());
! evts.add(evt);
}
--- 185,216 ----
*@return Events matched by the pattern
*/
! private Events processEvents( EventPattern p, String strData ) {
Events evts = new Events();
! Matcher m = p.getRegexPattern().matcher( strData );
String strPartValue;
String strPartName;
! logger.finest( "Looking for matches of type " + p.getType() + " (RE="
! + p.getRegexPattern().pattern() + ")" );
! while ( m.find() ) {
! logger.fine( "Matched event in: " + m.group() );
! Event evt = new Event( p.getType() );
// Extract the event parts and store them in the event object
! logger.finest( "There are " + m.groupCount()
! + " groups in the match" );
! for ( int i = 1; i <= m.groupCount(); i++ ) {
! strPartValue = m.group( i ).trim();
! strPartName = p.getPartName( i );
! evt.putPart( strPartName, strPartValue );
! logger.finest( "Set " + strPartName + " to " + strPartValue
! + " (part #" + i + ")" );
}
! logger.fine( "Added event of type " + p.getType() );
! evts.add( evt );
}
***************
*** 231,259 ****
* cannot be generated
*/
! public String parseEventsUID(String strData, String strType)
throws EventParserConfigurationException {
StringBuffer sb = new StringBuffer();
Matcher m;
! logger.entering("org.fanfoot.scoring.EventParser",
! "parseEventUID(strData, strType");
// get the UID element
! EventPattern uidPattern = this.conf.getEventsUIDPattern(strType);
! m = uidPattern.getRegexPattern().matcher(strData);
! logger.finest("UID pattern is "
! + uidPattern.getRegexPattern().pattern());
// get the UID parts
! while(m.find()) {
// Extract the UID parts and build the UID
! for(int i = 1; i <= m.groupCount(); i++) {
! sb.append('_');
! sb.append(m.group(i).trim());
}
}
! logger.exiting("org.fanfoot.scoring.EventParser",
! "parseEventUID(strData, strType");
// concatenate the parts
--- 231,259 ----
* cannot be generated
*/
! public String parseEventsUID( String strData, String strType )
throws EventParserConfigurationException {
StringBuffer sb = new StringBuffer();
Matcher m;
! logger.entering( "org.fanfoot.scoring.EventParser",
! "parseEventUID(strData, strType" );
// get the UID element
! EventPattern uidPattern = this.conf.getEventsUIDPattern( strType );
! m = uidPattern.getRegexPattern().matcher( strData );
! logger.finest( "UID pattern is "
! + uidPattern.getRegexPattern().pattern() );
// get the UID parts
! while ( m.find() ) {
// Extract the UID parts and build the UID
! for ( int i = 1; i <= m.groupCount(); i++ ) {
! sb.append( '_' );
! sb.append( m.group( i ).trim() );
}
}
! logger.exiting( "org.fanfoot.scoring.EventParser",
! "parseEventUID(strData, strType" );
// concatenate the parts
***************
*** 277,281 ****
*@param conf New value of property conf.
*/
! public void setConfiguration(EventParserConfiguration conf) {
this.conf = conf;
}
--- 277,281 ----
*@param conf New value of property conf.
*/
! public void setConfiguration( EventParserConfiguration conf ) {
this.conf = conf;
}
***************
*** 289,296 ****
* Exception
*/
! public void loadConfiguration(String strConf)
throws EventParserConfigurationException {
! EventParserConfiguration conf = new EventParserConfiguration(strConf);
! setConfiguration(conf);
}
--- 289,296 ----
* Exception
*/
! public void loadConfiguration( String strConf )
throws EventParserConfigurationException {
! EventParserConfiguration conf = new EventParserConfiguration( strConf );
! setConfiguration( conf );
}
***************
*** 301,307 ****
*@param epl the listener to add
*/
! public synchronized void addListener(EventParserListener epl) {
Vector v = (Vector) listeners.clone();
! v.addElement(epl);
listeners = v;
}
--- 301,307 ----
*@param epl the listener to add
*/
! public synchronized void addListener( EventParserListener epl ) {
Vector v = (Vector) listeners.clone();
! v.addElement( epl );
listeners = v;
}
***************
*** 313,319 ****
*@param epl the listener to remove
*/
! public synchronized void removeListener(EventParserListener epl) {
Vector v = (Vector) listeners.clone();
! v.removeElement(epl);
listeners = v;
}
--- 313,319 ----
*@param epl the listener to remove
*/
! public synchronized void removeListener( EventParserListener epl ) {
Vector v = (Vector) listeners.clone();
! v.removeElement( epl );
listeners = v;
}
***************
*** 322,339 ****
/** Notify all listeners when the commentary has been retrieved */
protected void notifyRetrievedCommentary() {
! logger.entering("org.fanfoot.scoring.EventParser",
! "notifyRetrievedCommentary()");
Vector l;
! EventObject e = new EventObject(this);
l = listeners;
// Atomic assignment
EventParserListener epl = null;
! for(int i = 0; i < l.size(); i++) {
! epl = (EventParserListener) l.elementAt(i);
! epl.retrievedCommentary(e);
}
! logger.entering("org.fanfoot.scoring.EventParser",
! "notifyRetrievedCommentary()");
}
--- 322,339 ----
/** Notify all listeners when the commentary has been retrieved */
protected void notifyRetrievedCommentary() {
! logger.entering( "org.fanfoot.scoring.EventParser",
! "notifyRetrievedCommentary()" );
Vector l;
! EventObject e = new EventObject( this );
l = listeners;
// Atomic assignment
EventParserListener epl = null;
! for ( int i = 0; i < l.size(); i++ ) {
! epl = (EventParserListener) l.elementAt( i );
! epl.retrievedCommentary( e );
}
! logger.entering( "org.fanfoot.scoring.EventParser",
! "notifyRetrievedCommentary()" );
}
***************
*** 348,360 ****
String strCommentary;
try {
! strCommentary = XMLUtils.xmlToString(docCommentary);
! } catch(javax.xml.transform.TransformerConfigurationException tce) {
! logger.log(Level.WARNING,
! "Unable to convert commentary document to string", tce);
strCommentary = "ERROR: Unable to convert commentary document to "
+ "a string due to a Transformer Configuration problem";
! } catch(javax.xml.transform.TransformerException te) {
! logger.log(Level.WARNING,
! "Unable to convert commentary document to string", te);
strCommentary = "ERROR: Unable to convert commentary document to "
+ "a string du to a Transformer problem";
--- 348,360 ----
String strCommentary;
try {
! strCommentary = XMLUtils.xmlToString( docCommentary );
! } catch ( javax.xml.transform.TransformerConfigurationException tce ) {
! logger.log( Level.WARNING,
! "Unable to convert commentary document to string", tce );
strCommentary = "ERROR: Unable to convert commentary document to "
+ "a string due to a Transformer Configuration problem";
! } catch ( javax.xml.transform.TransformerException te ) {
! logger.log( Level.WARNING,
! "Unable to convert commentary document to string", te );
strCommentary = "ERROR: Unable to convert commentary document to "
+ "a string du to a Transformer problem";
|