Package com.levigo.jadice.server.vcf
Class Vcf2HtmlWorker
- java.lang.Object
-
- com.levigo.jadice.server.core.NodeWorker<T>
-
- com.levigo.jadice.server.core.StreamWorker<Vcf2HtmlNode>
-
- com.levigo.jadice.server.vcf.Vcf2HtmlWorker
-
- All Implemented Interfaces:
QualifiedLogEventReceiver
,WorkerController<Vcf2HtmlNode>
,Runnable
public class Vcf2HtmlWorker extends StreamWorker<Vcf2HtmlNode>
Worker that converts vcf data to html via velocity templating.
-
-
Constructor Summary
Constructors Constructor Description Vcf2HtmlWorker()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
buildVcfConfigPath()
Resolve the config folder path.protected List<Stream>
convertVcf2Html(Stream vcfStream, String vcardResourceUri, boolean skipPhotos)
This function convert a vcf stream to a list of html streams.protected void
convertWithEncoding(Stream vcfStream, org.apache.velocity.Template template, com.levigo.jadice.document.io.SeekableInputStream inputStreamBeforeCutting, Charset charset, List<Stream> conversionResultStreamsList, boolean skipPhotos)
Converts a vcf stream with a specific encoding to html.protected org.apache.velocity.VelocityContext
createVelocityContext(Stream vcfStream, Charset charset, boolean skipPhotos)
This function builds the context that can be used within the velocity template.protected List<InputStream>
cutVcfInputStream(com.levigo.jadice.document.io.SeekableInputStream inputStreamBeforeCutting, Charset charset)
Since vcf streams can be concatenated into one vcf file with the delimiters BEGIN:VCARD and END:VCARD in between we have to split up such concatenated vcf streams into multiple vcf streams that only contain one vcf data set.protected String
determineBeginNeedle(String groupedVCF)
Determine the vcf begin needle label.String
getVcfConfigPath()
protected void
injectContextMapIntoVelocityContext(org.apache.velocity.VelocityContext context, Map<String,Object> contextMap)
This method injects the variables from the contextMap into the actual velocity context object.protected void
injectCustomInfoIntoVelocityContext(org.apache.velocity.VelocityContext context, ezvcard.VCard vCard)
This method injects custom field information into the velocity context.protected void
preventUTF16Conversion(com.levigo.jadice.document.io.SeekableInputStream inputStreamBeforeCutting)
protected void
work(Stream stream)
Implement this method in order to work on a single stream.protected BundledStream
writeHtmlStream(Stream vcfStream, org.apache.velocity.Template template, org.apache.velocity.VelocityContext context, Charset charset)
This method performs the html templating via velocity.-
Methods inherited from class com.levigo.jadice.server.core.StreamWorker
accept, reject, work
-
Methods inherited from class com.levigo.jadice.server.core.NodeWorker
abort, abortNow, addInputBundle, addOutputBundle, doAbort, doAbortNow, error, error, error, fail, fail, fail, getController, getInputBundle, getInputBundles, getJob, getLimitSupport, getNode, getOutputBundle, getOutputBundles, getServerJob, getState, getStreamTransportFactory, getTransportSender, initialize, isAbortRequested, postWork, preWork, run, setDescriptor, setJob, toString, warn, warn, warn
-
-
-
-
Method Detail
-
work
protected void work(Stream stream) throws Throwable
Description copied from class:StreamWorker
Implement this method in order to work on a single stream.- Specified by:
work
in classStreamWorker<Vcf2HtmlNode>
- Parameters:
stream
- theStream
to work on- Throws:
Throwable
- in case of processing failure
-
convertVcf2Html
protected List<Stream> convertVcf2Html(Stream vcfStream, String vcardResourceUri, boolean skipPhotos) throws IOException
This function convert a vcf stream to a list of html streams.- Parameters:
vcfStream
- the vcf datavcardResourceUri
- the velocity config base folderskipPhotos
- whether to skip converting images since they might lead to problem during the html conversion.- Returns:
- list of converted html streams
- Throws:
IOException
- if an io error happened
-
convertWithEncoding
protected void convertWithEncoding(Stream vcfStream, org.apache.velocity.Template template, com.levigo.jadice.document.io.SeekableInputStream inputStreamBeforeCutting, Charset charset, List<Stream> conversionResultStreamsList, boolean skipPhotos) throws IOException
Converts a vcf stream with a specific encoding to html.- Parameters:
vcfStream
- the vcf that shall be converted to htmltemplate
- the templating used for creating the htmlinputStreamBeforeCutting
- the input stream before it is cut into a single vcf stream (vcfs can be combined).charset
- the charset used for reading and writing the conversion filesconversionResultStreamsList
- the list of conversion results. Since there might be multiple vcfs merge into one.skipPhotos
- whether to skip converting images since they might lead to problem during the html conversion.- Throws:
IOException
- if an i/o error occurs
-
preventUTF16Conversion
protected void preventUTF16Conversion(com.levigo.jadice.document.io.SeekableInputStream inputStreamBeforeCutting)
-
createVelocityContext
protected org.apache.velocity.VelocityContext createVelocityContext(Stream vcfStream, Charset charset, boolean skipPhotos) throws IOException
This function builds the context that can be used within the velocity template. E.g. it initialises variable that can be used for the templating.- Parameters:
vcfStream
- the vcf stream that shall be converted- Returns:
- the velocity context that can be used inside templates
- Throws:
IOException
- if an io error happens
-
writeHtmlStream
protected BundledStream writeHtmlStream(Stream vcfStream, org.apache.velocity.Template template, org.apache.velocity.VelocityContext context, Charset charset)
This method performs the html templating via velocity.- Parameters:
vcfStream
- the vcf streamtemplate
- the template that has been chosen for creating the htmlcontext
- the velocity context that contains the variable information- Returns:
- the resulting bundled html stream
-
cutVcfInputStream
protected List<InputStream> cutVcfInputStream(com.levigo.jadice.document.io.SeekableInputStream inputStreamBeforeCutting, Charset charset) throws IOException
Since vcf streams can be concatenated into one vcf file with the delimiters BEGIN:VCARD and END:VCARD in between we have to split up such concatenated vcf streams into multiple vcf streams that only contain one vcf data set.- Parameters:
inputStreamBeforeCutting
- the vcf input stream before cutting the stream into it's parts- Returns:
- a list of input streams that represent the different vcf parts which only contain one vcf data set
- Throws:
IOException
- if an io error happens
-
injectContextMapIntoVelocityContext
protected void injectContextMapIntoVelocityContext(org.apache.velocity.VelocityContext context, Map<String,Object> contextMap)
This method injects the variables from the contextMap into the actual velocity context object.- Parameters:
context
- velocity contextcontextMap
- the context variable map
-
injectCustomInfoIntoVelocityContext
protected void injectCustomInfoIntoVelocityContext(org.apache.velocity.VelocityContext context, ezvcard.VCard vCard)
This method injects custom field information into the velocity context.- Parameters:
vCard
- the vCard object as it has been parsedcontext
- the velocity context
-
buildVcfConfigPath
protected String buildVcfConfigPath()
Resolve the config folder path.- Returns:
- the config folder path.
-
determineBeginNeedle
protected String determineBeginNeedle(String groupedVCF)
Determine the vcf begin needle label. Since some vcf files might write the needle differently this is needed to determine the right needle. e.g. the needle could be BEGIN:vCard vs BEGIN:VCARD- Parameters:
groupedVCF
- the grouped vcf file that shall be split- Returns:
- the begin needle with which we can split the concatinated vcf file.
-
getVcfConfigPath
public String getVcfConfigPath()
-
-