/[fenfire]/fenfire/org/fenfire/util/AlphContent.java
ViewVC logotype

Diff of /fenfire/org/fenfire/util/AlphContent.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by mudyc, Wed Mar 26 16:05:59 2003 UTC revision 1.3 by mudyc, Wed Mar 26 18:56:00 2003 UTC
# Line 9  import com.hp.hpl.mesa.rdf.jena.model.*; Line 9  import com.hp.hpl.mesa.rdf.jena.model.*;
9  import com.hp.hpl.mesa.rdf.jena.common.*;  import com.hp.hpl.mesa.rdf.jena.common.*;
10    
11  import java.util.*;  import java.util.*;
12    import java.io.*;
13    import javax.xml.parsers.*;
14    
15    
16  /** Help class to work with Alph  /** Help class to work with Alph
17   */   */
18  public class AlphContent {  public class AlphContent {
19  public static final String rcsid = "$Id$";  public static final String rcsid = "$Id$";
20      private static void pa(String s) { System.out.println("Alph: "+s); }      private static void pa(String s) { System.out.println("AlphContent: "+s); }
21    
22    
23      // Static helpers..      // Static helpers..
# Line 25  public static final String rcsid = "$Id$ Line 28  public static final String rcsid = "$Id$
28       */       */
29      public Span getSpan(Model model, RDFNode node)      public Span getSpan(Model model, RDFNode node)
30      { try {      { try {
         Selector selector = new SelectorImpl((Resource)node, ALPH.content, (RDFNode) null);  
         StmtIterator iter = model.listStatements(selector);  
         if (iter.hasNext()) {  
             Statement stmt = iter.next();  
             //return stmt.getInt();  
             // XXX how do you get the span??  
             
31    
32                        NodeIterator iter = model.listObjectsOfProperty((Resource)node, ALPH.content);
33            if (iter.hasNext()) {
34                Literal lit = (Literal)iter.next();
35    
36              return null;              try {
37                    SpanReader sr = new SpanReader();
38                    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
39                    parser.parse(new StringBufferInputStream(lit.getString()), sr);
40    
41                    ArrayList l = (ArrayList)sr.getSpans();
42                    return (Span)l.get(0);
43                    
44                } catch (Exception e) {
45                    pa("Exception!: "+e);
46                    throw new Error("getspan has an Exception!");
47                }
48          }          }
49          else throw new Error("No available resources!");          else throw new Error("No available content!");
50    
51      } catch (RDFException e) {      } catch (RDFException e) {
52          pa("Exception ocurred!: "+e);          pa("Exception ocurred!: "+e);
# Line 48  public static final String rcsid = "$Id$ Line 57  public static final String rcsid = "$Id$
57      /** helper to present text contents on screen      /** helper to present text contents on screen
58       * Content MUST be TextSpan so check it put first.       * Content MUST be TextSpan so check it put first.
59       */       */
60      public Span getString(Model model, RDFNode node)      public String getString(Model model, RDFNode node)
61      { try {      { try {
62          Selector selector = new SelectorImpl((Resource)node, ALPH.content, (RDFNode) null);  
63          StmtIterator iter = model.listStatements(selector);          NodeIterator iter = model.listObjectsOfProperty((Resource)node, ALPH.content);
64          if (iter.hasNext()) {          if (iter.hasNext()) {
65              Statement stmt = iter.next();              Literal lit = (Literal)iter.next();
             //return stmt.getInt();  
             // XXX how do you get the span??  
               
66    
67              return null;              try {
68                    SpanReader sr = new SpanReader();
69                    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
70                    parser.parse(new StringBufferInputStream(lit.getString()), sr);
71    
72                    String text="";
73                    
74                    ArrayList l = (ArrayList)sr.getSpans();
75                    for (int i=0; i<l.size(); i++)
76                        text += ((TextSpan)l.get(i)).getText();
77                    return text;
78                    
79                } catch (Exception e) {
80                    pa("Exception!: "+e);
81                    throw new Error("getspan has an Exception!");
82                }
83          }          }
84          else throw new Error("No available resources!");          else throw new Error("No available content!");
85    
86      } catch (RDFException e) {      } catch (RDFException e) {
87          pa("Exception ocurred!: "+e);          pa("Exception ocurred!: "+e);

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26