/* * The MIT License (MIT) * * Copyright (c) 2014 México Abierto * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * For more information visit https://github.com/mxabierto/avisos. */ package mx.org.cedn.avisosconagua.engine; import com.google.publicalerts.cap.Alert; import java.util.ArrayList; import java.util.Date; import mx.org.cedn.avisosconagua.mongo.CAPGenerator; import mx.org.cedn.avisosconagua.mongo.MongoInterface; /** * Utility class to generate an ATOM 1.0 Feed using Google's CAP Library. * @author Hasdai Pacheco */ public class FeedGenerator { /** An object instance from the FeedWriter implementation **/ private final FeedWriter feedWriter; /** Mongo interface object to gather information from MongoDB **/ private static final MongoInterface mi = MongoInterface.getInstance(); /** * Constructor. Creates a new instance of a FeedGenerator using default settings for CONAGUA. */ public FeedGenerator() { feedWriter = new FeedWriter("atom_1.0", "Alertas por ciclones tropicales", "Comisión Nacional del Agua"); feedWriter.setPubDate(new Date(System.currentTimeMillis())); } /** * Constructor. Creates a new instance of a FeedGenerator using the provided information. * @param feedType code for the feed type (atom_1.0, atom_2.0, RSS) * @param feedTitle title for the feed * @param feedAuthor author of the feed */ public FeedGenerator(String feedType, String feedTitle, String feedAuthor) { feedWriter = new FeedWriter("atom_1.0", "Alertas por ciclones tropicales", "Comisión Nacional del Agua"); feedWriter.setPubDate(new Date(System.currentTimeMillis())); } /** * Generates the XML feed. * @return String containing the XMl generated for the feed. */ public String generateXML() { ArrayList<String> alertIds = mi.listPublishedHurricanes(10); for(String id : alertIds) { CAPGenerator gen = new CAPGenerator(id); Alert alert = gen.generateAlert(); feedWriter.addAlert(alert); } return feedWriter.getXML(); } }