/* FakeTextSpan.java * * Copyright (c) 2002, Ted Nelson and Tuomas Lukka * * This file is part of Gzz. * * Gzz 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. * * Gzz 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 Gzz; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * */ /* * Written by Tuomas Lukka */ package org.nongnu.alph.impl; import org.nongnu.alph.*; import org.nongnu.storm.util.*; /** An object that behaves like a text span but is not stored in a real Storm block. * Used for things like coordinates or other computer-generated rapidly changing * content. Must be atomic: if you give one piece away, you give * the whole thing away. Must be short, because the whole thing * is repeated whereever one piece goes. See PEG miniblocks--benja. */ public class FakeTextSpan implements TextSpan, java.io.Serializable { public static final String rcsid = "$Id: FakeTextSpan.java,v 1.1 2003/03/25 14:36:12 tjl Exp $"; String text; transient FakeTextScrollBlock sb; transient char[] textarr; public FakeTextSpan(String s) { String id = URN5Namespace.instance.getStormDataBlockId(); id = id + "," + URIUtil.escapeUTF8(s); sb = new FakeTextScrollBlock(/*s, id*/); this.text = s; } public String getText() { return text; } public int offset() { return 0; } public int length() { return text.length(); } public Span1D subSpan(int o1, int o2) { return new FakeTextSpan(text.substring(o1,o2)); } public Span1D subSpan(int o1) { return new FakeTextSpan(text.substring(o1)); } public int getRelativeStart(Span1D subspan) { throw new Error("Not inside"); } public int getRelativeEnd(Span1D subspan) { throw new Error("Not inside"); } public Span1D append(Span s) { return null; } public boolean equals(Object o) { if(!(o instanceof FakeTextSpan)) return false; return ((FakeTextSpan)o).text.equals(text); } public int hashCode() { return 78 ^ text.hashCode(); } public String toString() { return "FAKESPAN "+text; } public boolean intersects(Span s) { return false; } protected class FakeTextScrollBlock implements TextScrollBlock { /* protected String str, id; protected FakeTextScrollBlock(String id) { if(!id.startsWith("storm:data:")) throw IllegalArgumentException("Cannot handle URI: "+id); // ignore everything between storm:data: and :[], int j = id.indexOf(','); int i = id.lastIndexOf(':', j); String type = str.substring(i+1, j); if(!type.equals("") && !type.equals("text/plain;charset=UTF-8")) throw IllegalArgumentException("Cannot handle content type: "+type); this.str = URIUtil.unescapeUTF8(str.substring(j+1)); this.id = id; } */ public String getID() { return "" /*id*/; } public Span getCurrent() { return FakeTextSpan.this; } public boolean isFinalized() { return true; } public TextSpan append(char ch) throws ImmutableException { throw new ImmutableException(); } public TextSpan append(String s) throws ImmutableException { throw new ImmutableException(); } public char[] getCharArray() { if(textarr == null) textarr = text.toCharArray(); return textarr; } public Span getSpan(int offs, int len) { return FakeTextSpan.this.subSpan(offs, offs+len); } } public ScrollBlock getScrollBlock() { if(sb == null) sb = new FakeTextScrollBlock(); return sb; } }