oscom-lenya-notimes/pubs/ina/java/src/org/oscom MostRecentPublicationDate.java,NONE,1.1 SectionAggregator.java,NONE,1.1
Michael Wechner <[email protected]> Mon, 19 May 2003 23:35:46 +0200
| Newsgroups | gmane.comp.cms.wyona.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /usr/local/repositories/oscom-lenya-notimes/pubs/ina/java/src/org/oscom In directory erbium:/tmp/cvs-serv5456/pubs/ina/java/src/org/oscom Added Files: MostRecentPublicationDate.java SectionAggregator.java Log Message: packages renamed --- NEW FILE: MostRecentPublicationDate.java --- /* * $Id: MostRecentPublicationDate.java,v 1.1 2003/05/19 21:35:43 michi Exp $ * <License> * The Apache Software License * * Copyright (c) 2002 lenya. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * 3. All advertising materials mentioning features or use of this software must * display the following acknowledgment: "This product includes software developed * by lenya (http://www.lenya.org)" * * 4. The name "lenya" must not be used to endorse or promote products derived from * this software without prior written permission. For written permission, please * contact [email protected] * * 5. Products derived from this software may not be called "lenya" nor may "lenya" * appear in their names without prior written permission of lenya. * * 6. Redistributions of any form whatsoever must retain the following acknowledgment: * "This product includes software developed by lenya (http://www.lenya.org)" * * THIS SOFTWARE IS PROVIDED BY lenya "AS IS" WITHOUT ANY WARRANTY EXPRESS OR IMPLIED, * INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED WARRANTIES OF MERCHANTI- * BILITY AND FITNESS FOR A PARTICULAR PURPOSE. lenya WILL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY YOU AS A RESULT OF USING THIS SOFTWARE. IN NO EVENT WILL lenya BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR LOST PROFITS EVEN IF lenya HAS * BEEN ADVISED OF THE POSSIBILITY OF THEIR OCCURRENCE. lenya WILL NOT BE LIABLE FOR ANY * THIRD PARTY CLAIMS AGAINST YOU. * * Lenya includes software developed by the Apache Software Foundation, W3C, * DOM4J Project, BitfluxEditor and Xopus. * </License> */ package org.oscom; import java.io.File; import java.io.FilenameFilter; import java.text.DecimalFormat; import java.util.Arrays; import java.util.Calendar; import java.util.GregorianCalendar; import java.lang.Integer; import org.apache.log4j.Category; /** * This class searches through a publication and searches for the most * recent arcticles. It expects a directory structure as follows: * * rootPath/year/month/day/* * * @author Christian Egli */ public class MostRecentPublicationDate { private static MostRecentPublicationDate singleton; static Category log = Category.getInstance(MostRecentPublicationDate.class); public static MostRecentPublicationDate getInstance() { if (singleton == null) { singleton = new MostRecentPublicationDate(); } return singleton; } // FIXME: the \d doesn't seem to work // public class NumberFilenameFilter implements FilenameFilter { // //Accept all directories of the form 12, 1999 or 04. // public boolean accept(File dir, // String name) { // if (name.matches("\d")) { // return true; // } // return false; // } // //The description of this filter // public String getDescription() { // return "Just Numbers"; // } // } /** * */ public String calendarToString(File rootPath) { Calendar cal = getMostRecentPublicationDate(rootPath); DecimalFormat df = new DecimalFormat("00"); return cal.get(Calendar.YEAR) + File.separator + df.format(cal.get(Calendar.MONTH)) + File.separator + df.format(cal.get(Calendar.DAY_OF_MONTH)); } /** * */ public Calendar getMostRecentPublicationDate(File rootPath) { // NumberFilenameFilter filter = new NumberFilenameFilter(); if (rootPath == null) { return null; } log.debug("rootPath: " + rootPath); String[] years = rootPath.list(); // String[] years = rootPath.list(filter); Arrays.sort(years); String year = years[years.length-1]; log.debug("years: " + years); log.debug("year: " + year); String[] months = (new File(rootPath.getAbsolutePath(), year)).list(); // String[] months = (new File(rootPath.getAbsolutePath(), year)).list(filter); Arrays.sort(months); String month = months[months.length-1]; log.debug("months: " + months); log.debug("month: " + month); String[] days = (new File(rootPath.getAbsolutePath() + File.separator + year, month)).list(); // String[] days = (new File(rootPath.getAbsolutePath() + File.separator + year, month)).list(filter); Arrays.sort(days); String day = days[days.length-1]; log.debug("days: " + days); log.debug("day: " + day); return new GregorianCalendar(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day)); } } --- NEW FILE: SectionAggregator.java --- /* * $Id: SectionAggregator.java,v 1.1 2003/05/19 21:35:43 michi Exp $ * <License> * The Apache Software License * * Copyright (c) 2002 lenya. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * 3. All advertising materials mentioning features or use of this software must * display the following acknowledgment: "This product includes software developed * by lenya (http://www.lenya.org)" * * 4. The name "lenya" must not be used to endorse or promote products derived from * this software without prior written permission. For written permission, please * contact [email protected] * * 5. Products derived from this software may not be called "lenya" nor may "lenya" * appear in their names without prior written permission of lenya. * * 6. Redistributions of any form whatsoever must retain the following acknowledgment: * "This product includes software developed by lenya (http://www.lenya.org)" * * THIS SOFTWARE IS PROVIDED BY lenya "AS IS" WITHOUT ANY WARRANTY EXPRESS OR IMPLIED, * INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED WARRANTIES OF MERCHANTI- * BILITY AND FITNESS FOR A PARTICULAR PURPOSE. lenya WILL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY YOU AS A RESULT OF USING THIS SOFTWARE. IN NO EVENT WILL lenya BE LIABLE * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR LOST PROFITS EVEN IF lenya HAS * BEEN ADVISED OF THE POSSIBILITY OF THEIR OCCURRENCE. lenya WILL NOT BE LIABLE FOR ANY * THIRD PARTY CLAIMS AGAINST YOU. * * Lenya includes software developed by the Apache Software Foundation, W3C, * DOM4J Project, BitfluxEditor and Xopus. * </License> */ package org.oscom; import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; import org.apache.log4j.Category; /** * * @author Michael Wechner */ public class SectionAggregator { static Category log = Category.getInstance(SectionAggregator.class); /** * */ public static void main(String[] args) { if (args.length != 1) { System.err.println("Usage: "); return; } SectionAggregator aggregator = new SectionAggregator(); String dateString = "2003/03/14"; String area = "authoring"; String[] sections = {"culture", "finance", "oped", "politics", "sports", "technology", "topstories"}; for (int i = 0; i < sections.length; i++) { File[] docs = aggregator.aggregate(new File(args[0]), area, dateString, sections[i]); System.err.print("Aggregate: "); for (int j = 0; j < docs.length; j++) { System.err.print(docs[j].getName() + ", "); } } } /** * Return a the first document from a given section for a given * date for each pub in rootDir. * * @param rootDir a <code>File</code> value * @param area can be either 'live' or 'authoring' * @param dateString a <code>String</code> value * @param section a <code>String</code> value * @return a <code>File[]</code> value */ public File[] aggregate(File rootDir, String area, String dateString, String section) { ArrayList docs = new ArrayList(); String articlePath = "content" + File.separator + area + File.separator + "articles"; //String articlePath = "content" + File.separator + "authoring" + File.separator + "articles"; File[] newsPapers = rootDir.listFiles(); for (int i = 0; i < newsPapers.length; i++) { String sectionDirName = newsPapers[i] + File.separator + articlePath + File.separator + dateString + File.separator + section; log.debug("sectionDirName: " + sectionDirName); File sectionDir = new File(sectionDirName); if (sectionDir != null && sectionDir.exists() && sectionDir.isDirectory()) { File[] sectionDocs = sectionDir.listFiles(); if (sectionDocs.length > 0) { // simply use the first article of the section docs.add(sectionDir.listFiles()[0]); } } } return (File[])docs.toArray(new File[docs.size()]); } }