Ticket #2424: applet_fix.patch

File applet_fix.patch, 28.0 KB (added by meddle, 15 years ago)

applet fix patch

  • modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/actions/SetKindAction.java

    ### Eclipse Workspace Patch 1.0
    #P sophie
     
     1package org.sophie2.base.model.book.actions; 
     2 
     3import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     4import org.sophie2.base.model.resources.r4.resources.ResourceR4; 
     5import org.sophie2.base.skins.Message; 
     6 
     7/** 
     8 * {@link AutoAction} for setting the kind of a resource. 
     9 *  
     10 * @author kyli 
     11 */ 
     12public class SetKindAction extends AutoAction { 
     13         
     14        private final String kind; 
     15 
     16        /** 
     17         * Constructs the action with the new kind to set. 
     18         *  
     19         * @param description 
     20         *                      Description of the action. 
     21         * @param significant 
     22         *                      Significance of the action. 
     23         * @param kind 
     24         *                      The new kind. 
     25         */ 
     26        public SetKindAction(Message description, boolean significant, 
     27                        String kind) { 
     28                super(description, significant); 
     29                 
     30                this.kind = kind; 
     31        } 
     32 
     33        @Override 
     34        public void performAuto() { 
     35                getChanger().setRaw(ResourceR4.KEY_KIND, this.kind); 
     36        } 
     37} 
  • modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/AutoActionsUtil.java

     
    11package org.sophie2.base.model.book; 
    22 
     3import org.sophie2.base.model.book.actions.ChangeTitleAction; 
    34import org.sophie2.base.model.resources.r4.access.ResourceAccess; 
    45import org.sophie2.base.model.resources.r4.changes.AutoAction; 
    56import org.sophie2.base.model.resources.r4.resources.ResourceH; 
    6 import org.sophie2.base.model.resources.r4.resources.ResourceR4; 
    77import org.sophie2.base.skins.Message; 
    88 
    99/** 
     
    7070         *                      The new title of the resource. 
    7171         */ 
    7272        public static void changeResourceTitle(ResourceH resource, final String newTitle) { 
    73                 new AutoAction(Message.create(RES_TITLE, newTitle), true) { 
    74  
    75                         @Override 
    76                         public void performAuto() { 
    77                                 getChanger().setRaw(ResourceR4.KEY_TITLE, newTitle); 
    78                         } 
    79                          
    80                 }.register(resource.getAccess()); 
     73                AutoAction action = new ChangeTitleAction(Message.create(RES_TITLE, newTitle), true,  
     74                                newTitle); 
     75                action.register(resource.getAccess()); 
    8176        } 
    8277} 
  • modules/org.sophie2.s2s/src/main/java/org/sophie2/s2s/ServerModule.java

     
    4646                                                ServerResourceHelper helper = resourceHelperExtension.getObject(); 
    4747                                                helper.initialize(); 
    4848 
    49                                                 WebAppModule.get().startServer(9090); 
     49                                                WebAppModule.get().startServer(); 
    5050                                        } 
    5151                                }); 
    5252 
  • modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/actions/RemoveSubElementAction.java

     
     1package org.sophie2.base.model.book.actions; 
     2 
     3import org.sophie2.base.commons.util.ImmList; 
     4import org.sophie2.base.model.book.interfaces.CompositeElement; 
     5import org.sophie2.base.model.book.timelines.ActivationChannel; 
     6import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     7import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     8import org.sophie2.base.skins.Message; 
     9 
     10/** 
     11 * {@link AutoAction} for removing the sub elements of an element. 
     12 *  
     13 * @author kyli 
     14 */ 
     15public class RemoveSubElementAction extends AutoAction { 
     16         
     17        private final ResourceRefR4 elementRef; 
     18        private final ImmList<ActivationChannel> children; 
     19        private final ResourceRefR4 element; 
     20 
     21        /** 
     22         * Constructs the action with the element to be removed. 
     23         *  
     24         * @param description 
     25         *                      Description of the action. 
     26         * @param significant 
     27         *                      Significance of the action. 
     28         * @param elementRef 
     29         *                      Relative reference to the element to be removed, 
     30         * @param children  
     31         *                      The current sub elements of the element which sub element will be removed. 
     32         * @param element  
     33         *                      Absolute reference to the element to b removed.  
     34         */ 
     35        public RemoveSubElementAction(Message description, boolean significant, 
     36                        ResourceRefR4 elementRef, ImmList<ActivationChannel> children, ResourceRefR4 element) { 
     37                super(description, significant); 
     38                 
     39                this.elementRef = elementRef; 
     40                this.children = children; 
     41                this.element = element; 
     42        } 
     43 
     44        @Override 
     45        public void performAuto() { 
     46                int index = -1; 
     47                for (int i = 0; i < this.children.size(); i++) { 
     48                        ResourceRefR4 childRef = this.children.get(i) 
     49                        .getElementResource(); 
     50                        if (childRef.equals(this.element)) { 
     51                                index = i; 
     52                                break; 
     53                        } 
     54                } 
     55 
     56                ImmList<ActivationChannel> newChildren = this.children.remove(index); 
     57                getChanger().setRaw(CompositeElement.KEY_SUB_ELEMENTS, 
     58                                newChildren); 
     59                if (!this.elementRef.isAbsolute()) { 
     60                        getChanger().removeResource(this.elementRef); 
     61                } 
     62        } 
     63} 
  • modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/ElementH.java

     
    1414import org.sophie2.base.commons.util.position.ImmSize; 
    1515import org.sophie2.base.commons.util.position.Position; 
    1616import org.sophie2.base.media.TimePos; 
     17import org.sophie2.base.model.book.actions.RemoveSubElementAction; 
    1718import org.sophie2.base.model.book.frame.BoundMode; 
    1819import org.sophie2.base.model.book.frame.FrameR4; 
    1920import org.sophie2.base.model.book.frame.WrappingModes; 
     
    418419                        Message actionName, boolean significance) { 
    419420 
    420421                ResourceAccess access = getAccess(); 
    421                 final ImmList<ActivationChannel> children = CompositeElement.KEY_SUB_ELEMENTS 
    422                 .get(access); 
    423  
    424                 final ResourceRefR4 frameRef = ResourceRefR4.makeChild(element 
    425                                 .getName()); 
     422                final ImmList<ActivationChannel> children = CompositeElement.KEY_SUB_ELEMENTS.get(access); 
    426423 
    427                 new AutoAction(actionName, significance) { 
    428                         @Override 
    429                         public void performAuto() { 
    430                                 int index = -1; 
    431                                 for (int i = 0; i < children.size(); i++) { 
    432                                         ResourceRefR4 childRef = children.get(i) 
    433                                         .getElementResource(); 
    434                                         if (childRef.equals(element)) { 
    435                                                 index = i; 
    436                                                 break; 
    437                                         } 
    438                                 } 
     424                final ResourceRefR4 elementRef = ResourceRefR4.makeChild(element.getName()); 
    439425 
    440                                 ImmList<ActivationChannel> newChildren = children.remove(index); 
    441                                 getChanger().setRaw(CompositeElement.KEY_SUB_ELEMENTS, 
    442                                                 newChildren); 
    443                                 if (!frameRef.isAbsolute()) { 
    444                                         getChanger().removeResource(frameRef); 
    445                                 } 
    446                         } 
    447                 }.register(access); 
     426                AutoAction action = new RemoveSubElementAction(actionName, significance, elementRef, 
     427                                children, element); 
     428                action.register(access); 
    448429 
    449430        } 
    450431 
  • modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/util/AppViewUtil.java

     
    1616import org.sophie2.base.model.resources.r4.resources.ResourceH; 
    1717import org.sophie2.base.model.resources.r4.resources.ResourceR4; 
    1818import org.sophie2.base.visual.VisualElement; 
     19import org.sophie2.core.logging.SophieLog; 
    1920import org.sophie2.core.modularity.SophieExtension; 
    2021import org.sophie2.core.mvc.LogicR3; 
    2122import org.sophie2.core.prolib.errors.NotAvailableException; 
     
    275276                try { 
    276277                        bookAccess = locator.open(bookRef, options); 
    277278                } catch (SophieSourceNotFoundException e) { 
     279                        SophieLog.error("Cannot open book from ref: " + bookRef); 
    278280                        DialogUtils.showErrorDialog(null, 
    279281                                        "The specified file does not contain a book.", "Error"); 
    280282                        return false; 
     
    283285 
    284286                String resourceKind = ResourceR4.KEY_KIND.get(bookAccess); 
    285287                if (!BookR4.KIND.equals(resourceKind)) { 
     288                        SophieLog.error("Cannot open book from ref: " + bookRef + " with access: " + bookAccess + " with kind: " + resourceKind); 
    286289                        DialogUtils.showErrorDialog(null, 
    287290                                        "The specified file does not contain a book.", "Error"); 
    288291                        return false; 
  • modules/org.sophie2.launcher/src/main/resources/reader-run/applet.bundles.config

     
    44org.sophie2.core.mvc started 
    55org.sophie2.base.bound installed 
    66org.sophie2.base.commons installed 
     7org.sophie2.base.config started 
    78org.sophie2.base.model.resources.r4 started 
    89org.sophie2.base.dialogs installed 
    910org.sophie2.base.dnd installed 
  • modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/actions/CreateTestFrameAction.java

     
     1package org.sophie2.base.model.book.actions; 
     2 
     3import org.sophie2.base.commons.util.ImmList; 
     4import org.sophie2.base.model.book.FrameH; 
     5import org.sophie2.base.model.book.frame.FrameR4; 
     6import org.sophie2.base.model.book.timelines.ActivationChannel; 
     7import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     8import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     9import org.sophie2.base.skins.Message; 
     10 
     11/** 
     12 * {@link AutoAction} for adding a new frame for testing to an element. 
     13 *  
     14 * @author meddle 
     15 */ 
     16public class CreateTestFrameAction extends AutoAction { 
     17 
     18        private final ResourceRefR4 frameRef; 
     19        private final ImmList<ActivationChannel> children; 
     20         
     21        /** 
     22         * Constructs the action with a frame reference pointing to the new frame 
     23         * to be added and the current channels of the page to be modified. 
     24         *  
     25         * @param description 
     26         *                      Description of the action. 
     27         * @param significant 
     28         *                      Significance of the action. 
     29         * @param frameRef 
     30         *                      Reference to the frame to be added. 
     31         * @param children 
     32         *                      List with the current channels of the page which will contain the new frame. 
     33         */ 
     34        public CreateTestFrameAction(Message description, boolean significant, ResourceRefR4 frameRef, 
     35                        ImmList<ActivationChannel> children) { 
     36                super(description, significant); 
     37                 
     38                this.frameRef = frameRef; 
     39                this.children = children; 
     40        } 
     41 
     42        @Override 
     43        public void performAuto() { 
     44                FrameH.create(getChanger(), this.frameRef, FrameR4.DEFAULT_TITLE,  
     45                                this.children, FrameR4.KIND, FrameH.DEFAULT_FRAME_LOCATION, 
     46                                FrameR4.DEFAULT_FRAME_SIZE); 
     47        } 
     48 
     49} 
  • modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/actions/ChangeTitleAction.java

     
     1package org.sophie2.base.model.book.actions; 
     2 
     3import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     4import org.sophie2.base.model.resources.r4.resources.ResourceR4; 
     5import org.sophie2.base.skins.Message; 
     6 
     7/** 
     8 * {@link AutoAction} for changing the title of a resource. 
     9 *  
     10 * @author mira 
     11 */ 
     12public class ChangeTitleAction extends AutoAction { 
     13         
     14        private final String newTitle; 
     15 
     16        /** 
     17         * Constructs the action with the new title of the resource. 
     18         *  
     19         * @param description 
     20         *                      Description of the action. 
     21         * @param significant 
     22         *                      Significance of the action. 
     23         * @param newTitle 
     24         *                      The new title, 
     25         */ 
     26        public ChangeTitleAction(Message description, boolean significant, String newTitle) { 
     27                super(description, significant); 
     28                 
     29                this.newTitle = newTitle; 
     30        } 
     31 
     32        @Override 
     33        public void performAuto() { 
     34                getChanger().setRaw(ResourceR4.KEY_TITLE, this.newTitle); 
     35        } 
     36} 
  • modules/org.sophie2.dev/src/test/java/org/sophie2/dev/author/TextChainingSystemTest.java

     
    251251                HeadTextFrameH.createTextFrameAction(curBook(), 
    252252                                curPageWorkArea().getRootPageView().model().get(), 
    253253                                text, ResourceRefR4.NONE_REF.toUri(), null, 
    254                                 Message.create(INSERT_FULL_TEXT_FRAME), true, true); 
     254                                Message.create(INSERT_FULL_TEXT_FRAME), true); 
    255255 
    256256                TextFrameView frameViewToSelect = 
    257257                        curPageWorkArea().getAll(TextFrameView.class).get(4); 
  • modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/BookH.java

     
    77import org.sophie2.base.commons.structures.ImmTreeList; 
    88import org.sophie2.base.commons.util.ImmList; 
    99import org.sophie2.base.commons.util.position.ImmSize; 
     10import org.sophie2.base.model.book.actions.InitBookAction; 
    1011import org.sophie2.base.model.book.resource.AudioResourceH; 
    1112import org.sophie2.base.model.book.resource.r4.BookR4; 
    1213import org.sophie2.base.model.book.resource.r4.PageR4; 
     
    455456         */ 
    456457        public static AutoAction createInitAction(final ResourceRefR4 pageRef,  
    457458                        final String pageTitle) { 
    458                 return new AutoAction(Message.create(CREATE_BLANK_PAGE), true) { 
    459                         @Override 
    460                         public void performAuto() { 
    461                                 BookH.addNewPage(getChanger(), pageRef, BookR4.KEY_PAGES 
    462                                                 .getDefault(), pageTitle); 
    463                         } 
    464                 }; 
     459                return new InitBookAction(Message.create(CREATE_BLANK_PAGE), true, pageRef, pageTitle); 
    465460        } 
    466461 
    467462        @Override 
  • modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/testing/ModelTestBase.java

     
    1212import org.sophie2.base.model.book.BookH; 
    1313import org.sophie2.base.model.book.FrameH; 
    1414import org.sophie2.base.model.book.PageH; 
    15 import org.sophie2.base.model.book.frame.FrameR4; 
     15import org.sophie2.base.model.book.actions.CreateTestFrameAction; 
     16import org.sophie2.base.model.book.actions.CreateTestPageAction; 
    1617import org.sophie2.base.model.book.interfaces.CompositeElement; 
    1718import org.sophie2.base.model.book.resource.r4.BookR4; 
    1819import org.sophie2.base.model.book.resource.r4.PageR4; 
     
    128129                book.getAccess().getHead().getModel().debugPrint(); 
    129130                final ResourceRefList pages = book.get(BookR4.KEY_PAGES); 
    130131                 
    131                 new AutoAction(Message.create(CREATE_TEST_PAGE), true) { 
    132                         @Override 
    133                         public void performAuto() { 
    134                                 BookH.addNewPage(getChanger(), pageRef, pages, PageR4.DEFAULT_TITLE); 
    135                         } 
    136                 }.register(bookAccess); 
     132                AutoAction action = new CreateTestPageAction(Message.create(CREATE_TEST_PAGE), true, 
     133                                pageRef, pages); 
     134                action.register(bookAccess); 
     135                 
    137136                return ResourceH.getHelper(bookAccess.open(pageRef, 
    138137                                bookAccess.getAccessOptions()), PageH.class); 
    139138        } 
     
    153152                final ImmList<ActivationChannel> children =  
    154153                        CompositeElement.KEY_SUB_ELEMENTS.get(page.getAccess()); 
    155154 
    156                 new AutoAction(Message.create(CREATE_TEST_FRAME), true) { 
    157                         @Override 
    158                         public void performAuto() { 
    159                                 FrameH.create(getChanger(), frameRef, FrameR4.DEFAULT_TITLE,  
    160                                                 children, FrameR4.KIND, FrameH.DEFAULT_FRAME_LOCATION, 
    161                                                 FrameR4.DEFAULT_FRAME_SIZE); 
    162                         } 
    163                 }.register(pageAccess); 
     155                AutoAction action = new CreateTestFrameAction(Message.create(CREATE_TEST_FRAME), true, 
     156                                frameRef, children); 
     157                action.register(pageAccess); 
    164158                 
    165159                return ResourceH.getHelper(pageAccess.open(frameRef, 
    166160                                pageAccess.getAccessOptions()), FrameH.class); 
  • modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/FrameH.java

     
    66import org.sophie2.base.commons.util.position.ImmPoint; 
    77import org.sophie2.base.commons.util.position.ImmSize; 
    88import org.sophie2.base.media.TimePos; 
     9import org.sophie2.base.model.book.actions.SetKindAction; 
    910import org.sophie2.base.model.book.frame.BoundMode; 
    1011import org.sophie2.base.model.book.frame.FrameR4; 
    1112import org.sophie2.base.model.book.frame.WrappingModes; 
     
    242243                                                        && templateRef.equals(this.prevTemplate) 
    243244                                                        && ResourceFrame.KEY_MAIN_RESOURCE.getApplyKey().get(templateAccess)) { 
    244245                                                 
    245                                                 new AutoAction(Message.create(CHANGE_KIND), true) { 
    246  
    247                                                         @Override 
    248                                                         public void performAuto() { 
    249                                                                 getChanger().setRaw(ResourceR4.KEY_KIND, templateKind); 
    250                                                         } 
    251                                                          
    252                                                 }.register(getAccess()); 
     246                                                AutoAction action = new SetKindAction(Message.create(CHANGE_KIND), 
     247                                                                true, templateKind); 
     248                                                action.register(getAccess()); 
    253249                                        }        
    254250                                } 
    255251                                 
  • modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/actions/InitBookAction.java

     
     1package org.sophie2.base.model.book.actions; 
     2 
     3import org.sophie2.base.model.book.BookH; 
     4import org.sophie2.base.model.book.resource.r4.BookR4; 
     5import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     6import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     7import org.sophie2.base.skins.Message; 
     8 
     9/** 
     10 * {@link AutoAction} for creating an initial book. 
     11 *  
     12 * @author meddle 
     13 */ 
     14public class InitBookAction extends AutoAction { 
     15         
     16        private final ResourceRefR4 pageRef; 
     17        private final String pageTitle; 
     18 
     19         
     20        /** 
     21         * Constructs the action the reference and the name of the first page  
     22         * and only page of the new book. 
     23         *  
     24         * @param description 
     25         *                      Description of the action. 
     26         * @param significant 
     27         *                      Significance of the action. 
     28         * @param pageRef 
     29         *                      Reference to the first page of the new book, 
     30         * @param pageTitle  
     31         *                      Title of the only page of the initial book.  
     32         */ 
     33        public InitBookAction(Message description, boolean significant, ResourceRefR4 pageRef, 
     34                        String pageTitle) { 
     35                super(description, significant); 
     36                 
     37                this.pageRef = pageRef; 
     38                this.pageTitle = pageTitle; 
     39        } 
     40 
     41        @Override 
     42        public void performAuto() { 
     43                BookH.addNewPage(getChanger(), this.pageRef, BookR4.KEY_PAGES.getDefault(), this.pageTitle); 
     44        } 
     45} 
  • modules/org.sophie2.launcher/src/main/java/org/sophie2/launcher/Launcher.java

     
    77import java.net.URL; 
    88import java.util.ArrayList; 
    99import java.util.List; 
     10import java.util.UUID; 
    1011 
    1112import javax.swing.RootPaneContainer; 
    1213 
     
    129130                } 
    130131                 
    131132                // Create a temporary bundle cache directory. 
    132                 this.cachedir = File.createTempFile("org.sophie2.applet.bundle-cache", null); 
    133                 this.cachedir.delete(); 
     133                 
     134                String tempDir = System.getProperty("java.io.tmpdir"); 
     135                this.cachedir = new File(tempDir, UUID.randomUUID() + "-sophie-cache"); 
     136                assert this.cachedir.mkdirs() : "Could not write in the temporary directory?"; 
     137                 
     138//              this.cachedir.deleteOnExit(); 
    134139                StringMap configMap = new StringMap(false); 
    135140                 
    136141                System.setProperty("java.protocol.handler.pkgs", ""); 
     
    199204                configMap.put(AutoActivator.AUTO_INSTALL_PROP + ".1", notStarted.toString()); 
    200205 
    201206                configMap.put(FelixConstants.LOG_LEVEL_PROP, "1"); 
    202                 configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, this.cachedir 
    203                                 .getAbsolutePath()); 
     207                configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, this.cachedir.getAbsolutePath()); 
    204208                 
    205209                // Create a list to hold custom framework activators. 
    206210                List<BundleActivator> activatorList = new ArrayList<BundleActivator>(); 
     
    257261                                deleteFileOrDir(child); 
    258262                        } 
    259263                } 
     264                 
    260265                file.delete(); 
    261266        } 
    262267 
  • modules/org.sophie2.server.webui/src/main/resources/jsps/resource_book.jspx

     
    2323                        <span>${book.pageCount}</span> 
    2424                </li> 
    2525                </ul> 
     26                <form name="appletParams"> 
     27                        <input type="hidden" name="uwidth" value="${book.pageSize.width}"/> 
     28                        <input type="hidden" name="uheight" value="${book.pageSize.height}"/> 
     29                </form> 
    2630                <c:choose> 
    2731                <c:when test="${param.showApplet}"> 
    2832                        <div style="width: 100%; overflow: auto"> 
    29                                 <fmt:setBundle basename="org.sophie2.server.webui.config" var="configBundle" /> 
    30                                  
     33 
    3134                                <script src="http://www.java.com/js/deployJava.js"><!--  --></script> 
    3235                                <script> 
    33                                     <fmt:message bundle="${configBundle}" key="applet.deploy_script"> 
    34                                                 <fmt:param value="${book.pageSize.width}" /> 
    35                                                 <fmt:param value="${book.pageSize.height}" /> 
    36                                         </fmt:message>  
     36                                                var userWidth = document.forms['appletParams'].uwidth.value; 
     37                                                var userHeight = document.forms['appletParams'].uheight.value; 
     38                                 
     39                                                var width = parseInt(userWidth) + 300; 
     40                                                var height = parseInt(userHeight) + 200; 
     41                                                 
     42                                                var href = window.location.href; 
     43                                                var bookRefValue = window.location.href + "&amp;action=download"; 
     44                                                var attributes = { 
     45                                                        code: "org.sophie2.launcher.AppletMain.class", 
     46                                                        codebase: "http://sophie2.org/sophie2-reader-applet/reader/", 
     47                                                        archive: "org.sophie2.launcher-2.0.1.jar", 
     48                                                        width: width, 
     49                                                        height: height 
     50                                                                        }; 
     51                                                var parameters = { 
     52                                                        edition: "reader", 
     53                                                                bundlesConfigFile: "applet.bundles.config", 
     54                                                                bookRef: bookRefValue, 
     55                                                                separate_jvm: "true" 
     56                                                                        }; 
     57                                                var version = "1.5"; 
     58                                                deployJava.runApplet(attributes, parameters, version); 
    3759                                </script> 
    3860                        </div> 
    3961                        <a href="javascript:location.href=location.href.substring(0, location.href.length - location.search.length)">Hide applet</a> 
  • modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/actions/CreateTestPageAction.java

     
     1package org.sophie2.base.model.book.actions; 
     2 
     3import org.sophie2.base.model.book.BookH; 
     4import org.sophie2.base.model.book.resource.r4.PageR4; 
     5import org.sophie2.base.model.resources.r4.ResourceRefList; 
     6import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     7import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     8import org.sophie2.base.skins.Message; 
     9 
     10/** 
     11 * {@link AutoAction} for adding a new page for testing to a book. 
     12 *  
     13 * @author meddle 
     14 */ 
     15public class CreateTestPageAction extends AutoAction { 
     16 
     17        private final ResourceRefR4 pageRef; 
     18        private final ResourceRefList pages; 
     19         
     20        /** 
     21         * Constructs the action with a page reference pointing to the new page 
     22         * to be added and the current pages of the book to be modified. 
     23         *  
     24         * @param description 
     25         *                      Description of the action. 
     26         * @param significant 
     27         *                      Significance of the action. 
     28         * @param pageRef 
     29         *                      Reference to the page to be added. 
     30         * @param pages 
     31         *                      List with the current pages of the book which will contain the new page. 
     32         */ 
     33        public CreateTestPageAction(Message description, boolean significant, 
     34                        ResourceRefR4 pageRef, ResourceRefList pages) { 
     35                super(description, significant); 
     36                 
     37                this.pageRef = pageRef; 
     38                this.pages = pages; 
     39        } 
     40 
     41        @Override 
     42        public void performAuto() { 
     43                BookH.addNewPage(getChanger(), this.pageRef, this.pages, PageR4.DEFAULT_TITLE); 
     44        } 
     45 
     46} 
  • modules/org.sophie2.reader/src/main/java/org/sophie2/reader/ReaderModule.java

     
    11package org.sophie2.reader; 
    22 
     3import java.io.File; 
     4import java.io.FileOutputStream; 
     5import java.io.IOException; 
     6import java.io.InputStream; 
     7import java.net.URI; 
    38import java.util.List; 
    49import java.util.Timer; 
    510import java.util.TimerTask; 
    611 
    712import org.sophie2.base.commons.util.ImageUtil; 
     13import org.sophie2.base.commons.util.bindata.BinData; 
    814import org.sophie2.base.commons.util.bindata.TmpChunksDirProvider; 
    915import org.sophie2.base.layout.BaseLayoutModule; 
    1016import org.sophie2.base.layout.LayoutEngine; 
     
    119125                } 
    120126                //open only first book. 
    121127                ResourceRefR4 bookRef; 
     128                if ( startUpBookFiles.length == 0 || startUpBookFiles[0] == null) { 
     129                        return null; 
     130                } 
    122131                if (startUpBookFiles[0].startsWith(LocationPrefix.FILE)) { 
    123132                        bookRef = ResourceRefR4.make(startUpBookFiles[0]); 
     133                } else if (startUpBookFiles[0].startsWith(LocationPrefix.SERVER)) { 
     134                        bookRef = ResourceRefR4.make(startUpBookFiles[0]); 
     135                        URI uri = bookRef.toUri(); 
     136                        if (!uri.isAbsolute()) { 
     137                                SophieLog.warnf("Cannot open non absolute ref %s.", bookRef); 
     138                                return null; 
     139                        } 
     140                        InputStream from = null; 
     141                        FileOutputStream to = null; 
     142                        try { 
     143                                from = uri.toURL().openStream(); 
     144                                // I do not believe in file entry manger so just use tmp folder. 
     145                                File resourceFile = File.createTempFile("sophieStartupBook", ".book.s2"); 
     146                                resourceFile.deleteOnExit(); 
     147                                to = new FileOutputStream(resourceFile); 
     148                                BinData.transport(from, to); 
     149                                 
     150                                return ResourceRefR4.make(resourceFile); 
     151                        } catch (IOException e) { 
     152                                throw new RuntimeException(e); 
     153                        } finally { 
     154                                try { 
     155                                        if (to != null) { 
     156                                                to.close(); 
     157                                        } 
     158                                        if (from != null) { 
     159                                                from.close(); 
     160                                        } 
     161                                } catch (IOException e) { 
     162                                        throw new RuntimeException(e); 
     163                                } 
     164                        } 
    124165                } else { 
    125166                        bookRef = ResourceRefR4.make(LocationPrefix.FILE + startUpBookFiles[0]); 
    126167                }