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; 24 25 import org.w3c.dom.Document; 26 27 import com.sun.star.beans.PropertyValue; 28 import com.sun.star.frame.XDispatch; 29 import com.sun.star.frame.XFrame; 30 import com.sun.star.lang.XMultiServiceFactory; 31 import com.sun.star.util.URL; 32 import com.sun.star.wizards.common.Desktop; 33 import com.sun.star.wizards.common.FileAccess; 34 import com.sun.star.wizards.common.PropertyNames; 35 import com.sun.star.wizards.common.UCB; 36 import com.sun.star.wizards.ui.event.Task; 37 import com.sun.star.wizards.web.data.CGLayout; 38 import com.sun.star.wizards.web.data.CGSettings; 39 40 /** 41 * @author rpiterman 42 * This class both copies necessary files to 43 * a temporary directory, generates a temporary TOC page, 44 * and opens the generated html document in a web browser, 45 * by default "index.html" (unchangeable). 46 * <br/> 47 * Since the files are both static and dynamic (some are always the same, 48 * while other change according to user choices) 49 * I divide this tasks to two: all necessary 50 * static files, which should not regularily update are copied upon 51 * instanciation. 52 * The TOC is generated in refresh(...); 53 */ 54 public class TOCPreview 55 { 56 57 private String tempDir = null; 58 private XMultiServiceFactory xmsf; 59 private FileAccess fileAccess; 60 private WebWizardDialogResources resources; 61 private URL openHyperlink; 62 private XDispatch xDispatch; 63 private PropertyValue[] loadArgs; 64 private UCB ucb; 65 private XFrame xFrame; 66 67 /** 68 * @param xmsf_ 69 * @param settings web wizard settings 70 * @param res resources 71 * @param tempDir_ destination 72 * @throws Exception 73 */ TOCPreview(XMultiServiceFactory xmsf_, CGSettings settings, WebWizardDialogResources res, String tempDir_, XFrame _xFrame)74 public TOCPreview(XMultiServiceFactory xmsf_, CGSettings settings, WebWizardDialogResources res, String tempDir_, XFrame _xFrame) 75 throws Exception 76 { 77 xFrame = _xFrame; 78 xmsf = xmsf_; 79 resources = res; 80 fileAccess = new FileAccess(xmsf); 81 tempDir = tempDir_; 82 loadArgs = loadArgs(FileAccess.connectURLs(tempDir, "/index.html")); 83 openHyperlink = Desktop.getDispatchURL(xmsf, ".uno:OpenHyperlink"); 84 xDispatch = Desktop.getDispatcher(xmsf, xFrame, "_top", openHyperlink); 85 ucb = new UCB(xmsf); 86 87 Process.copyStaticImages(ucb, settings, tempDir); 88 } 89 90 /** 91 * generates a TOC, copies the layout-specific files, and 92 * calles a browser to show "index.html". 93 * @param settings 94 * @throws Exception 95 */ refresh(CGSettings settings)96 public void refresh(CGSettings settings) 97 throws Exception 98 { 99 Document doc = (Document) settings.cp_DefaultSession.createDOM(); 100 CGLayout layout = settings.cp_DefaultSession.getLayout(); 101 Task task = new Task(PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING, 10000); 102 Process.generate(xmsf, layout, doc, fileAccess, tempDir, task); 103 Process.copyLayoutFiles(ucb, fileAccess, settings, layout, tempDir); 104 xDispatch.dispatch(openHyperlink, loadArgs); //Dispatch.dispatch(openHyperlink, loadArgs); 105 } 106 loadArgs(String url)107 private PropertyValue[] loadArgs(String url) 108 { 109 PropertyValue pv = new PropertyValue(); 110 pv.Name = PropertyNames.URL; 111 pv.Value = url; 112 return new PropertyValue[] 113 { 114 pv 115 }; 116 } 117 } 118