/* PointerBlock.java * * Copyright (c) 2002, Benja Fallenstein * * This file is part of Storm. * * Storm 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 of the License, or * (at your option) any later version. * * Storm 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 Storm; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * */ /* * Written by Benja Fallenstein */ package org.nongnu.storm.pointers; import org.nongnu.storm.*; import org.nongnu.storm.impl.AsyncSetCollector; import java.util.*; import com.bitzi.util.*; import java.io.*; import java.security.*; public class TitleIndex { public static boolean dbg = false; private static void p(String s) { System.out.println("PointerIndex:: "+s); } public static final String uri = "http://fenfire.org/2003/05/pointer-title-index-0.1"; public static final IndexType type = new IndexType(); protected IndexedPool pool; protected IndexedPool.DB db; /** Return a set of words from a title. * E.g. "Hifi sp82;kzz1 anT hifi anT" * would become {"hifi","sp82","kzzl","ant"}. */ public static Set splitWords(String title) { Set words = new HashSet(); String s = ""; for(int i=0; i 0) words.add(s.toLowerCase()); s = ""; } } if(s.length() > 0) words.add(s.toLowerCase()); return words; } protected static class IndexType implements IndexedPool.IndexType { public Set getMappings(Block block) throws IOException { PointerBlock p; try { p = new PointerBlock(block); } catch(Throwable _) { if(dbg) _.printStackTrace(); return Collections.EMPTY_SET; } Set mappings = new HashSet(); String name = p.getName(); if(name == null) return mappings; // Mapping pointer id -> pointer blocks // for resolving a pointer mappings.add(new IndexedPool.Mapping(block.getId(), p.getPointer().toString(), ""+p.getTimestamp())); // Mapping "" -> pointer id // for finding all pointers mappings.add(new IndexedPool.Mapping(block.getId(), "", p.getPointer().toString())); return mappings; } public Object createIndex(IndexedPool pool, IndexedPool.DB db) { return new PointerIndex(pool, db); } public String getIndexTypeURI() { return uri; } public String getHumanReadableName() { return ("An index of 0.1 pointer blocks by pointer URN."); } } public TitleIndex(IndexedPool pool, IndexedPool.DB db) { this.pool = pool; this.db = db; } }