1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.wizards.web.export;
24 
25 import com.sun.star.io.IOException;
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.wizards.common.Properties;
28 import com.sun.star.wizards.ui.event.Task;
29 import com.sun.star.wizards.web.data.CGDocument;
30 import com.sun.star.wizards.web.data.CGExporter;
31 
32 /**
33  * @author rpiterman
34  *
35  * An exporter which is configured with a filter name, and
36  * uses the specified filter to export documents.
37  */
38 public class FilterExporter extends AbstractExporter
39 {
40 
41     protected String filterName;
42     protected Properties props = new Properties();
43 
44     /* (non-Javadoc)
45      * @see com.sun.star.wizards.web.export.Exporter#export(java.lang.Object, java.io.File, com.sun.star.wizards.web.data.CGSettings, com.sun.star.lang.XMultiServiceFactory)
46      */
export(CGDocument source, String target, XMultiServiceFactory xmsf, Task task)47     public boolean export(CGDocument source, String target, XMultiServiceFactory xmsf, Task task) throws IOException
48     {
49 
50         boolean result = true;
51         Object document = null;
52 
53         try
54         {
55             document = openDocument(source, xmsf);
56             task.advance(true);
57             storeToURL(document, target, filterName, props.getProperties());
58             task.advance(true);
59 
60         }
61         catch (IOException iox)
62         {
63             iox.printStackTrace(System.out);
64             result = false;
65             throw iox;
66         }
67         finally
68         {
69             closeDocument(document, xmsf);
70             calcFileSize(source, target, xmsf);
71             task.advance(true);
72         }
73         return result;
74 
75     }
76 
77     /* (non-Javadoc)
78      * @see com.sun.star.wizards.web.export.Exporter#init(com.sun.star.wizards.web.data.CGExporter)
79      */
init(CGExporter exporter_)80     public void init(CGExporter exporter_)
81     {
82         super.init(exporter_);
83         filterName = getArgument("Filter", exporter_);
84     }
85 }
86