10 |
*/ |
*/ |
11 |
public abstract class AbstractScrollBlock implements ScrollBlock { |
public abstract class AbstractScrollBlock implements ScrollBlock { |
12 |
|
|
13 |
StormPool ms; |
protected final Alph alph; |
14 |
BlockId msid; |
protected Object blockid; |
15 |
|
protected final String contentType; |
16 |
public AbstractScrollBlock(StormPool ms, BlockId msid) { |
|
17 |
this.ms = ms; |
public AbstractScrollBlock(Alph alph, Object blockid, String contentType) { |
18 |
this.msid = msid; |
this.alph = alph; |
19 |
|
this.blockid = blockid; |
20 |
|
this.contentType = (contentType != null ? |
21 |
|
contentType.intern() : null); |
22 |
} |
} |
23 |
|
|
24 |
public BlockFile getBlockFile() throws java.io.FileNotFoundException { |
public BlockFile getBlockFile() throws java.io.FileNotFoundException { |
25 |
if(msid == null) return null; |
return alph.getBlockFile(this); |
|
try { |
|
|
return new StdBlockFile(BlockTmpFile.get(ms.get(msid))); |
|
|
} catch(Exception e) { |
|
|
throw new java.io.FileNotFoundException("Loading blocktmpfile"); |
|
|
} |
|
26 |
} |
} |
27 |
|
|
28 |
public boolean isPermanent() { |
public boolean isPermanent() { |
29 |
return msid != null; |
return blockid != null; |
30 |
|
} |
31 |
|
|
32 |
|
public Object getBlockId() { |
33 |
|
return blockid; |
34 |
} |
} |
35 |
|
|
36 |
public String getID() { |
public String getID() { |
37 |
if(msid != null) return msid.toString(); |
if(blockid != null) return blockid.toString(); |
38 |
return "!!!TMPID!!!XXXFOO"; |
return "!!!TMPID!!!XXXFOO"; |
39 |
} |
} |
40 |
|
|
41 |
public int hashCode() { |
public int hashCode() { |
42 |
return getID().hashCode(); |
return getID().hashCode(); |
43 |
} |
} |
44 |
|
|
45 |
|
|
46 |
|
static final String gzz1 = "application/x-gzigzag-GZZ1"; |
47 |
|
public static ScrollBlock createBlock(Alph alph, Object id, |
48 |
|
String ct) { |
49 |
|
|
50 |
|
int ind = ct.indexOf('/'); |
51 |
|
if(ind < 0) |
52 |
|
throw new IllegalArgumentException("Can't parse mediatype "+ ct); |
53 |
|
String type = ct.substring(0,ind); |
54 |
|
|
55 |
|
if(type.equals("text") && |
56 |
|
!ct.equals("text/plain; charset=UTF-8")) |
57 |
|
throw new IllegalArgumentException( |
58 |
|
"Unknown text mime type '"+ct+"'"); |
59 |
|
|
60 |
|
if(type.equals("text") || ct.equals(gzz1)) { |
61 |
|
return new PermanentTextScroll(alph, id, ct); |
62 |
|
|
63 |
|
} else if(type.equals("image")) { |
64 |
|
} else if(type.equals("application")) { |
65 |
|
return new PageImageScroll(alph, id, ct); |
66 |
|
} |
67 |
|
|
68 |
|
throw new IllegalArgumentException( |
69 |
|
"Unknown mediatype "+ct); |
70 |
|
|
71 |
|
} |
72 |
|
|
73 |
|
|
74 |
} |
} |
75 |
|
|