All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jaeksoft.searchlib.webservice.screenshot.ScreenshotImpl Maven / Gradle / Ivy

Go to download

OpenSearchServer is a powerful, enterprise-class, search engine program. Using the web user interface, the crawlers (web, file, database, ...) and the REST/RESTFul API you will be able to integrate quickly and easily advanced full-text search capabilities in your application. OpenSearchServer runs on Windows and Linux/Unix/BSD.

The newest version!
/**   
 * License Agreement for OpenSearchServer
 *
 * Copyright (C) 2011-2013 Emmanuel Keller / Jaeksoft
 * 
 * http://www.open-search-server.com
 * 
 * This file is part of OpenSearchServer.
 *
 * OpenSearchServer is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 * OpenSearchServer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with OpenSearchServer. 
 *  If not, see .
 **/
package com.jaeksoft.searchlib.webservice.screenshot;

import java.awt.Dimension;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.WebApplicationException;
import javax.xml.ws.WebServiceException;

import com.jaeksoft.searchlib.ClientFactory;
import com.jaeksoft.searchlib.crawler.web.browser.BrowserDriverEnum;
import com.jaeksoft.searchlib.crawler.web.screenshot.ScreenshotThread;
import com.jaeksoft.searchlib.webservice.ApiIdentifier;
import com.jaeksoft.searchlib.webservice.CommonServices;
import com.jaeksoft.searchlib.webservice.screenshot.RestScreenshot;

public class ScreenshotImpl extends CommonServices implements RestScreenshot {

	@Override
	public byte[] captureScreenshotAPI(String login, String key, URL url,
			Integer browserWidth, Integer browserHeight,
			Integer reductionPercent, Boolean visiblePartOnly, Integer wait,
			HttpServletRequest request) {
		try {
			ClientFactory.INSTANCE.properties.checkApi(key,
					ApiIdentifier.capt00, request.getRemoteAddr());
			if (browserWidth == null)
				browserWidth = 1280;
			if (browserHeight == null)
				browserHeight = 768;
			if (browserWidth > 1600)
				browserWidth = 1600;
			if (browserHeight > 1200)
				browserHeight = 1200;
			if (reductionPercent == null)
				reductionPercent = 100;
			if (visiblePartOnly == null)
				visiblePartOnly = false;
			if (wait == null)
				wait = 0;
			if (wait > 20)
				wait = 20;
			ScreenshotThread screenshotThread = new ScreenshotThread(
					new Dimension(browserWidth, browserHeight),
					reductionPercent, visiblePartOnly, url, wait,
					BrowserDriverEnum.find(ClientFactory.INSTANCE
							.getDefaultWebBrowserDriver().getValue(),
							BrowserDriverEnum.FIREFOX));
			screenshotThread.runner();
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			ImageIO.write(screenshotThread.getImage(), "png", baos);
			return baos.toByteArray();
		} catch (WebApplicationException e) {
			throw e;
		} catch (InterruptedException e) {
			throw new WebServiceException(e);
		} catch (IOException e) {
			throw new WebServiceException();
		} catch (Exception e) {
			throw new WebServiceException(e);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy