Ticket #2470: appletBinaries.patch

File appletBinaries.patch, 26.9 KB (added by mira, 15 years ago)
  • modules/org.sophie2.base.model.resources.r4/src/main/java/org/sophie2/base/model/resources/r4/access/cacheKey/ServerAccessCacheKey.java

    ### Eclipse Workspace Patch 1.0
    #P sophie
     
    11package org.sophie2.base.model.resources.r4.access.cacheKey; 
    22 
    33import org.sophie2.base.model.resources.r4.ResourceRefR4; 
    4 import org.sophie2.base.model.resources.r4.access.MasterTopAccess; 
    54import org.sophie2.base.model.resources.r4.access.ResourceAccess; 
    65 
    76/** 
    8  * A key used for caching server {@link MasterTopAccess}es. It contains the  
    9  * {@link ResourceRefR4} and sesionId of the access. 
     7 * A container class that holds {@link ResourceRefR4} to server resource  
     8 * and sesionId for the facade communication. It is used to cache different 
     9 * thing. 
    1010 *  
    1111 * @author mira 
    1212 */ 
  • modules/org.sophie2.reader/pom.xml

     
    1515        <packaging>bundle</packaging> 
    1616        <description>Sophie 2 Reader Edition for only reading the books.</description> 
    1717        <dependencies> 
     18             <dependency> 
     19                <groupId>org.sophie2</groupId> 
     20                <artifactId>org.sophie2.main.func.servers</artifactId> 
     21                <version>2.0.6</version> 
     22             </dependency> 
    1823                <dependency> 
    1924                <groupId>org.sophie2</groupId> 
    2025                <artifactId>org.sophie2.core.modularity</artifactId> 
  • modules/org.sophie2.main.func.servers/src/main/java/org/sophie2/main/func/servers/resources/ServerResourceLocator.java

     
    1818import org.sophie2.base.model.resources.r4.model.ResourceRevision; 
    1919import org.sophie2.base.model.resources.r4.model.RevisionId; 
    2020import org.sophie2.core.logging.SophieLog; 
     21import org.sophie2.main.func.servers.MainFuncServersModule; 
    2122import org.sophie2.main.func.servers.ServerConnection; 
    2223 
    2324/** 
     
    5859        private final FacadeR4 facade; 
    5960        private final ResourceRefR4 serverTopRef; 
    6061         
    61  
    6262        /** 
    6363         * Creates a <code>ServerResourceLocator</code> instance by specified 
    6464         * connection, accessOptions and parent. 
    6565         *  
    66          * @param serverConnection  
    67          *                      The connection to be used by the locator. 
     66         * @param connection  
     67         *                      The ServerConnection to the server. 
    6868         * @param accessOptions  
    6969         *                      The access options for the locator. 
    7070         * @param parentLocator  
    7171         *                      The parent to delegate to. 
    7272         */ 
    73         public ServerResourceLocator(ServerConnection serverConnection, 
     73        public ServerResourceLocator(ServerConnection connection, 
    7474                        AccessOptions accessOptions, ResourceLocator parentLocator) { 
    7575                super(accessOptions, parentLocator); 
    76                 this.facade = serverConnection.getFacade(); 
    77                 this.serverTopRef = ResourceRefR4.make( 
    78                                 serverConnection.account().get().getServerUrl()); 
     76                this.facade = connection.getFacade(); 
     77                this.serverTopRef = ResourceRefR4.make(connection.account().get().getServerUrl()); 
     78        } 
     79         
     80        /** 
     81         * Creates a <code>ServerResourceLocator</code> instance by specified 
     82         * the serverUrl, accessOptions and parent. 
     83         *  
     84         * @param serverUrl  
     85         *                      The server url. 
     86         * @param accessOptions  
     87         *                      The access options for the locator. 
     88         * @param parentLocator  
     89         *                      The parent to delegate to. 
     90         */ 
     91        public ServerResourceLocator(String serverUrl, 
     92                        AccessOptions accessOptions, ResourceLocator parentLocator) { 
     93                super(accessOptions, parentLocator); 
     94                this.serverTopRef = ResourceRefR4.make(serverUrl); 
     95                this.facade = MainFuncServersModule.getFacade(serverUrl); 
    7996        } 
    8097 
    8198        @Override 
     
    101118        @Override 
    102119        protected ResourceRefR4 getTopRef(ResourceRefR4 ref) { 
    103120                String location = ref.getLocation(); 
    104                 assert location.startsWith(LocationPrefix.SERVER); 
     121                assert location.startsWith(this.serverTopRef.getLocation()); 
    105122                return this.serverTopRef; 
    106123        } 
    107124         
  • modules/org.sophie2.main.func.servers/src/main/java/org/sophie2/main/func/servers/ServerConnection.java

     
    11package org.sophie2.main.func.servers; 
    22 
    3 import org.sophie2.base.connectivity.Connector; 
    43import org.sophie2.base.connectivity.facade.FacadeR4; 
    54import org.sophie2.base.connectivity.facade.Response; 
    65import org.sophie2.base.model.resources.r4.ResourceRefR4; 
    76import org.sophie2.base.model.security.UserR4; 
    87import org.sophie2.core.logging.SophieLog; 
    9 import org.sophie2.core.modularity.SophieExtension; 
    108import org.sophie2.core.prolib.impl.AutoProperty; 
    119import org.sophie2.core.prolib.impl.BaseProObject; 
    1210import org.sophie2.core.prolib.interfaces.Prop; 
     
    7068                        @Override 
    7169                        protected FacadeR4 compute() { 
    7270                                String serverUrl = account().get().getServerUrl(); 
    73                                 Connector connector = null; 
    74                                 for (SophieExtension<Connector> extension : MainFuncServersModule.get() 
    75                                                 .getConnectorPoint().extensions().get()) { 
    76                                         Connector conn = extension.getObject(); 
    77                                         if (conn.supports(serverUrl)) { 
    78                                                 // A suitable connector is found 
    79                                                 connector = conn; 
    80                                                 break; 
    81                                         } 
    82                                 } 
    83  
    84                                 if (connector == null) { 
    85                                         throw new RuntimeException( 
    86                                                         "No suitable connector was found for url " + serverUrl); 
    87                                 } 
    88                                 FacadeR4 facade = connector.getFacade(serverUrl); 
    89  
    90                                 assert facade != null : "cannot get facade from connector"; 
    91                                 return facade; 
     71                                return MainFuncServersModule.getFacade(serverUrl); 
    9272                        } 
    9373 
    9474                } 
  • modules/org.sophie2.main.func.servers/src/main/java/org/sophie2/main/func/servers/MainFuncServersModule.java

     
    55import org.sophie2.base.commons.util.ImageUtil; 
    66import org.sophie2.base.connectivity.Connector; 
    77import org.sophie2.base.connectivity.TransferManager; 
     8import org.sophie2.base.connectivity.facade.FacadeR4; 
    89import org.sophie2.base.dialogs.Dialog; 
    910import org.sophie2.base.model.resources.r4.access.server.ResourceLocatorProvider; 
    1011import org.sophie2.base.model.resources.r4.resources.ResourceR4; 
     
    108109                res.add(new SimpleSophieExtension<Persister>(Persister.class,  
    109110                                new PasswordPersister())); 
    110111 
    111                 AutoVisualProvider.fillExtensions(res, ServersTab.class); 
    112                 AutoVisualProvider.fillExtensions(res, SaveToServerDialog.UploadResourceDialog.class); 
    113                  
    114                 res.add(SimpleVisualProvider.createExtension(SaveBookOnServerItem.class, 
    115                                 FileMenu.class, "file-menu-item", "eb-file-save-on-server-item")); 
     112                if (System.getProperties().get("sophie2.applet") == null) { 
     113                        AutoVisualProvider.fillExtensions(res, ServersTab.class); 
     114                        AutoVisualProvider.fillExtensions(res, SaveToServerDialog.UploadResourceDialog.class); 
     115                        res.add(SimpleVisualProvider.createExtension(SaveBookOnServerItem.class, 
     116                                        FileMenu.class, "file-menu-item", "eb-file-save-on-server-item")); 
     117                        res.add(new SimpleSophieExtension<Dialog>(Dialog.class, 
     118                                        new SaveToServerDialog())); 
     119                        res.add(new SimpleSophieExtension<Dialog>(Dialog.class, new ServerLoginDialog())); 
     120                        AutoVisualProvider.fillExtensions(res, SwingLoginDialog.class); 
     121 
     122                        SimpleOperation.fillExtensions(res, ServersTabLogic.class); 
     123                        SimpleOperation.fillExtensions(res, TransferLogic.class); 
     124                        SimpleOperation.fillExtensions(res, ServerLoginDialogLogic.class); 
     125                         
     126                        SimpleOperation.fillExtensions(res, SaveToServerDialogLogic.class); 
     127                } 
    116128                 
    117129                SimpleSkinPartsProvider provider = new SimpleSkinPartsProvider(); 
    118130                provider.parts().add(makeSkinPart()); 
    119131                provider.parts().add(makeLanguagePackPart()); 
    120132                res.add(provider.asExtension()); 
    121133                 
    122                  
    123                 res.add(new SimpleSophieExtension<Dialog>(Dialog.class, 
    124                                 new SaveToServerDialog())); 
    125134                res.add(getResourceLocatorExtension()); 
    126135                res.add(SimpleVisualProvider.createExtension(SaveToServerDialog.UploadResourceDialog.class, 
    127136                                ConnectionsPalette.class, "save-on-server-dialog", "aaa-save-on-servers-dialog")); 
    128137 
    129138                res.add(new SimpleSophieExtension<TransferManager<?>> ( 
    130139                                (Class) TransferManager.class, new BinaryTransferManager())); 
    131                 res.add(new SimpleSophieExtension<Dialog>(Dialog.class, new ServerLoginDialog())); 
    132                 AutoVisualProvider.fillExtensions(res, SwingLoginDialog.class); 
    133140 
    134                 SimpleOperation.fillExtensions(res, ServersTabLogic.class); 
    135                 SimpleOperation.fillExtensions(res, TransferLogic.class); 
    136                 SimpleOperation.fillExtensions(res, ServerLoginDialogLogic.class); 
    137                  
    138                  
    139                 SimpleOperation.fillExtensions(res, SaveToServerDialogLogic.class); 
    140141        } 
    141142 
    142143        private BaseSkinPart makeSkinPart() { 
     
    197198                } 
    198199 
    199200        } 
     201         
     202        /** 
     203         * Adds a handled server url by the first provider. 
     204         *  
     205         * @param serverUrl 
     206         *                      The server url. 
     207         */ 
     208        public void addHandledServerUrl(String serverUrl) { 
     209                //TODO There could be other locator providers. 
     210                ((ServerResourceLocatorProvider) getResourceLocatorExtension().getObject()).addHandledUrl(serverUrl); 
     211        } 
     212         
     213        /** 
     214         * Gets appropriate facade for this server url by a supporting it connector. 
     215         *  
     216         * @param serverUrl 
     217         *                      The server url. 
     218         * @return 
     219         *                      The appropriate facade to communicate with the server. 
     220         */ 
     221        public static FacadeR4 getFacade(String serverUrl) { 
     222                Connector connector = null; 
     223                for (SophieExtension<Connector> extension : MainFuncServersModule.get() 
     224                                .getConnectorPoint().extensions().get()) { 
     225                        Connector conn = extension.getObject(); 
     226                        if (conn.supports(serverUrl)) { 
     227                                // A suitable connector is found 
     228                                connector = conn; 
     229                                break; 
     230                        } 
     231                } 
     232 
     233                if (connector == null) { 
     234                        throw new RuntimeException( 
     235                                        "No suitable connector was found for url " + serverUrl); 
     236                } 
     237                FacadeR4 facade = connector.getFacade(serverUrl); 
     238 
     239                assert facade != null : "cannot get facade from connector"; 
     240                return facade; 
     241        } 
    200242} 
  • 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(); 
     49                                                WebAppModule.get().startServer(9016); 
    5050                                        } 
    5151                                }); 
    5252 
  • modules/org.sophie2.main.func.servers/src/main/java/org/sophie2/main/func/servers/resources/ServerResourceLocatorProvider.java

     
    66import org.sophie2.base.model.resources.r4.LocationPrefix; 
    77import org.sophie2.base.model.resources.r4.ResourceRefR4; 
    88import org.sophie2.base.model.resources.r4.access.AccessOptions; 
    9 import org.sophie2.base.model.resources.r4.access.ResourceAccess; 
    109import org.sophie2.base.model.resources.r4.access.ResourceLocator; 
     10import org.sophie2.base.model.resources.r4.access.cacheKey.ServerAccessCacheKey; 
    1111import org.sophie2.base.model.resources.r4.access.server.ResourceLocatorProvider; 
    1212import org.sophie2.main.func.servers.ConnectionStatus; 
    1313import org.sophie2.main.func.servers.ServerConnection; 
     
    2020 */ 
    2121public class ServerResourceLocatorProvider implements ResourceLocatorProvider { 
    2222 
    23         private Map<ServerConnection, ServerResourceLocator> connections = new LinkedHashMap<ServerConnection, ServerResourceLocator>(); 
     23        private Map<String, ServerResourceLocator> serverLocators =  
     24                new LinkedHashMap<String, ServerResourceLocator>(); 
    2425 
    2526        /** 
    26          * Adds a new connection with corresponding list of {@link ResourceAccess}es 
    27          * related to it. 
     27         * Adds a handled url for this resource locator provider. 
    2828         *  
    2929         * @param connection 
    30          *            The {@link ServerConnection} to be added. 
     30         *            The {@link ServerConnection} whose url should be added. 
    3131         */ 
    3232        public void addConnection(ServerConnection connection) { 
    3333                assert ConnectionStatus.CONNECTED.equals(connection.status().get()); 
    34                 assert !this.connections.containsKey(connection); 
    35                 this.connections.put(connection, null); 
     34                String url = connection.account().get().getServerUrl(); 
     35                addHandledUrl(url); 
     36        } 
     37         
     38        /** 
     39         * Adds a new handled server url.  
     40         *  
     41         * @param serverUrl  
     42         *                      The serverUrl. 
     43         */ 
     44        public void addHandledUrl(String serverUrl) { 
     45                if (!this.serverLocators.containsKey(serverUrl)) { 
     46                        this.serverLocators.put(serverUrl, null); 
     47                } 
    3648        } 
    3749 
    3850        /** 
     
    4355         */ 
    4456        public void removeConnection(ServerConnection connection) { 
    4557                assert ConnectionStatus.DISCONNECTED.equals(connection.status().get()); 
    46                 ServerResourceLocator locator = this.connections.remove(connection); 
    47                 if (locator != null) { 
    48                         locator.close(); 
    49                 } 
     58                String url = connection.account().get().getServerUrl(); 
     59                String sessionId = connection.sessionId().get(); 
     60                ServerAccessCacheKey cacheKey =  
     61                        new ServerAccessCacheKey(ResourceRefR4.make(url), sessionId); 
     62                ServerResourceLocator locator = this.serverLocators.get(url); 
     63                locator.closeTopAccess(cacheKey); 
    5064        } 
    5165 
    5266        public boolean canHandle(ResourceRefR4 target) { 
    53                 return findConnection(target) != null; 
     67                return findServerURL(target) != null; 
    5468        } 
    55  
    56         private ServerConnection findConnection(ResourceRefR4 target) { 
     69         
     70        private String findServerURL(ResourceRefR4 target) { 
    5771                assert target.getLocation().startsWith(LocationPrefix.SERVER); 
    5872                String targetUrl = target.getLocation(); 
    59                 for (ServerConnection connection : this.connections.keySet()) { 
    60                         if (ConnectionStatus.CONNECTED.equals(connection.status().get())) { 
    61                                 String serverUrl = connection.account().get().getServerUrl(); 
    62                                 if (targetUrl.startsWith(serverUrl)) { 
    63                                         return connection; 
    64                                 } 
     73                for (String serverUrl : this.serverLocators.keySet()) { 
     74                        if (targetUrl.startsWith(serverUrl)) { 
     75                                return serverUrl; 
    6576                        } 
    6677                } 
    6778                return null; 
    68  
    6979        } 
    7080 
    7181        public ResourceLocator getLocator(ResourceRefR4 target, 
    7282                        AccessOptions accessOptions, ResourceLocator parent) { 
    73                 ServerConnection connection = findConnection(target); 
    74                 if (connection == null) { 
    75                         throw new RuntimeException("Cannot find connection for " + target); 
     83                String serverUrl = findServerURL(target); 
     84                if (serverUrl == null) { 
     85                        throw new RuntimeException("Cannot handle this target - " + target); 
    7686                } 
    77                 assert this.connections.containsKey(connection); 
    78                 if (this.connections.get(connection) == null) { 
     87                if (this.serverLocators.get(serverUrl) == null) { 
    7988                        ServerResourceLocator locator = new ServerResourceLocator( 
    80                                         connection, accessOptions, parent); 
    81                         this.connections.put(connection, locator); 
     89                                        serverUrl, accessOptions, parent); 
     90                        this.serverLocators.put(serverUrl, locator); 
    8291                } 
    83                 return this.connections.get(connection); 
     92                 
     93                return this.serverLocators.get(serverUrl); 
    8494        } 
    8595 
    8696} 
  • modules/org.sophie2.base.model.resources.r4/src/main/java/org/sophie2/base/model/resources/r4/access/BaseLocator.java

     
    9595        } 
    9696         
    9797        /** 
     98         * Closes a top access of this locator. 
     99         *  
     100         * @param key 
     101         *                      The {@link CacheKey} to find the access to close.  
     102         */ 
     103        public void closeTopAccess(CacheKey key) { 
     104                MasterTopAccess toClose = this.topAccessesCache.get(key); 
     105                if (toClose != null) { 
     106                        toClose.close(); 
     107                } 
     108        } 
     109         
     110        /** 
    98111         * Gets the top part of the ref. For example for ref with location  
    99112         * "file://D:/MIRA/persisted_book.sjrb/Page_A" the top ref cloud be 
    100113         *  "file://D:/MIRA/persisted_book.sjrb" and for "mem://Book_A/ScrptA" 
     
    141154         *         The prefix of the {@link ResourceRefR4} that this root access can open. 
    142155         */ 
    143156        protected abstract String getHandledPrefix(); 
    144  
     157         
    145158} 
  • modules/org.sophie2.server.webui/src/main/resources/jsps/resource_book.jspx

     
    2626                <form name="appletParams"> 
    2727                        <input type="hidden" name="uwidth" value="${book.pageSize.width}"/> 
    2828                        <input type="hidden" name="uheight" value="${book.pageSize.height}"/> 
     29                        <input type="hidden" name="usessionId" value="${sessionId}"/> 
    2930                </form> 
    3031                <c:choose> 
    3132                <c:when test="${param.showApplet}"> 
     
    3334 
    3435                                <script src="http://www.java.com/js/deployJava.js"><!--  --></script> 
    3536                                <script> 
     37                                                var serverUrl = "http://" + window.location.hostname + ":" + window.location.port; 
    3638                                                var userWidth = document.forms['appletParams'].uwidth.value; 
    3739                                                var userHeight = document.forms['appletParams'].uheight.value; 
     40                                                var userSessionId = document.forms['appletParams'].usessionId.value; 
    3841                                 
    3942                                                var width = parseInt(userWidth) + 300; 
    4043                                                var height = parseInt(userHeight) + 200; 
    4144                                                 
    4245                                                var href = window.location.href; 
    43                                                 var bookRefValue = window.location.href + "&amp;action=download"; 
     46                                                var qIndex = href.indexOf("?"); 
     47                                                href = href.substring(0, qIndex);  
     48                                                 
     49                                                var separator = "|"; 
     50                                                var bookRefValue = href + separator + serverUrl + separator + userSessionId; 
    4451                                                var attributes = { 
    4552                                                        code: "org.sophie2.launcher.AppletMain.class", 
    46                                                         codebase: "http://sophie2.org/sophie2-reader-applet/reader/", 
     53                                                        codebase: "http://straxil.asteasolutions.net/applet-demo/reader/", 
    4754                                                        archive: "org.sophie2.launcher-2.0.1.jar", 
    4855                                                        width: width, 
    4956                                                        height: height 
  • modules/org.sophie2.launcher/src/main/resources/reader-run/applet.bundles.config

     
    33org.sophie2.core.modularity started 
    44org.sophie2.core.mvc started 
    55org.sophie2.base.bound installed 
    6 org.sophie2.base.commons installed 
     6org.sophie2.base.connectivity started 
     7org.sophie2.base.commons started 
    78org.sophie2.base.config started 
    89org.sophie2.base.model.resources.r4 started 
    910org.sophie2.base.dialogs installed 
     
    4142org.sophie2.main.func.templates started 
    4243org.sophie2.main.func.media started 
    4344org.sophie2.main.func.image started 
     45org.sophie2.main.func.servers started 
    4446org.sophie2.main.func.resources started 
    4547org.sophie2.main.func.timelines started 
    4648org.sophie2.main.layout.mydoggy started 
    4749org.sophie2.main.scene.simple started 
    4850org.sophie2.main.skin.alternative started 
     51org.sophie2.main.ws_connector started 
    4952org.sophie2.reader started 
     53 No newline at end of file 
  • modules/org.sophie2.reader/src/main/java/org/sophie2/reader/ReaderModule.java

     
    11package org.sophie2.reader; 
    22 
    3 import java.io.File; 
    4 import java.io.FileOutputStream; 
    5 import java.io.IOException; 
    6 import java.io.InputStream; 
    7 import java.net.URI; 
    83import java.util.List; 
    94import java.util.Timer; 
    105import java.util.TimerTask; 
    116 
    127import org.sophie2.base.commons.util.ImageUtil; 
    13 import org.sophie2.base.commons.util.bindata.BinData; 
    148import org.sophie2.base.commons.util.bindata.TmpChunksDirProvider; 
     9import org.sophie2.base.connectivity.facade.FacadeR4; 
     10import org.sophie2.base.connectivity.resources.ServerAccessOptions; 
    1511import org.sophie2.base.layout.BaseLayoutModule; 
    1612import org.sophie2.base.layout.LayoutEngine; 
    1713import org.sophie2.base.layout.model.MainWindow; 
    1814import org.sophie2.base.model.resources.r4.LocationPrefix; 
    1915import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     16import org.sophie2.base.model.resources.r4.access.AccessOptions; 
    2017import org.sophie2.base.skins.BaseSkinPart; 
    2118import org.sophie2.base.skins.SkinUtil; 
    2219import org.sophie2.base.skins.providers.SimpleSkinPartsProvider; 
     
    2724import org.sophie2.core.modularity.SophieModule; 
    2825import org.sophie2.main.app.commons.app.AppMainWindow; 
    2926import org.sophie2.main.app.commons.util.AppViewUtil; 
     27import org.sophie2.main.func.servers.MainFuncServersModule; 
    3028 
    3129/** 
    3230 * Module class for Sophie Reader. 
     
    7573                assert instance == null; 
    7674                instance = this; 
    7775                 
    78                 final ResourceRefR4 bookRef = checkStartupBook(); 
    7976 
    8077                new Timer().schedule(new TimerTask() { 
    8178                        @Override 
     
    9996                                                engine.mainWindows().add(window); 
    10097                                                System.setProperty("sophie2.loaded", "true"); 
    10198                                                 
    102                                                 if (bookRef != null) { 
    103                                                         AppViewUtil.openBook(window, bookRef, null, true); 
     99                                                ResourceAccessInfo bookInfo = checkStartupBook(); 
     100                                                if (bookInfo != null) { 
     101                                                        AppViewUtil.openBook(window, bookInfo.getLocation(), bookInfo.getOptions(), true); 
    104102                                                } 
    105103                                        } 
    106104                                }); 
     
    118116         *                      startup book or <code>null</code> if the system property is not 
    119117         *                      set or is not a valid absolute URL. 
    120118         */ 
    121         private ResourceRefR4 checkStartupBook(){ 
     119        protected ResourceAccessInfo checkStartupBook(){ 
    122120                String[] startUpBookFiles = (String[]) System.getProperties().get("sophie2.loadOnStartUpFiles"); 
    123121                if (startUpBookFiles == null) { 
    124122                        return null; 
    125123                } 
    126                 //open only first book. 
    127                 ResourceRefR4 bookRef; 
    128                 if ( startUpBookFiles.length == 0 || startUpBookFiles[0] == null ) { 
     124 
     125                if (startUpBookFiles.length == 0 || startUpBookFiles[0] == null) { 
    129126                        return null; 
    130127                } 
    131                 if (startUpBookFiles[0].startsWith(LocationPrefix.FILE)) { 
    132                         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); 
     128                //open only first book. 
     129                ResourceRefR4 bookRef; 
     130                AccessOptions options = AccessOptions.DEFAULT_ACCESS_OPTIONS.modifyViewId(); 
     131                String bookLocation = startUpBookFiles[0]; 
     132                if (bookLocation.startsWith(LocationPrefix.FILE)) { 
     133                        bookRef = ResourceRefR4.make(bookLocation); 
     134                } else if (bookLocation.startsWith(LocationPrefix.SERVER)) { 
     135                        String[] parts = bookLocation.split("\\|"); 
     136                        if (parts.length < 2) { 
     137                                SophieLog.warnf("Cannot open the server ref - %s ", bookLocation); 
    138138                                return null; 
    139139                        } 
    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                         } 
     140                        bookRef = ResourceRefR4.make(parts[0]); 
     141                        String serverUrl = parts[1]; 
     142                        MainFuncServersModule.get().addHandledServerUrl(serverUrl); 
     143                         
     144                        String sessionId; 
     145                        if (parts.length > 2) { 
     146                                sessionId = parts[2]; 
     147                        } else { 
     148                                FacadeR4 facade = MainFuncServersModule.getFacade(serverUrl); 
     149                                sessionId = facade.openSession().extract(); 
     150                        }  
     151                        options = new ServerAccessOptions(options, sessionId); 
    165152                } else { 
    166                         bookRef = ResourceRefR4.make(LocationPrefix.FILE + startUpBookFiles[0]); 
     153                        bookRef = ResourceRefR4.make(LocationPrefix.FILE + bookLocation); 
    167154                } 
     155 
     156                return new ResourceAccessInfo(bookRef, options); 
     157        } 
     158         
     159        /** 
     160         * Class used to encapsulate the information needed to acquire an access 
     161         * to a resource. 
     162         *  
     163         * @author mira 
     164         */ 
     165        class ResourceAccessInfo { 
    168166                 
    169                 if (!bookRef.isAbsolute()) { 
    170                         SophieLog.warnf("Cannot open non absolute ref %s.", bookRef); 
    171                         return null; 
     167                private final ResourceRefR4 location; 
     168                private final AccessOptions options; 
     169                 
     170                /** 
     171                 * Constructor. 
     172                 *  
     173                 * @param location 
     174                 *                      The location of the resource.  
     175                 * @param options 
     176                 *                      The access options used to acquire access to the resource. 
     177                 */ 
     178                public ResourceAccessInfo(ResourceRefR4 location, AccessOptions options) { 
     179                        this.location = location; 
     180                        this.options = options; 
     181                } 
     182 
     183                /** 
     184                 * Gets the location of the resource. 
     185                 *  
     186                 * @return 
     187                 *                      ResourceRefR4 to the resource. 
     188                 */ 
     189                public ResourceRefR4 getLocation() { 
     190                        return this.location; 
    172191                } 
    173192 
    174                 return bookRef; 
     193                /** 
     194                 * Gets options to be used for opening appropriate access. 
     195                 *  
     196                 * @return 
     197                 *                      {@link AccessOptions} for the access to the resource 
     198                 */ 
     199                public AccessOptions getOptions() { 
     200                        return this.options; 
     201                } 
     202                 
    175203        } 
    176204 
    177205        @Override 
     
    197225                 
    198226                res.add(TmpChunksDirProvider.createExtension()); 
    199227        } 
     228         
    200229} 
  • modules/org.sophie2.base.commons/src/main/java/org/sophie2/base/commons/util/bindata/TmpChunksDirProvider.java

     
    5151                         
    5252                        this.chunksDir = new File(tmp, dirName); 
    5353                         
    54                         assert this.chunksDir.mkdirs() : "No permissions to write in tmp??"; 
     54                        boolean made = this.chunksDir.mkdirs(); 
     55                        assert made : "No permissions to write in tmp??"; 
    5556                        this.chunksDir.deleteOnExit(); 
    5657                } 
    5758