- cora package has now no dependencies to other yacy packages and becomes a 'base' package (refactoring)

- cleaned up (removed special code and documentation for 27c3)
- added remote search functions to be used within cora

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7420 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent 0e54233408
commit 10ae8d961b

@ -37,6 +37,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.document.Document;
@ -44,7 +45,6 @@ import net.yacy.document.Parser;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.crawler.CrawlProfile;
import de.anomic.data.BookmarkHelper;
@ -316,7 +316,7 @@ public class Bookmarks {
}
prop.putHTML("display_bookmarks_"+count+"_title", bookmark.getTitle());
prop.putHTML("display_bookmarks_"+count+"_description", bookmark.getDescription());
prop.put("display_bookmarks_"+count+"_date", DateFormatter.formatISO8601(new Date(bookmark.getTimeStamp())));
prop.put("display_bookmarks_"+count+"_date", ISO8601Formatter.FORMATTER.format(new Date(bookmark.getTimeStamp())));
prop.put("display_bookmarks_"+count+"_rfc822date", HeaderFramework.formatRFC1123(new Date(bookmark.getTimeStamp())));
prop.put("display_bookmarks_"+count+"_public", (bookmark.getPublic() ? "1" : "0"));

@ -35,7 +35,6 @@ import java.util.Set;
import net.yacy.cora.protocol.ConnectionInfo;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.workflow.WorkflowThread;
//import de.anomic.http.client.ConnectionInfo;
@ -45,6 +44,7 @@ import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.server.serverCore.Session;
import de.anomic.yacy.yacyPeerActions;
import de.anomic.yacy.yacySeed;
public final class Connections_p {
@ -117,7 +117,7 @@ public final class Connections_p {
prop.put("list_" + idx + "_proto", prot);
if (sessionTime > 1000*60) {
prop.put("list_" + idx + "_ms", "0");
prop.put("list_" + idx + "_ms_duration",DateFormatter.formatInterval(sessionTime));
prop.put("list_" + idx + "_ms_duration",yacyPeerActions.formatInterval(sessionTime));
} else {
prop.put("list_" + idx + "_ms", "1");
prop.putNum("list_" + idx + "_ms_duration", sessionTime);

@ -23,14 +23,14 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import java.io.File;
import java.util.Date;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.document.content.dao.Dao;
import net.yacy.document.content.dao.ImportDump;
import net.yacy.document.content.dao.PhpBB3Dao;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
@ -107,7 +107,7 @@ public class ContentIntegrationPHPBB3_p {
dbpw
);
int files = db.writeSurrogates(db.query(0, -1, 100), sb.surrogatesInPath, "fullexport-" + DateFormatter.formatShortSecond(), ppf);
int files = db.writeSurrogates(db.query(0, -1, 100), sb.surrogatesInPath, "fullexport-" + GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date()), ppf);
prop.put("export", 1);
prop.put("export_files", files);
db.close();

@ -164,7 +164,7 @@ public class CrawlStartScanner_p {
// execute the scan results
if (Scanner.scancacheSize() > 0) {
// make a comment cache
Map<byte[], String> apiCommentCache = Scanner.commentCache(sb);
Map<byte[], String> apiCommentCache = WorkTables.commentCache(sb);
String urlString;
DigestURI u;
@ -196,7 +196,7 @@ public class CrawlStartScanner_p {
// write scan table
if (Scanner.scancacheSize() > 0) {
// make a comment cache
Map<byte[], String> apiCommentCache = Scanner.commentCache(sb);
Map<byte[], String> apiCommentCache = WorkTables.commentCache(sb);
// show scancache table
prop.put("servertable", 1);

@ -34,6 +34,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.document.Condenser;
import net.yacy.kelondro.data.meta.DigestURI;
@ -49,7 +50,6 @@ import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.rwi.Reference;
import net.yacy.kelondro.rwi.ReferenceContainer;
import net.yacy.kelondro.rwi.ReferenceContainerCache;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.repository.Blacklist;
@ -432,7 +432,7 @@ public class IndexControlRWIs_p {
prop.putNum("genUrlList_urlList_"+i+"_urlExists_ybr", RankingProcess.ybr(entry.hash()));
prop.putNum("genUrlList_urlList_"+i+"_urlExists_tf", 1000.0 * entry.word().termFrequency());
prop.putNum("genUrlList_urlList_"+i+"_urlExists_authority", (ranked.getOrder() == null) ? -1 : ranked.getOrder().authority(entry.hash()));
prop.put("genUrlList_urlList_"+i+"_urlExists_date", DateFormatter.formatShortDay(new Date(entry.word().lastModified())));
prop.put("genUrlList_urlList_"+i+"_urlExists_date", GenericFormatter.SHORT_DAY_FORMATTER.format(new Date(entry.word().lastModified())));
prop.putNum("genUrlList_urlList_"+i+"_urlExists_wordsintitle", entry.word().wordsintitle());
prop.putNum("genUrlList_urlList_"+i+"_urlExists_wordsintext", entry.word().wordsintext());
prop.putNum("genUrlList_urlList_"+i+"_urlExists_phrasesintext", entry.word().phrasesintext());

@ -28,8 +28,10 @@
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Date;
import java.util.Iterator;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.meta.URIMetadataRow;
@ -37,8 +39,6 @@ import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.RotateIterator;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.crawler.CrawlProfile;
import de.anomic.search.MetadataRepository;
import de.anomic.search.Segment;
@ -102,7 +102,7 @@ public class IndexControlURLs_p {
prop.put("reload", 1);
} else {
prop.put("lurlexport", 1);
prop.put("lurlexport_exportfile", sb.getDataPath() + "/DATA/EXPORT/" + DateFormatter.formatShortSecond());
prop.put("lurlexport_exportfile", sb.getDataPath() + "/DATA/EXPORT/" + GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date()));
if (export == null) {
// there has never been an export
prop.put("lurlexportfinished", 0);

@ -39,7 +39,6 @@ import java.util.regex.PatternSyntaxException;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.MapTools;
//import de.anomic.http.client.Client;
@ -50,6 +49,7 @@ import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyClient;
import de.anomic.yacy.yacyNewsDB;
import de.anomic.yacy.yacyNewsPool;
import de.anomic.yacy.yacyPeerActions;
import de.anomic.yacy.yacySeed;
import de.anomic.yacy.yacyVersion;
@ -131,7 +131,7 @@ public class Network {
myqph = 60d * sb.averageQPM();
prop.put("table_my-version", seed.get(yacySeed.VERSION, "-"));
prop.put("table_my-utc", seed.get(yacySeed.UTC, "-"));
prop.put("table_my-uptime", DateFormatter.formatInterval(60000 * Long.parseLong(seed.get(yacySeed.UPTIME, ""))));
prop.put("table_my-uptime", yacyPeerActions.formatInterval(60000 * Long.parseLong(seed.get(yacySeed.UPTIME, ""))));
prop.putNum("table_my-LCount", LCount);
prop.putNum("table_my-ICount", ICount);
prop.putNum("table_my-RCount", RCount);
@ -437,7 +437,7 @@ public class Network {
prop.putHTML(STR_TABLE_LIST + conCount + "_version", yacyVersion.combined2prettyVersion(seed.get(yacySeed.VERSION, "0.1"), shortname));
prop.putNum(STR_TABLE_LIST + conCount + "_lastSeen", /*seed.getLastSeenString() + " " +*/ lastseen);
prop.put(STR_TABLE_LIST + conCount + "_utc", seed.get(yacySeed.UTC, "-"));
prop.putHTML(STR_TABLE_LIST + conCount + "_uptime", DateFormatter.formatInterval(60000 * Long.parseLong(seed.get(yacySeed.UPTIME, "0"))));
prop.putHTML(STR_TABLE_LIST + conCount + "_uptime", yacyPeerActions.formatInterval(60000 * Long.parseLong(seed.get(yacySeed.UPTIME, "0"))));
prop.putNum(STR_TABLE_LIST + conCount + "_LCount", seed.getLinkCount());
prop.putNum(STR_TABLE_LIST + conCount + "_ICount", seed.getWordCount());
prop.putNum(STR_TABLE_LIST + conCount + "_RCount", seed.getLong(yacySeed.RCOUNT, 0));

@ -28,11 +28,10 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
@ -117,10 +116,10 @@ public class News {
final String category = record.category();
prop.put("table_list_" + i + "_id", record.id());
prop.putHTML("table_list_" + i + "_ori", (seed == null) ? record.originator() : seed.getName());
prop.put("table_list_" + i + "_cre", DateFormatter.formatShortSecond(record.created()));
prop.put("table_list_" + i + "_cre", GenericFormatter.SHORT_SECOND_FORMATTER.format(record.created()));
prop.put("table_list_" + i + "_crerfcdate", HeaderFramework.formatRFC1123(record.created()));
prop.putHTML("table_list_" + i + "_cat", category);
prop.put("table_list_" + i + "_rec", (record.received() == null) ? "-" : DateFormatter.formatShortSecond(record.received()));
prop.put("table_list_" + i + "_rec", (record.received() == null) ? "-" : GenericFormatter.SHORT_SECOND_FORMATTER.format(record.received()));
prop.put("table_list_" + i + "_dis", record.distributed());
final Map<String, String> attributeMap = record.attributes();

@ -31,13 +31,13 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.data.WorkTables;
import de.anomic.search.Switchboard;
import de.anomic.search.SwitchboardConstants;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyPeerActions;
import de.anomic.yacy.yacySeed;
import de.anomic.yacy.yacyVersion;
@ -119,7 +119,7 @@ public class RemoteCrawl_p {
prop.putHTML(STR_TABLE_LIST + conCount + "_version", yacyVersion.combined2prettyVersion(seed.get(yacySeed.VERSION, "0.1"), shortname));
prop.putNum(STR_TABLE_LIST + conCount + "_lastSeen", /*seed.getLastSeenString() + " " +*/ lastseen);
prop.put(STR_TABLE_LIST + conCount + "_utc", seed.get(yacySeed.UTC, "-"));
prop.putHTML(STR_TABLE_LIST + conCount + "_uptime", DateFormatter.formatInterval(60000 * Long.parseLong(seed.get(yacySeed.UPTIME, "0"))));
prop.putHTML(STR_TABLE_LIST + conCount + "_uptime", yacyPeerActions.formatInterval(60000 * Long.parseLong(seed.get(yacySeed.UPTIME, "0"))));
prop.putNum(STR_TABLE_LIST + conCount + "_LCount", seed.getLinkCount());
prop.putNum(STR_TABLE_LIST + conCount + "_ICount", seed.getWordCount());
prop.putNum(STR_TABLE_LIST + conCount + "_RCount", rcount);

@ -40,7 +40,6 @@ import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.Digest;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.Formatter;
import de.anomic.http.server.HTTPDemon;
@ -50,6 +49,7 @@ import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacyPeerActions;
import de.anomic.yacy.yacySeed;
import de.anomic.yacy.yacySeedUploader;
@ -524,7 +524,7 @@ public class SettingsAck_p {
}
// everything is ok
prop.put("info_crawler.clientTimeout",(crawlerTimeout==0) ? "0" :DateFormatter.formatInterval(crawlerTimeout));
prop.put("info_crawler.clientTimeout",(crawlerTimeout==0) ? "0" :yacyPeerActions.formatInterval(crawlerTimeout));
prop.put("info_crawler.http.maxFileSize",(maxHttpSize==-1)? "-1":Formatter.bytesToString(maxHttpSize));
prop.put("info_crawler.ftp.maxFileSize", (maxFtpSize==-1) ? "-1":Formatter.bytesToString(maxFtpSize));
prop.put("info_crawler.smb.maxFileSize", (maxSmbSize==-1) ? "-1":Formatter.bytesToString(maxSmbSize));

@ -33,9 +33,6 @@ import java.util.Date;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.io.ByteCount;
//import net.yacy.kelondro.io.ByteCountInputStream;
//import net.yacy.kelondro.io.ByteCountOutputStream;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.Formatter;
import net.yacy.kelondro.util.MemoryControl;
import net.yacy.kelondro.util.OS;
@ -48,6 +45,7 @@ import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacyBuildProperties;
import de.anomic.yacy.yacyPeerActions;
import de.anomic.yacy.yacySeed;
public class Status {
@ -203,7 +201,7 @@ public class Status {
} else {
final long uptime = 60000 * Long.parseLong(sb.peers.mySeed().get(yacySeed.UPTIME, "0"));
prop.put("peerStatistics", "1");
prop.put("peerStatistics_uptime", DateFormatter.formatInterval(uptime));
prop.put("peerStatistics_uptime", yacyPeerActions.formatInterval(uptime));
prop.putNum("peerStatistics_pagesperminute", sb.peers.mySeed().getPPM());
prop.putNum("peerStatistics_queriesperhour", Math.round(6000d * sb.peers.mySeed().getQPM()) / 100d);
prop.putNum("peerStatistics_links", sb.peers.mySeed().getLinkCount());
@ -262,7 +260,7 @@ public class Status {
prop.putHTML("seedServer_seedFile", sb.getConfig("seedFilePath", ""));
}
prop.put("seedServer_lastUpload",
DateFormatter.formatInterval(System.currentTimeMillis() - sb.peers.lastSeedUpload_timeStamp));
yacyPeerActions.formatInterval(System.currentTimeMillis() - sb.peers.lastSeedUpload_timeStamp));
} else {
prop.put(SEEDSERVER, "0"); // disabled
}

@ -31,6 +31,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.storage.DynamicScore;
import net.yacy.cora.storage.ScoreCluster;
@ -38,7 +39,6 @@ import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.index.Row;
import net.yacy.kelondro.index.Row.Entry;
import net.yacy.kelondro.order.NaturalOrder;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.repository.Blacklist;
import de.anomic.search.Switchboard;
@ -106,7 +106,7 @@ public class Supporter {
//accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);
//accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.PUBLISHED_DB);
final DynamicScore<String> ranking = new ScoreCluster<String>(); // score cluster for url hashes
final Row rowdef = new Row("String url-255, String title-120, String description-120, String refid-" + (DateFormatter.PATTERN_SHORT_SECOND.length() + 12), NaturalOrder.naturalOrder);
final Row rowdef = new Row("String url-255, String title-120, String description-120, String refid-" + (GenericFormatter.PATTERN_SHORT_SECOND.length() + 12), NaturalOrder.naturalOrder);
final HashMap<String, Entry> Supporter = new HashMap<String, Entry>(); // a mapping from an url hash to a kelondroRow.Entry with display properties
accumulateSupporter(sb, Supporter, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.INCOMING_DB);
//accumulateSupporter(Supporter, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);

@ -31,6 +31,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.storage.DynamicScore;
import net.yacy.cora.storage.ScoreCluster;
@ -38,7 +39,6 @@ import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.index.Row;
import net.yacy.kelondro.index.Row.Entry;
import net.yacy.kelondro.order.NaturalOrder;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.repository.Blacklist;
import de.anomic.search.Switchboard;
@ -114,7 +114,7 @@ public class Surftips {
//accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);
//accumulateVotes(negativeHashes, positiveHashes, yacyNewsPool.PUBLISHED_DB);
final DynamicScore<String> ranking = new ScoreCluster<String>(); // score cluster for url hashes
final Row rowdef = new Row("String url-255, String title-120, String description-120, String refid-" + (DateFormatter.PATTERN_SHORT_SECOND.length() + 12), NaturalOrder.naturalOrder);
final Row rowdef = new Row("String url-255, String title-120, String description-120, String refid-" + (GenericFormatter.PATTERN_SHORT_SECOND.length() + 12), NaturalOrder.naturalOrder);
final HashMap<String, Entry> surftips = new HashMap<String, Entry>(); // a mapping from an url hash to a kelondroRow.Entry with display properties
accumulateSurftips(sb, surftips, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.INCOMING_DB);
//accumulateSurftips(surftips, ranking, rowdef, negativeHashes, positiveHashes, yacyNewsPool.OUTGOING_DB);

@ -3,10 +3,10 @@
import java.util.Date;
import java.util.Iterator;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.document.parser.html.CharacterCoding;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.data.BookmarkHelper;
import de.anomic.data.BookmarksDB;
@ -160,7 +160,7 @@ public class get_bookmarks {
if (bookmark != null) {
prop.put("display_bookmarks_"+count+"_id",count);
prop.put("display_bookmarks_"+count+"_link",bookmark.getUrl());
prop.put("display_bookmarks_"+count+"_date", DateFormatter.formatISO8601(new Date(bookmark.getTimeStamp())));
prop.put("display_bookmarks_"+count+"_date", ISO8601Formatter.FORMATTER.format(new Date(bookmark.getTimeStamp())));
prop.put("display_bookmarks_"+count+"_rfc822date", HeaderFramework.formatRFC1123(new Date(bookmark.getTimeStamp())));
prop.put("display_bookmarks_"+count+"_public", (bookmark.getPublic() ? "0" : "1"));
prop.put("display_bookmarks_"+count+"_hash", bookmark.getUrlHash());
@ -253,7 +253,7 @@ public class get_bookmarks {
date = new Date(bookmark.getTimeStamp());
prop.put("display_xbel_"+count+"_elements", "<bookmark id=\"" + bookmark.getUrlHash()
+ "\" href=\"" + CharacterCoding.unicode2xml(bookmark.getUrl(), true)
+ "\" added=\"" + CharacterCoding.unicode2xml(DateFormatter.formatISO8601(date), true)+"\">");
+ "\" added=\"" + CharacterCoding.unicode2xml(ISO8601Formatter.FORMATTER.format(date), true)+"\">");
count++;
prop.put("display_xbel_"+count+"_elements", "<title>");
count++;

@ -2,9 +2,9 @@
import java.util.Date;
import java.util.Iterator;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.order.Digest;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.data.BookmarksDB;
import de.anomic.search.Switchboard;
@ -37,8 +37,8 @@ public class all {
prop.putXML("posts_"+count+"_title", bookmark.getTitle());
prop.putXML("posts_"+count+"_description", bookmark.getDescription());
prop.putXML("posts_"+count+"_md5", Digest.encodeMD5Hex(bookmark.getUrl()));
date=new Date(bookmark.getTimeStamp());
prop.putXML("posts_"+count+"_time", DateFormatter.formatISO8601(date));
date = new Date(bookmark.getTimeStamp());
prop.putXML("posts_"+count+"_time", ISO8601Formatter.FORMATTER.format(date));
prop.putXML("posts_"+count+"_tags", bookmark.getTagsString().replaceAll(","," "));
// additional XML tags

@ -4,10 +4,9 @@ import java.text.ParseException;
import java.util.Date;
import java.util.List;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.order.Digest;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.data.BookmarksDB;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
@ -24,12 +23,12 @@ public class get {
//String url=""; //urlfilter not yet implemented
if (post != null && post.containsKey("tag")) {
tag=post.get("tag");
tag = post.get("tag");
}
if (post != null && post.containsKey("date")) {
date=post.get("date");
date = post.get("date");
} else {
date=DateFormatter.formatISO8601(new Date(System.currentTimeMillis()));
date = ISO8601Formatter.FORMATTER.format(new Date(System.currentTimeMillis()));
}
// if an extended xml should be used
@ -39,7 +38,7 @@ public class get {
Date parsedDate = null;
try {
parsedDate = DateFormatter.parseISO8601(date);
parsedDate = ISO8601Formatter.FORMATTER.parse(date);
} catch (final ParseException e) {
parsedDate = new Date();
}
@ -48,7 +47,7 @@ public class get {
BookmarksDB.Bookmark bookmark = null;
for (final String bookmark_hash : bookmark_hashes){
bookmark=switchboard.bookmarksDB.getBookmark(bookmark_hash);
if(DateFormatter.formatISO8601(new Date(bookmark.getTimeStamp())).equals(date) &&
if (ISO8601Formatter.FORMATTER.format(new Date(bookmark.getTimeStamp())).equals(date) &&
tag==null || bookmark.getTags().contains(tag) &&
isAdmin || bookmark.getPublic()){
prop.putHTML("posts_"+count+"_url", bookmark.getUrl());

@ -3,10 +3,9 @@
import java.util.Date;
import java.util.Iterator;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.document.parser.html.CharacterCoding;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.data.BookmarkHelper;
import de.anomic.data.BookmarksDB;
import de.anomic.search.Switchboard;
@ -111,7 +110,7 @@ public class xbel {
date=new Date(bookmark.getTimeStamp());
prop.put("xbel_"+count+"_elements", "<bookmark id=\"" + bookmark.getUrlHash()
+ "\" href=\"" + CharacterCoding.unicode2xml(bookmark.getUrl(), true)
+ "\" added=\"" + CharacterCoding.unicode2xml(DateFormatter.formatISO8601(date), true)+"\">");
+ "\" added=\"" + CharacterCoding.unicode2xml(ISO8601Formatter.FORMATTER.format(date), true)+"\">");
count++;
prop.put("xbel_"+count+"_elements", "<title>");
count++;

@ -25,9 +25,8 @@ import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.crawler.Latency;
import de.anomic.crawler.NoticedURL;
import de.anomic.crawler.Latency.Host;
@ -49,7 +48,7 @@ public class latency_p {
host = e.getValue();
prop.putXML("domains_" + c + "_hosthash", e.getKey());
prop.putXML("domains_" + c + "_host", host.host());
prop.putXML("domains_" + c + "_lastaccess", DateFormatter.formatShortSecond(new Date(host.lastacc())));
prop.putXML("domains_" + c + "_lastaccess", GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date(host.lastacc())));
prop.put("domains_" + c + "_count", host.count());
prop.put("domains_" + c + "_average", host.average());
prop.put("domains_" + c + "_robots", host.robotsDelay());

@ -28,6 +28,7 @@ import java.util.Date;
import java.util.Iterator;
import java.util.TreeSet;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.data.word.WordReference;
@ -36,7 +37,6 @@ import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.rwi.ReferenceContainer;
import net.yacy.kelondro.rwi.TermSearch;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.ISO639;
import de.anomic.search.QueryParams;
@ -108,7 +108,7 @@ public final class timeline {
while (i.hasNext() && c < count) {
entry = i.next();
lm = new Date(entry.lastModified());
lms = DateFormatter.formatANSIC(lm);
lms = GenericFormatter.ANSIC_FORMATTER.format(lm);
prop.put("event_" + c + "_start", lms); // like "Wed May 01 1963 00:00:00 GMT-0600"
prop.put("event_" + c + "_end", lms); // like "Sat Jun 01 1963 00:00:00 GMT-0600"
prop.put("event_" + c + "_isDuration", 0); // 0 (only a point) or 1 (period of time)

@ -6,6 +6,7 @@ import java.util.EnumMap;
import java.util.Iterator;
import java.util.TreeMap;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.document.Document;
import net.yacy.document.Parser.Failure;
@ -14,7 +15,6 @@ import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.crawler.CrawlProfile;
import de.anomic.crawler.retrieval.Response;
import de.anomic.data.UserDB;
@ -147,7 +147,7 @@ public class get_treeview {
if(key.startsWith("date")) {
final String d = new String(bmk_row.get(key));
if(!d.isEmpty()) {
final String date = DateFormatter.formatISO8601(new Date(Long.parseLong(d)));
final String date = ISO8601Formatter.FORMATTER.format(new Date(Long.parseLong(d)));
prop.put("folders_"+count+"_foldername","<small><b>"+key+":</b> " + date + "</small>");
putProp(count, "date");
count++;

@ -30,12 +30,12 @@ import java.io.File;
import java.io.IOException;
import java.util.Date;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.document.ImageParser;
import net.yacy.document.parser.html.CharacterCoding;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
import de.anomic.search.Switchboard;
@ -52,7 +52,7 @@ public class cytag {
// harvest request information
StringBuilder connect = new StringBuilder();
connect.append('{');
appendJSON(connect, "time", DateFormatter.formatShortMilliSecond(new Date()));
appendJSON(connect, "time", GenericFormatter.SHORT_MILSEC_FORMATTER.format(new Date()));
appendJSON(connect, "trail", (referer == null) ? "" : referer.toNormalform(false, false));
appendJSON(connect, "nick", (post == null) ? "" : post.get("nick", ""));
appendJSON(connect, "tag", (post == null) ? "" : post.get("tag", ""));

@ -28,12 +28,12 @@
// if the shell's current path is HTROOT
import java.io.IOException;
import java.util.Date;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.search.Segments;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
@ -75,7 +75,7 @@ public final class query {
final String obj = post.get("object", ""); // keyword for query subject
final String env = post.get("env", ""); // argument to query
prop.put("mytime", DateFormatter.formatShortSecond());
prop.put("mytime", GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date()));
// check if we are the right target and requester has correct information about this peer
if (sb.peers.mySeed() == null || !sb.peers.mySeed().hash.equals(youare)) {

@ -29,11 +29,11 @@
import java.io.IOException;
import java.text.ParseException;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.document.RSSMessage;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.repository.Blacklist;
import de.anomic.crawler.retrieval.EventOrigin;
@ -52,7 +52,7 @@ public final class transferURL {
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) throws InterruptedException {
final long start = System.currentTimeMillis();
long freshdate = 0;
try {freshdate = DateFormatter.parseShortDay("20061101").getTime();} catch (final ParseException e1) {}
try {freshdate = GenericFormatter.SHORT_DAY_FORMATTER.parse("20061101").getTime();} catch (final ParseException e1) {}
// return variable that accumulates replacements
final Switchboard sb = (Switchboard) env;

@ -27,11 +27,10 @@
import java.io.IOException;
import java.util.Date;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.crawler.NoticedURL;
import de.anomic.crawler.retrieval.Request;
import de.anomic.search.Segments;
@ -93,7 +92,7 @@ public class urls {
prop.putXML("item_" + c + "_referrer", (referrer == null) ? "" : referrer.toNormalform(true, false));
prop.putXML("item_" + c + "_description", entry.name());
prop.put("item_" + c + "_author", "");
prop.put("item_" + c + "_pubDate", DateFormatter.formatShortSecond(entry.appdate()));
prop.put("item_" + c + "_pubDate", GenericFormatter.SHORT_SECOND_FORMATTER.format(entry.appdate()));
prop.put("item_" + c + "_guid", entry.url().hash());
c++;
maxCount--;
@ -123,7 +122,7 @@ public class urls {
prop.putXML("item_" + c + "_referrer", (referrer == null) ? "" : referrer.toNormalform(true, false));
prop.putXML("item_" + c + "_description", metadata.dc_title());
prop.put("item_" + c + "_author", metadata.dc_creator());
prop.put("item_" + c + "_pubDate", DateFormatter.formatShortSecond(entry.moddate()));
prop.put("item_" + c + "_pubDate", GenericFormatter.SHORT_SECOND_FORMATTER.format(entry.moddate()));
prop.put("item_" + c + "_guid", new String(entry.hash()));
c++;
}

@ -68,25 +68,7 @@ To see a list of all APIs, please visit the <a href="http://www.yacy-websuche.de
</div>
<div id="downloadscript" style="clear:both;"></div>
<div id="searchresults" style="clear:both;">
<h3>DECENTRALIZE - run this search portal yourself (if you like). Just follow these steps:</h3>
<ul>
<li>download the software from yacy.net and run it. (you need OpenJDK6). A http server is started and serves the administration pages.</li>
<li>open http://localhost:8080/ConfigBasic.html and select 'Search portal for your own web pages' ('Intranet Indexing' if you wanto to do this for your / other network) -> Set Configuration</li>
<li>click on 'System Update' and use 'Automatic Update' to get the latest features which are needed for this. The Peer re-starts automatically. Wait and open http://localhost:8080 again.</li>
<li>click 'Index Creation' -> 'Network Scanner' ( http://localhost:8080/CrawlStartScanner_p.html )</li>
<li>in 'Scan Range' enter some IPs (comma-separated) that shall be used as prototype for a 255.255.255.0 subrange. I use '81.163.150.96,81.163.2.42,81.163.18.81,81.163.62.38,81.163.22.118, 81.163.112.96' (without quotes)</li>
<li>at 'Scheduler' select 'scan and add all sites with granted access automatically' -> Scan. Wait. This makes a portscan and ftp/smb access test on the given range. Wait at least one minute. Keep calm.</li>
<li>You should now see a list of hosts that are crawled. Your CPU load should increase. All IPs are scanned every 10 minutes, but crawls are done only for new visible servers.</li>
<li>You can monitor the crawler at 'Crawler Monitor' ( http://localhost:8080/Crawler_p.html ).</li>
<li>You may want to increase the memory at 'Admin Console' -> 'Performance' ( http://localhost:8080/Performance_p.html ) (you must restart then but wait until the FTP site-listing is done it is lost otherwards :-(</li>
<li>Please set a very low download limit at 'Advanced Settings' -> 'Crawler Settings' ( http://localhost:8080/Settings_p.html?page=crawler ) .. if documents are not loaded, just their document name is indexed.</li>
<li>Ready - search at 'Interactive local search' ( http://localhost:8080/yacyinteractive.html )</li>
<li>You may want to set a peer password at http://localhost:8080/ConfigAccounts_p.html</li>
<li>Get the right look at http://localhost:8080/ConfigAppearance_p.html and select the 27c3 Skin</li>
<li>Set search page descriptions and images at http://localhost:8080/ConfigPortal.html</li>
<li>Visit our <a href="http://forum.yacy-websuche.de/viewtopic.php?p=21332#p21332">forum</a> if there are any questions.</li>
</ul>
<div><img src="PerformanceGraph.png" id="graph" alt="PerformanceGraph" width="660" height="240"/></div>
<!-- <div><img src="PerformanceGraph.png" id="graph" alt="PerformanceGraph" width="660" height="240"/></div> -->
</div>
<script type="text/javascript">
//<![CDATA[

@ -20,6 +20,7 @@
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import net.yacy.cora.document.RSSMessage;
@ -91,7 +92,8 @@ public class yacysearch_location {
if (search_title || search_publisher || search_creator || search_subject) try {
// get a queue of search results
String rssSearchServiceURL = "http://localhost:" + sb.getConfig("port", "8080") + "/yacysearch.rss";
BlockingQueue<RSSMessage> results = Search.search(rssSearchServiceURL, query, false, false, maximumTime, Integer.MAX_VALUE);
BlockingQueue<RSSMessage> results = new LinkedBlockingQueue<RSSMessage>();
Search.searchSRURSS(rssSearchServiceURL, query, maximumTime, Integer.MAX_VALUE, false, false, results);
// take the results and compute some locations
RSSMessage message;

@ -28,11 +28,11 @@ import java.net.MalformedURLException;
import java.util.List;
import java.util.TreeSet;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.EventTracker;
import net.yacy.kelondro.util.Formatter;
@ -116,7 +116,7 @@ public class yacysearchitem {
prop.put("content", 1); // switch on specific content
prop.put("content_authorized", authenticated ? "1" : "0");
prop.put("content_authorized_recommend", "0" /*(sb.peers.newsPool.getSpecific(yacyNewsPool.OUTGOING_DB, yacyNewsPool.CATEGORY_SURFTIPP_ADD, "url", result.urlstring()) == null) ? "1" : "0"*/); // emergency fix! please re-design net.yacy.kelondro.table.ChunkIterator.<init>(ChunkIterator.java:63)
prop.put("content_authorized_recommend", (sb.peers.newsPool.getSpecific(yacyNewsPool.OUTGOING_DB, yacyNewsPool.CATEGORY_SURFTIPP_ADD, "url", result.urlstring()) == null) ? "1" : "0");
prop.putHTML("content_authorized_recommend_deletelink", "/yacysearch.html?query=" + theQuery.queryString.replace(' ', '+') + "&Enter=Search&count=" + theQuery.displayResults() + "&offset=" + (theQuery.neededResults() - theQuery.displayResults()) + "&order=" + crypt.simpleEncode(theQuery.ranking.toExternalString()) + "&resource=local&time=3&deleteref=" + new String(result.hash()) + "&urlmaskfilter=.*");
prop.putHTML("content_authorized_recommend_recommendlink", "/yacysearch.html?query=" + theQuery.queryString.replace(' ', '+') + "&Enter=Search&count=" + theQuery.displayResults() + "&offset=" + (theQuery.neededResults() - theQuery.displayResults()) + "&order=" + crypt.simpleEncode(theQuery.ranking.toExternalString()) + "&resource=local&time=3&recommendref=" + new String(result.hash()) + "&urlmaskfilter=.*");
prop.put("content_authorized_urlhash", new String(result.hash()));
@ -131,7 +131,7 @@ public class yacysearchitem {
prop.put("content_urlhash", resulthashString);
prop.put("content_urlhexhash", yacySeed.b64Hash2hexHash(resulthashString));
prop.putHTML("content_urlname", nxTools.shortenURLString(result.urlname(), urllength));
prop.put("content_date", DateFormatter.formatRFC1123_short(result.modified()));
prop.put("content_date", GenericFormatter.RFC1123_SHORT_FORMATTER.format(result.modified()));
prop.put("content_date822", HeaderFramework.formatRFC1123(result.modified()));
//prop.put("content_ybr", RankingProcess.ybr(result.hash()));
prop.putHTML("content_size", Integer.toString(result.filesize())); // we don't use putNUM here because that number shall be usable as sorting key. To print the size, use 'sizename'

@ -29,6 +29,7 @@ package de.anomic.crawler.retrieval;
import java.io.ByteArrayInputStream;
import java.util.Date;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.protocol.ResponseHeader;
@ -37,8 +38,6 @@ import net.yacy.document.Document;
import net.yacy.document.Parser;
import net.yacy.document.TextParser;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.crawler.CrawlProfile;
public class Response {
@ -217,7 +216,7 @@ public class Response {
if (docDate == null) docDate = responseHeader.date();
}
if (docDate == null && request != null) docDate = request.appdate();
if (docDate == null) docDate = new Date(DateFormatter.correctedUTCTime());
if (docDate == null) docDate = new Date(GenericFormatter.correctedUTCTime());
return docDate;
}
@ -332,7 +331,7 @@ public class Response {
if (date == null) return "stale_no_date_given_in_response";
try {
final long ttl = 1000 * Long.parseLong(cacheControl.substring(8)); // milliseconds to live
if (DateFormatter.correctedUTCTime() - date.getTime() > ttl) {
if (GenericFormatter.correctedUTCTime() - date.getTime() > ttl) {
//System.out.println("***not indexed because cache-control");
return "stale_expired";
}
@ -419,8 +418,8 @@ public class Response {
if (!responseHeader.containsKey(HeaderFramework.LAST_MODIFIED)) { return false; }
// parse date
Date d1, d2;
d2 = responseHeader.lastModified(); if (d2 == null) { d2 = new Date(DateFormatter.correctedUTCTime()); }
d1 = requestHeader.ifModifiedSince(); if (d1 == null) { d1 = new Date(DateFormatter.correctedUTCTime()); }
d2 = responseHeader.lastModified(); if (d2 == null) { d2 = new Date(GenericFormatter.correctedUTCTime()); }
d1 = requestHeader.ifModifiedSince(); if (d1 == null) { d1 = new Date(GenericFormatter.correctedUTCTime()); }
// finally, we shall treat the cache as stale if the modification time is after the if-.. time
if (d2.after(d1)) { return false; }
}
@ -461,7 +460,7 @@ public class Response {
final Date expires = responseHeader.expires();
if (expires != null) {
// System.out.println("EXPIRES-TEST: expires=" + expires + ", NOW=" + serverDate.correctedGMTDate() + ", url=" + url);
if (expires.before(new Date(DateFormatter.correctedUTCTime()))) { return false; }
if (expires.before(new Date(GenericFormatter.correctedUTCTime()))) { return false; }
}
final Date lastModified = responseHeader.lastModified();
cacheControl = responseHeader.get(HeaderFramework.CACHE_CONTROL);
@ -475,13 +474,13 @@ public class Response {
// file may only be treated as fresh for one more month, not more.
Date date = responseHeader.date();
if (lastModified != null) {
if (date == null) { date = new Date(DateFormatter.correctedUTCTime()); }
if (date == null) { date = new Date(GenericFormatter.correctedUTCTime()); }
final long age = date.getTime() - lastModified.getTime();
if (age < 0) { return false; }
// TTL (Time-To-Live) is age/10 = (d2.getTime() - d1.getTime()) / 10
// the actual living-time is serverDate.correctedGMTDate().getTime() - d2.getTime()
// therefore the cache is stale, if serverDate.correctedGMTDate().getTime() - d2.getTime() > age/10
if (DateFormatter.correctedUTCTime() - date.getTime() > age / 10) { return false; }
if (GenericFormatter.correctedUTCTime() - date.getTime() > age / 10) { return false; }
}
// -cache-control in cached response
@ -500,7 +499,7 @@ public class Response {
if (date == null) { return false; }
try {
final long ttl = 1000 * Long.parseLong(cacheControl.substring(8)); // milliseconds to live
if (DateFormatter.correctedUTCTime() - date.getTime() > ttl) {
if (GenericFormatter.correctedUTCTime() - date.getTime() > ttl) {
return false;
}
} catch (final Exception e) {
@ -588,7 +587,7 @@ public class Response {
// parse date
Date d = responseHeader.lastModified();
if (d == null) {
d = new Date(DateFormatter.correctedUTCTime());
d = new Date(GenericFormatter.correctedUTCTime());
}
// finally, we shall treat the cache as stale if the modification time is after the if-.. time
if (d.after(ifModifiedSince)) {
@ -613,7 +612,7 @@ public class Response {
// sometimes, the expires date is set to the past to prevent that a page is cached
// we use that information to see if we should index it
final Date expires = responseHeader.expires();
if (expires != null && expires.before(new Date(DateFormatter.correctedUTCTime()))) {
if (expires != null && expires.before(new Date(GenericFormatter.correctedUTCTime()))) {
return "Stale_(Expired)";
}
@ -646,7 +645,7 @@ public class Response {
}
try {
final long ttl = 1000 * Long.parseLong(cacheControl.substring(8)); // milliseconds to live
if (DateFormatter.correctedUTCTime() - date.getTime() > ttl) {
if (GenericFormatter.correctedUTCTime() - date.getTime() > ttl) {
//System.out.println("***not indexed because cache-control");
return "Stale_(expired_by_cache-control)";
}

@ -46,12 +46,12 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.kelondro.blob.MapHeap;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.NaturalOrder;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.kelondroException;
import org.w3c.dom.Document;
@ -209,7 +209,7 @@ public class BlogBoard {
}
try {
date = DateFormatter.parseShortSecond(StrDate);
date = GenericFormatter.SHORT_SECOND_FORMATTER.parse(StrDate);
} catch (final ParseException e1) {
date = new Date();
}
@ -414,7 +414,7 @@ public class BlogBoard {
}
return new Date();
}
return DateFormatter.parseShortSecond(date);
return GenericFormatter.SHORT_SECOND_FORMATTER.parse(date);
} catch (final ParseException ex) {
return new Date();
}
@ -425,7 +425,7 @@ public class BlogBoard {
if (ret == null) {
ret = new Date();
}
record.put("date", DateFormatter.formatShortSecond(ret));
record.put("date", GenericFormatter.SHORT_SECOND_FORMATTER.format(ret));
}
public String getTimestamp() {
@ -434,7 +434,7 @@ public class BlogBoard {
if (Log.isFinest("Blog")) {
Log.logFinest("Blog", "ERROR: date field missing in blogBoard");
}
return DateFormatter.formatShortSecond();
return GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date());
}
return timestamp;
}

@ -52,13 +52,13 @@ import org.xml.sax.SAXException;
import de.anomic.data.BookmarksDB.Bookmark;
import de.anomic.data.BookmarksDB.Tag;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.document.parser.html.ContentScraper;
import net.yacy.document.parser.html.TransformerWriter;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
public class BookmarkHelper {
@ -229,7 +229,7 @@ public class BookmarkHelper {
Date parsedDate = null;
try {
parsedDate = DateFormatter.parseISO8601(time);
parsedDate = ISO8601Formatter.FORMATTER.parse(time);
} catch (final ParseException e) {
parsedDate = new Date();
}

@ -31,9 +31,12 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.http.HTTPClient;
import net.yacy.kelondro.blob.Tables;
import net.yacy.kelondro.data.meta.DigestURI;
@ -41,8 +44,9 @@ import net.yacy.kelondro.data.word.WordReference;
import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.rwi.IndexCell;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
public class WorkTables extends Tables {
@ -120,7 +124,7 @@ public class WorkTables extends Tables {
Data data = new Data();
data.put(TABLE_API_COL_TYPE, type.getBytes());
data.put(TABLE_API_COL_COMMENT, comment.getBytes());
byte[] date = DateFormatter.formatShortMilliSecond(new Date()).getBytes();
byte[] date = GenericFormatter.SHORT_MILSEC_FORMATTER.format(new Date()).getBytes();
data.put(TABLE_API_COL_DATE_RECORDING, date);
data.put(TABLE_API_COL_DATE_LAST_EXEC, date);
data.put(TABLE_API_COL_URL, apiurl.getBytes());
@ -132,7 +136,7 @@ public class WorkTables extends Tables {
// modify and update existing entry
// modify date attributes and patch old values
row.put(TABLE_API_COL_DATE_LAST_EXEC, DateFormatter.formatShortMilliSecond(new Date()).getBytes());
row.put(TABLE_API_COL_DATE_LAST_EXEC, GenericFormatter.SHORT_MILSEC_FORMATTER.format(new Date()).getBytes());
if (!row.containsKey(TABLE_API_COL_DATE_RECORDING)) row.put(TABLE_API_COL_DATE_RECORDING, row.get(TABLE_API_COL_DATE));
row.remove(TABLE_API_COL_DATE);
@ -181,7 +185,7 @@ public class WorkTables extends Tables {
Data data = new Data();
data.put(TABLE_API_COL_TYPE, type.getBytes());
data.put(TABLE_API_COL_COMMENT, comment.getBytes());
byte[] date = DateFormatter.formatShortMilliSecond(new Date()).getBytes();
byte[] date = GenericFormatter.SHORT_MILSEC_FORMATTER.format(new Date()).getBytes();
data.put(TABLE_API_COL_DATE_RECORDING, date);
data.put(TABLE_API_COL_DATE_LAST_EXEC, date);
data.put(TABLE_API_COL_URL, apiurl.getBytes());
@ -305,7 +309,7 @@ public class WorkTables extends Tables {
try {
// create and insert new entry
Data data = new Data();
byte[] date = DateFormatter.formatShortMilliSecond(new Date()).getBytes();
byte[] date = GenericFormatter.SHORT_MILSEC_FORMATTER.format(new Date()).getBytes();
data.put(TABLE_SEARCH_FAILURE_COL_URL, url.toNormalform(true, false));
data.put(TABLE_SEARCH_FAILURE_COL_DATE, date);
data.put(TABLE_SEARCH_FAILURE_COL_WORDS, queryHashes.export());
@ -324,4 +328,20 @@ public class WorkTables extends Tables {
return false;
}
}
public static Map<byte[], String> commentCache(Switchboard sb) {
Map<byte[], String> comments = new TreeMap<byte[], String>(Base64Order.enhancedCoder);
Iterator<Tables.Row> i;
try {
i = sb.tables.iterator(WorkTables.TABLE_API_NAME);
Tables.Row row;
while (i.hasNext()) {
row = i.next();
comments.put(row.getPK(), new String(row.get(WorkTables.TABLE_API_COL_COMMENT)));
}
} catch (IOException e) {
Log.logException(e);
}
return comments;
}
}

@ -16,6 +16,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.document.Condenser;
import net.yacy.document.Document;
import net.yacy.kelondro.blob.Tables;
@ -25,7 +26,6 @@ import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.search.Segment;
public class YMarkTables {
@ -202,7 +202,7 @@ public class YMarkTables {
if(date != null) {
final String s = new String(date);
if(s != null && s.length() > 0)
return DateFormatter.formatISO8601(new Date(Long.parseLong(s)));
return ISO8601Formatter.FORMATTER.format(new Date(Long.parseLong(s)));
}
return "";
}
@ -419,9 +419,9 @@ public class YMarkTables {
if (urlEntry != null) {
metadata.put(METADATA.IN_URLDB, "true");
metadata.put(METADATA.SIZE, String.valueOf(urlEntry.size()));
metadata.put(METADATA.FRESHDATE, DateFormatter.formatISO8601(urlEntry.freshdate()));
metadata.put(METADATA.LOADDATE, DateFormatter.formatISO8601(urlEntry.loaddate()));
metadata.put(METADATA.MODDATE, DateFormatter.formatISO8601(urlEntry.moddate()));
metadata.put(METADATA.FRESHDATE, ISO8601Formatter.FORMATTER.format(urlEntry.freshdate()));
metadata.put(METADATA.LOADDATE, ISO8601Formatter.FORMATTER.format(urlEntry.loaddate()));
metadata.put(METADATA.MODDATE, ISO8601Formatter.FORMATTER.format(urlEntry.moddate()));
metadata.put(METADATA.SNIPPET, String.valueOf(urlEntry.snippet()));
metadata.put(METADATA.WORDCOUNT, String.valueOf(urlEntry.wordCount()));
metadata.put(METADATA.MIMETYPE, String.valueOf(urlEntry.doctype()));

@ -1,26 +1,26 @@
// httpdAlternativeDomainNames.java
// (C) 2008 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// first published 05.05.2008 on http://yacy.net
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
// LICENSE
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/**
* AlternativeDomainNames
* (C) 2008 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
* first published 05.05.2008 on http://yacy.net
*
* $LastChangedDate$
* $LastChangedRevision$
* $LastChangedBy$
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt
* If not, see <http://www.gnu.org/licenses/>.
*/
package de.anomic.http.server;

@ -79,6 +79,7 @@ import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.zip.GZIPOutputStream;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
@ -90,7 +91,6 @@ import net.yacy.document.parser.html.ScraperInputStream;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.ByteBuffer;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.MemoryControl;
import net.yacy.visualization.RasterPlotter;
@ -490,7 +490,7 @@ public final class HTTPDFileHandler {
if (author != null && author.length() > 0) aBuffer.append("Author: " + author + "<br/>");
if (publisher != null && publisher.length() > 0) aBuffer.append("Publisher: " + publisher + "<br/>");
if (description != null && description.length() > 0) aBuffer.append("Description: " + description + "<br/>");
aBuffer.append(DateFormatter.formatShortDay(new Date(f.lastModified())) + ", " + size + ((images > 0) ? ", " + images + " images" : "") + ((links > 0) ? ", " + links + " links" : "") + "<br/></li>\n");
aBuffer.append(GenericFormatter.SHORT_DAY_FORMATTER.format(new Date(f.lastModified())) + ", " + size + ((images > 0) ? ", " + images + " images" : "") + ((links > 0) ? ", " + links + " links" : "") + "<br/></li>\n");
}
}
aBuffer.append(" </ul>\n</body>\n</html>\n");
@ -823,7 +823,7 @@ public final class HTTPDFileHandler {
templatePatterns.put(servletProperties.PEER_STAT_UPTIME, ((System.currentTimeMillis() - serverCore.startupTime) / 1000) / 60); // uptime in minutes
templatePatterns.putHTML(servletProperties.PEER_STAT_CLIENTNAME, switchboard.getConfig("peerName", "anomic"));
templatePatterns.putHTML(servletProperties.PEER_STAT_CLIENTID, ((Switchboard) switchboard).peers.myID());
templatePatterns.put(servletProperties.PEER_STAT_MYTIME, DateFormatter.formatShortSecond());
templatePatterns.put(servletProperties.PEER_STAT_MYTIME, GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date()));
yacySeed myPeer = sb.peers.mySeed();
templatePatterns.put("newpeer", myPeer.getAge() >= 1 ? 0 : 1);
templatePatterns.putHTML("newpeer_peerhash", myPeer.hash);

@ -48,6 +48,7 @@ import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import net.yacy.cora.protocol.Domains;
@ -398,7 +399,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
: readHeader(prop, session);
// handling transparent proxy support
HeaderFramework.handleTransparentProxySupport(header, prop, virtualHost, HTTPDProxyHandler.isTransparentProxy);
handleTransparentProxySupport(header, prop, virtualHost, HTTPDProxyHandler.isTransparentProxy);
// determines if the connection should be kept alive
handlePersistentConnection(header, prop);
@ -464,7 +465,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
else header = readHeader(prop,session);
// handle transparent proxy support
HeaderFramework.handleTransparentProxySupport(header, prop, virtualHost, HTTPDProxyHandler.isTransparentProxy);
handleTransparentProxySupport(header, prop, virtualHost, HTTPDProxyHandler.isTransparentProxy);
// determines if the connection should be kept alive
handlePersistentConnection(header, prop);
@ -530,7 +531,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
}
// handle transparent proxy support
HeaderFramework.handleTransparentProxySupport(header, prop, virtualHost, HTTPDProxyHandler.isTransparentProxy);
handleTransparentProxySupport(header, prop, virtualHost, HTTPDProxyHandler.isTransparentProxy);
// determines if the connection should be kept alive
handlePersistentConnection(header, prop);
@ -564,7 +565,22 @@ public final class HTTPDemon implements serverHandler, Cloneable {
return serverCore.TERMINATE_CONNECTION;
}
}
public static void handleTransparentProxySupport(final RequestHeader header, final Properties prop, final String virtualHost, final boolean isTransparentProxy) {
// transparent proxy support is only available for http 1.0 and above connections
if (prop.getProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, "HTTP/0.9").equals("HTTP/0.9")) return;
// if the transparent proxy support was disabled, we have nothing todo here ...
if (!(isTransparentProxy && header.containsKey(HeaderFramework.HOST))) return;
// we only need to do the transparent proxy support if the request URL didn't contain the hostname
// and therefor was set to virtualHost by function parseQuery()
if (!prop.getProperty(HeaderFramework.CONNECTION_PROP_HOST).equals(virtualHost)) return;
// TODO: we could have problems with connections from extern here ...
final String dstHostSocket = header.get(HeaderFramework.HOST);
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST,(HTTPDemon.isThisHostName(dstHostSocket)?virtualHost:dstHostSocket));
}
public Boolean CONNECT(String arg, Session session) throws IOException {
// establish a ssh-tunneled http connection
@ -628,7 +644,7 @@ public final class HTTPDemon implements serverHandler, Cloneable {
private final Properties parseRequestLine(final String cmd, final String s, Session session) {
// parsing the header
Properties p = RequestHeader.parseRequestLine(cmd, s, virtualHost);
Properties p = parseRequestLine(cmd, s, virtualHost);
// track the request
final String path = p.getProperty(HeaderFramework.CONNECTION_PROP_URL);
@ -1425,5 +1441,126 @@ public final class HTTPDemon implements serverHandler, Cloneable {
return header;
}
private static final Pattern P_20 = Pattern.compile(" ", Pattern.LITERAL);
private static final Pattern P_7B = Pattern.compile("{", Pattern.LITERAL);
private static final Pattern P_7D = Pattern.compile("}", Pattern.LITERAL);
private static final Pattern P_7C = Pattern.compile("|", Pattern.LITERAL);
private static final Pattern P_5C = Pattern.compile("\\", Pattern.LITERAL);
private static final Pattern P_5E = Pattern.compile("^", Pattern.LITERAL);
private static final Pattern P_5B = Pattern.compile("[", Pattern.LITERAL);
private static final Pattern P_5D = Pattern.compile("]", Pattern.LITERAL);
private static final Pattern P_60 = Pattern.compile("`", Pattern.LITERAL);
public static Properties parseRequestLine(final String cmd, String args, final String virtualHost) {
final Properties prop = new Properties();
// storing informations about the request
prop.setProperty(HeaderFramework.CONNECTION_PROP_METHOD, cmd);
prop.setProperty(HeaderFramework.CONNECTION_PROP_REQUESTLINE, cmd + " " + args);
// this parses a whole URL
if (args.length() == 0) {
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST, virtualHost);
prop.setProperty(HeaderFramework.CONNECTION_PROP_PATH, "/");
prop.setProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_0_9);
prop.setProperty(HeaderFramework.CONNECTION_PROP_EXT, "");
return prop;
}
// store the version propery "HTTP" and cut the query at both ends
int sep = args.lastIndexOf(' ');
if ((sep >= 0)&&(args.substring(sep + 1).toLowerCase().startsWith("http/"))) {
// HTTP version is given
prop.setProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, args.substring(sep + 1).trim());
args = args.substring(0, sep).trim(); // cut off HTTP version mark
} else {
// HTTP version is not given, it will be treated as ver 0.9
prop.setProperty(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_0_9);
}
// replacing spaces in the url string correctly
args = P_20.matcher(args).replaceAll("%20");
// replace unwise characters (see RFC 2396, 2.4.3), which may not be escaped
args = P_7B.matcher(args).replaceAll("%7B");
args = P_7D.matcher(args).replaceAll("%7D");
args = P_7C.matcher(args).replaceAll("%7C");
args = P_5C.matcher(args).replaceAll("%5C");
args = P_5E.matcher(args).replaceAll("%5E");
args = P_5B.matcher(args).replaceAll("%5B");
args = P_5D.matcher(args).replaceAll("%5D");
args = P_60.matcher(args).replaceAll("%60");
// properties of the query are stored with the prefix "&"
// additionally, the values URL and ARGC are computed
String argsString = "";
sep = args.indexOf('?');
if (sep >= 0) {
// there are values attached to the query string
argsString = args.substring(sep + 1); // cut head from tail of query
args = args.substring(0, sep);
}
prop.setProperty(HeaderFramework.CONNECTION_PROP_URL, args); // store URL
//System.out.println("HTTPD: ARGS=" + argsString);
if (argsString.length() != 0) prop.setProperty(HeaderFramework.CONNECTION_PROP_ARGS, argsString); // store arguments in original form
// finally find host string
String path;
if (args.toUpperCase().startsWith("HTTP://")) {
// a host was given. extract it and set path
args = args.substring(7);
sep = args.indexOf('/');
if (sep < 0) {
// this is a malformed url, something like
// http://index.html
// we are lazy and guess that it means
// /index.html
// which is a localhost access to the file servlet
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST, args);
path = "/";
} else {
// THIS IS THE "GOOD" CASE
// a perfect formulated url
final String dstHostSocket = args.substring(0, sep);
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST, (HTTPDemon.isThisHostName(dstHostSocket) ? virtualHost : dstHostSocket));
path = args.substring(sep); // yes, including beginning "/"
}
} else {
// no host in url. set path
if (args.length() > 0 && args.charAt(0) == '/') {
// thats also fine, its a perfect localhost access
// in this case, we simulate a
// http://localhost/s
// access by setting a virtual host
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST, virtualHost);
path = args;
} else {
// the client 'forgot' to set a leading '/'
// this is the same case as above, with some lazyness
prop.setProperty(HeaderFramework.CONNECTION_PROP_HOST, virtualHost);
path = "/" + args;
}
}
prop.setProperty(HeaderFramework.CONNECTION_PROP_PATH, path);
// find out file extension (we already stripped ?-parameters from args)
String ext = ""; // default when no file extension
sep = path.lastIndexOf('.');
if (sep >= 0) {
final int ancpos = path.indexOf("#", sep + 1);
if (ancpos >= sep) {
// ex: /foo/bar.html#xy => html
ext = path.substring(sep + 1, ancpos).toLowerCase();
} else {
// ex: /foo/bar.php => php
ext = path.substring(sep + 1).toLowerCase();
}
}
prop.setProperty(HeaderFramework.CONNECTION_PROP_EXT, ext);
return prop;
}
}

@ -26,12 +26,12 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.data.LibraryProvider;
public class AccessTracker {
@ -85,7 +85,7 @@ public class AccessTracker {
//if (query.resultcount == 0) return;
if (query.queryString == null || query.queryString.length() == 0) return;
StringBuilder sb = new StringBuilder(40);
sb.append(DateFormatter.formatShortSecond());
sb.append(GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date()));
sb.append(' ');
sb.append(Integer.toString(query.resultcount));
sb.append(' ');

@ -75,6 +75,7 @@ import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.document.RSSFeed;
import net.yacy.cora.document.RSSMessage;
@ -104,7 +105,6 @@ import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.Digest;
import net.yacy.kelondro.order.NaturalOrder;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.EventTracker;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.MemoryControl;
@ -2457,7 +2457,7 @@ public final class Switchboard extends serverSwitch {
peers.mySeed().put(yacySeed.VERSION, yacyBuildProperties.getLongVersion());
peers.mySeed().setFlagDirectConnect(true);
peers.mySeed().setLastSeenUTC();
peers.mySeed().put(yacySeed.UTC, DateFormatter.UTCDiffString());
peers.mySeed().put(yacySeed.UTC, GenericFormatter.UTCDiffString());
peers.mySeed().setFlagAcceptRemoteCrawl(getConfig("crawlResponse", "").equals("true"));
peers.mySeed().setFlagAcceptRemoteIndex(getConfig("allowReceiveIndex", "").equals("true"));
//mySeed.setFlagAcceptRemoteIndex(true);

@ -56,7 +56,6 @@ import java.util.regex.Pattern;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.document.parser.html.CharacterCoding;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.Formatter;
import de.anomic.search.Switchboard;
@ -160,10 +159,6 @@ public class serverObjects extends HashMap<String, String> implements Cloneable
return this.put(key, value.toString());
}
public String put(final String key, final DateFormatter value) {
return this.put(key, value.toString());
}
public String put(final String key, final InetAddress value) {
return this.put(key, value.toString());
}

@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.yacy.cora.date.AbstractFormatter;
import net.yacy.cora.storage.DynamicScore;
import net.yacy.cora.storage.ScoreCluster;
import net.yacy.kelondro.data.word.Word;
@ -38,7 +39,6 @@ import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.Digest;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.kelondroException;
import de.anomic.yacy.yacyCore;
@ -351,7 +351,7 @@ public class PeerSelection {
while ((s.hasNext()) && (searchcount-- > 0)) {
ys = s.next();
if ((ys != null) && (ys.get(yacySeed.LASTSEEN, "").length() > 10)) try {
absage = Math.abs(System.currentTimeMillis() + DateFormatter.dayMillis - ys.getLastSeenUTC()) / 1000 / 60;
absage = Math.abs(System.currentTimeMillis() + AbstractFormatter.dayMillis - ys.getLastSeenUTC()) / 1000 / 60;
if (absage > Integer.MAX_VALUE) absage = Integer.MAX_VALUE;
seedScore.inc(ys.hash, (int) absage); // the higher absage, the older is the peer
} catch (final Exception e) {}

@ -37,12 +37,12 @@ import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.document.Condenser;
import net.yacy.document.Document;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.LookAheadIterator;
@ -150,7 +150,7 @@ public class WebStructureGraph {
private static String map2refstr(final Map<String, Integer> map) {
final StringBuilder s = new StringBuilder(map.size() * 10);
s.append(DateFormatter.formatShortDay(new Date()));
s.append(GenericFormatter.SHORT_DAY_FORMATTER.format(new Date()));
String h;
for (final Map.Entry<String, Integer> entry : map.entrySet()) {
s.append(entry.getKey());
@ -229,7 +229,7 @@ public class WebStructureGraph {
return new structureEntry(
domhash,
host,
DateFormatter.formatShortDay(new Date()),
GenericFormatter.SHORT_DAY_FORMATTER.format(new Date()),
domhashes);
}

@ -372,7 +372,7 @@ public final class yacyClient {
public static RSSFeed search(final yacySeed targetSeed, String query, boolean verify, boolean global, long timeout, int startRecord, int maximumRecords) throws IOException {
String address = (targetSeed == null || targetSeed == Switchboard.getSwitchboard().peers.mySeed()) ? "localhost:" + Switchboard.getSwitchboard().getConfig("port", "8080") : targetSeed.getClusterAddress();
String urlBase = "http://" + address + "/yacysearch.rss";
return Search.search(urlBase, query, verify, global, timeout, startRecord, maximumRecords);
return Search.loadSRURSS(urlBase, query, timeout, startRecord, maximumRecords, verify, global);
}
@SuppressWarnings("unchecked")

@ -49,12 +49,11 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.document.RSSFeed;
import net.yacy.cora.document.RSSMessage;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.search.Switchboard;
import de.anomic.server.serverCore;
import de.anomic.yacy.dht.PeerSelection;
@ -256,14 +255,14 @@ public class yacyCore {
if (newSeed.getLastSeenUTC() >= this.seed.getLastSeenUTC()) {
if (log.isFine()) log.logFine("publish: recently handshaked " + this.seed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_SENIOR) +
" peer '" + this.seed.getName() + "' at " + this.seed.getPublicAddress() + " with old LastSeen: '" +
DateFormatter.formatShortSecond(new Date(newSeed.getLastSeenUTC())) + "'");
GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date(newSeed.getLastSeenUTC())) + "'");
newSeed.setLastSeenUTC();
sb.peers.peerActions.peerArrival(newSeed, true);
} else {
if (log.isFine()) log.logFine("publish: recently handshaked " + this.seed.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_SENIOR) +
" peer '" + this.seed.getName() + "' at " + this.seed.getPublicAddress() + " with old LastSeen: '" +
DateFormatter.formatShortSecond(new Date(newSeed.getLastSeenUTC())) + "', this is more recent: '" +
DateFormatter.formatShortSecond(new Date(this.seed.getLastSeenUTC())) + "'");
GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date(newSeed.getLastSeenUTC())) + "', this is more recent: '" +
GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date(this.seed.getLastSeenUTC())) + "'");
this.seed.setLastSeenUTC();
sb.peers.peerActions.peerArrival(this.seed, true);
}

@ -33,9 +33,8 @@ import java.util.Date;
import java.util.LinkedHashMap;
//import java.util.List;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.kelondro.order.Digest;
import net.yacy.kelondro.util.DateFormatter;
//import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.StringBody;
@ -115,7 +114,7 @@ public class yacyNetwork {
if (targetHash != null) parts.put("youare", new StringBody(targetHash));
// time information for synchronization
parts.put("mytime", new StringBody(DateFormatter.formatShortSecond(new Date())));
parts.put("mytime", new StringBody(GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date())));
parts.put("myUTC", new StringBody(Long.toString(System.currentTimeMillis())));
// network identification

@ -54,6 +54,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.index.Index;
import net.yacy.kelondro.index.Row;
@ -62,7 +63,6 @@ import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.NaturalOrder;
import net.yacy.kelondro.table.Table;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.kelondroException;
import net.yacy.kelondro.util.MapTools;
@ -76,7 +76,7 @@ public class yacyNewsDB {
protected Index news;
private static final int categoryStringLength = 8;
public static final int idLength = DateFormatter.PATTERN_SHORT_SECOND.length() + Word.commonHashLength;
public static final int idLength = GenericFormatter.PATTERN_SHORT_SECOND.length() + Word.commonHashLength;
public yacyNewsDB(
final File path,
@ -87,12 +87,12 @@ public class yacyNewsDB {
this.attributesMaxLength = maxNewsRecordLength
- idLength
- categoryStringLength
- DateFormatter.PATTERN_SHORT_SECOND.length()
- GenericFormatter.PATTERN_SHORT_SECOND.length()
- 2;
this.rowdef = new Row(
"String idx-" + idLength + " \"id = created + originator\"," +
"String cat-" + categoryStringLength + "," +
"String rec-" + DateFormatter.PATTERN_SHORT_SECOND.length() + "," +
"String rec-" + GenericFormatter.PATTERN_SHORT_SECOND.length() + "," +
"short dis-2 {b64e}," +
"String att-" + attributesMaxLength,
NaturalOrder.naturalOrder
@ -189,7 +189,7 @@ public class yacyNewsDB {
return new yacyNewsDB.Record(
b.getColString(0, null),
b.getColString(1, "UTF-8"),
(b.empty(2)) ? null : DateFormatter.parseShortSecond(b.getColString(2, null), DateFormatter.UTCDiffString()),
(b.empty(2)) ? null : GenericFormatter.SHORT_SECOND_FORMATTER.parse(b.getColString(2, null), GenericFormatter.UTCDiffString()),
(int) b.getColLong(3),
MapTools.string2map(b.getColString(4, "UTF-8"), ",")
);
@ -206,7 +206,7 @@ public class yacyNewsDB {
final Row.Entry entry = this.news.row().newEntry();
entry.setCol(0, r.id().getBytes());
entry.setCol(1, r.category().getBytes("UTF-8"));
entry.setCol(2, (r.received() == null) ? null : DateFormatter.formatShortSecond(r.received()).getBytes());
entry.setCol(2, (r.received() == null) ? null : GenericFormatter.SHORT_SECOND_FORMATTER.format(r.received()).getBytes());
entry.setCol(3, Base64Order.enhancedCoder.encodeLong(r.distributed(), 2).getBytes());
entry.setCol(4, attributes.getBytes("UTF-8"));
return entry;
@ -265,8 +265,8 @@ public class yacyNewsDB {
if (attributes.toString().length() > attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + attributesMaxLength + ")");
this.category = (attributes.containsKey("cat")) ? attributes.get("cat") : "";
if (category.length() > yacyNewsDB.categoryStringLength) throw new IllegalArgumentException("category length (" + category.length() + ") exceeds maximum (" + yacyNewsDB.categoryStringLength + ")");
this.received = (attributes.containsKey("rec")) ? DateFormatter.parseShortSecond(attributes.get("rec"), DateFormatter.UTCDiffString()) : new Date();
this.created = (attributes.containsKey("cre")) ? DateFormatter.parseShortSecond(attributes.get("cre"), DateFormatter.UTCDiffString()) : new Date();
this.received = (attributes.containsKey("rec")) ? GenericFormatter.SHORT_SECOND_FORMATTER.parse(attributes.get("rec"), GenericFormatter.UTCDiffString()) : new Date();
this.created = (attributes.containsKey("cre")) ? GenericFormatter.SHORT_SECOND_FORMATTER.parse(attributes.get("cre"), GenericFormatter.UTCDiffString()) : new Date();
this.distributed = (attributes.containsKey("dis")) ? Integer.parseInt(attributes.get("dis")) : 0;
this.originator = (attributes.containsKey("ori")) ? attributes.get("ori") : "";
removeStandards();
@ -289,10 +289,10 @@ public class yacyNewsDB {
if (attributes.toString().length() > attributesMaxLength) throw new IllegalArgumentException("attributes length (" + attributes.toString().length() + ") exceeds maximum (" + attributesMaxLength + ")");
this.attributes = attributes;
this.received = received;
this.created = DateFormatter.parseShortSecond(id.substring(0, DateFormatter.PATTERN_SHORT_SECOND.length()), DateFormatter.UTCDiffString());
this.created = GenericFormatter.SHORT_SECOND_FORMATTER.parse(id.substring(0, GenericFormatter.PATTERN_SHORT_SECOND.length()), GenericFormatter.UTCDiffString());
this.category = category;
this.distributed = distributed;
this.originator = id.substring(DateFormatter.PATTERN_SHORT_SECOND.length());
this.originator = id.substring(GenericFormatter.PATTERN_SHORT_SECOND.length());
removeStandards();
}
@ -309,8 +309,8 @@ public class yacyNewsDB {
// attention: this has no additional encoding
if (this.originator != null) attributes.put("ori", this.originator);
if (this.category != null) attributes.put("cat", this.category);
if (this.created != null) attributes.put("cre", DateFormatter.formatShortSecond(this.created));
if (this.received != null) attributes.put("rec", DateFormatter.formatShortSecond(this.received));
if (this.created != null) attributes.put("cre", GenericFormatter.SHORT_SECOND_FORMATTER.format(this.created));
if (this.received != null) attributes.put("rec", GenericFormatter.SHORT_SECOND_FORMATTER.format(this.received));
attributes.put("dis", Integer.toString(this.distributed));
final String theString = attributes.toString();
removeStandards();
@ -318,7 +318,7 @@ public class yacyNewsDB {
}
public String id() {
return DateFormatter.formatShortSecond(created) + originator;
return GenericFormatter.SHORT_SECOND_FORMATTER.format(created) + originator;
}
public String originator() {

@ -50,13 +50,13 @@ import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.kelondro.index.Column;
import net.yacy.kelondro.index.Row;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.NaturalOrder;
import net.yacy.kelondro.table.Table;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
@ -68,7 +68,7 @@ public class yacyNewsQueue {
public static final Row rowdef = new Row(new Column[]{
new Column("newsid", Column.celltype_string, Column.encoder_bytes, yacyNewsDB.idLength, "id = created + originator"),
new Column("last touched", Column.celltype_string, Column.encoder_bytes, DateFormatter.PATTERN_SHORT_SECOND.length(), "")
new Column("last touched", Column.celltype_string, Column.encoder_bytes, GenericFormatter.PATTERN_SHORT_SECOND.length(), "")
},
NaturalOrder.naturalOrder
);
@ -173,7 +173,7 @@ public class yacyNewsQueue {
}
final Row.Entry b = queueStack.row().newEntry(new byte[][]{
r.id().getBytes(),
DateFormatter.formatShortSecond(new Date()).getBytes()});
GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date()).getBytes()});
return b;
}

@ -29,7 +29,6 @@ import java.util.concurrent.ConcurrentHashMap;
import net.yacy.cora.document.RSSMessage;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.MapTools;
@ -107,7 +106,7 @@ public class yacyPeerActions {
}
if (Math.abs(nowUTC0Time - ctimeUTC0) / 1000 / 60 > 60 * 6 ) {
// the new connection is out-of-age, we reject the connection
if (yacyCore.log.isFine()) yacyCore.log.logFine("connect: rejecting out-dated peer '" + seed.getName() + "' from " + seed.getPublicAddress() + "; nowUTC0=" + nowUTC0Time + ", seedUTC0=" + ctimeUTC0 + ", TimeDiff=" + DateFormatter.formatInterval(Math.abs(nowUTC0Time - ctimeUTC0)));
if (yacyCore.log.isFine()) yacyCore.log.logFine("connect: rejecting out-dated peer '" + seed.getName() + "' from " + seed.getPublicAddress() + "; nowUTC0=" + nowUTC0Time + ", seedUTC0=" + ctimeUTC0 + ", TimeDiff=" + formatInterval(Math.abs(nowUTC0Time - ctimeUTC0)));
return false;
}
@ -254,4 +253,31 @@ public class yacyPeerActions {
return (userAgent == null) ? "" : userAgent;
}
/**
* Format a time inteval in milliseconds into a String of the form
* X 'day'['s'] HH':'mm
*/
public static String formatInterval(final long millis) {
try {
final long mins = millis / 60000;
final StringBuilder uptime = new StringBuilder();
final int uptimeDays = (int) (Math.floor(mins/1440.0));
final int uptimeHours = (int) (Math.floor(mins/60.0)%24);
final int uptimeMins = (int) mins%60;
uptime.append(uptimeDays)
.append(((uptimeDays == 1)?" day ":" days "))
.append((uptimeHours < 10)?"0":"")
.append(uptimeHours)
.append(":")
.append((uptimeMins < 10)?"0":"")
.append(uptimeMins);
return uptime.toString();
} catch (final Exception e) {
return "unknown";
}
}
}

@ -57,12 +57,13 @@ import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import net.yacy.cora.date.AbstractFormatter;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.protocol.Domains;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.Digest;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.MapTools;
import de.anomic.tools.bitfield;
@ -209,7 +210,7 @@ public class yacySeed implements Cloneable {
this.dna.put(yacySeed.IPTYPE, "&empty;");
// settings that can only be computed by visiting peer
this.dna.put(yacySeed.LASTSEEN, DateFormatter.formatShortSecond(new Date(System.currentTimeMillis() /*- DateFormatter.UTCDiff()*/))); // for last-seen date
this.dna.put(yacySeed.LASTSEEN, GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date(System.currentTimeMillis() /*- DateFormatter.UTCDiff()*/))); // for last-seen date
this.dna.put(yacySeed.USPEED, yacySeed.ZERO); // the computated uplink speed of the peer
// settings that are needed to organize the seed round-trip
@ -493,7 +494,7 @@ public class yacySeed implements Cloneable {
// because java thinks it must apply the UTC offset to the current time,
// to create a string that looks like our current time, it adds the local UTC offset to the
// time. To create a corrected UTC Date string, we first subtract the local UTC offset.
String ls = DateFormatter.formatShortSecond(new Date(System.currentTimeMillis() /*- DateFormatter.UTCDiff()*/));
String ls = GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date(System.currentTimeMillis() /*- DateFormatter.UTCDiff()*/));
//System.out.println("SETTING LAST-SEEN of " + this.getName() + " to " + ls);
dna.put(yacySeed.LASTSEEN, ls );
}
@ -503,7 +504,7 @@ public class yacySeed implements Cloneable {
*/
public final long getLastSeenUTC() {
try {
final long t = DateFormatter.parseShortSecond(get(yacySeed.LASTSEEN, "20040101000000")).getTime();
final long t = GenericFormatter.SHORT_SECOND_FORMATTER.parse(get(yacySeed.LASTSEEN, "20040101000000")).getTime();
// getTime creates a UTC time number. But in this case java thinks, that the given
// time string is a local time, which has a local UTC offset applied.
// Therefore java subtracts the local UTC offset, to get a UTC number.
@ -512,9 +513,9 @@ public class yacySeed implements Cloneable {
// offset again.
return t /*+ DateFormatter.UTCDiff()*/;
} catch (final java.text.ParseException e) { // in case of an error make seed look old!!!
return System.currentTimeMillis() - DateFormatter.dayMillis;
return System.currentTimeMillis() - AbstractFormatter.dayMillis;
} catch (final java.lang.NumberFormatException e) {
return System.currentTimeMillis() - DateFormatter.dayMillis;
return System.currentTimeMillis() - AbstractFormatter.dayMillis;
}
}
@ -530,7 +531,7 @@ public class yacySeed implements Cloneable {
/** @return the age of the seed in number of days */
public final int getAge() {
try {
final long t = DateFormatter.parseShortSecond(get(yacySeed.BDATE, "20040101000000")).getTime();
final long t = GenericFormatter.SHORT_SECOND_FORMATTER.parse(get(yacySeed.BDATE, "20040101000000")).getTime();
return (int) ((System.currentTimeMillis() - (t /*- getUTCDiff() + DateFormatter.UTCDiff()*/)) / 1000 / 60 / 60 / 24);
} catch (final java.text.ParseException e) {
return -1;
@ -740,9 +741,9 @@ public class yacySeed implements Cloneable {
// now calculate other information about the host
newSeed.dna.put(yacySeed.NAME, (name) == null ? "anonymous" : name);
newSeed.dna.put(yacySeed.PORT, Integer.toString((port <= 0) ? 8080 : port));
newSeed.dna.put(yacySeed.BDATE, DateFormatter.formatShortSecond(new Date(System.currentTimeMillis() /*- DateFormatter.UTCDiff()*/)) );
newSeed.dna.put(yacySeed.BDATE, GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date(System.currentTimeMillis() /*- DateFormatter.UTCDiff()*/)) );
newSeed.dna.put(yacySeed.LASTSEEN, newSeed.dna.get(yacySeed.BDATE)); // just as initial setting
newSeed.dna.put(yacySeed.UTC, DateFormatter.UTCDiffString());
newSeed.dna.put(yacySeed.UTC, GenericFormatter.UTCDiffString());
newSeed.dna.put(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN);
return newSeed;

@ -54,8 +54,8 @@ import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.kelondroException;
//import de.anomic.http.client.Client;
import de.anomic.http.server.HTTPDemon;
import de.anomic.http.server.AlternativeDomainNames;
import de.anomic.http.server.HTTPDemon;
//import de.anomic.http.server.ResponseContainer;
import de.anomic.search.Switchboard;
import de.anomic.server.serverCore;
@ -849,26 +849,6 @@ public final class yacySeedDB implements AlternativeDomainNames {
reqHeader.put(HeaderFramework.CACHE_CONTROL, "no-cache"); // httpc uses HTTP/1.0 is this necessary?
reqHeader.put(HeaderFramework.USER_AGENT, MultiProtocolURI.yacybotUserAgent);
// init http-client
// final Client client = new Client(10000, reqHeader);
// byte[] content = null;
// ResponseContainer res = null;
// try {
// // send request
// res = client.GET(seedURL.toString());
//
// // check response code
// if (res.getStatusCode() != 200) {
// throw new IOException("Server returned status: " + res.getStatusLine());
// }
//
// // read byte array
// content = res.getData();
// } finally {
// if(res != null) {
// res.closeStream();
// }
// }
final HTTPClient client = new HTTPClient();
client.setHeader(reqHeader.entrySet());
byte[] content = null;

@ -0,0 +1,45 @@
/**
* AbstractFormatter
* Copyright 2011 by Michael Peter Christen
* First released 2.1.2011 at http://yacy.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt
* If not, see <http://www.gnu.org/licenses/>.
*/
package net.yacy.cora.date;
import java.text.ParseException;
import java.util.Date;
import java.util.TimeZone;
public abstract class AbstractFormatter implements DateFormatter {
protected static final TimeZone TZ_GMT = TimeZone.getTimeZone("GMT");
// statics
public final static long secondMillis = 1000;
public final static long minuteMillis = 60 * secondMillis;
public final static long hourMillis = 60 * minuteMillis;
public final static long dayMillis = 24 * hourMillis;
public final static long normalyearMillis = 365 * dayMillis;
public final static long leapyearMillis = 366 * dayMillis;
protected long last_time;
protected String last_format;
public abstract Date parse(String s) throws ParseException;
public abstract String format(final Date date);
}

@ -0,0 +1,31 @@
/**
* DateFormatter
* Copyright 2011 by Michael Peter Christen
* First released 2.1.2011 at http://yacy.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt
* If not, see <http://www.gnu.org/licenses/>.
*/
package net.yacy.cora.date;
import java.text.ParseException;
import java.util.Date;
public interface DateFormatter {
public Date parse(String s) throws ParseException;
public String format(final Date date);
}

@ -0,0 +1,168 @@
/**
* GenericFormatter
* Copyright 2011 by Michael Peter Christen
* First released 2.1.2011 at http://yacy.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt
* If not, see <http://www.gnu.org/licenses/>.
*/
package net.yacy.cora.date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class GenericFormatter extends AbstractFormatter implements DateFormatter {
public static final String PATTERN_SHORT_DAY = "yyyyMMdd";
public static final String PATTERN_SHORT_SECOND = "yyyyMMddHHmmss";
public static final String PATTERN_SHORT_MILSEC = "yyyyMMddHHmmssSSS";
private static final String PATTERN_RFC1123_SHORT = "EEE, dd MMM yyyy";
private static final String PATTERN_ANSIC = "EEE MMM d HH:mm:ss yyyy";
private static final SimpleDateFormat FORMAT_SHORT_DAY = new SimpleDateFormat(PATTERN_SHORT_DAY, Locale.US);
private static final SimpleDateFormat FORMAT_SHORT_SECOND = new SimpleDateFormat(PATTERN_SHORT_SECOND, Locale.US);
private static final SimpleDateFormat FORMAT_SHORT_MILSEC = new SimpleDateFormat(PATTERN_SHORT_MILSEC, Locale.US);
private static final SimpleDateFormat FORMAT_ANSIC = new SimpleDateFormat(PATTERN_ANSIC, Locale.US);
private static final SimpleDateFormat FORMAT_RFC1123_SHORT = new SimpleDateFormat(PATTERN_RFC1123_SHORT, Locale.US);
// find out time zone and DST offset
private static Calendar thisCalendar = Calendar.getInstance();
static {
// we want GMT times on the formats as well as they don't support any timezone
FORMAT_SHORT_DAY.setTimeZone(TZ_GMT);
FORMAT_SHORT_SECOND.setTimeZone(TZ_GMT);
FORMAT_SHORT_MILSEC.setTimeZone(TZ_GMT);
}
public static final GenericFormatter SHORT_DAY_FORMATTER = new GenericFormatter(FORMAT_SHORT_DAY);
public static final GenericFormatter SHORT_SECOND_FORMATTER = new GenericFormatter(FORMAT_SHORT_SECOND);
public static final GenericFormatter SHORT_MILSEC_FORMATTER = new GenericFormatter(FORMAT_SHORT_MILSEC);
public static final GenericFormatter ANSIC_FORMATTER = new GenericFormatter(FORMAT_ANSIC);
public static final GenericFormatter RFC1123_SHORT_FORMATTER = new GenericFormatter(FORMAT_RFC1123_SHORT);
private SimpleDateFormat dateFormat;
public GenericFormatter(SimpleDateFormat dateFormat) {
this.dateFormat = dateFormat;
this.last_time = 0;
this.last_format = "";
}
/**
* Note: The short day format doesn't include any timezone information. This method
* transforms the date into the GMT/UTC timezone. Example: If the local system time is,
* 2007-12-18 01:15:00 +0200, then the resulting String will be "2007-12-17".
* In case you need a format with a timezon offset, use {@link #formatShortDay(TimeZone)}
* @return a String representation of the current system date in GMT using the
* short day format, e.g. "20071218".
*/
@Override
public String format(final Date date) {
if (date == null) return "";
if (Math.abs(date.getTime() - last_time) < 1000) return last_format;
synchronized (this.dateFormat) {
last_format = this.dateFormat.format(date);
last_time = date.getTime();
}
return last_format;
}
/**
* Parse a String representation of a Date in short day format assuming the date
* is aligned to the GMT/UTC timezone. An example for such a date string is "20071218".
* @see #formatShortDay()
* @throws ParseException The exception is thrown if an error occured during while parsing
* the String.
*/
@Override
public Date parse(final String timeString) throws ParseException {
synchronized (this.dateFormat) {
return this.dateFormat.parse(timeString);
}
}
/**
* Like {@link #parseShortSecond(String)} using additional timezone information provided in an
* offset String, like "+0100" for CET.
*/
public Date parse(final String timeString, final String UTCOffset) {
// FIXME: This method returns an incorrect date, check callers!
// ex: de.anomic.server.serverDate.parseShortSecond("20070101120000", "+0200").toGMTString()
// => 1 Jan 2007 13:00:00 GMT
if (timeString == null || timeString.length() == 0) { return new Date(); }
if (UTCOffset == null || UTCOffset.length() == 0) { return new Date(); }
try {
return new Date(this.dateFormat.parse(timeString).getTime() - UTCDiff() + UTCDiff(UTCOffset));
} catch (final java.text.ParseException e) {
//serverLog.logFinest("parseUniversalDate", e.getMessage() + ", remoteTimeString=[" + remoteTimeString + "]");
return new Date();
} catch (final java.lang.NumberFormatException e) {
//serverLog.logFinest("parseUniversalDate", e.getMessage() + ", remoteTimeString=[" + remoteTimeString + "]");
return new Date();
}
}
private static long UTCDiff(final String diffString) {
if (diffString.length() != 5) throw new IllegalArgumentException("UTC String malformed (wrong size):" + diffString);
boolean ahead = true;
if (diffString.length() > 0 && diffString.charAt(0) == '+') ahead = true;
else if (diffString.length() > 0 && diffString.charAt(0) == '-') ahead = false;
else throw new IllegalArgumentException("UTC String malformed (wrong sign):" + diffString);
final long oh = Long.parseLong(diffString.substring(1, 3));
final long om = Long.parseLong(diffString.substring(3));
return ((ahead) ? (long) 1 : (long) -1) * (oh * AbstractFormatter.hourMillis + om * AbstractFormatter.minuteMillis);
}
private static long UTCDiff() {
// DST_OFFSET is dependent on the time of the Calendar, so it has to be updated
// to get the correct current offset
synchronized (thisCalendar) {
thisCalendar.setTimeInMillis(System.currentTimeMillis());
final long zoneOffsetHours = thisCalendar.get(Calendar.ZONE_OFFSET);
final long DSTOffsetHours = thisCalendar.get(Calendar.DST_OFFSET);
return zoneOffsetHours + DSTOffsetHours;
}
}
public static String UTCDiffString() {
// we express the UTC Difference in 5 digits:
// SHHMM
// S ::= '+'|'-'
// HH ::= '00'|'01'|'02'|'03'|'04'|'05'|'06'|'07'|'08'|'09'|'10'|'11'|'12'
// MM ::= '00'|'15'|'30'|'45'
// since there are some places on earth where there is a time shift of half an hour
// we need too show also the minutes of the time shift
// Examples: http://www.timeanddate.com/library/abbreviations/timezones/
final long offsetHours = UTCDiff();
final int om = Math.abs((int) (offsetHours / AbstractFormatter.minuteMillis)) % 60;
final int oh = Math.abs((int) (offsetHours / AbstractFormatter.hourMillis));
String diff = Integer.toString(om);
if (diff.length() < 2) diff = "0" + diff;
diff = Integer.toString(oh) + diff;
if (diff.length() < 4) diff = "0" + diff;
if (offsetHours < 0) {
return "-" + diff;
}
return "+" + diff;
}
public static long correctedUTCTime() {
return System.currentTimeMillis() - UTCDiff();
}
}

@ -0,0 +1,191 @@
/**
* ISO8601
* Copyright 2011 by Michael Peter Christen
* First released 2.1.2011 at http://yacy.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt
* If not, see <http://www.gnu.org/licenses/>.
*/
package net.yacy.cora.date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
public class ISO8601Formatter extends AbstractFormatter implements DateFormatter {
/** pattern for a W3C datetime variant of a non-localized ISO8601 date */
private static final String PATTERN_ISO8601 = "yyyy-MM-dd'T'HH:mm:ss'Z'";
/** Date formatter/non-sloppy parser for W3C datetime (ISO8601) in GMT/UTC */
private static final SimpleDateFormat FORMAT_ISO8601 = new SimpleDateFormat(PATTERN_ISO8601, Locale.US);
static {
FORMAT_ISO8601.setTimeZone(TZ_GMT);
}
public static final ISO8601Formatter FORMATTER = new ISO8601Formatter();
public ISO8601Formatter() {
last_time = 0;
last_format = "";
}
/**
* Parse dates as defined in {@linkplain http://www.w3.org/TR/NOTE-datetime}.
* This format (also specified in ISO8601) allows different "precisions".
* The following lower precision versions for the complete date
* "2007-12-19T10:20:30.567+0300" are allowed:<br>
* "2007"<br>
* "2007-12"<br>
* "2007-12-19"<br>
* "2007-12-19T10:20+0300<br>
* "2007-12-19T10:20:30+0300<br>
* "2007-12-19T10:20:30.567+0300<br>
* Additionally a timezone offset of "+0000" can be substituted as "Z".<br>
* Parsing is done in a fuzzy way. If there is an illegal character somewhere in
* the String, the date parsed so far will be returned, e.g. the input
* "2007-12-19FOO" would return a date that represents "2007-12-19".
*
* @param s
* @return
* @throws ParseException
*/
@Override
public Date parse(String s) throws ParseException {
// do some lazy checks here
s = s.trim();
while (s.length() > 0 && s.endsWith("?")) s = s.substring(0, s.length() - 1); // sometimes used if write is not sure about date
if (s.startsWith("{")) s = s.substring(1);
if (s.endsWith("}")) s = s.substring(0, s.length() - 1);
if (s.startsWith("[")) s = s.substring(1);
if (s.endsWith("]")) s = s.substring(0, s.length() - 1);
while (s.length() > 0 && (s.charAt(0) > '9' || s.charAt(0) < '0')) s = s.substring(1);
if (s.endsWith("--")) s = s.substring(0, s.length() - 2) + "00";
int p = s.indexOf(';'); if (p >= 0) s = s.substring(0, p); // a semicolon may be used to separate two dates from each other; then we take the first
p = s.indexOf(','); if (p >= 0) s = s.substring(0, p); // a comma may be used to separate two dates from each other; then we take the first
while (s.length() > 0 && s.endsWith("?")) s = s.substring(0, s.length() - 1); // sometimes used if write is not sure about date
// no go for exact parsing
final Calendar cal = Calendar.getInstance(TZ_GMT, Locale.US);
cal.clear();
// split 2007-12-19T10:20:30.789+0500 into its parts
// correct: yyyy['-'MM['-'dd['T'HH':'MM[':'ss['.'SSS]]('Z'|ZZZZZ)]]]
final StringTokenizer t = new StringTokenizer(s, "-T:.Z+", true);
if (s == null || t.countTokens() == 0)
throw new ParseException("parseISO8601: Cannot parse '" + s + "'", 0);
try {
// year
cal.set(Calendar.YEAR, Integer.parseInt(t.nextToken()));
// month
if (t.nextToken().equals("-")) {
cal.set(Calendar.MONTH, Integer.parseInt(t.nextToken()) - 1);
} else {
return cal.getTime();
}
// day
if (t.nextToken().equals("-")) {
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(t.nextToken()));
} else {
return cal.getTime();
}
// The standard says:
// if there is an hour there has to be a minute and a timezone token, too.
if (t.nextToken().equals("T")) {
final int hour = Integer.parseInt(t.nextToken());
// no error, got hours
int min = 0;
int sec = 0;
int msec = 0;
if (t.nextToken().equals(":")) {
min = Integer.parseInt(t.nextToken());
// no error, got minutes
// need TZ or seconds
String token = t.nextToken();
if (token.equals(":")) {
sec = Integer.parseInt(t.nextToken());
// need millisecs or TZ
token = t.nextToken();
if (token.equals(".")) {
msec = Integer.parseInt(t.nextToken());
// need TZ
token = t.nextToken();
}
}
// check for TZ data
int offset;
if (token.equals("Z")) {
offset = 0;
} else {
int sign = 0;
if (token.equals("+")) {
sign = 1;
} else if (token.equals("-")) {
sign = -1;
} else {
// no legal TZ offset found
return cal.getTime();
}
offset = sign * Integer.parseInt(t.nextToken()) * 10 * 3600;
}
cal.set(Calendar.ZONE_OFFSET, offset);
}
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, min);
cal.set(Calendar.SECOND, sec);
cal.set(Calendar.MILLISECOND, msec);
}
} catch (final NoSuchElementException e) {
// ignore this as it is perfectly fine to have non-complete date in this format
} catch (final Exception e) {
// catch all Exceptions and return what we parsed so far
//serverLog.logInfo("SERVER", "parseISO8601: DATE ERROR with: '" + s + "' got so far: '" + cal.toString());
}
// in case we couldn't even parse a year
if (!cal.isSet(Calendar.YEAR))
throw new ParseException("parseISO8601: Cannot parse '" + s + "'", 0);
Date d = cal.getTime();
return d;
}
/**
* Creates a String representation of a Date using the format defined
* in ISO8601/W3C datetime
* The result will be in UTC/GMT, e.g. "2007-12-19T10:20:30Z".
*
* @param date The Date instance to transform.
* @return A fixed width (20 chars) ISO8601 date String.
*/
@Override
public final String format(final Date date) {
if (date == null) return "";
if (Math.abs(date.getTime() - last_time) < 1000) return last_format;
synchronized (FORMAT_ISO8601) {
last_format = FORMAT_ISO8601.format(date);
last_time = date.getTime();
}
return last_format;
}
}

@ -54,6 +54,7 @@ import net.yacy.cora.protocol.http.HTTPClient;
*/
public class MultiProtocolURI implements Serializable, Comparable<MultiProtocolURI> {
public static final MultiProtocolURI POISON = new MultiProtocolURI(); // poison pill for concurrent link generators
private static final long serialVersionUID = -1173233022912141884L;
private static final long SMB_TIMEOUT = 5000;

@ -20,11 +20,14 @@
package net.yacy.cora.document;
import java.net.MalformedURLException;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class RSSFeed implements Iterable<RSSMessage> {
@ -58,6 +61,14 @@ public class RSSFeed implements Iterable<RSSMessage> {
return this.imageURL;
}
public Set<MultiProtocolURI> getLinks() {
Set<MultiProtocolURI> links = new HashSet<MultiProtocolURI>();
for (RSSMessage message: messages.values()) {
try {links.add(new MultiProtocolURI(message.getLink()));} catch (MalformedURLException e) {}
}
return links;
}
public void addMessage(final RSSMessage item) {
final String guid = item.getGuid();
messages.put(guid, item);

@ -27,9 +27,9 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.kelondro.util.DateFormatter;
public class RSSMessage implements Hit {
@ -89,7 +89,7 @@ public class RSSMessage implements Hit {
map.put("title", title);
map.put("description", description);
map.put("link", link);
map.put("pubDate", DateFormatter.formatShortSecond(new Date()));
map.put("pubDate", ISO8601Formatter.FORMATTER.format(new Date()));
map.put("guid", artificialGuidPrefix + Integer.toHexString((title + description + link).hashCode()));
}
@ -150,10 +150,10 @@ public class RSSMessage implements Hit {
String dateString = Token.pubDate.valueFrom(this.map);
Date date;
try {
date = DateFormatter.parseShortSecond(dateString);
date = ISO8601Formatter.FORMATTER.parse(dateString);
} catch (ParseException e) {
try {
date = DateFormatter.parseISO8601(dateString);
date = GenericFormatter.SHORT_SECOND_FORMATTER.parse(dateString);
} catch (ParseException e1) {
date = HeaderFramework.parseHTTPDate(dateString);
}
@ -228,7 +228,7 @@ public class RSSMessage implements Hit {
}
public void setPubDate(Date pubdate) {
setValue("pubDate", DateFormatter.formatISO8601(new Date()));
setValue("pubDate", ISO8601Formatter.FORMATTER.format(pubdate));
}
public void setReferrer(String referrer) {

@ -54,19 +54,6 @@ public class RSSReader extends DefaultHandler {
type = Type.none;
}
public RSSReader(int maxsize, final String path) throws IOException {
this(maxsize);
final SAXParserFactory factory = SAXParserFactory.newInstance();
try {
final SAXParser saxParser = factory.newSAXParser();
saxParser.parse(path, this);
} catch (SAXException e) {
throw new IOException (e.getMessage());
} catch (ParserConfigurationException e) {
throw new IOException (e.getMessage());
}
}
public RSSReader(int maxsize, final InputStream stream, Type type) throws IOException {
this(maxsize);
this.type = type;

@ -38,7 +38,6 @@ import java.util.regex.Pattern;
import net.yacy.cora.storage.ARC;
import net.yacy.cora.storage.ConcurrentARC;
import net.yacy.kelondro.logging.Log;
public class Domains {
@ -603,7 +602,6 @@ public class Domains {
}
}
} catch (SocketException e) {
Log.logException(e);
}
// now look up the host name
@ -617,7 +615,6 @@ public class Domains {
InetAddress[] moreAddresses = InetAddress.getAllByName(localHostName);
if (moreAddresses != null) for (InetAddress a: moreAddresses) localHostAddresses.add(a);
} catch (UnknownHostException e) {
Log.logException(e);
}
// fill a cache of local host names

@ -39,8 +39,6 @@ import java.util.TreeMap;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import de.anomic.http.server.HTTPDemon;
import net.yacy.cora.document.MultiProtocolURI;
@ -564,23 +562,6 @@ public class HeaderFramework extends TreeMap<String, String> implements Map<Stri
return url;
}
public static void handleTransparentProxySupport(final RequestHeader header, final Properties prop, final String virtualHost, final boolean isTransparentProxy) {
// transparent proxy support is only available for http 1.0 and above connections
if (prop.getProperty(CONNECTION_PROP_HTTP_VER, "HTTP/0.9").equals("HTTP/0.9")) return;
// if the transparent proxy support was disabled, we have nothing todo here ...
if (!(isTransparentProxy && header.containsKey(HOST))) return;
// we only need to do the transparent proxy support if the request URL didn't contain the hostname
// and therefor was set to virtualHost by function parseQuery()
if (!prop.getProperty(CONNECTION_PROP_HOST).equals(virtualHost)) return;
// TODO: we could have problems with connections from extern here ...
final String dstHostSocket = header.get(HeaderFramework.HOST);
prop.setProperty(CONNECTION_PROP_HOST,(HTTPDemon.isThisHostName(dstHostSocket)?virtualHost:dstHostSocket));
}
/**
* Reading http headers from a reader class and building up a httpHeader object
* @param reader the {@link BufferedReader} that is used to read the http header lines

@ -23,14 +23,9 @@ package net.yacy.cora.protocol;
import java.net.MalformedURLException;
import java.util.Date;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Pattern;
import de.anomic.http.server.HTTPDemon;
import net.yacy.cora.document.MultiProtocolURI;
public class RequestHeader extends HeaderFramework {
// request header properties
@ -59,16 +54,6 @@ public class RequestHeader extends HeaderFramework {
private static final long serialVersionUID = 0L;
private static final Pattern P_20 = Pattern.compile(" ", Pattern.LITERAL);
private static final Pattern P_7B = Pattern.compile("{", Pattern.LITERAL);
private static final Pattern P_7D = Pattern.compile("}", Pattern.LITERAL);
private static final Pattern P_7C = Pattern.compile("|", Pattern.LITERAL);
private static final Pattern P_5C = Pattern.compile("\\", Pattern.LITERAL);
private static final Pattern P_5E = Pattern.compile("^", Pattern.LITERAL);
private static final Pattern P_5B = Pattern.compile("[", Pattern.LITERAL);
private static final Pattern P_5D = Pattern.compile("]", Pattern.LITERAL);
private static final Pattern P_60 = Pattern.compile("`", Pattern.LITERAL);
public RequestHeader() {
super();
}
@ -120,116 +105,4 @@ public class RequestHeader extends HeaderFramework {
return ((containsKey(ACCEPT_ENCODING)) &&
((get(ACCEPT_ENCODING)).toUpperCase().indexOf("GZIP")) != -1);
}
public static Properties parseRequestLine(final String cmd, String args, final String virtualHost) {
final Properties prop = new Properties();
// storing informations about the request
prop.setProperty(CONNECTION_PROP_METHOD, cmd);
prop.setProperty(CONNECTION_PROP_REQUESTLINE, cmd + " " + args);
// this parses a whole URL
if (args.length() == 0) {
prop.setProperty(CONNECTION_PROP_HOST, virtualHost);
prop.setProperty(CONNECTION_PROP_PATH, "/");
prop.setProperty(CONNECTION_PROP_HTTP_VER, HTTP_VERSION_0_9);
prop.setProperty(CONNECTION_PROP_EXT, "");
return prop;
}
// store the version propery "HTTP" and cut the query at both ends
int sep = args.lastIndexOf(' ');
if ((sep >= 0)&&(args.substring(sep + 1).toLowerCase().startsWith("http/"))) {
// HTTP version is given
prop.setProperty(CONNECTION_PROP_HTTP_VER, args.substring(sep + 1).trim());
args = args.substring(0, sep).trim(); // cut off HTTP version mark
} else {
// HTTP version is not given, it will be treated as ver 0.9
prop.setProperty(CONNECTION_PROP_HTTP_VER, HTTP_VERSION_0_9);
}
// replacing spaces in the url string correctly
args = P_20.matcher(args).replaceAll("%20");
// replace unwise characters (see RFC 2396, 2.4.3), which may not be escaped
args = P_7B.matcher(args).replaceAll("%7B");
args = P_7D.matcher(args).replaceAll("%7D");
args = P_7C.matcher(args).replaceAll("%7C");
args = P_5C.matcher(args).replaceAll("%5C");
args = P_5E.matcher(args).replaceAll("%5E");
args = P_5B.matcher(args).replaceAll("%5B");
args = P_5D.matcher(args).replaceAll("%5D");
args = P_60.matcher(args).replaceAll("%60");
// properties of the query are stored with the prefix "&"
// additionally, the values URL and ARGC are computed
String argsString = "";
sep = args.indexOf('?');
if (sep >= 0) {
// there are values attached to the query string
argsString = args.substring(sep + 1); // cut head from tail of query
args = args.substring(0, sep);
}
prop.setProperty(CONNECTION_PROP_URL, args); // store URL
//System.out.println("HTTPD: ARGS=" + argsString);
if (argsString.length() != 0) prop.setProperty(CONNECTION_PROP_ARGS, argsString); // store arguments in original form
// finally find host string
String path;
if (args.toUpperCase().startsWith("HTTP://")) {
// a host was given. extract it and set path
args = args.substring(7);
sep = args.indexOf('/');
if (sep < 0) {
// this is a malformed url, something like
// http://index.html
// we are lazy and guess that it means
// /index.html
// which is a localhost access to the file servlet
prop.setProperty(CONNECTION_PROP_HOST, args);
path = "/";
} else {
// THIS IS THE "GOOD" CASE
// a perfect formulated url
final String dstHostSocket = args.substring(0, sep);
prop.setProperty(CONNECTION_PROP_HOST, (HTTPDemon.isThisHostName(dstHostSocket)?virtualHost:dstHostSocket));
path = args.substring(sep); // yes, including beginning "/"
}
} else {
// no host in url. set path
if (args.length() > 0 && args.charAt(0) == '/') {
// thats also fine, its a perfect localhost access
// in this case, we simulate a
// http://localhost/s
// access by setting a virtual host
prop.setProperty(CONNECTION_PROP_HOST, virtualHost);
path = args;
} else {
// the client 'forgot' to set a leading '/'
// this is the same case as above, with some lazyness
prop.setProperty(CONNECTION_PROP_HOST, virtualHost);
path = "/" + args;
}
}
prop.setProperty(CONNECTION_PROP_PATH, path);
// find out file extension (we already stripped ?-parameters from args)
String ext = ""; // default when no file extension
sep = path.lastIndexOf('.');
if (sep >= 0) {
final int ancpos = path.indexOf("#", sep + 1);
if (ancpos >= sep) {
// ex: /foo/bar.html#xy => html
ext = path.substring(sep + 1, ancpos).toLowerCase();
} else {
// ex: /foo/bar.php => php
ext = path.substring(sep + 1).toLowerCase();
}
}
prop.setProperty(CONNECTION_PROP_EXT, ext);
return prop;
}
}

@ -32,21 +32,14 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.LinkedBlockingQueue;
import de.anomic.data.WorkTables;
import de.anomic.search.Switchboard;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.protocol.ftp.FTPClient;
import net.yacy.cora.protocol.http.HTTPClient;
import net.yacy.kelondro.blob.Tables;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
/**
* a protocol scanner
@ -208,7 +201,6 @@ public class Scanner extends Thread {
runner.start();
}
} catch (InterruptedException e) {
Log.logException(e);
}
}
@ -302,7 +294,6 @@ public class Scanner extends Thread {
try {
this.scanqueue.put(new Service(protocol, i));
} catch (InterruptedException e) {
Log.logException(e);
}
}
}
@ -336,22 +327,6 @@ public class Scanner extends Thread {
return null;
}
public static Map<byte[], String> commentCache(Switchboard sb) {
Map<byte[], String> comments = new TreeMap<byte[], String>(Base64Order.enhancedCoder);
Iterator<Tables.Row> i;
try {
i = sb.tables.iterator(WorkTables.TABLE_API_NAME);
Tables.Row row;
while (i.hasNext()) {
row = i.next();
comments.put(row.getPK(), new String(row.get(WorkTables.TABLE_API_COL_COMMENT)));
}
} catch (IOException e) {
Log.logException(e);
}
return comments;
}
public static void main(String[] args) {
//try {System.out.println("192.168.1.91: " + ping(new MultiProtocolURI("smb://192.168.1.91/"), 1000));} catch (MalformedURLException e) {}
Scanner scanner = new Scanner(100, 10);

@ -37,8 +37,6 @@ import java.util.concurrent.TimeoutException;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import net.yacy.kelondro.logging.Log;
/**
* TimeoutRequest is a class that can apply a timeout on method calls that may block
* for undefined time. Some network operations can only be accessed without a given
@ -316,7 +314,7 @@ public class TimeoutRequest<E> {
public String[] call() { try {
return file.list();
} catch (SmbException e) {
Log.logWarning("TimeoutRequest:list", file.toString() + " - no list", e);
//Log.logWarning("TimeoutRequest:list", file.toString() + " - no list", e);
return null;
} }
}).call(timeout);

@ -0,0 +1,74 @@
/**
* LinkExtractor
* Copyright 2011 by Michael Peter Christen
* First released 2.01.2011 at http://yacy.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt
* If not, see <http://www.gnu.org/licenses/>.
*/
package net.yacy.cora.protocol.http;
import java.net.MalformedURLException;
import java.util.WeakHashMap;
import java.util.regex.Pattern;
import net.yacy.cora.document.MultiProtocolURI;
public class LinkExtractor {
private static final char lb = '<', rb = '>', dquotes = '"', space = ' ';
private static final Object PRESENT = new Object();
private WeakHashMap<MultiProtocolURI, Object> links;
private Pattern blackpattern;
public LinkExtractor(Pattern blackpattern) {
this.links = new WeakHashMap<MultiProtocolURI, Object>();
this.blackpattern = blackpattern;
}
public void scrape(String text) {
text = text.replace(lb, space).replace(rb, space).replace(dquotes, space);
int p, q, s = 0;
String u;
while (s < text.length()) {
p = Math.min(find(text, "smb://", s), Math.min(find(text, "ftp://", s), Math.min(find(text, "http://", s), find(text, "https://", s))));
if (p == Integer.MAX_VALUE) break;
q = text.indexOf(" ", p + 1);
u = text.substring(p, q < 0 ? text.length() : q);
if (u.endsWith(".")) u = u.substring(0, u.length() - 1); // remove the '.' that was appended above
s = p + 1;
if (this.blackpattern.matcher(u).matches()) continue;
try {links.put(new MultiProtocolURI(u), PRESENT);} catch (MalformedURLException e) {}
}
}
/**
* return the links in the text in the order as they appear
* @return a list of urls
*/
public MultiProtocolURI[] getLinks() {
MultiProtocolURI[] urls = new MultiProtocolURI[this.links.size()];
int i = 0;
for (MultiProtocolURI uri: this.links.keySet()) urls[i++] = uri;
return urls;
}
private static final int find(final String s, final String m, final int start) {
final int p = s.indexOf(m, start);
return (p < 0) ? Integer.MAX_VALUE : p;
}
}

@ -23,8 +23,6 @@ package net.yacy.cora.protocol.http;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
//import org.apache.commons.httpclient.HostConfiguration;
//import org.apache.commons.httpclient.HttpClient;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;

@ -18,85 +18,132 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
package net.yacy.cora.services;
import java.io.IOException;
import java.net.MalformedURLException;
//import java.nio.charset.Charset;
//import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
//import java.util.List;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.document.RSSFeed;
import net.yacy.cora.document.RSSMessage;
import net.yacy.cora.document.RSSReader;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.protocol.http.HTTPClient;
import net.yacy.cora.protocol.http.HTTPConnector;
import net.yacy.cora.protocol.http.LinkExtractor;
import net.yacy.cora.storage.ScoreMap;
//import org.apache.commons.httpclient.methods.multipart.Part;
//import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.StringBody;
public class Search {
public static BlockingQueue<RSSMessage> search(String rssSearchServiceURL, String query, boolean verify, boolean global, long timeout, int maximumRecords) {
BlockingQueue<RSSMessage> queue = new LinkedBlockingQueue<RSSMessage>();
searchJob job = new searchJob(rssSearchServiceURL, query, verify, global, timeout, maximumRecords, queue);
job.start();
return queue;
}
private final static int recordsPerSession = 10;
public static class searchJob extends Thread {
public class Search extends Thread {
String urlBase, query;
boolean verify, global;
long timeout;
int startRecord, maximumRecords;
BlockingQueue<RSSMessage> queue;
private final static int recordsPerSession = 10;
public searchJob(String urlBase, String query, boolean verify, boolean global, long timeout, int maximumRecords, BlockingQueue<RSSMessage> queue) {
this.urlBase = urlBase;
this.query = query;
this.verify = verify;
this.global = global;
this.timeout = timeout;
this.startRecord = 0;
this.maximumRecords = maximumRecords;
this.queue = queue;
}
public static final String[] SRURSSServicesList = {
"http://yacy.dyndns.org:8000/yacysearch.rss",
"http://yacy.caloulinux.net:8085/yacysearch.rss",
"http://algire.dyndns.org:8085/yacysearch.rss",
"http://breyvogel.dyndns.org:8002/yacysearch.rss"
};
public static final String[] genericServicesList = {
"http://www.scroogle.org/cgi-bin/nbbw.cgi?Gw=$&n=2",
"http://blekko.com/ws/$+/rss",
"http://www.bing.com/search?q=$&format=rss",
"http://search.twitter.com/search.atom?q=$"
};
public void run() {
RSSMessage message;
mainloop: while (timeout > 0 && maximumRecords > 0) {
long st = System.currentTimeMillis();
RSSFeed feed;
public static Thread accumulateSRURSS(
final String urlBase,
final String query,
final long timeoutInit,
final int maximumRecordsInit,
final boolean verify,
final boolean global,
final Map<MultiProtocolURI, List<Integer>> result) {
Thread t = new Thread() {
BlockingQueue<RSSMessage> results = new LinkedBlockingQueue<RSSMessage>();
public void run() {
searchSRURSS(urlBase, query, timeoutInit, maximumRecordsInit, verify, global, results);
int p = 1;
RSSMessage message;
try {
feed = search(urlBase, query, verify, global, timeout, startRecord, recordsPerSession);
} catch (IOException e1) {
break mainloop;
while ((message = results.poll(timeoutInit, TimeUnit.MILLISECONDS)) != RSSMessage.POISON) {
MultiProtocolURI uri;
if (message == null) break;
try {
uri = new MultiProtocolURI(message.getLink());
List<Integer> m = result.get(uri);
if (m == null) m = new ArrayList<Integer>();
m.add(new Integer(p++));
result.put(uri, m);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
if (feed == null || feed.isEmpty()) break mainloop;
maximumRecords -= feed.size();
innerloop: while (!feed.isEmpty()) {
message = feed.pollMessage();
if (message == null) break innerloop;
}
};
t.start();
return t;
}
public static Thread searchSRURSS(
final String urlBase,
final String query,
final long timeoutInit,
final int maximumRecordsInit,
final boolean verify,
final boolean global,
final BlockingQueue<RSSMessage> queue) {
Thread job = new Thread() {
public void run() {
int startRecord = 0;
RSSMessage message;
int maximumRecords = maximumRecordsInit;
long timeout = timeoutInit;
mainloop: while (timeout > 0 && maximumRecords > 0) {
long st = System.currentTimeMillis();
RSSFeed feed;
try {
queue.put(message);
} catch (InterruptedException e) {
break innerloop;
feed = loadSRURSS(urlBase, query, timeout, startRecord, recordsPerSession, verify, global);
} catch (IOException e1) {
break mainloop;
}
if (feed == null || feed.isEmpty()) break mainloop;
maximumRecords -= feed.size();
innerloop: while (!feed.isEmpty()) {
message = feed.pollMessage();
if (message == null) break innerloop;
try {
queue.put(message);
} catch (InterruptedException e) {
break innerloop;
}
}
startRecord += recordsPerSession;
timeout -= System.currentTimeMillis() - st;
}
startRecord += recordsPerSession;
timeout -= System.currentTimeMillis() - st;
try { queue.put(RSSMessage.POISON); } catch (InterruptedException e) {}
}
try { queue.put(RSSMessage.POISON); } catch (InterruptedException e) {}
}
};
job.start();
return job;
}
/**
@ -110,7 +157,14 @@ public class Search {
* @param timeout milliseconds that are waited at maximum for a search result
* @return
*/
public static RSSFeed search(String rssSearchServiceURL, String query, boolean verify, boolean global, long timeout, int startRecord, int maximumRecords) throws IOException {
public static RSSFeed loadSRURSS(
String rssSearchServiceURL,
String query,
long timeout,
int startRecord,
int maximumRecords,
boolean verify,
boolean global) throws IOException {
MultiProtocolURI uri = null;
try {
uri = new MultiProtocolURI(rssSearchServiceURL);
@ -142,5 +196,118 @@ public class Search {
throw new IOException("cora.Search error asking peer '" + uri.getHost() + "':" + e.toString());
}
}
public static Thread accumulateGeneric(
String query,
String service,
final Map<MultiProtocolURI, List<Integer>> result,
final int timeout) {
query = query.replace(' ', '+');
final String servicePatched = service.replaceAll("\\$", query);
Thread t = new Thread() {
public void run() {
try {
MultiProtocolURI[] sr = loadGeneric(new MultiProtocolURI(servicePatched), timeout);
int p = 1;
for (MultiProtocolURI u: sr) {
List<Integer> m = result.get(u);
if (m == null) m = new ArrayList<Integer>();
m.add(new Integer(p++));
result.put(u, m);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
};
t.start();
return t;
}
private static MultiProtocolURI[] loadGeneric(MultiProtocolURI uri, long timeout) throws IOException {
final RequestHeader requestHeader = new RequestHeader();
requestHeader.put(HeaderFramework.USER_AGENT, MultiProtocolURI.yacybotUserAgent);
final HTTPClient client = new HTTPClient();
client.setTimout((int) timeout);
client.setHeader(requestHeader.entrySet());
byte[] result = client.GETbytes(uri.toString());
client.finish();
if (client.getStatusCode() != 200) {
throw new IOException("Server returned status: " + client.getHttpResponse().getStatusLine());
}
if (result == null) throw new IOException("cora.Search error asking peer '" + uri.getHost() + "': null");
LinkExtractor le = new LinkExtractor(Pattern.compile(".*" + uri.getHost() + ".*"));
le.scrape(new String(result));
MultiProtocolURI[] links = le.getLinks();
return links;
}
public static RSSFeed links2feed(Set<MultiProtocolURI> links, String source) {
RSSFeed feed = new RSSFeed(Integer.MAX_VALUE);
String u;
RSSMessage message;
for (MultiProtocolURI uri: links) {
u = uri.toNormalform(true, false);
message = new RSSMessage(u, "", u);
message.setAuthor(source);
feed.addMessage(message);
}
return feed;
}
private Map<MultiProtocolURI, List<Integer>> result;
private String query;
private int count;
private String[] yacyServices, rssServices, genericServices;
private List<Thread> threads;
public Search(String query, int count, String[] rssServices, String[] genericServices) {
this.result = new ConcurrentHashMap<MultiProtocolURI, List<Integer>>();
this.query = query;
this.count = count;
this.yacyServices = yacyServices;
this.rssServices = rssServices;
this.genericServices = genericServices;
this.threads = new ArrayList<Thread>();
}
public void run() {
for (String service: this.rssServices) threads.add(accumulateSRURSS(service, this.query, 10000, this.count, false, true, this.result));
for (String service: this.genericServices) threads.add(accumulateGeneric(this.query, service, this.result, 10000));
}
public ScoreMap<MultiProtocolURI> getResults() {
ScoreMap<MultiProtocolURI> scores = new ScoreMap<MultiProtocolURI>();
int m = this.rssServices.length + this.genericServices.length;
for (Map.Entry<MultiProtocolURI, List<Integer>> entry: this.result.entrySet()) {
int a = 0;
for (Integer i : entry.getValue()) a += i.intValue();
scores.inc(entry.getKey(), a * m / entry.getValue().size());
}
return scores;
}
public void waitTermination() {
for (Thread t: threads) try {t.join();} catch (InterruptedException e) {}
}
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
for (String s: args) sb.append(s).append(' ');
String query = sb.toString().trim();
Search search = new Search(query, 100, SRURSSServicesList, genericServicesList);
search.start();
try {Thread.sleep(100);} catch (InterruptedException e1) {}
search.waitTermination();
ScoreMap<MultiProtocolURI> result = search.getResults();
Iterator<MultiProtocolURI> i = result.keys(true);
MultiProtocolURI u;
while (i.hasNext()) {
u = i.next();
System.out.println("[" + result.get(u) + "] " + u.toNormalform(true, false));
}
try {HTTPClient.closeConnectionManager();} catch (InterruptedException e) {}
}
}

@ -94,4 +94,8 @@ public class IntScore implements Comparable<IntScore>, Comparator<IntScore> {
public int compare(IntScore o1, IntScore o2) {
return o1.compareTo(o2);
}
public String toString() {
return Integer.toString(this.value);
}
}

@ -0,0 +1,39 @@
/**
* OutOfLimitsException
* Copyright 2006 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany
* First released 17.01.2006 at http://yacy.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt
* If not, see <http://www.gnu.org/licenses/>.
*/
package net.yacy.cora.storage;
public class OutOfLimitsException extends java.lang.RuntimeException {
private static final long serialVersionUID = 1L;
public OutOfLimitsException() {
super("unspecific-error");
}
public OutOfLimitsException(final int expectedLimit, final int actualSize) {
super("Object size is " + actualSize + "; it exceeds the size limit " + expectedLimit);
}
public OutOfLimitsException(final int actualSize) {
super("Object size is " + actualSize + "; must not be negative");
}
}

@ -30,9 +30,6 @@ import java.util.Random;
import java.util.SortedMap;
import java.util.TreeMap;
import net.yacy.kelondro.util.kelondroOutOfLimitsException;
public final class ScoreCluster<E> implements DynamicScore<E> {
protected final Map<E, Long> map; // a mapping from a reference to the cluster key
@ -198,7 +195,7 @@ public final class ScoreCluster<E> implements DynamicScore<E> {
if (obj == null) return;
synchronized (this) {
Long usk = map.remove(obj); // get unique score key, old entry is not needed any more
if (newScore < 0) throw new kelondroOutOfLimitsException(newScore);
if (newScore < 0) throw new OutOfLimitsException(newScore);
if (usk == null) {
// set new value
@ -235,7 +232,7 @@ public final class ScoreCluster<E> implements DynamicScore<E> {
if (usk == null) {
// set new value
if (incrementScore < 0) throw new kelondroOutOfLimitsException(incrementScore);
if (incrementScore < 0) throw new OutOfLimitsException(incrementScore);
usk = Long.valueOf(scoreKey(encnt++, incrementScore));
// put new value into cluster
@ -253,7 +250,7 @@ public final class ScoreCluster<E> implements DynamicScore<E> {
// set new value
final int newValue = oldScore + incrementScore;
if (newValue < 0) throw new kelondroOutOfLimitsException(newValue);
if (newValue < 0) throw new OutOfLimitsException(newValue);
usk = Long.valueOf(scoreKey(oldHandle, newValue)); // generates an unique key for a specific score
map.put(obj, usk);
pam.put(usk, obj);

@ -50,12 +50,12 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.document.parser.html.ContentScraper;
import net.yacy.document.parser.html.ImageEntry;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.ByteBuffer;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
@ -593,7 +593,7 @@ dc_rights
}
String language = this.dc_language();
if (language != null && language.length() > 0) os.write("<dc:language>" + this.dc_language() + "</dc:language>\n");
os.write("<dc:date>" + DateFormatter.formatISO8601(date) + "</dc:date>\n");
os.write("<dc:date>" + ISO8601Formatter.FORMATTER.format(date) + "</dc:date>\n");
os.write("</record>\n");
}

@ -36,10 +36,10 @@ import java.util.HashSet;
import java.util.Locale;
import java.util.TreeMap;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.document.Document;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
public class DCEntry extends TreeMap<String, String> {
@ -67,7 +67,7 @@ public class DCEntry extends TreeMap<String, String> {
) {
super((Collator) insensitiveCollator.clone());
this.put("dc:identifier", url.toNormalform(true, false));
this.put("dc:date", DateFormatter.formatISO8601(date));
this.put("dc:date", ISO8601Formatter.FORMATTER.format(date));
this.put("dc:title", title);
this.put("dc:creator", author);
this.put("dc:description", body);
@ -98,7 +98,7 @@ public class DCEntry extends TreeMap<String, String> {
if (d == null) return null;
if (d.length() == 0) return null;
try {
return DateFormatter.parseISO8601(d);
return ISO8601Formatter.FORMATTER.parse(d);
} catch (ParseException e) {
Log.logException(e);
return new Date();

@ -32,9 +32,9 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.repository.LoaderDispatcher;
import de.anomic.search.Switchboard;
@ -202,7 +202,7 @@ public class OAIPMHImporter extends Thread implements Importer, Comparable<OAIPM
for (String s: surrogates.list()) {
if (s.startsWith(filenamePrefix) && s.endsWith(".xml") && s.charAt(s.length() - 22) == filenameSeparationChar) {
try {
Date fd = DateFormatter.parseShortMilliSecond(s.substring(s.length() - 21, s.length() - 4));
Date fd = GenericFormatter.SHORT_MILSEC_FORMATTER.parse(s.substring(s.length() - 21, s.length() - 4));
String hostID = s.substring(7, s.length() - 22);
Date md = map.get(hostID);
if (md == null || fd.after(md)) map.put(hostID, fd);
@ -242,6 +242,6 @@ public class OAIPMHImporter extends Thread implements Importer, Comparable<OAIPM
public static final String filename4Source(DigestURI source) {
return filenamePrefix + OAIPMHImporter.filenameSeparationChar +
OAIPMHImporter.hostID(source) + OAIPMHImporter.filenameSeparationChar +
DateFormatter.formatShortMilliSecond(new Date()) + ".xml";
GenericFormatter.SHORT_MILSEC_FORMATTER.format(new Date()) + ".xml";
}
}

@ -39,9 +39,9 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
public class ResumptionToken extends TreeMap<String, String> {
@ -142,7 +142,7 @@ public class ResumptionToken extends TreeMap<String, String> {
// can be detected with given expiration date
Date expiration = getExpirationDate();
if (expiration != null) {
if (expiration.before(new Date())) throw new IOException("the resumption is expired at " + DateFormatter.formatISO8601(expiration) + " (now: " + DateFormatter.formatISO8601(new Date()));
if (expiration.before(new Date())) throw new IOException("the resumption is expired at " + ISO8601Formatter.FORMATTER.format(expiration) + " (now: " + ISO8601Formatter.FORMATTER.format(new Date()));
// the resumption token is still fresh
}
String u = url + "verb=ListRecords&resumptionToken=" + escape(token);
@ -191,7 +191,7 @@ public class ResumptionToken extends TreeMap<String, String> {
String d = this.get("expirationDate");
if (d == null) return null;
try {
return DateFormatter.parseISO8601(d);
return ISO8601Formatter.FORMATTER.parse(d);
} catch (ParseException e) {
Log.logException(e);
return new Date();
@ -241,7 +241,7 @@ public class ResumptionToken extends TreeMap<String, String> {
}
public String toString() {
return "source = " + this.source + ", expirationDate=" + DateFormatter.formatISO8601(this.getExpirationDate()) + ", completeListSize=" + getCompleteListSize() +
return "source = " + this.source + ", expirationDate=" + ISO8601Formatter.FORMATTER.format(this.getExpirationDate()) + ", completeListSize=" + getCompleteListSize() +
", cursor=" + this.getCursor() + ", token=" + this.getToken();
}

@ -45,6 +45,7 @@ import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import net.yacy.cora.date.ISO8601Formatter;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
@ -57,7 +58,6 @@ import net.yacy.document.TextParser;
import net.yacy.document.parser.html.ImageEntry;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.io.ByteCountInputStream;
import net.yacy.kelondro.util.DateFormatter;
public class sitemapParser extends AbstractParser implements Parser {
@ -198,7 +198,7 @@ public class sitemapParser extends AbstractParser implements Parser {
public Date lastmod(final Date dflt) {
try {
return DateFormatter.parseISO8601(lastmod);
return ISO8601Formatter.FORMATTER.parse(lastmod);
} catch (final ParseException e) {
return dflt;
}
@ -219,7 +219,7 @@ public class sitemapParser extends AbstractParser implements Parser {
public Date lastmod(final Date dflt) {
try {
return DateFormatter.parseISO8601(lastmod);
return ISO8601Formatter.FORMATTER.parse(lastmod);
} catch (final ParseException e) {
return dflt;
}

@ -47,6 +47,7 @@ import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.kelondro.index.Row;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
@ -58,7 +59,6 @@ import net.yacy.kelondro.rwi.Reference;
import net.yacy.kelondro.rwi.ReferenceContainer;
import net.yacy.kelondro.rwi.ReferenceFactory;
import net.yacy.kelondro.rwi.ReferenceIterator;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.LookAheadIterator;
import net.yacy.kelondro.util.NamePrefixThreadFactory;
@ -161,7 +161,7 @@ public class ArrayStack implements BLOB {
f.delete();
deletions = true;
} else try {
d = DateFormatter.parseShortSecond(files[i].substring(0, 14));
d = GenericFormatter.SHORT_SECOND_FORMATTER.parse(files[i].substring(0, 14));
f.renameTo(newBLOB(d));
deletions = true;
} catch (ParseException e) {continue;}
@ -177,7 +177,7 @@ public class ArrayStack implements BLOB {
for (int i = 0; i < files.length; i++) {
if (files[i].length() >= 22 && files[i].startsWith(prefix) && files[i].endsWith(".blob")) {
try {
d = DateFormatter.parseShortMilliSecond(files[i].substring(prefix.length() + 1, prefix.length() + 18));
d = GenericFormatter.SHORT_MILSEC_FORMATTER.parse(files[i].substring(prefix.length() + 1, prefix.length() + 18));
time = d.getTime();
if (time > maxtime) maxtime = time;
} catch (ParseException e) {continue;}
@ -188,7 +188,7 @@ public class ArrayStack implements BLOB {
for (int i = 0; i < files.length; i++) {
if (files[i].length() >= 22 && files[i].startsWith(prefix) && files[i].endsWith(".blob")) {
try {
d = DateFormatter.parseShortMilliSecond(files[i].substring(prefix.length() + 1, prefix.length() + 18));
d = GenericFormatter.SHORT_MILSEC_FORMATTER.parse(files[i].substring(prefix.length() + 1, prefix.length() + 18));
f = new File(heapLocation, files[i]);
time = d.getTime();
if (time == maxtime && !trimall) {
@ -231,7 +231,7 @@ public class ArrayStack implements BLOB {
public synchronized void mountBLOB(File location, boolean full) throws IOException {
Date d;
try {
d = DateFormatter.parseShortMilliSecond(location.getName().substring(prefix.length() + 1, prefix.length() + 18));
d = GenericFormatter.SHORT_MILSEC_FORMATTER.parse(location.getName().substring(prefix.length() + 1, prefix.length() + 18));
} catch (ParseException e) {
throw new IOException("date parse problem with file " + location.toString() + ": " + e.getMessage());
}
@ -365,7 +365,7 @@ public class ArrayStack implements BLOB {
*/
public synchronized File newBLOB(Date creation) {
//return new File(heapLocation, DateFormatter.formatShortSecond(creation) + "." + blobSalt + ".blob");
return new File(heapLocation, prefix + "." + DateFormatter.formatShortMilliSecond(creation) + ".blob");
return new File(heapLocation, prefix + "." + GenericFormatter.SHORT_MILSEC_FORMATTER.format(creation) + ".blob");
}
public String name() {

@ -33,6 +33,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@ -40,6 +41,7 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.storage.ARC;
import net.yacy.cora.storage.ConcurrentARC;
import net.yacy.kelondro.index.RowSpaceExceededException;
@ -48,7 +50,6 @@ import net.yacy.kelondro.order.ByteOrder;
import net.yacy.kelondro.order.CloneableIterator;
import net.yacy.kelondro.order.NaturalOrder;
import net.yacy.kelondro.order.RotateIterator;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.kelondroException;
@ -139,7 +140,7 @@ public class MapHeap implements Map<byte[], Map<String, String>> {
assert key.length > 0;
assert newMap != null;
key = normalizeKey(key);
String s = map2string(newMap, "W" + DateFormatter.formatShortSecond() + " ");
String s = map2string(newMap, "W" + GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date()) + " ");
assert s != null;
byte[] sb = s.getBytes();
synchronized (this) {

@ -41,11 +41,11 @@ import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.ByteArray;
import net.yacy.kelondro.util.ByteBuffer;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.LookAheadIterator;
@ -408,7 +408,7 @@ public class Tables {
}
public void put(String colname, Date value) {
super.put(colname, DateFormatter.formatShortMilliSecond(value).getBytes());
super.put(colname, GenericFormatter.SHORT_MILSEC_FORMATTER.format(value).getBytes());
}
public byte[] get(String colname, byte[] dflt) {
@ -447,7 +447,7 @@ public class Tables {
byte[] r = this.get(colname);
if (r == null) return dflt;
try {
return DateFormatter.parseShortMilliSecond(new String(r));
return GenericFormatter.SHORT_MILSEC_FORMATTER.parse(new String(r));
} catch (ParseException e) {
return dflt;
}

@ -34,6 +34,7 @@ import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.kelondro.data.word.WordReferenceRow;
import net.yacy.kelondro.data.word.WordReferenceVars;
import net.yacy.kelondro.index.Row;
@ -44,7 +45,6 @@ import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.order.Digest;
import net.yacy.kelondro.order.NaturalOrder;
import net.yacy.kelondro.util.ByteBuffer;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.kelondroException;
import net.yacy.kelondro.util.MapTools;
@ -228,17 +228,17 @@ public class URIMetadataRow implements URIMetadata {
this.entry.setCol(col_hash, url.hash()); // FIXME potential null pointer access
this.entry.setCol(col_comp, encodeComp(url, descr, dc_creator, tags, dc_publisher));
try {
encodeDate(col_mod, DateFormatter.parseShortDay(prop.getProperty("mod", "20000101")));
encodeDate(col_mod, GenericFormatter.SHORT_DAY_FORMATTER.parse(prop.getProperty("mod", "20000101")));
} catch (final ParseException e) {
encodeDate(col_mod, new Date());
}
try {
encodeDate(col_load, DateFormatter.parseShortDay(prop.getProperty("load", "20000101")));
encodeDate(col_load, GenericFormatter.SHORT_DAY_FORMATTER.parse(prop.getProperty("load", "20000101")));
} catch (final ParseException e) {
encodeDate(col_load, new Date());
}
try {
encodeDate(col_fresh, DateFormatter.parseShortDay(prop.getProperty("fresh", "20000101")));
encodeDate(col_fresh, GenericFormatter.SHORT_DAY_FORMATTER.parse(prop.getProperty("fresh", "20000101")));
} catch (final ParseException e) {
encodeDate(col_fresh, new Date());
}
@ -305,11 +305,11 @@ public class URIMetadataRow implements URIMetadata {
assert (s.toString().indexOf(0) < 0);
s.append(",publisher=").append(crypt.simpleEncode(metadata.dc_publisher()));
assert (s.toString().indexOf(0) < 0);
s.append(",mod=").append(DateFormatter.formatShortDay(moddate()));
s.append(",mod=").append(GenericFormatter.SHORT_DAY_FORMATTER.format(moddate()));
assert (s.toString().indexOf(0) < 0);
s.append(",load=").append(DateFormatter.formatShortDay(loaddate()));
s.append(",load=").append(GenericFormatter.SHORT_DAY_FORMATTER.format(loaddate()));
assert (s.toString().indexOf(0) < 0);
s.append(",fresh=").append(DateFormatter.formatShortDay(freshdate()));
s.append(",fresh=").append(GenericFormatter.SHORT_DAY_FORMATTER.format(freshdate()));
assert (s.toString().indexOf(0) < 0);
s.append(",referrer=").append(referrerHash() == null ? "" : new String(referrerHash()));
assert (s.toString().indexOf(0) < 0);

@ -41,6 +41,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.kelondro.blob.ArrayStack;
import net.yacy.kelondro.index.Cache;
import net.yacy.kelondro.index.HandleSet;
@ -54,7 +55,6 @@ import net.yacy.kelondro.order.CloneableIterator;
import net.yacy.kelondro.order.MergeIterator;
import net.yacy.kelondro.order.Order;
import net.yacy.kelondro.order.StackIterator;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.NamePrefixThreadFactory;
@ -136,7 +136,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
}
private String newFilename() {
return prefix + "." + DateFormatter.formatShortMilliSecond(new Date()) + ".table";
return prefix + "." + GenericFormatter.SHORT_MILSEC_FORMATTER.format(new Date()) + ".table";
}
private void init() throws RowSpaceExceededException {
@ -172,7 +172,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
(tablefile[i].length() == prefix.length() + 24)) {
f = new File(path, tablefile[i]);
try {
d = DateFormatter.parseShortMilliSecond(tablefile[i].substring(prefix.length() + 1, prefix.length() + 18));
d = GenericFormatter.SHORT_MILSEC_FORMATTER.parse(tablefile[i].substring(prefix.length() + 1, prefix.length() + 18));
} catch (ParseException e) {
Log.logSevere("SplitTable", "", e);
continue;
@ -331,7 +331,7 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
String name = new File(table.filename()).getName();
long d;
try {
d = DateFormatter.parseShortMilliSecond(name.substring(prefix.length() + 1, prefix.length() + 18)).getTime();
d = GenericFormatter.SHORT_MILSEC_FORMATTER.parse(name.substring(prefix.length() + 1, prefix.length() + 18)).getTime();
} catch (ParseException e) {
Log.logSevere("SplitTable", "", e);
d = 0;

@ -828,19 +828,14 @@ public class Table implements Index, Iterable<Row.Entry> {
int idx;
byte[] key;
public rowIteratorNoOrder() throws IOException {
public rowIteratorNoOrder() {
// don't use the ChunkIterator here because it may create too many open files during string load
//ri = new ChunkIterator(tablefile, rowdef.objectsize, rowdef.objectsize);
i = index.iterator();
}
public CloneableIterator<Entry> clone(Object modifier) {
try {
return new rowIteratorNoOrder();
} catch (IOException e) {
Log.logSevere("Table", "", e);
return null;
}
return new rowIteratorNoOrder();
}
public boolean hasNext() {

@ -1,473 +0,0 @@
// serverDate.java
// -------------------------------------------
// (C) by Michael Peter Christen; mc@yacy.net
// (C) by by Bjoern 'Fuchs' Krombholz; fox.box@gmail.com
// first published on http://www.anomic.de
// Frankfurt, Germany, 2005, 2007
// last major change: 14.03.2005
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// this class is needed to replace the slow java built-in date method by a faster version
package net.yacy.kelondro.util;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.TimeZone;
public final class DateFormatter {
/** minimal date format without time information (fixed width: 8) */
public static final String PATTERN_SHORT_DAY = "yyyyMMdd";
/** minimal date format (fixed width: 14) */
public static final String PATTERN_SHORT_SECOND = "yyyyMMddHHmmss";
/** minimal date format including milliseconds (fixed width: 17) */
public static final String PATTERN_SHORT_MILSEC = "yyyyMMddHHmmssSSS";
/** default HTTP 1.1 header date format pattern */
public static final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss Z"; // with numeric time zone indicator as defined in RFC5322
public static final String PATTERN_RFC1123_SHORT = "EEE, dd MMM yyyy";
/** date pattern used in older HTTP implementations */
public static final String PATTERN_ANSIC = "EEE MMM d HH:mm:ss yyyy";
/** date pattern used in older HTTP implementations */
public static final String PATTERN_RFC1036 = "EEEE, dd-MMM-yy HH:mm:ss zzz";
/** pattern for a W3C datetime variant of a non-localized ISO8601 date */
public static final String PATTERN_ISO8601 = "yyyy-MM-dd'T'HH:mm:ss'Z'";
/** predefined GMT TimeZone object */
private static final TimeZone TZ_GMT = TimeZone.getTimeZone("GMT");
/** predefined non-localized Calendar object for generic GMT dates */
private static final Calendar CAL_GMT = Calendar.getInstance(TZ_GMT, Locale.US);
/** Date formatter/parser for minimal yyyyMMdd pattern */
private static final SimpleDateFormat FORMAT_SHORT_DAY = new SimpleDateFormat(PATTERN_SHORT_DAY, Locale.US);
/** Date formatter/parser for minimal yyyyMMddHHmmss pattern */
private static final SimpleDateFormat FORMAT_SHORT_SECOND = new SimpleDateFormat(PATTERN_SHORT_SECOND, Locale.US);
/** Date formatter/parser for minimal yyyyMMddHHmmssSSS pattern */
private static final SimpleDateFormat FORMAT_SHORT_MILSEC = new SimpleDateFormat(PATTERN_SHORT_MILSEC, Locale.US);
/** Date formatter/non-sloppy parser for W3C datetime (ISO8601) in GMT/UTC */
private static final SimpleDateFormat FORMAT_ISO8601 = new SimpleDateFormat(PATTERN_ISO8601, Locale.US);
/** Date formatter/parser for standard compliant HTTP header dates (RFC 1123) */
private static final SimpleDateFormat FORMAT_ANSIC = new SimpleDateFormat(PATTERN_ANSIC, Locale.US);
private static final SimpleDateFormat FORMAT_RFC1123_SHORT = new SimpleDateFormat(PATTERN_RFC1123_SHORT, Locale.US);
/** Initialization of static formats */
static {
// 2-digit dates are automatically parsed by SimpleDateFormat,
// we need to detect the real year by adding 1900 or 2000 to
// the year value starting with 1970
CAL_GMT.setTimeInMillis(0);
// we want GMT times on the SHORT formats as well as they don't support any timezone
FORMAT_SHORT_DAY.setTimeZone(TZ_GMT);
FORMAT_SHORT_SECOND.setTimeZone(TZ_GMT);
FORMAT_SHORT_MILSEC.setTimeZone(TZ_GMT);
FORMAT_ISO8601.setTimeZone(TZ_GMT);
}
/**
* Creates a String representation of a Date using the format defined
* in ISO8601/W3C datetime
* The result will be in UTC/GMT, e.g. "2007-12-19T10:20:30Z".
*
* @param date The Date instance to transform.
* @return A fixed width (20 chars) ISO8601 date String.
*/
private static long FORMAT_ISO8601_last_time = 0;
private static String FORMAT_ISO8601_last_format = "";
public static final String formatISO8601(final Date date) {
if (date == null) return "";
if (Math.abs(date.getTime() - FORMAT_ISO8601_last_time) < 1000) return FORMAT_ISO8601_last_format;
FORMAT_ISO8601_last_format = format(FORMAT_ISO8601, date);
FORMAT_ISO8601_last_time = date.getTime();
return FORMAT_ISO8601_last_format;
}
public static final String formatANSIC(final Date date) {
if (date == null) return "";
return format(FORMAT_ANSIC, date);
}
public static String formatRFC1123_short(final Date date) {
if (date == null) return "";
return FORMAT_RFC1123_SHORT.format(date);
}
/**
* Identical to {@link #formatShortDay(Date)}, but for short second format.
*/
private static long FORMAT_SHORT_SECOND_last_time = 0;
private static String FORMAT_SHORT_SECOND_last_format = "";
public static String formatShortSecond(final Date date) {
if (date == null) return "";
if (Math.abs(date.getTime() - FORMAT_SHORT_SECOND_last_time) < 1000) return FORMAT_SHORT_SECOND_last_format;
FORMAT_SHORT_SECOND_last_format = format(FORMAT_SHORT_SECOND, date);
FORMAT_SHORT_SECOND_last_time = date.getTime();
return FORMAT_SHORT_SECOND_last_format;
}
public static String formatShortMilliSecond(final Date date) {
return format(FORMAT_SHORT_MILSEC, date);
}
/**
* Note: The short day format doesn't include any timezone information. This method
* transforms the date into the GMT/UTC timezone. Example: If the local system time is,
* 2007-12-18 01:15:00 +0200, then the resulting String will be "2007-12-17".
* In case you need a format with a timezon offset, use {@link #formatShortDay(TimeZone)}
* @return a String representation of the current system date in GMT using the
* short day format, e.g. "20071218".
*/
public static String formatShortDay() {
return format(FORMAT_SHORT_DAY, new Date());
}
/**
* @see #formatShortDay()
* @param date the Date to transform
*/
private static long FORMAT_SHORT_DAY_last_time = 0;
private static String FORMAT_SHORT_DAY_last_format = "";
public static String formatShortDay(final Date date) {
if (date == null) return "";
if (Math.abs(date.getTime() - FORMAT_SHORT_DAY_last_time) < 1000) return FORMAT_SHORT_DAY_last_format;
FORMAT_SHORT_DAY_last_format = format(FORMAT_SHORT_DAY, date);
FORMAT_SHORT_DAY_last_time = date.getTime();
return FORMAT_SHORT_DAY_last_format;
}
/**
* Parse dates as defined in {@linkplain http://www.w3.org/TR/NOTE-datetime}.
* This format (also specified in ISO8601) allows different "precisions".
* The following lower precision versions for the complete date
* "2007-12-19T10:20:30.567+0300" are allowed:<br>
* "2007"<br>
* "2007-12"<br>
* "2007-12-19"<br>
* "2007-12-19T10:20+0300<br>
* "2007-12-19T10:20:30+0300<br>
* "2007-12-19T10:20:30.567+0300<br>
* Additionally a timezone offset of "+0000" can be substituted as "Z".<br>
* Parsing is done in a fuzzy way. If there is an illegal character somewhere in
* the String, the date parsed so far will be returned, e.g. the input
* "2007-12-19FOO" would return a date that represents "2007-12-19".
*
* @param s
* @return
* @throws ParseException
*/
public static Date parseISO8601(String s) throws ParseException {
// do some lazy checks here
s = s.trim();
while (s.length() > 0 && s.endsWith("?")) s = s.substring(0, s.length() - 1); // sometimes used if write is not sure about date
if (s.startsWith("{")) s = s.substring(1);
if (s.endsWith("}")) s = s.substring(0, s.length() - 1);
if (s.startsWith("[")) s = s.substring(1);
if (s.endsWith("]")) s = s.substring(0, s.length() - 1);
while (s.length() > 0 && (s.charAt(0) > '9' || s.charAt(0) < '0')) s = s.substring(1);
if (s.endsWith("--")) s = s.substring(0, s.length() - 2) + "00";
int p = s.indexOf(';'); if (p >= 0) s = s.substring(0, p); // a semicolon may be used to separate two dates from each other; then we take the first
p = s.indexOf(','); if (p >= 0) s = s.substring(0, p); // a comma may be used to separate two dates from each other; then we take the first
while (s.length() > 0 && s.endsWith("?")) s = s.substring(0, s.length() - 1); // sometimes used if write is not sure about date
// no go for exact parsing
final Calendar cal = Calendar.getInstance(TZ_GMT, Locale.US);
cal.clear();
// split 2007-12-19T10:20:30.789+0500 into its parts
// correct: yyyy['-'MM['-'dd['T'HH':'MM[':'ss['.'SSS]]('Z'|ZZZZZ)]]]
final StringTokenizer t = new StringTokenizer(s, "-T:.Z+", true);
if (s == null || t.countTokens() == 0)
throw new ParseException("parseISO8601: Cannot parse '" + s + "'", 0);
try {
// year
cal.set(Calendar.YEAR, Integer.parseInt(t.nextToken()));
// month
if (t.nextToken().equals("-")) {
cal.set(Calendar.MONTH, Integer.parseInt(t.nextToken()) - 1);
} else {
return cal.getTime();
}
// day
if (t.nextToken().equals("-")) {
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(t.nextToken()));
} else {
return cal.getTime();
}
// The standard says: if there is an hour there has to be a minute and a
// timezone token, too.
// hour
if (t.nextToken().equals("T")) {
final int hour = Integer.parseInt(t.nextToken());
// no error, got hours
int min = 0;
int sec = 0;
int msec = 0;
if (t.nextToken().equals(":")) {
min = Integer.parseInt(t.nextToken());
// no error, got minutes
// need TZ or seconds
String token = t.nextToken();
if (token.equals(":")) {
sec = Integer.parseInt(t.nextToken());
// need millisecs or TZ
token = t.nextToken();
if (token.equals(".")) {
msec = Integer.parseInt(t.nextToken());
// need TZ
token = t.nextToken();
}
}
// check for TZ data
int offset;
if (token.equals("Z")) {
offset = 0;
} else {
int sign = 0;
if (token.equals("+")) {
sign = 1;
} else if (token.equals("-")) {
sign = -1;
} else {
// no legal TZ offset found
return cal.getTime();
}
offset = sign * Integer.parseInt(t.nextToken()) * 10 * 3600;
}
cal.set(Calendar.ZONE_OFFSET, offset);
}
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, min);
cal.set(Calendar.SECOND, sec);
cal.set(Calendar.MILLISECOND, msec);
}
} catch (final NoSuchElementException e) {
// ignore this as it is perfectly fine to have non-complete date in this format
} catch (final Exception e) {
// catch all Exceptions and return what we parsed so far
//serverLog.logInfo("SERVER", "parseISO8601: DATE ERROR with: '" + s + "' got so far: '" + cal.toString());
}
// in case we couldn't even parse a year
if (!cal.isSet(Calendar.YEAR))
throw new ParseException("parseISO8601: Cannot parse '" + s + "'", 0);
Date d = cal.getTime();
return d;
}
/**
* Parse a String representation of a Date in short day format assuming the date
* is aligned to the GMT/UTC timezone. An example for such a date string is "20071218".
* @see #formatShortDay()
* @throws ParseException The exception is thrown if an error occured during while parsing
* the String.
*/
public static Date parseShortDay(final String timeString) throws ParseException {
return parse(FORMAT_SHORT_DAY, timeString);
}
/**
* Returns the current date in short second format which is a fixed width (14 chars)
* String including the date and the time like "20071218233510". The result is in GMT/UTC.
* @see #formatShortDay()
*/
public static String formatShortSecond() {
return formatShortSecond(new Date());
}
//TODO check the following 2 parse methods for correct use (GMT vs. different timezone)
/**
* Like {@link #parseShortDay(String)}, but for the "short second" format which is short date
* plus a 6 digit day time value, like "20071218233510". The String should be in GMT/UTC to
* get a correct Date.
*/
public static Date parseShortSecond(final String timeString) throws ParseException {
return parse(FORMAT_SHORT_SECOND, timeString);
}
public static Date parseShortMilliSecond(final String timeString) throws ParseException {
return parse(FORMAT_SHORT_MILSEC, timeString);
}
/**
* Like {@link #parseShortSecond(String)} using additional timezone information provided in an
* offset String, like "+0100" for CET.
*/
public static Date parseShortSecond(final String remoteTimeString, final String remoteUTCOffset) {
// FIXME: This method returns an incorrect date, check callers!
// ex: de.anomic.server.serverDate.parseShortSecond("20070101120000", "+0200").toGMTString()
// => 1 Jan 2007 13:00:00 GMT
if (remoteTimeString == null || remoteTimeString.length() == 0) { return new Date(); }
if (remoteUTCOffset == null || remoteUTCOffset.length() == 0) { return new Date(); }
try {
return new Date(parse(FORMAT_SHORT_SECOND, remoteTimeString).getTime() - DateFormatter.UTCDiff() + DateFormatter.UTCDiff(remoteUTCOffset));
} catch (final java.text.ParseException e) {
//serverLog.logFinest("parseUniversalDate", e.getMessage() + ", remoteTimeString=[" + remoteTimeString + "]");
return new Date();
} catch (final java.lang.NumberFormatException e) {
//serverLog.logFinest("parseUniversalDate", e.getMessage() + ", remoteTimeString=[" + remoteTimeString + "]");
return new Date();
}
}
/**
* Format a time inteval in milliseconds into a String of the form
* X 'day'['s'] HH':'mm
*/
public static String formatInterval(final long millis) {
try {
final long mins = millis / 60000;
final StringBuilder uptime = new StringBuilder();
final int uptimeDays = (int) (Math.floor(mins/1440.0));
final int uptimeHours = (int) (Math.floor(mins/60.0)%24);
final int uptimeMins = (int) mins%60;
uptime.append(uptimeDays)
.append(((uptimeDays == 1)?" day ":" days "))
.append((uptimeHours < 10)?"0":"")
.append(uptimeHours)
.append(":")
.append((uptimeMins < 10)?"0":"")
.append(uptimeMins);
return uptime.toString();
} catch (final Exception e) {
return "unknown";
}
}
/** called by all public format...(...) methods */
private static String format(final SimpleDateFormat format, final Date date) {
synchronized (format) {
return format.format(date);
}
}
/** calles by all public parse...(...) methods */
private static Date parse(final SimpleDateFormat format, final String dateString) throws ParseException {
synchronized (format) {
return format.parse(dateString);
}
}
// statics
public final static long secondMillis = 1000;
public final static long minuteMillis = 60 * secondMillis;
public final static long hourMillis = 60 * minuteMillis;
public final static long dayMillis = 24 * hourMillis;
public final static long normalyearMillis = 365 * dayMillis;
public final static long leapyearMillis = 366 * dayMillis;
public final static int january = 31, normalfebruary = 28, leapfebruary = 29, march = 31,
april = 30, may = 31, june = 30, july = 31, august = 31,
september = 30, october = 31, november = 30, december = 31;
public final static int[] dimnormal = {january, normalfebruary, march, april, may, june, july, august, september, october, november, december};
public final static int[] dimleap = {january, leapfebruary, march, april, may, june, july, august, september, october, november, december};
public final static String[] wkday = {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
//private final static String[] month = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
// find out time zone and DST offset
private static Calendar thisCalendar = Calendar.getInstance();
public static String UTCDiffString() {
// we express the UTC Difference in 5 digits:
// SHHMM
// S ::= '+'|'-'
// HH ::= '00'|'01'|'02'|'03'|'04'|'05'|'06'|'07'|'08'|'09'|'10'|'11'|'12'
// MM ::= '00'|'15'|'30'|'45'
// since there are some places on earth where there is a time shift of half an hour
// we need too show also the minutes of the time shift
// Examples: http://www.timeanddate.com/library/abbreviations/timezones/
final long offsetHours = UTCDiff();
final int om = Math.abs((int) (offsetHours / minuteMillis)) % 60;
final int oh = Math.abs((int) (offsetHours / hourMillis));
String diff = Integer.toString(om);
if (diff.length() < 2) diff = "0" + diff;
diff = Integer.toString(oh) + diff;
if (diff.length() < 4) diff = "0" + diff;
if (offsetHours < 0) {
return "-" + diff;
}
return "+" + diff;
}
private static long UTCDiff() {
// DST_OFFSET is dependent on the time of the Calendar, so it has to be updated
// to get the correct current offset
synchronized(thisCalendar) {
thisCalendar.setTimeInMillis(System.currentTimeMillis());
final long zoneOffsetHours = thisCalendar.get(Calendar.ZONE_OFFSET);
final long DSTOffsetHours = thisCalendar.get(Calendar.DST_OFFSET);
return zoneOffsetHours + DSTOffsetHours;
}
}
private static long UTCDiff(final String diffString) {
if (diffString.length() != 5) throw new IllegalArgumentException("UTC String malformed (wrong size):" + diffString);
boolean ahead = true;
if (diffString.length() > 0 && diffString.charAt(0) == '+') ahead = true;
else if (diffString.length() > 0 && diffString.charAt(0) == '-') ahead = false;
else throw new IllegalArgumentException("UTC String malformed (wrong sign):" + diffString);
final long oh = Long.parseLong(diffString.substring(1, 3));
final long om = Long.parseLong(diffString.substring(3));
return ((ahead) ? (long) 1 : (long) -1) * (oh * hourMillis + om * minuteMillis);
}
public static long correctedUTCTime() {
return System.currentTimeMillis() - UTCDiff();
}
public static long remainingTime(final long start, final long due, final long minimum) {
if (due < 0) return -1;
final long r = due + start - System.currentTimeMillis();
if (r <= 0) return minimum;
return r;
}
public static void main(final String[] args) {
//System.out.println("kelondroDate is (" + new kelondroDate().toString() + ")");
System.out.println("offset is " + (UTCDiff()/1000/60/60) + " hours, javaDate is " + new Date() + ", correctedDate is " + new Date(correctedUTCTime()));
System.out.println(" javaDate : " + formatShortSecond());
System.out.println("serverDate : " + new DateFormatter().toString());
System.out.println(" JavaDate : " + DateFormat.getDateInstance().format(new Date()));
System.out.println(" JavaDate0: " + format(FORMAT_SHORT_SECOND, new Date(0)));
System.out.println(" JavaDate0: " + DateFormat.getDateInstance().format(new Date(0)));
//String testresult;
final int cycles = 10000;
long start;
final String[] testresult = new String[10000];
start = System.currentTimeMillis();
for (int i = 0; i < cycles; i++) testresult[i] = format(FORMAT_SHORT_SECOND, new Date());
System.out.println("time for " + cycles + " calls to javaDate:" + (System.currentTimeMillis() - start) + " milliseconds");
}
}

@ -1,41 +0,0 @@
// kelondroOutOfLimitsException.java
// ---------------------------------
// part of The Kelondro Database
// (C) by Michael Peter Christen; mc@yacy.net
// first published on http://www.anomic.de
// Frankfurt, Germany, 2006
// created: 17.01.2006
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package net.yacy.kelondro.util;
public class kelondroOutOfLimitsException extends java.lang.RuntimeException {
private static final long serialVersionUID = 1L;
public kelondroOutOfLimitsException() {
super("unspecific-error");
}
public kelondroOutOfLimitsException(final int expectedLimit, final int actualSize) {
super("Object size is " + actualSize + "; it exceeds the size limit " + expectedLimit);
}
public kelondroOutOfLimitsException(final int actualSize) {
super("Object size is " + actualSize + "; must not be negative");
}
}

@ -46,6 +46,7 @@ import java.util.concurrent.Semaphore;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.protocol.http.HTTPClient;
@ -63,7 +64,6 @@ import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.rwi.Reference;
import net.yacy.kelondro.rwi.ReferenceContainer;
import net.yacy.kelondro.util.DateFormatter;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.Formatter;
import net.yacy.kelondro.util.MemoryControl;
@ -192,7 +192,7 @@ public final class yacy {
Log.logConfig("STARTUP", "Operation system: " + System.getProperty("os.name","unknown"));
Log.logConfig("STARTUP", "Application root-path: " + appHome);
Log.logConfig("STARTUP", "Data root-path: " + dataHome);
Log.logConfig("STARTUP", "Time zone: UTC" + DateFormatter.UTCDiffString() + "; UTC+0000 is " + System.currentTimeMillis());
Log.logConfig("STARTUP", "Time zone: UTC" + GenericFormatter.UTCDiffString() + "; UTC+0000 is " + System.currentTimeMillis());
Log.logConfig("STARTUP", "Maximum file system path length: " + OS.maxPathLength);
f = new File(dataHome, "DATA/yacy.running");

Loading…
Cancel
Save