1 |
//(c): Tuomas J. Lukka and Matti Katila |
//(c): Tuomas J. Lukka and Matti Katila |
2 |
|
|
3 |
package org.fenfire.modules.pp; |
package org.fenfire.modules.pp; |
4 |
import org.fenfire.util.URN5Namespace; |
import org.fenfire.vocab.*; |
5 |
|
import org.fenfire.util.*; |
6 |
import java.io.IOException; |
import java.io.IOException; |
7 |
import java.rmi.*; |
import java.rmi.*; |
8 |
import java.rmi.server.*; |
import java.rmi.server.*; |
18 |
protected static void p(String s) { if(dbg) pa(s); } |
protected static void p(String s) { if(dbg) pa(s); } |
19 |
protected static void pa(String s) { System.out.println(s); } |
protected static void pa(String s) { System.out.println(s); } |
20 |
|
|
|
private PPVocab PP = new PPVocab(); |
|
21 |
private Model model; |
private Model model; |
22 |
public void setModel(Model model) { this.model = model; } |
public void setModel(Model model) { this.model = model; } |
23 |
|
|
38 |
Resource paper = model.createResource(uri); |
Resource paper = model.createResource(uri); |
39 |
|
|
40 |
// and resource must be also paper.. |
// and resource must be also paper.. |
41 |
paper.addProperty(RDF.type, PP.PaperType); |
paper.addProperty(RDF.type, PP.paperType); |
42 |
|
|
43 |
// set creation time |
// set creation time |
44 |
// XXX we need iso 8601 time presentation here |
// XXX we need iso 8601 time presentation here |
45 |
paper.addProperty(PP.CreationTime, "123"); |
paper.addProperty(PP.creationTime, "123"); |
46 |
|
|
47 |
return uri; |
return uri; |
48 |
} catch (RDFException e) { |
} catch (RDFException e) { |
70 |
}} |
}} |
71 |
|
|
72 |
|
|
73 |
public String cloneNote(String paperURI, String noteURI, |
|
74 |
int x, int y, String text) |
public String newNote(String paperURI, int x, int y, String text) |
75 |
throws RemoteException |
throws RemoteException |
76 |
{ synchronized(model) { try { |
{ synchronized(model) { try { |
77 |
|
|
78 |
// find the paper |
// find the paper |
79 |
Resource paper = model.getResource(paperURI); |
Resource paper = model.getResource(paperURI); |
81 |
// note doesn't exist so we need to make one |
// note doesn't exist so we need to make one |
82 |
String note_uri = URN5Namespace.instance.generateId(); |
String note_uri = URN5Namespace.instance.generateId(); |
83 |
Resource note = model.createResource(note_uri); |
Resource note = model.createResource(note_uri); |
84 |
note.addProperty(RDF.type, PP.NoteType); |
note.addProperty(RDF.type, PP.noteType); |
85 |
|
|
86 |
// set note to paper |
// set note to paper |
87 |
paper.addProperty(PP.Contains, note); |
paper.addProperty(PP.contains, note); |
88 |
|
|
89 |
// set coords |
// set coords |
90 |
note.addProperty(PP.CoordX, ""+x); |
note.addProperty(SPATIAL.coordX, ""+x); |
91 |
note.addProperty(PP.CoordY, ""+y); |
note.addProperty(SPATIAL.coordY, ""+y); |
92 |
|
|
93 |
// set depth... |
// set depth... |
94 |
note.addProperty(PP.Depth, "10"); |
note.addProperty(PP.depth, "10"); |
95 |
|
|
96 |
// scale etc.. XXX |
// scale etc.. XXX |
97 |
|
|
98 |
|
|
99 |
// content |
// XXX use real Alph!!!! |
100 |
if (noteURI == null) { |
note.addProperty(ALPH.content, text); |
|
// then handle as a new note |
|
|
|
|
|
// ref to real data must be created |
|
|
String data_uri = URN5Namespace.instance.generateId(); |
|
|
Resource data = model.createResource(data_uri); |
|
|
|
|
|
note.addProperty(PP.LinkToContentRef, data); |
|
|
data.addProperty(PP.Data, text); |
|
|
data.addProperty(RDF.type, PP.DataType); |
|
|
|
|
|
} else { |
|
|
// check if uri really exists? |
|
|
// XXX maybe RDFException ? |
|
|
Resource clone = model.getResource(noteURI); |
|
|
Resource data = null; |
|
|
NodeIterator iter = |
|
|
model.listObjectsOfProperty(clone, PP.LinkToContentRef); |
|
|
while (iter.hasNext()) { |
|
|
data = (Resource) iter.next(); |
|
|
} |
|
|
if (data == null) |
|
|
throw new Error("No data available when cloning!!!"); |
|
|
note.addProperty(PP.LinkToContentRef, data); |
|
|
} |
|
101 |
return note_uri; |
return note_uri; |
102 |
|
|
103 |
} catch (RDFException e) { |
} catch (RDFException e) { |
104 |
pa("Fault doing a clone/new note: "+e); |
pa("Fault creating a new note: "+e); |
105 |
return ""; |
return ""; |
106 |
}}} |
}}} |
107 |
|
|
108 |
|
|
|
public String newNote(String paperURI, int x, int y, String text) |
|
|
throws RemoteException |
|
|
{ synchronized(model) { |
|
|
return cloneNote(paperURI, null, x,y,text); |
|
|
}} |
|
|
|
|
|
|
|
109 |
public void deleteNote(String noteURI) |
public void deleteNote(String noteURI) |
110 |
throws RemoteException |
throws RemoteException |
111 |
{ synchronized(model) { try { |
{ synchronized(model) { try { |
158 |
if (note == null) return; |
if (note == null) return; |
159 |
|
|
160 |
// delete all old coords |
// delete all old coords |
161 |
RDFNode empty = null; |
ShortRDF.rmObj(model, note, SPATIAL.coordX); |
162 |
Selector selector = new SelectorImpl(note, PP.CoordX, empty); |
ShortRDF.rmObj(model, note, SPATIAL.coordY); |
|
StmtIterator it = model.listStatements(selector); |
|
|
while (it.hasNext()) { |
|
|
Statement stmt = it.next(); |
|
|
p("deleting X: "+stmt); |
|
|
model.remove(stmt); |
|
|
} |
|
|
selector = new SelectorImpl(note, PP.CoordY, empty); |
|
|
it = model.listStatements(selector); |
|
|
while (it.hasNext()) { |
|
|
Statement stmt = it.next(); |
|
|
p("deleting Y"+stmt); |
|
|
model.remove(stmt); |
|
|
} |
|
163 |
|
|
164 |
// set coords |
// set coords |
165 |
note.addProperty(PP.CoordX, ""+x); |
note.addProperty(SPATIAL.coordX, ""+x); |
166 |
note.addProperty(PP.CoordX, ""+x); |
note.addProperty(SPATIAL.coordX, ""+x); |
167 |
} catch (RDFException e) { |
} catch (RDFException e) { |
168 |
pa("Fault moving note: "+e); |
pa("Fault moving note: "+e); |
169 |
}}} |
}}} |
182 |
|
|
183 |
if (side < 0) { |
if (side < 0) { |
184 |
// check if already associated |
// check if already associated |
185 |
Selector slctr = new SelectorImpl(assoc, PP.Association, note); |
if (((ModelCom)model).contains(assoc, PP.association, (RDFNode)note)) { |
|
StmtIterator iter = model.listStatements(slctr); |
|
|
if (iter.hasNext()) { |
|
186 |
pa("Already associated!"); |
pa("Already associated!"); |
187 |
return; |
return; |
188 |
} |
} |
189 |
|
|
190 |
// assoc |
// assoc |
191 |
assoc.addProperty(PP.Association, note); |
assoc.addProperty(PP.association, note); |
192 |
} else { |
} else { |
193 |
// check if already associated |
// check if already associated |
194 |
Selector slctr = new SelectorImpl(note, PP.Association, assoc); |
if (((ModelCom)model).contains(note, PP.association, (RDFNode)assoc)) { |
|
StmtIterator iter = model.listStatements(slctr); |
|
|
if (iter.hasNext()) { |
|
195 |
pa("Already associated!"); |
pa("Already associated!"); |
196 |
return; |
return; |
197 |
} |
} |
198 |
|
|
199 |
// assoc |
// assoc |
200 |
note.addProperty(PP.Association, assoc); |
note.addProperty(PP.association, assoc); |
201 |
} |
} |
202 |
} catch (RDFException e) { |
} catch (RDFException e) { |
203 |
pa("Fault associationing notes: "+e); |
pa("Fault associationing notes: "+e); |
234 |
|
|
235 |
public void insertText(String noteURI, int offs, String text) |
public void insertText(String noteURI, int offs, String text) |
236 |
throws RemoteException |
throws RemoteException |
237 |
{ synchronized(model) { try { |
{ synchronized(model) { //try { |
238 |
/* |
/* |
239 |
Cell note = space.getCell(noteId); |
Cell note = space.getCell(noteId); |
240 |
note.insertText(offs, text); |
note.insertText(offs, text); |
241 |
*/ |
*/ |
242 |
|
|
243 |
|
/* |
244 |
Resource note = model.getResource(noteURI); |
Resource note = model.getResource(noteURI); |
245 |
|
|
246 |
// find actual data |
// find actual data |
271 |
|
|
272 |
} catch (RDFException e) { |
} catch (RDFException e) { |
273 |
pa("Fault inserting text to note: "+e); |
pa("Fault inserting text to note: "+e); |
274 |
}}} |
} */ |
275 |
|
}} |
276 |
|
|
277 |
|
|
278 |
public void deleteText(String noteURI, int begin, int end) |
public void deleteText(String noteURI, int begin, int end) |
279 |
throws RemoteException |
throws RemoteException |
280 |
{ synchronized(model) { try { |
{ synchronized(model) { // try { |
281 |
/* |
/* |
282 |
Cell note = space.getCell(noteId); |
Cell note = space.getCell(noteId); |
283 |
note.deleteText(begin, end); |
note.deleteText(begin, end); |
284 |
*/ |
*/ |
285 |
|
|
286 |
|
/* |
287 |
Resource note = model.getResource(noteURI); |
Resource note = model.getResource(noteURI); |
288 |
|
|
289 |
// find actual data |
// find actual data |
314 |
|
|
315 |
} catch (RDFException e) { |
} catch (RDFException e) { |
316 |
pa("Fault deleting text from the note: "+e); |
pa("Fault deleting text from the note: "+e); |
317 |
}}} |
} |
318 |
|
*/ |
319 |
|
}} |
320 |
} |
} |