/*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2001-2006 The Mir-coders group
*
* This file is part of Mir.
*
*
* In addition, as a special exception, The Mir-coders gives permission to link
* the code of this program with any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
* and distribute linked combinations including the two. You must obey the
* GNU General Public License in all respects for all of the code used other than
* the above mentioned libraries. If you modify this file, you may extend this
*/
package mir.rss;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import mir.util.DateTimeFunctions;
+import mir.util.DateTimeRoutines;
import mir.util.HTTPClientHelper;
import mir.util.xml.XMLParserEngine;
import mir.util.xml.XMLParserExc;
import mir.util.xml.XMLParserFailure;
-/**
- *
- * <p>Title: </p>
- * <p>Description: </p>
- * <p>Copyright: Copyright (c) 2003</p>
- * <p>Company: </p>
- * @author not attributable
- * @version 1.0
- */
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class RSSReader {
public static final String RDF_NAMESPACE_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
public RSSData parseUrl(String anUrl) throws RSSExc, RSSFailure {
try {
- HTTPClientHelper httpClientHelper = new HTTPClientHelper();
+ HTTPClientHelper httpClientHelper = new HTTPClientHelper();
InputStream inputStream = httpClientHelper.getUrl(anUrl);
if (inputStream==null)
throw new RSSExc("RSSChannel.parseUrl: Can't get url content");
if (aTag.getLocalName().equals("RDF")) {
return new RDFSectionHandler(data);
}
- else
- throw new XMLParserFailure(new RSSExc("'RDF' tag expected"));
- };
+ throw new XMLParserFailure(new RSSExc("'RDF' tag expected"));
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
if (aCharacters.trim().length()>0)
throw new XMLParserExc("No character data allowed here");
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
}
private class RDFSectionHandler extends mir.util.xml.AbstractSectionHandler {
String rdfClass = makeQualifiedName(aTag);
return new RDFResourceSectionHandler(rdfClass, identifier);
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof RDFResourceSectionHandler) {
data.addResource(((RDFResourceSectionHandler) aHandler).getResource());
}
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
if (aCharacters.trim().length()>0)
throw new XMLParserExc("No character data allowed here");
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
}
private mir.util.xml.SectionHandler makePropertyValueSectionHandler(mir.util.xml.XMLName aTag, Map anAttributes) {
currentTag = aTag;
return makePropertyValueSectionHandler(aTag, anAttributes);
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof PropertyValueSectionHandler) {
usePropertyValueSectionHandler(resource, (PropertyValueSectionHandler) aHandler, currentTag);
// resource.set(makeQualifiedName(currentTag), ( (PropertyValueSectionHandler) aHandler).getFieldValue());
}
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
if (aCharacters.trim().length()>0)
throw new XMLParserExc("No character data allowed here");
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public RDFResource getResource() {
if ((resource.getIdentifier()==null || resource.getIdentifier().length()==0) && resource.get("rss:link")!=null) {
return new RDFSequenceSectionHandler();
else
return new DiscardingSectionHandler();
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof RDFSequenceSectionHandler) {
structuredData= ((RDFSequenceSectionHandler) aHandler).getItems();
}
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
stringData.append(aCharacters);
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public String getData() {
return stringData.toString();
public Object getValue() {
if (structuredData==null)
return stringData.toString();
- else
- return structuredData;
+ return structuredData;
}
}
return new RDFSequenceSectionHandler();
else
return new DiscardingSectionHandler();
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
if (aHandler instanceof RDFSequenceSectionHandler) {
items.addAll(((RDFSequenceSectionHandler) aHandler).getItems());
}
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
if (aCharacters.trim().length()>0)
throw new XMLParserExc("No character data allowed here");
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public List getItems() {
return items;
public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
throw new XMLParserFailure(new RSSExc("No subtags allowed here"));
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
data.append(aCharacters);
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public String getData() {
return data.toString();
public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
throw new XMLParserFailure(new RSSExc("No subtags allowed here"));
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
data.append(aCharacters);
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public Object getValue() {
try {
String expression = data.toString().trim();
- return DateTimeFunctions.parseW3CDTFString(expression);
+ return DateTimeRoutines.parseW3CDTFString(expression);
}
catch (Throwable t) {
}
return new DiscardingSectionHandler();
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public List getItems() {
return items;
data.append("<"+tag+">");
return new RDFLiteralSectionHandler();
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
data.append(((RDFLiteralSectionHandler) aHandler).getData());
data.append("</"+tag+">");
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
data.append(aCharacters);
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
public Object getValue() {
return data.toString();
private class DiscardingSectionHandler extends mir.util.xml.AbstractSectionHandler {
public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc {
return this;
- };
+ }
public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc {
- };
+ }
public void characters(String aCharacters) throws XMLParserExc {
- };
+ }
public void finishSection() throws XMLParserExc {
- };
+ }
}
}