org.linkeddatafragments.fragments.tpf.TPFRequestParser Maven / Gradle / Ivy
The newest version!
package org.linkeddatafragments.fragments.tpf;
import org.linkeddatafragments.config.ConfigReader;
import org.linkeddatafragments.fragments.FragmentRequestParserBase;
import org.linkeddatafragments.fragments.IFragmentRequestParser;
import org.linkeddatafragments.fragments.ILinkedDataFragmentRequest;
import org.linkeddatafragments.util.TriplePatternElementParser;
import javax.servlet.http.HttpServletRequest;
/**
* An {@link IFragmentRequestParser} for {@link ITriplePatternFragmentRequest}s.
*
* @param
* @param
*
* @author Olaf Hartig
* @param
*/
public class TPFRequestParser
extends FragmentRequestParserBase
{
public final TriplePatternElementParser elmtParser;
/**
*
* @param elmtParser
*/
public TPFRequestParser(
final TriplePatternElementParser elmtParser )
{
this.elmtParser = elmtParser;
}
/**
*
* @param httpRequest
* @param config
* @return
* @throws IllegalArgumentException
*/
@Override
protected Worker getWorker( final HttpServletRequest httpRequest,
final ConfigReader config )
throws IllegalArgumentException
{
return new Worker( httpRequest, config );
}
/**
*
*/
protected class Worker extends FragmentRequestParserBase.Worker
{
/**
*
* @param request
* @param config
*/
public Worker( final HttpServletRequest request,
final ConfigReader config )
{
super( request, config );
}
/**
*
* @return
* @throws IllegalArgumentException
*/
@Override
public ILinkedDataFragmentRequest createFragmentRequest()
throws IllegalArgumentException
{
return new TriplePatternFragmentRequestImpl(
getFragmentURL(),
getDatasetURL(),
pageNumberWasRequested,
pageNumber,
getSubject(),
getPredicate(),
getObject() );
}
/**
*
* @return
*/
public ITriplePatternElement getSubject() {
return getParameterAsTriplePatternElement(
ITriplePatternFragmentRequest.PARAMETERNAME_SUBJ );
}
/**
*
* @return
*/
public ITriplePatternElement getPredicate() {
return getParameterAsTriplePatternElement(
ITriplePatternFragmentRequest.PARAMETERNAME_PRED );
}
/**
*
* @return
*/
public ITriplePatternElement getObject() {
return getParameterAsTriplePatternElement(
ITriplePatternFragmentRequest.PARAMETERNAME_OBJ );
}
/**
*
* @param paramName
* @return
*/
public ITriplePatternElement
getParameterAsTriplePatternElement( final String paramName )
{
final String parameter = request.getParameter( paramName );
return elmtParser.parseIntoTriplePatternElement( parameter );
}
} // end of class Worker
}