use of com.sun.syndication.feed.WireFeed in project ofbiz-framework by apache.
the class RomeEventHandler method invoke.
/**
* @see org.apache.ofbiz.webapp.event.EventHandler#invoke(ConfigXMLReader.Event, ConfigXMLReader.RequestMap, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public String invoke(Event event, RequestMap requestMap, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException {
RequestHandler handler = (RequestHandler) request.getSession().getServletContext().getAttribute("_REQUEST_HANDLER_");
if (handler == null) {
throw new EventHandlerException("No request handler found in servlet context!");
}
// generate the main and entry links
String entryLinkReq = request.getParameter("entryLinkReq");
String mainLinkReq = request.getParameter("mainLinkReq");
// create the links; but the query string must be created by the service
String entryLink = handler.makeLink(request, response, entryLinkReq, true, false, false);
String mainLink = handler.makeLink(request, response, mainLinkReq, true, false, false);
request.setAttribute("entryLink", entryLink);
request.setAttribute("mainLink", mainLink);
String feedType = request.getParameter("feedType");
if (feedType == null) {
request.setAttribute("feedType", defaultFeedType);
}
// invoke the feed generator service (implements rssFeedInterface)
String respCode = service.invoke(event, requestMap, request, response);
// pull out the RSS feed from the request attributes
WireFeed wireFeed = (WireFeed) request.getAttribute("wireFeed");
response.setContentType(mime);
try {
out.output(wireFeed, response.getWriter());
} catch (IOException e) {
throw new EventHandlerException("Unable to get response writer", e);
} catch (FeedException e) {
throw new EventHandlerException("Unable to write RSS feed", e);
}
return respCode;
}
use of com.sun.syndication.feed.WireFeed in project sis by apache.
the class LocationServlet method init.
/**
* Read GeoRSS data (location information provide sis-location-config.xml )
* and build quad-tree.
*
* @param config
* Servlet configuration file
* @exception ServletException
* General exception for servlet
*/
@SuppressWarnings("unchecked")
public void init(ServletConfig config) throws ServletException {
this.context = config.getServletContext();
long startTime = 0;
long endTime = 0;
int capacity = -1, depth = -1;
this.qtreeIdxPath = this.context.getInitParameter("org.apache.sis.services.config.qIndexPath");
this.georssStoragePath = this.context.getInitParameter("org.apache.sis.services.config.geodataPath");
if (!this.qtreeIdxPath.endsWith("/"))
this.qtreeIdxPath += "/";
if (!this.georssStoragePath.endsWith("/"))
this.georssStoragePath += "/";
InputStream indexStream = null;
try {
indexStream = new FileInputStream(qtreeIdxPath + "node_0.txt");
} catch (FileNotFoundException e) {
System.out.println("[INFO] Existing qtree index at: [" + qtreeIdxPath + "] not found. Creating new index.");
}
if (indexStream != null) {
startTime = System.currentTimeMillis();
this.tree = QuadTreeReader.readFromFile(qtreeIdxPath, "tree_config.txt", "node_0.txt");
try {
indexStream.close();
} catch (IOException e) {
e.printStackTrace();
}
endTime = System.currentTimeMillis();
this.timeToLoad = "Quad Tree fully loaded from index files in " + Double.toString((endTime - startTime) / 1000L) + " seconds";
System.out.println("[INFO] Finished loading tree from stored index");
} else {
startTime = System.currentTimeMillis();
WireFeedInput wf = new WireFeedInput(true);
// read quad tree properties set in config xml file
InputStream configStream = null;
try {
configStream = new FileInputStream(this.context.getInitParameter("org.apache.sis.services.config.filePath"));
} catch (Exception e) {
e.printStackTrace();
}
if (configStream != null) {
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document configDoc = docBuilder.parse(configStream);
NodeList capacityNode = configDoc.getElementsByTagName("capacity");
if (capacityNode.item(0) != null) {
capacity = Integer.parseInt(capacityNode.item(0).getFirstChild().getNodeValue());
}
NodeList depthNode = configDoc.getElementsByTagName("depth");
if (depthNode.item(0) != null) {
depth = Integer.parseInt(depthNode.item(0).getFirstChild().getNodeValue());
}
// TODO make this
this.tree = new QuadTree(capacity, depth);
// configurable
NodeList urlNodes = configDoc.getElementsByTagName("url");
for (int i = 0; i < urlNodes.getLength(); i++) {
// read in georss and build tree
String georssUrlStr = urlNodes.item(i).getFirstChild().getNodeValue();
WireFeed feed = null;
try {
feed = wf.build(new XmlReader(new URL(georssUrlStr)));
} catch (Exception e) {
System.out.println("[ERROR] Error obtaining geodata url: [" + georssUrlStr + "]: Message: " + e.getMessage() + ": skipping and continuing");
continue;
}
Channel c = (Channel) feed;
List<Item> items = (List<Item>) c.getItems();
for (Item item : items) {
GeoRSSModule geoRSSModule = (GeoRSSModule) item.getModule(GeoRSSModule.GEORSS_GEORSS_URI);
if (geoRSSModule == null)
geoRSSModule = (GeoRSSModule) item.getModule(GeoRSSModule.GEORSS_GML_URI);
if (geoRSSModule == null)
geoRSSModule = (GeoRSSModule) item.getModule(GeoRSSModule.GEORSS_W3CGEO_URI);
// then discard it
if (geoRSSModule != null && geoRSSModule.getPosition() != null) {
String filename = "";
if (item.getGuid() != null)
filename = cleanStr(item.getGuid().getValue()) + ".txt";
else
filename = cleanStr(item.getLink()) + ".txt";
GeoRSSData data = new GeoRSSData(filename, new DirectPosition2D(geoRSSModule.getPosition().getLongitude(), geoRSSModule.getPosition().getLatitude()));
if (this.tree.insert(data)) {
data.saveToFile(item, geoRSSModule, georssStoragePath);
} else {
System.out.println("[INFO] Unable to store data at location " + data.getLatLon().y + ", " + data.getLatLon().x + " under filename " + data.getFileName());
}
}
}
}
configStream.close();
endTime = System.currentTimeMillis();
this.timeToLoad = "Quad Tree fully loaded from retrieving GeoRSS files over the network in " + Double.toString((endTime - startTime) / 1000L) + " seconds";
QuadTreeWriter.writeTreeToFile(tree, qtreeIdxPath);
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
} else {
throw new ServletException("Unable to read location service XML config: null!");
}
}
}
Aggregations