@ -14,11 +14,10 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult ;
import javax.xml.transform.stream.StreamSource ;
import net.yacy.yacy ;
import net.yacy.document.parser.rdfa.IRDFaTriple ;
import net.yacy.kelondro.logging.Log ;
import net.yacy.yacy ;
public class RDFaTripleImpl {
private static Templates templates = null ;
@ -30,9 +29,9 @@ public class RDFaTripleImpl{
private String value = null ;
private String dataType = null ;
private String language = null ;
private Reader in ;
private Transformer aTransformer ;
private ArrayList < IRDFaTriple > allRDFaTriples = new ArrayList < IRDFaTriple > ( ) ;
private final Reader in ;
private final Transformer aTransformer ;
private final ArrayList < IRDFaTriple > allRDFaTriples = new ArrayList < IRDFaTriple > ( ) ;
public RDFaTripleImpl ( Reader in , String base ) throws IOException ,
@ -44,39 +43,32 @@ public class RDFaTripleImpl{
bufReader . reset ( ) ;
}
if ( templates = = null ) {
File f = new File ( yacy . homedir + File . separatorChar + "defaults" + File . separatorChar + "RDFaParser.xsl" ) ;
try {
File f = new File ( yacy . homedir + File . separatorChar + "RDFaParser" + File . separatorChar + "RDFaParser.xsl" ) ;
StreamSource aSource = new StreamSource ( f ) ;
TransformerFactory aFactory = TransformerFactory . newInstance ( ) ;
templates = aFactory . newTemplates ( aSource ) ;
}
catch ( Exception e ) {
Log . logSevere ( "RDFA PARSER" , "XSL template could not be loaded from " + yacy . homedir + File . separatorChar + "RDFaParser" + File . separatorChar + "RDFaParser.xsl" ) ;
} catch ( Exception e ) {
Log . logSevere ( "RDFA PARSER" , "XSL template could not be loaded from " + f . toString ( ) ) ;
}
}
this . aTransformer = templates . newTransformer ( ) ;
aTransformer. setParameter ( "parser" , this ) ;
aTransformer. setParameter ( "url" , base ) ;
this . aTransformer. setParameter ( "parser" , this ) ;
this . aTransformer. setParameter ( "url" , base ) ;
this . in = bufReader ;
}
public IRDFaTriple [ ] parse ( ) {
try {
aTransformer . transform ( new StreamSource ( in) , new StreamResult ( System . out ) ) ;
this . aTransformer . transform ( new StreamSource ( this . in) , new StreamResult ( System . out ) ) ;
} catch ( TransformerException e ) {
Log . logWarning ( "RDFA PARSER" , "Error while reading RDFa" ) ;
// e.printStackTrace();
}
return allRDFaTriples . toArray ( new IRDFaTriple [ ] { } ) ;
return this . allRDFaTriples . toArray ( new IRDFaTriple [ ] { } ) ;
}
@ -93,7 +85,7 @@ public class RDFaTripleImpl{
String propertyURI , String value , String dataType ,
String language , String objectNodeURI , String objectURI ) {
IRDFaTriple triple = new RDFaTripleContent ( subjectURI , subjectNodeURI , propertyURI , value , dataType , language , objectNodeURI , objectURI ) ;
allRDFaTriples. add ( triple ) ;
this . allRDFaTriples. add ( triple ) ;
}
private static void nullAllValues ( RDFaTripleImpl parser ) {