// Path: src/main/java/org/linkeddatafragments/fragments/ILinkedDataFragment.java
// public interface ILinkedDataFragment extends Closeable
// {
//     /**
//      * Returns an iterator over the RDF data of this fragment (possibly only
//      * partial if the data is paged, as indicated by {@link #isPageOnly()}).
//      * @return 
//      */
//     StmtIterator getTriples();
// 
//     /**
//      * Returns true if {@link #getTriples()} returns a page of data only.
//      * In this case, {@link #getPageNumber()} can be used to obtain the
//      * corresponding page number.
//      * @return 
//      */
//     boolean isPageOnly();
// 
//     /**
//      * Returns the number of the page of data returned by {@link #getTriples()}
//      * if the data is paged (that is, if {@link #isPageOnly()} returns true).
//      *
//      * If the data is not paged, this method throws an exception.
//      *
//      * @return 
//      * @throws UnsupportedOperationException
//      *         If the data of this fragment is not paged. 
//      */
//     long getPageNumber() throws UnsupportedOperationException;
// 
//     /**
//      * Returns true if {@link #getTriples()} returns a page of data only and
//      * this is the last page of the fragment.
//      *
//      * If the data is not paged (i.e., if {@link #isPageOnly()} returns false),
//      * this method throws an exception.
//      *
//      * @return 
//      * @throws UnsupportedOperationException
//      *         If the data of this fragment is not paged. 
//      */
//     boolean isLastPage() throws UnsupportedOperationException;
// 
//     /**
//      * Returns the maximum number of triples per page if {@link #getTriples()}
//      * returns a page of data only (that is, if {@link #isPageOnly()} returns
//      * true).
//      *
//      * If the data is not paged, this method throws an exception.
//      *
//      * @return 
//      * @throws UnsupportedOperationException
//      *         If the data of this fragment is not paged. 
//      */
//     long getMaxPageSize() throws UnsupportedOperationException;
// 
//     /**
//      * Returns an iterator over the metadata of this fragment.
//      * @return 
//      */
//     StmtIterator getMetadata();
// 
//     /**
//      * Returns an iterator over an RDF description of the controls associated
//      * with this fragment.
//      * @return 
//      */
//     StmtIterator getControls();
// }


import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import org.apache.jena.query.ARQ;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.RDFLanguages;
import org.linkeddatafragments.datasource.IDataSource;
import org.linkeddatafragments.fragments.ILinkedDataFragment;
import org.linkeddatafragments.fragments.ILinkedDataFragmentRequest;
package org.linkeddatafragments.views;



/**
 *  Serializes an {@link ILinkedDataFragment} to an RDF format
 * 
 * @author Miel Vander Sande
 */
class RdfWriterImpl extends LinkedDataFragmentWriterBase implements ILinkedDataFragmentWriter {

    private final Lang contentType;

    public RdfWriterImpl(Map<String, String> prefixes, HashMap<String, IDataSource> datasources, String mimeType) {
        super(prefixes, datasources);
        this.contentType = RDFLanguages.contentTypeToLang(mimeType);
        ARQ.init();
    }

    @Override
    public void writeNotFound(ServletOutputStream outputStream, HttpServletRequest request) throws IOException {
        outputStream.println(request.getRequestURL().toString() + " not found!");
        outputStream.close();
    }

    @Override
    public void writeError(ServletOutputStream outputStream, Exception ex) throws IOException {
        outputStream.println(ex.getMessage());
        outputStream.close();
    }

    @Override
// Path: src/main/java/org/linkeddatafragments/fragments/ILinkedDataFragment.java
// public interface ILinkedDataFragment extends Closeable
// {
//     /**
//      * Returns an iterator over the RDF data of this fragment (possibly only
//      * partial if the data is paged, as indicated by {@link #isPageOnly()}).
//      * @return 
//      */
//     StmtIterator getTriples();
// 
//     /**
//      * Returns true if {@link #getTriples()} returns a page of data only.
//      * In this case, {@link #getPageNumber()} can be used to obtain the
//      * corresponding page number.
//      * @return 
//      */
//     boolean isPageOnly();
// 
//     /**
//      * Returns the number of the page of data returned by {@link #getTriples()}
//      * if the data is paged (that is, if {@link #isPageOnly()} returns true).
//      *
//      * If the data is not paged, this method throws an exception.
//      *
//      * @return 
//      * @throws UnsupportedOperationException
//      *         If the data of this fragment is not paged. 
//      */
//     long getPageNumber() throws UnsupportedOperationException;
// 
//     /**
//      * Returns true if {@link #getTriples()} returns a page of data only and
//      * this is the last page of the fragment.
//      *
//      * If the data is not paged (i.e., if {@link #isPageOnly()} returns false),
//      * this method throws an exception.
//      *
//      * @return 
//      * @throws UnsupportedOperationException
//      *         If the data of this fragment is not paged. 
//      */
//     boolean isLastPage() throws UnsupportedOperationException;
// 
//     /**
//      * Returns the maximum number of triples per page if {@link #getTriples()}
//      * returns a page of data only (that is, if {@link #isPageOnly()} returns
//      * true).
//      *
//      * If the data is not paged, this method throws an exception.
//      *
//      * @return 
//      * @throws UnsupportedOperationException
//      *         If the data of this fragment is not paged. 
//      */
//     long getMaxPageSize() throws UnsupportedOperationException;
// 
//     /**
//      * Returns an iterator over the metadata of this fragment.
//      * @return 
//      */
//     StmtIterator getMetadata();
// 
//     /**
//      * Returns an iterator over an RDF description of the controls associated
//      * with this fragment.
//      * @return 
//      */
//     StmtIterator getControls();
// }


// Path: src/main/java/org/linkeddatafragments/views/RdfWriterImpl.java
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import org.apache.jena.query.ARQ;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.RDFLanguages;
import org.linkeddatafragments.datasource.IDataSource;
import org.linkeddatafragments.fragments.ILinkedDataFragment;
import org.linkeddatafragments.fragments.ILinkedDataFragmentRequest;

package org.linkeddatafragments.views;



/**
 *  Serializes an {@link ILinkedDataFragment} to an RDF format
 * 
 * @author Miel Vander Sande
 */
class RdfWriterImpl extends LinkedDataFragmentWriterBase implements ILinkedDataFragmentWriter {

    private final Lang contentType;

    public RdfWriterImpl(Map<String, String> prefixes, HashMap<String, IDataSource> datasources, String mimeType) {
        super(prefixes, datasources);
        this.contentType = RDFLanguages.contentTypeToLang(mimeType);
        ARQ.init();
    }

    @Override
    public void writeNotFound(ServletOutputStream outputStream, HttpServletRequest request) throws IOException {
        outputStream.println(request.getRequestURL().toString() + " not found!");
        outputStream.close();
    }

    @Override
    public void writeError(ServletOutputStream outputStream, Exception ex) throws IOException {
        outputStream.println(ex.getMessage());
        outputStream.close();
    }

    @Override
    public void writeFragment(ServletOutputStream outputStream, IDataSource datasource, ILinkedDataFragment fragment, ILinkedDataFragmentRequest ldfRequest) throws Exception {