[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] alph/org/nongnu/alph ScrollBlock.java impl/Abst...
From: |
Tuomas J. Lukka |
Subject: |
[Gzz-commits] alph/org/nongnu/alph ScrollBlock.java impl/Abst... |
Date: |
Mon, 21 Apr 2003 12:31:24 -0400 |
CVSROOT: /cvsroot/alph
Module name: alph
Changes by: Tuomas J. Lukka <address@hidden> 03/04/21 12:31:23
Modified files:
org/nongnu/alph: ScrollBlock.java
org/nongnu/alph/impl: AbstractScrollBlock.java FakeTextSpan.java
PageImageScroll.java
PermanentTextScroll.java
ScrollBlockManager.java
SimpleImageScroll.java
TransientTextScroll.java
org/nongnu/alph/util: psimages.py
Added files:
org/nongnu/alph: Alph.java
org/nongnu/alph/impl: StormAlph.java
Log message:
Moving towards better architecture, which enables .dsc files &c
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/Alph.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/ScrollBlock.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/StormAlph.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/AbstractScrollBlock.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/FakeTextSpan.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/PageImageScroll.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/PermanentTextScroll.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/ScrollBlockManager.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/SimpleImageScroll.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/impl/TransientTextScroll.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/alph/alph/org/nongnu/alph/util/psimages.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
Patches:
Index: alph/org/nongnu/alph/ScrollBlock.java
diff -u alph/org/nongnu/alph/ScrollBlock.java:1.3
alph/org/nongnu/alph/ScrollBlock.java:1.4
--- alph/org/nongnu/alph/ScrollBlock.java:1.3 Sun Apr 20 04:50:02 2003
+++ alph/org/nongnu/alph/ScrollBlock.java Mon Apr 21 12:31:23 2003
@@ -37,7 +37,7 @@
*/
public interface ScrollBlock {
-String rcsid = "$Id: ScrollBlock.java,v 1.3 2003/04/20 08:50:02 tjl Exp $";
+String rcsid = "$Id: ScrollBlock.java,v 1.4 2003/04/21 16:31:23 tjl Exp $";
/** Get the data of the scrollblock in a tmp file.
* May return null, if data not yet finalized.
@@ -58,6 +58,11 @@
* XXX Exact semantics, tmp ids
*/
String getID();
+
+ /** Get the globally unique identifier of this block.
+ * XXX Exact semantics, tmp ids
+ */
+ Object getBlockId();
/** Compare this scrollblock with the other one and return
* -1, 0 or 1 accordingly.
Index: alph/org/nongnu/alph/impl/AbstractScrollBlock.java
diff -u alph/org/nongnu/alph/impl/AbstractScrollBlock.java:1.1
alph/org/nongnu/alph/impl/AbstractScrollBlock.java:1.2
--- alph/org/nongnu/alph/impl/AbstractScrollBlock.java:1.1 Sun Apr 20
04:50:02 2003
+++ alph/org/nongnu/alph/impl/AbstractScrollBlock.java Mon Apr 21 12:31:23 2003
@@ -10,35 +10,66 @@
*/
public abstract class AbstractScrollBlock implements ScrollBlock {
- StormPool ms;
- BlockId msid;
+ protected final Alph alph;
+ protected Object blockid;
+ protected final String contentType;
- public AbstractScrollBlock(StormPool ms, BlockId msid) {
- this.ms = ms;
- this.msid = msid;
+ public AbstractScrollBlock(Alph alph, Object blockid, String contentType) {
+ this.alph = alph;
+ this.blockid = blockid;
+ this.contentType = (contentType != null ?
+ contentType.intern() : null);
}
public BlockFile getBlockFile() throws java.io.FileNotFoundException {
- if(msid == null) return null;
- try {
- return new StdBlockFile(BlockTmpFile.get(ms.get(msid)));
- } catch(Exception e) {
- throw new java.io.FileNotFoundException("Loading blocktmpfile");
- }
+ return alph.getBlockFile(this);
}
public boolean isPermanent() {
- return msid != null;
+ return blockid != null;
+ }
+
+ public Object getBlockId() {
+ return blockid;
}
public String getID() {
- if(msid != null) return msid.toString();
+ if(blockid != null) return blockid.toString();
return "!!!TMPID!!!XXXFOO";
}
public int hashCode() {
return getID().hashCode();
}
+
+
+ static final String gzz1 = "application/x-gzigzag-GZZ1";
+ public static ScrollBlock createBlock(Alph alph, Object id,
+ String ct) {
+
+ int ind = ct.indexOf('/');
+ if(ind < 0)
+ throw new IllegalArgumentException("Can't parse mediatype "+ ct);
+ String type = ct.substring(0,ind);
+
+ if(type.equals("text") &&
+ !ct.equals("text/plain; charset=UTF-8"))
+ throw new IllegalArgumentException(
+ "Unknown text mime type '"+ct+"'");
+
+ if(type.equals("text") || ct.equals(gzz1)) {
+ return new PermanentTextScroll(alph, id, ct);
+
+ } else if(type.equals("image")) {
+ } else if(type.equals("application")) {
+ return new PageImageScroll(alph, id, ct);
+ }
+
+ throw new IllegalArgumentException(
+ "Unknown mediatype "+ct);
+
+ }
+
}
Index: alph/org/nongnu/alph/impl/FakeTextSpan.java
diff -u alph/org/nongnu/alph/impl/FakeTextSpan.java:1.4
alph/org/nongnu/alph/impl/FakeTextSpan.java:1.5
--- alph/org/nongnu/alph/impl/FakeTextSpan.java:1.4 Sun Apr 20 04:50:02 2003
+++ alph/org/nongnu/alph/impl/FakeTextSpan.java Mon Apr 21 12:31:23 2003
@@ -38,10 +38,9 @@
*/
public class FakeTextSpan implements TextSpan, java.io.Serializable {
-public static final String rcsid = "$Id: FakeTextSpan.java,v 1.4 2003/04/20
08:50:02 tjl Exp $";
+public static final String rcsid = "$Id: FakeTextSpan.java,v 1.5 2003/04/21
16:31:23 tjl Exp $";
String text;
- transient FakeTextScrollBlock sb;
transient char[] textarr;
public FakeTextSpan(String s) {
@@ -81,49 +80,6 @@
public boolean intersects(Span s) { return false; }
public String getScrollId() { return ""; }
-
- 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 :[<mimetype>],<data>
- 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 isPermanent() { 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 BlockFile getBlockFile() {
- return null;
- }
- }
public ScrollBlock getScrollBlock() {
return null;
Index: alph/org/nongnu/alph/impl/PageImageScroll.java
diff -u alph/org/nongnu/alph/impl/PageImageScroll.java:1.4
alph/org/nongnu/alph/impl/PageImageScroll.java:1.5
--- alph/org/nongnu/alph/impl/PageImageScroll.java:1.4 Sun Apr 20 04:50:02 2003
+++ alph/org/nongnu/alph/impl/PageImageScroll.java Mon Apr 21 12:31:23 2003
@@ -39,7 +39,7 @@
*/
public class PageImageScroll extends AbstractScrollBlock {
-String rcsid = "$Id: PageImageScroll.java,v 1.4 2003/04/20 08:50:02 tjl Exp $";
+String rcsid = "$Id: PageImageScroll.java,v 1.5 2003/04/21 16:31:23 tjl Exp $";
public static boolean dbg = true;
final static void p(String s) { if(dbg) System.out.println(s); }
final static void pa(String s) { System.out.println(s); }
@@ -63,8 +63,8 @@
}
// Mediaserver.Block block;
- public PageImageScroll(StormPool ms, BlockId id) {
- super(ms, id);
+ public PageImageScroll(Alph alph, Object blockId, String contentType) {
+ super(alph, blockId, contentType);
checkLen();
}
Index: alph/org/nongnu/alph/impl/PermanentTextScroll.java
diff -u alph/org/nongnu/alph/impl/PermanentTextScroll.java:1.3
alph/org/nongnu/alph/impl/PermanentTextScroll.java:1.4
--- alph/org/nongnu/alph/impl/PermanentTextScroll.java:1.3 Sun Apr 20
04:50:02 2003
+++ alph/org/nongnu/alph/impl/PermanentTextScroll.java Mon Apr 21 12:31:23 2003
@@ -38,15 +38,13 @@
public class PermanentTextScroll extends AbstractScrollBlock
implements TextScrollBlock
{
-String rcsid = "$Id: PermanentTextScroll.java,v 1.3 2003/04/20 08:50:02 tjl
Exp $";
+String rcsid = "$Id: PermanentTextScroll.java,v 1.4 2003/04/21 16:31:23 tjl
Exp $";
char[] chars;
boolean loadingFailed;
- public PermanentTextScroll(StormPool ms, BlockId msid) {
- super(ms, msid);
- this.ms = ms;
- this.msid = msid;
+ public PermanentTextScroll(Alph alph, Object blockId, String contentType) {
+ super(alph, blockId, contentType);
}
public boolean equals(Object o) {
@@ -57,31 +55,24 @@
protected final void load() {
if(chars != null || loadingFailed) return;
-
- Block block ;
- String ct;
- try {
- block = ms.request(msid, null);
- ct = msid.getContentType();
- } catch(IOException e) {
- loadingFailed = true;
- e.printStackTrace();
- throw new Error("Couldn't load block: "+e);
- }
+ loadingFailed = true;
// Note: for the legacy string content to work, we need to be able
// to load GZZ1 diffs as text blocks (see GZZ1Handler.LegacyContent
// javadoc for more info).
- if(!ct.equals("text/plain; charset=UTF-8") &&
- !ct.equals("application/x-gzigzag-GZZ1") &&
- !ct.equals("message/rfc822")) {
- loadingFailed = true;
- throw new Error("Unknown text block '"+ct+"'");
+ if(!contentType.equals("text/plain; charset=UTF-8") &&
+ !contentType.equals("application/x-gzigzag-GZZ1") &&
+ !contentType.equals("message/rfc822")) {
+ throw new Error("Unknown text block content type '"+
+ contentType+"'");
}
String string;
try {
- string = new String(SlurpStream.slurp(block.getInputStream()),
"UTF8");
+ BlockFile f = getBlockFile();
+ string = new String(SlurpStream.slurp(
+ new FileInputStream(f.getFile())), "UTF8");
+ f.close();
} catch(Exception e) {
loadingFailed = true;
e.printStackTrace();
@@ -89,6 +80,7 @@
}
this.chars = string.toCharArray();
+ loadingFailed = false;
}
public TextSpan append(char ch) throws ImmutableException {
Index: alph/org/nongnu/alph/impl/ScrollBlockManager.java
diff -u alph/org/nongnu/alph/impl/ScrollBlockManager.java:1.5
alph/org/nongnu/alph/impl/ScrollBlockManager.java:1.6
--- alph/org/nongnu/alph/impl/ScrollBlockManager.java:1.5 Sun Apr 20
04:50:02 2003
+++ alph/org/nongnu/alph/impl/ScrollBlockManager.java Mon Apr 21 12:31:23 2003
@@ -41,7 +41,7 @@
*/
public class ScrollBlockManager {
-String rcsid = "$Id: ScrollBlockManager.java,v 1.5 2003/04/20 08:50:02 tjl Exp
$";
+String rcsid = "$Id: ScrollBlockManager.java,v 1.6 2003/04/21 16:31:23 tjl Exp
$";
public static boolean dbg = false;
final static void p(String s) { if(dbg) System.out.println(s); }
final static void pa(String s) { System.out.println(s); }
@@ -384,7 +384,7 @@
throw new Error("Loading image failed: "+id);
}
if(block==null) {
- block = new SimpleImageScroll(ms, id);
+// block = new SimpleImageScroll(ms, id);
msCache.put(id, block);
}
return block.getSpan(x, y, w, h);
@@ -402,10 +402,12 @@
} catch (CannotLoadScrollBlockException _) {
throw new Error("Loading pageimage failed: "+id);
}
+ /*
if(block==null) {
block = new PageImageScroll(ms, id);
msCache.put(id, block);
}
+ */
return block.getSpan(p0, p1, x, y, w, h);
}
@@ -419,10 +421,12 @@
if(id == null)
throw new NullPointerException("cannot get block with id null");
TextScrollBlock b = (TextScrollBlock)msCache.get(id);
+ /*
if(b == null) {
b = new PermanentTextScroll(ms, id);
msCache.put(id, b);
}
+ */
return b;
}
@@ -493,17 +497,18 @@
!ct.equals("application/x-gzigzag-GZZ1"))
throw new CannotLoadScrollBlockException("Unknown text block '"+ct
+"'");
- return new PermanentTextScroll(ms, id);
+ // return new PermanentTextScroll(ms, id);
} else if(type.equals("image")) {
- return new SimpleImageScroll(ms, id);
+ // return new SimpleImageScroll(ms, id);
} else if(ct.equals("application/postscript") ||
ct.equals("application/pdf")) {
p("Loaded page image scroll block.");
- return new PageImageScroll(ms, id);
+ // return new PageImageScroll(ms, id);
} else {
throw new CannotLoadScrollBlockException("Unknown mediatype "+ct);
}
+ return null;
}
Index: alph/org/nongnu/alph/impl/SimpleImageScroll.java
diff -u alph/org/nongnu/alph/impl/SimpleImageScroll.java:1.3
alph/org/nongnu/alph/impl/SimpleImageScroll.java:1.4
--- alph/org/nongnu/alph/impl/SimpleImageScroll.java:1.3 Sun Apr 20
04:50:02 2003
+++ alph/org/nongnu/alph/impl/SimpleImageScroll.java Mon Apr 21 12:31:23 2003
@@ -39,17 +39,12 @@
*/
public class SimpleImageScroll extends AbstractScrollBlock {
-String rcsid = "$Id: SimpleImageScroll.java,v 1.3 2003/04/20 08:50:02 tjl Exp
$";
+String rcsid = "$Id: SimpleImageScroll.java,v 1.4 2003/04/21 16:31:23 tjl Exp
$";
int width=-1, height=-1;
- public SimpleImageScroll(StormPool ms, BlockId id) {
- super(ms, id);
- try {
- ms.request(id, null);
- } catch(IOException e) {
- throw new Error("Couldn't load image block");
- }
+ public SimpleImageScroll(Alph alph, Object blockid, String contentType) {
+ super(alph, blockid, contentType);
}
public boolean equals(Object o) {
@@ -62,17 +57,21 @@
}
private void loadImageSize() {
-
- String ct = msid.getContentType();
+ int ind = contentType.indexOf('/');
+ int ind2 = contentType.indexOf(';');
+ if(ind2 < 0) ind2 = contentType.length();
- if(!ct.substring(0,ct.indexOf('/')).equals("image"))
- throw new Error("Block isn't an image");
+ String type = contentType.substring(0,ind);
+ String subtype = contentType.substring(ind+1, ind2);
+
+ if(!type.equals("image"))
+ throw new Error("Image Block isn't an image");
Block block ;
Dimension d;
+
try {
- block = ms.get(msid);
- java.io.InputStream is = block.getInputStream();
+ java.io.InputStream is = alph.getBlockInputStream(this);
d = org.nongnu.navidoc.util.ImageSize.readSize(is);
if(d == null)
throw new Error("Couldn't get size of image block");
Index: alph/org/nongnu/alph/impl/TransientTextScroll.java
diff -u alph/org/nongnu/alph/impl/TransientTextScroll.java:1.3
alph/org/nongnu/alph/impl/TransientTextScroll.java:1.4
--- alph/org/nongnu/alph/impl/TransientTextScroll.java:1.3 Sun Apr 20
04:50:02 2003
+++ alph/org/nongnu/alph/impl/TransientTextScroll.java Mon Apr 21 12:31:23 2003
@@ -35,10 +35,10 @@
public class TransientTextScroll extends AbstractScrollBlock
implements TextScrollBlock, ScrollBlockManager.StormSaveableScrollBlock
{
-String rcsid = "$Id: TransientTextScroll.java,v 1.3 2003/04/20 08:50:02 tjl
Exp $";
+String rcsid = "$Id: TransientTextScroll.java,v 1.4 2003/04/21 16:31:23 tjl
Exp $";
public TransientTextScroll() {
- super(null, null);
+ super(null, null, "text/plain; charset=UTF-8");
}
boolean finalized = false;
Index: alph/org/nongnu/alph/util/psimages.py
diff -u alph/org/nongnu/alph/util/psimages.py:1.2
alph/org/nongnu/alph/util/psimages.py:1.3
--- alph/org/nongnu/alph/util/psimages.py:1.2 Tue Apr 15 23:44:23 2003
+++ alph/org/nongnu/alph/util/psimages.py Mon Apr 21 12:31:23 2003
@@ -10,6 +10,8 @@
import os
import re
+def convertFile(block, toPrefix):
+
def doPool(pool):
for file in os.listdir(pool):
if not file.startswith("data_"): continue
@@ -31,5 +33,6 @@
print "RUNNING ",cmdline
os.system(cmdline)
-for pool in pools: doPool(pool)
+if __name__ == '__main__':
+ for pool in pools: doPool(pool)
- [Gzz-commits] alph/org/nongnu/alph ScrollBlock.java impl/Abst...,
Tuomas J. Lukka <=