// Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java
// public class SampleFopService {
// 
// 	private static SampleFopService instance;
// 	private FopFactory fopFactory;
// 	private TransformerFactory transformerFactory;
// 	private static volatile Object lock = new Object();
// 	
// 	private SampleFopService()
// 	{
// 		transformerFactory = TransformerFactory.newInstance();
// 		fopFactory = FopFactory.newInstance();
// 	}
// 
// 	public static SampleFopService getInstance()
// 	{
// 		if (instance == null)
// 		{
// 			synchronized (lock)
// 			{
// 				if (null == instance)
// 				{
// 					instance = new SampleFopService();
// 				}
// 			}
// 		}
// 		return instance;
// 	}
// 	
// 	public void getContent(InputStream  is, String mimeType, OutputStream os) throws Exception
// 	{
// 		Source source = null;
// 		try
// 		{	
// 			Transformer transformer = transformerFactory.newTransformer(); // identity transformer
// 			source = new StreamSource(is);		
// 			Fop fop = fopFactory.newFop(mimeType, os);
// 			Result res = new SAXResult(fop.getDefaultHandler());
// 			transformer.transform(source, res);			
// 		} catch (Exception e)
// 		{
// 			throw e;
// 		}
// 	}
// 
// }
// 
// Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java
// public class SampleConfigurator {
// 
// 	private Properties properties;
// 	private static SampleConfigurator instance;
// 	
// 	private SampleConfigurator() {};
// 	
// 	public static void initialize(String configPath) throws IOException
// 	{
// 		Properties properties = new Properties();
// 		properties.load(new FileInputStream(configPath));
// 		SampleConfigurator instance = new SampleConfigurator();
// 		instance.properties = properties;
// 		SampleConfigurator.instance = instance;
// 	}
// 	public static SampleConfigurator getInstance()
// 	{
// 		return instance;
// 	}
// 	public String getConfig(String key)
// 	{
// 		if (properties.containsKey(key))
// 			return properties.get(key).toString();
// 		else
// 			return "";
// 	}
// 
// }


import com.webpagebytes.wpbsample.utility.SampleFopService;
import com.webpagebytes.wpbsample.utility.SampleConfigurator;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.fop.apps.MimeConstants;
import com.webpagebytes.cms.WPBContentProvider;
import com.webpagebytes.cms.WPBContentService;
import com.webpagebytes.cms.WPBModel;

/*
 *   Copyright 2015 Webpagebytes
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.webpagebytes.wpbsample;






public class WPBSampleThread implements Runnable {

	private static final Logger log = Logger.getLogger(WPBSampleThread.class.getName());
	private WPBContentService contentService;
	public WPBSampleThread(WPBContentService contentService)
	{
		this.contentService = contentService;
	}
	@Override
	public void run() {
		try
		{			
			log.log(Level.INFO, "Execution of backgroud thread started");
			
			WPBContentProvider contentProvider = contentService.getContentProvider();
			
			WPBModel configModel = contentService.createModel();
			
			String  maxRunsStr = configModel.getCmsModel().get(WPBModel.GLOBALS_KEY).get("TEST_RUNS_PDF_GENERATION");;
			String user_name = configModel.getCmsModel().get(WPBModel.GLOBALS_KEY).get("TEST_USERNAME_PDF_GENERATION");
			if (null == maxRunsStr || user_name == null)
			{
				return;
			}
			
			long t0 = System.currentTimeMillis();

// Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java
// public class SampleFopService {
// 
// 	private static SampleFopService instance;
// 	private FopFactory fopFactory;
// 	private TransformerFactory transformerFactory;
// 	private static volatile Object lock = new Object();
// 	
// 	private SampleFopService()
// 	{
// 		transformerFactory = TransformerFactory.newInstance();
// 		fopFactory = FopFactory.newInstance();
// 	}
// 
// 	public static SampleFopService getInstance()
// 	{
// 		if (instance == null)
// 		{
// 			synchronized (lock)
// 			{
// 				if (null == instance)
// 				{
// 					instance = new SampleFopService();
// 				}
// 			}
// 		}
// 		return instance;
// 	}
// 	
// 	public void getContent(InputStream  is, String mimeType, OutputStream os) throws Exception
// 	{
// 		Source source = null;
// 		try
// 		{	
// 			Transformer transformer = transformerFactory.newTransformer(); // identity transformer
// 			source = new StreamSource(is);		
// 			Fop fop = fopFactory.newFop(mimeType, os);
// 			Result res = new SAXResult(fop.getDefaultHandler());
// 			transformer.transform(source, res);			
// 		} catch (Exception e)
// 		{
// 			throw e;
// 		}
// 	}
// 
// }
// 
// Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java
// public class SampleConfigurator {
// 
// 	private Properties properties;
// 	private static SampleConfigurator instance;
// 	
// 	private SampleConfigurator() {};
// 	
// 	public static void initialize(String configPath) throws IOException
// 	{
// 		Properties properties = new Properties();
// 		properties.load(new FileInputStream(configPath));
// 		SampleConfigurator instance = new SampleConfigurator();
// 		instance.properties = properties;
// 		SampleConfigurator.instance = instance;
// 	}
// 	public static SampleConfigurator getInstance()
// 	{
// 		return instance;
// 	}
// 	public String getConfig(String key)
// 	{
// 		if (properties.containsKey(key))
// 			return properties.get(key).toString();
// 		else
// 			return "";
// 	}
// 
// }


// Path: src/main/java/com/webpagebytes/wpbsample/WPBSampleThread.java
import com.webpagebytes.wpbsample.utility.SampleFopService;
import com.webpagebytes.wpbsample.utility.SampleConfigurator;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.fop.apps.MimeConstants;
import com.webpagebytes.cms.WPBContentProvider;
import com.webpagebytes.cms.WPBContentService;
import com.webpagebytes.cms.WPBModel;

/*
 *   Copyright 2015 Webpagebytes
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.webpagebytes.wpbsample;






public class WPBSampleThread implements Runnable {

	private static final Logger log = Logger.getLogger(WPBSampleThread.class.getName());
	private WPBContentService contentService;
	public WPBSampleThread(WPBContentService contentService)
	{
		this.contentService = contentService;
	}
	@Override
	public void run() {
		try
		{			
			log.log(Level.INFO, "Execution of backgroud thread started");
			
			WPBContentProvider contentProvider = contentService.getContentProvider();
			
			WPBModel configModel = contentService.createModel();
			
			String  maxRunsStr = configModel.getCmsModel().get(WPBModel.GLOBALS_KEY).get("TEST_RUNS_PDF_GENERATION");;
			String user_name = configModel.getCmsModel().get(WPBModel.GLOBALS_KEY).get("TEST_USERNAME_PDF_GENERATION");
			if (null == maxRunsStr || user_name == null)
			{
				return;
			}
			
			long t0 = System.currentTimeMillis();

			String basePath = SampleConfigurator.getInstance().getConfig("storageDir");
