20
20
*/
21
21
package org .silverpeas .openoffice ;
22
22
23
- import java .io .IOException ;
24
- import java .util .logging .Level ;
25
- import java .util .logging .Logger ;
26
-
23
+ import org .silverpeas .openoffice .util .ApplicationArguments ;
27
24
import org .silverpeas .openoffice .util .FinderFactory ;
28
25
import org .silverpeas .openoffice .util .MessageDisplayer ;
29
26
import org .silverpeas .openoffice .util .MessageUtil ;
32
29
import org .silverpeas .openoffice .windows .FileWebDavAccessManager ;
33
30
import org .silverpeas .openoffice .windows .MsOfficeVersion ;
34
31
35
- import org .apache .commons .httpclient .HttpException ;
32
+ import java .io .IOException ;
33
+ import java .util .logging .Level ;
34
+ import java .util .logging .Logger ;
36
35
37
36
/**
38
37
* @author Emmanuel Hugonnet
@@ -42,89 +41,105 @@ public class OfficeLauncher {
42
41
static final Logger logger = Logger .getLogger (OfficeLauncher .class .getName ());
43
42
44
43
/**
45
- * Launch the document editor.
44
+ * Launches the document editor corresponding to the type of the document to open.
45
+ *
46
+ * @see org.silverpeas.openoffice.util.ApplicationArguments
46
47
*
47
- * @param type type of editor for the document (word editor, presentation editor, etc.)
48
- * @param url the url to the document.
49
- * @param authInfo authentication parameters
50
- * @param useDeconnectedMode : set to true if you want to activate the Disconnected mode : 1)
51
- * download file using webdav to local temp directory 2) open it 3) after close, send it back to
52
- * silverpeas, still using webdav 4) delete temp file locally
53
- * @return the result of the process.
48
+ * @param arguments the arguments required to launch the document editor.
49
+ * @return the process execution status.
54
50
* @throws IOException
55
51
* @throws InterruptedException
56
52
* @throws OfficeNotFoundException
57
53
*/
58
- public static int launch (MsOfficeType type , String url , AuthenticationInfo authInfo ,
59
- boolean useDeconnectedMode ) throws IOException , InterruptedException , OfficeNotFoundException {
60
- OfficeFinder finder = FinderFactory .getFinder (type );
54
+ public static int launch (ApplicationArguments arguments )
55
+ throws IOException , InterruptedException , OfficeNotFoundException {
56
+ OfficeFinder finder = FinderFactory .getFinder (arguments . getContentType () );
61
57
logger .log (Level .INFO , "We are on {0} OS" , OsEnum .getOS ());
62
- String webdavUrl = url ;
63
- boolean modeDisconnected = ((OsEnum .isWindows () && useDeconnectedMode ) || OsEnum . getOS ()
64
- == OsEnum .MAC_OSX ) && finder .isMicrosoftOffice ();
65
- if (!modeDisconnected ) {
58
+ String webdavUrl = arguments . getUrl () ;
59
+ boolean disconnectedMode = ((OsEnum .isWindows () && arguments . isDisconnectedMode ()) ||
60
+ OsEnum . getOS () == OsEnum .MAC_OSX ) && finder .isMicrosoftOffice ();
61
+ if (!disconnectedMode ) {
66
62
if (finder .isMicrosoftOffice () && (OsEnum .getOS () == OsEnum .WINDOWS_XP || (OsEnum
67
- .isWindows () && MsOfficeVersion .isOldOffice (type )))) {
63
+ .isWindows () && MsOfficeVersion .isOldOffice (arguments . getContentType () )))) {
68
64
webdavUrl = webdavUrl .replace ("/repository/" , "/repository2000/" );
69
65
}
70
66
}
71
- switch (type ) {
67
+ switch (arguments . getContentType () ) {
72
68
case EXCEL :
73
- return launch (type , finder .findSpreadsheet (), webdavUrl , modeDisconnected , authInfo );
69
+ return launch (arguments .getContentType (), finder .findSpreadsheet (), webdavUrl ,
70
+ disconnectedMode , arguments .getLogin (), arguments .getToken ());
74
71
case POWERPOINT :
75
- return launch (type , finder .findPresentation (), webdavUrl , modeDisconnected , authInfo );
72
+ return launch (arguments .getContentType (), finder .findPresentation (), webdavUrl ,
73
+ disconnectedMode , arguments .getLogin (), arguments .getToken ());
76
74
case WORD :
77
- return launch (type , finder .findWordEditor (), webdavUrl , modeDisconnected , authInfo );
75
+ return launch (arguments .getContentType (), finder .findWordEditor (), webdavUrl ,
76
+ disconnectedMode , arguments .getLogin (), arguments .getToken ());
78
77
case NONE :
79
78
default :
80
- return launch (type , finder .findOther (), webdavUrl , modeDisconnected , authInfo );
79
+ return launch (arguments .getContentType (), finder .findOther (), webdavUrl , disconnectedMode ,
80
+ arguments .getLogin (), arguments .getToken ());
81
81
}
82
82
}
83
83
84
84
/**
85
85
* Launch document edition
86
86
*
87
- * @param path path to editor
88
- * @param url document url
89
- * @param modeDisconnected disconnected mode.
90
- * @param auth authentication info
91
- * @return status
87
+ * @param path the path of the editor to launch.
88
+ * @param url the URL at which the document is located.
89
+ * @param disconnectedMode is the document should be accessed in disconnected mode.
90
+ * @param authToken the authentication token required to access the document.
91
+ * @return status the process execution status.
92
92
* @throws IOException
93
93
* @throws InterruptedException
94
94
*/
95
- protected static int launch (MsOfficeType type , String path , String url , boolean modeDisconnected ,
96
- AuthenticationInfo auth ) throws IOException , InterruptedException {
95
+ protected static int launch (MsOfficeType type , String path , String url , boolean disconnectedMode ,
96
+ String login , String authToken ) throws IOException , InterruptedException {
97
97
logger .log (Level .INFO , "The path: {0}" , path );
98
98
logger .log (Level .INFO , "The url: {0}" , url );
99
- if (modeDisconnected ) {
99
+ logger .log (Level .INFO , "The token: {0}" , authToken );
100
+ String authenticatedUrl = getAuthenticatedUrl (url , authToken );
101
+ if (disconnectedMode ) {
100
102
try {
101
- String webdavUrl = url ;
102
- final FileWebDavAccessManager webdavAccessManager = new FileWebDavAccessManager (auth );
103
- if ('"' == url .charAt (0 )) {
104
- webdavUrl = url .substring (1 , url .length () - 1 );
105
- }
106
- String tmpFilePath = webdavAccessManager .retrieveFile (webdavUrl );
103
+ String webDavUrl = getAuthenticatedUrl (unquoteUrl (url ), authToken );
104
+ final FileWebDavAccessManager webdavAccessManager =
105
+ new FileWebDavAccessManager (login , authToken );
106
+ String tmpFilePath = webdavAccessManager .retrieveFile (webDavUrl );
107
107
logger .log (Level .INFO , "The exact exec line: {0} {1}" , new Object []{path , tmpFilePath });
108
108
Process process = Runtime .getRuntime ().exec (path + ' ' + tmpFilePath );
109
109
process .waitFor ();
110
- webdavAccessManager .pushFile (tmpFilePath , url );
110
+ webdavAccessManager .pushFile (tmpFilePath , authenticatedUrl );
111
111
MessageDisplayer .displayMessage (MessageUtil .getMessage ("info.ok" ));
112
112
return 0 ;
113
- } catch (HttpException ex ) {
114
- logger .log (Level .SEVERE , null , ex );
115
- throw new IOException (ex );
116
113
} catch (IOException ex ) {
117
114
logger .log (Level .SEVERE , null , ex );
118
115
throw ex ;
119
116
}
120
117
} else {
121
- // Standard mode : just open it
118
+ // Standard mode: just open it
122
119
logger .log (Level .INFO , "The exact exec line: {0} {1}" , new Object []{path , url });
123
- Process process = Runtime .getRuntime ().exec (path + ' ' + url );
120
+ Process process = Runtime .getRuntime ().exec (path + ' ' + authenticatedUrl );
124
121
return process .waitFor ();
125
122
}
126
123
}
127
124
128
125
private OfficeLauncher () {
129
126
}
127
+
128
+ private static String unquoteUrl (String url ) {
129
+ String unquotedUrl = url ;
130
+ if ('"' == url .charAt (0 )) {
131
+ unquotedUrl = url .substring (1 , url .length () - 1 );
132
+ }
133
+ return unquotedUrl ;
134
+ }
135
+
136
+ private static String getAuthenticatedUrl (String url , String authToken ) {
137
+ String authUrl ;
138
+ if ('"' == url .charAt (0 )) {
139
+ authUrl = "\" " + unquoteUrl (url ) + "?_=" + authToken + "\" " ;
140
+ } else {
141
+ authUrl = url + "?_=" + authToken ;
142
+ }
143
+ return authUrl ;
144
+ }
130
145
}
0 commit comments