package ld.ldhomework.crawler;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.semanticweb.yars.nx.Node;
import org.semanticweb.yars.nx.parser.NxParser;
import org.semanticweb.yars.nx.parser.ParseException;
import org.semanticweb.yars2.rdfxml.RDFXMLParser;

public class FileParser {

    private static final Logger LOG = java.util.logging.Logger
	    .getLogger(TripleEntry.class.getName());

    private List<Triple> triples;

    private boolean parsed = false;
    private InputStream is;
    private String baseUrl;

    public FileParser(InputStream is, String baseUrl) {
	this(is, baseUrl, null);
    }

    public FileParser(InputStream is, String baseUrl, String contentType) {
	triples = new ArrayList<Triple>();
	this.baseUrl = baseUrl;
	this.is = is;
    }

    public void parse() throws IOException {
	if (true) {
	    parseXml();
	} else if (false) {
	    parseNx();
	}
    }

    private void parseNx() {
	NxParser nxp = new NxParser(is);
	nxp = new NxParser(is);

	Node[] nxx;
	while (nxp.hasNext()) {
	    nxx = nxp.next();
	    triples.add(new Triple(nxx[0], nxx[1], nxx[2]));
	}
	parsed = true;

    }

    private void parseXml() {
	RDFXMLParser nxp;
	try {

	    nxp = new RDFXMLParser(is, baseUrl);

	    Node[] nxx;
	    while (nxp.hasNext()) {
		nxx = nxp.next();
		triples.add(new Triple(nxx[0], nxx[1], nxx[2]));
	    }

	    parsed = true;
	} catch (ParseException pe) {
	    LOG.log(Level.WARNING, "Error at parsing file", pe);
	} catch (IOException e) {
	    LOG.log(Level.WARNING, "Error at parsing file", e);
	}
    }

    public List<Triple> getTriples() {
	if (parsed) {
	    return triples;
	}
	throw new IllegalStateException("file not yet parsed");
    }

}

@@ -239,56 +239,8 @@
 de;%0A
-import org.semanticweb.yars.nx.parser.NxParser;%0A
 impo
@@ -477,16 +477,46 @@
 me());%0A%0A
+    private RDFXMLParser nxp;%0A
     priv
@@ -695,117 +695,8 @@
 ) %7B%0A
-%09this(is, baseUrl, null);%0A    %7D%0A%0A    public FileParser(InputStream is, String baseUrl, String contentType) %7B%0A
 %09tri
@@ -785,20 +785,23 @@
  public 
-void
+boolean
  parse()
@@ -826,365 +826,8 @@
 n %7B%0A
-%09if (true) %7B%0A%09    parseXml();%0A%09%7D else if (false) %7B%0A%09    parseNx();%0A%09%7D%0A    %7D%0A%0A    private void parseNx() %7B%0A%09NxParser nxp = new NxParser(is);%0A%09nxp = new NxParser(is);%0A%0A%09Node%5B%5D nxx;%0A%09while (nxp.hasNext()) %7B%0A%09    nxx = nxp.next();%0A%09    triples.add(new Triple(nxx%5B0%5D, nxx%5B1%5D, nxx%5B2%5D));%0A%09%7D%0A%09parsed = true;%0A%0A    %7D%0A%0A    private void parseXml() %7B%0A%09RDFXMLParser nxp;%0A
 %09try
@@ -919,16 +919,17 @@
 xt()) %7B%0A
+%0A
 %09%09nxx = 
@@ -940,16 +940,17 @@
 next();%0A
+%0A
 %09%09triple
@@ -1115,92 +1115,25 @@
 ;%0A%09%7D
- catch (IOException e) %7B%0A%09    LOG.log(Level.WARNING, %22Error at parsing file%22, e);%0A%09%7D
+%0A%0A%09return parsed;
 %0A   
@@ -1279,9 +1279,8 @@
     %7D%0A%0A%7D
-%0A

undo changes ...