/*************************************************************************
*
* $RCSfile: ConverterServlet.java,v $
*
* $Revision: 1.8 $
*
* last change: $Author: hr $ $Date: 2004/02/02 20:09:11 $
*
* The Contents of this file are made available subject to the terms of
* the BSD license.
*
* Copyright (c) 2003 by Sun Microsystems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Sun Microsystems, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*************************************************************************/
// UNO API
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.uno.XComponentContext;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.util.XCloseable;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
/** This class implements a http servlet in order to convert an incoming document
* with help of a running OpenOffice.org and to push the converted file back
* to the client.
*/
public class Converter2PDF{
/** Specifies the temporary directory on the web server.
*/
private String stringWorkingDirectory;
//System.getProperty( "java.io.tmpdir" ).replace( '\\', '/' );
/** Specifies the host for the office server.
*/
private String stringHost = "localhost";
/** Specifies the port for the office server.
*/
private String stringPort = "2002";
/** Called by the server (via the service method) to allow a servlet to handle
* a POST request. The file from the client will be uploaded to the web server
* and converted on the web server and after all pushed to the client.
* @param request Object that contains the request the client has made of the servlet.
* @param response Object that contains the response the servlet sends to the client.
* @throws ServletException If the request for the POST could not be handled.
* @throws IOException If an input or output error is detected when the servlet handles the request.
*/
/** This method converts a document to a given type by using a running
* OpenOffice.org and saves the converted document to the specified
* working directory.
* @param stringDocumentName The full path name of the file on the server to be converted.
* @param stringConvertType Type to convert to.
* @param stringExtension This string will be appended to the file name of the converted file.
* @return The full path name of the converted file will be returned.
* @see stringWorkingDirectory
*/
public String convertDocument( String stringDocumentName,
String stringConvertType,
String stringExtension)
throws Exception
{
String stringConvertedFile = "";
// Converting the document to the favoured type
// try {
// Composing the URL
String stringUrl = "file:///" + stringDocumentName;
/* Bootstraps a component context with the jurt base components
registered. Component context to be granted to a component for running.
Arbitrary values can be retrieved from the context. */
XComponentContext xcomponentcontext =
com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );
/* Gets the service manager instance to be used (or null). This method has
been added for convenience, because the service manager is a often used
object. */
XMultiComponentFactory xmulticomponentfactory =
xcomponentcontext.getServiceManager();
/* Creates an instance of the component UnoUrlResolver which
supports the services specified by the factory. */
Object objectUrlResolver =
xmulticomponentfactory.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", xcomponentcontext );
// Create a new url resolver
XUnoUrlResolver xurlresolver = ( XUnoUrlResolver )
UnoRuntime.queryInterface( XUnoUrlResolver.class,
objectUrlResolver );
// Resolves an object that is specified as follow:
// uno:<connection description>;<protocol description>;<initial object name>
Object objectInitial = xurlresolver.resolve(
"uno:socket,host=" + stringHost + ",port=" + stringPort +
";urp;StarOffice.ServiceManager" );
// Create a service manager from the initial object
xmulticomponentfactory = ( XMultiComponentFactory )
UnoRuntime.queryInterface( XMultiComponentFactory.class, objectInitial );
// Query for the XPropertySet interface.
XPropertySet xpropertysetMultiComponentFactory = ( XPropertySet )
UnoRuntime.queryInterface( XPropertySet.class, xmulticomponentfactory );
// Get the default context from the office server.
Object objectDefaultContext =
xpropertysetMultiComponentFactory.getPropertyValue( "DefaultContext" );
// Query for the interface XComponentContext.
xcomponentcontext = ( XComponentContext ) UnoRuntime.queryInterface(
XComponentContext.class, objectDefaultContext );
/* A desktop environment contains tasks with one or more
frames in which components can be loaded. Desktop is the
environment for components which can instanciate within
frames. */
XComponentLoader xcomponentloader = ( XComponentLoader )
UnoRuntime.queryInterface( XComponentLoader.class,
xmulticomponentfactory.createInstanceWithContext(
"com.sun.star.frame.Desktop", xcomponentcontext ) );
// Preparing properties for loading the document
PropertyValue propertyvalue[] = new P
Web在线读PDF,Doc 把Pdf导出JPG 超级好用
4星 · 超过85%的资源 需积分: 20 50 浏览量
2013-01-07
09:50:13
上传
评论 3
收藏 2.57MB RAR 举报
yongweb
- 粉丝: 33
- 资源: 163
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页