28 |
28 |
package org.txm.backtomedia.commands.function;
|
29 |
29 |
|
30 |
30 |
import java.io.File;
|
|
31 |
import java.io.IOException;
|
31 |
32 |
import java.io.InputStream;
|
32 |
33 |
import java.net.URL;
|
|
34 |
import java.util.Arrays;
|
33 |
35 |
import java.util.HashMap;
|
34 |
36 |
|
35 |
37 |
import org.eclipse.core.commands.AbstractHandler;
|
36 |
38 |
import org.eclipse.core.commands.ExecutionEvent;
|
37 |
39 |
import org.eclipse.core.commands.ExecutionException;
|
38 |
40 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
39 |
|
import org.eclipse.jface.dialogs.InputDialog;
|
40 |
41 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
41 |
42 |
import org.eclipse.osgi.util.NLS;
|
42 |
43 |
import org.eclipse.swt.widgets.Shell;
|
... | ... | |
50 |
51 |
import org.txm.concordance.rcp.editors.ConcordanceEditor;
|
51 |
52 |
import org.txm.core.messages.TXMCoreMessages;
|
52 |
53 |
import org.txm.core.preferences.TXMPreferences;
|
|
54 |
import org.txm.edition.rcp.editors.EditionPanel;
|
|
55 |
import org.txm.edition.rcp.editors.SynopticEditionEditor;
|
53 |
56 |
import org.txm.objects.CorpusCommandPreferences;
|
54 |
|
import org.txm.rcp.editors.ITXMResultEditor;
|
|
57 |
import org.txm.objects.Project;
|
|
58 |
import org.txm.objects.Text;
|
55 |
59 |
import org.txm.rcp.messages.TXMUIMessages;
|
56 |
60 |
import org.txm.rcp.swt.dialog.UsernamePasswordDialog;
|
57 |
61 |
import org.txm.rcp.utils.SWTEditorsUtils;
|
58 |
|
import org.txm.searchengine.core.SearchEngine;
|
59 |
62 |
import org.txm.searchengine.cqp.AbstractCqiClient;
|
60 |
63 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
61 |
64 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
|
62 |
65 |
import org.txm.searchengine.cqp.corpus.CQPCorpus;
|
63 |
66 |
import org.txm.searchengine.cqp.corpus.CorpusManager;
|
|
67 |
import org.txm.searchengine.cqp.corpus.MainCorpus;
|
64 |
68 |
import org.txm.searchengine.cqp.corpus.Property;
|
65 |
69 |
import org.txm.searchengine.cqp.corpus.QueryResult;
|
66 |
70 |
import org.txm.searchengine.cqp.corpus.StructuralUnit;
|
67 |
71 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
|
68 |
72 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
|
69 |
73 |
import org.txm.searchengine.cqp.corpus.query.Match;
|
|
74 |
import org.txm.searchengine.cqp.serverException.CqiServerError;
|
70 |
75 |
import org.txm.utils.logger.Log;
|
71 |
76 |
|
72 |
77 |
import vlcplayerrcp.MessagesMP;
|
... | ... | |
95 |
100 |
@Override
|
96 |
101 |
public Object execute(ExecutionEvent event) throws ExecutionException {
|
97 |
102 |
|
98 |
|
String corpus_parameter = event.getParameter("corpus"); //$NON-NLS-1$
|
99 |
|
String text_parameter = event.getParameter("text"); //$NON-NLS-1$
|
100 |
|
String word_parameter = event.getParameter("word"); //$NON-NLS-1$
|
101 |
|
String time_parameter = event.getParameter("time"); //$NON-NLS-1$
|
|
103 |
IWorkbenchPart page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
|
102 |
104 |
|
103 |
|
if (corpus_parameter != null && text_parameter != null && (word_parameter != null || time_parameter != null)) {
|
|
105 |
if (event.getParameter("corpus") != null && event.getParameter("text") != null && (event.getParameter("word") != null || event.getParameter("time") != null)) {
|
104 |
106 |
|
|
107 |
String corpus_parameter = event.getParameter("corpus"); //$NON-NLS-1$
|
|
108 |
String text_parameter = event.getParameter("text"); //$NON-NLS-1$
|
|
109 |
String word_parameter = event.getParameter("word"); //$NON-NLS-1$
|
|
110 |
String time_parameter = event.getParameter("time"); //$NON-NLS-1$
|
|
111 |
String sync_parameter = event.getParameter("sync"); //$NON-NLS-1$ Word, Structure, MileStone, etc.
|
|
112 |
|
105 |
113 |
try {
|
106 |
114 |
CQPCorpus cqpCorpus = CorpusManager.getCorpusManager().getCorpus(corpus_parameter);
|
107 |
115 |
if (cqpCorpus == null) {
|
... | ... | |
112 |
120 |
IWorkbenchPart editor = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
|
113 |
121 |
|
114 |
122 |
if (time_parameter != null) {
|
115 |
|
return backToMedia(cqpCorpus, text_parameter, 0, 0, time_parameter, time_parameter, editor, HandlerUtil.getActiveWorkbenchWindow(event).getShell());
|
|
123 |
return backToMedia(cqpCorpus, text_parameter, time_parameter, time_parameter, editor, HandlerUtil.getActiveWorkbenchWindow(event).getShell());
|
116 |
124 |
}
|
117 |
125 |
else {
|
118 |
|
CQLQuery query = new CQLQuery(NLS.bind("[id=\"{0}\" & _.text_id=\"{1}\"]", word_parameter, text_parameter));
|
119 |
|
QueryResult rez = cqpCorpus.query(query, "TMP", false);
|
120 |
|
if (rez.getNMatch() == 1) {
|
121 |
|
Match m = rez.getMatch(0);
|
122 |
|
|
123 |
|
return backToMedia(cqpCorpus, text_parameter, m.getStart(), m.getEnd(), null, null, (EditorPart) editor, HandlerUtil.getActiveWorkbenchWindow(event).getShell());
|
124 |
|
}
|
125 |
|
else {
|
126 |
|
Log.warning(NLS.bind("Fail to find word with id={0} in text with id={1}", word_parameter, text_parameter));
|
127 |
|
}
|
|
126 |
return backtoMediaFromWordSelection(cqpCorpus, text_parameter, new String[]{word_parameter, null}, (EditorPart) editor, HandlerUtil.getActiveWorkbenchWindow(event).getShell());
|
128 |
127 |
}
|
129 |
128 |
}
|
130 |
129 |
catch (Exception e) {
|
... | ... | |
133 |
132 |
}
|
134 |
133 |
return null;
|
135 |
134 |
}
|
136 |
|
else {
|
|
135 |
else if (page instanceof ConcordanceEditor) {
|
137 |
136 |
Object o = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
|
138 |
137 |
if (!(o instanceof IStructuredSelection)) {
|
139 |
138 |
Log.fine(MessagesMP.BackToMedia_0);
|
140 |
139 |
return null;
|
141 |
140 |
}
|
142 |
141 |
|
143 |
|
IWorkbenchPart page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
|
144 |
|
|
145 |
|
if (!(page instanceof ConcordanceEditor)) {
|
146 |
|
Log.fine(MessagesMP.BackToMedia_1);
|
147 |
|
System.out.println("Active page is not a ConcordanceEditor"); //$NON-NLS-1$
|
148 |
|
return null;
|
149 |
|
}
|
150 |
142 |
ConcordanceEditor ce = (ConcordanceEditor) page;
|
151 |
143 |
selection = (IStructuredSelection) o;
|
152 |
144 |
|
... | ... | |
160 |
152 |
String textid = line.getTextId();// line.getMatch().getValueForProperty(textP);// get text via text struc property id
|
161 |
153 |
CQPCorpus corpus = line.getConcordance().getCorpus();
|
162 |
154 |
|
163 |
|
return backToMedia(corpus, textid, m.getStart(), m.getEnd(), null, null, ce, ce.getContainer()
|
164 |
|
.getShell());
|
|
155 |
try {
|
|
156 |
return backtoMediaFromMatch(corpus, textid, m.getStart(), m.getEnd(), ce, ce.getContainer().getShell());
|
|
157 |
}
|
|
158 |
catch (Exception e) {
|
|
159 |
// TODO Auto-generated catch block
|
|
160 |
e.printStackTrace();
|
|
161 |
return null;
|
|
162 |
}
|
|
163 |
} else if (page instanceof SynopticEditionEditor) {
|
|
164 |
SynopticEditionEditor editor = (SynopticEditionEditor)page;
|
|
165 |
Text text = editor.getResult();
|
|
166 |
Project project = text.getProject();
|
|
167 |
MainCorpus cqpCorpus = (MainCorpus) project.getCorpusBuild(null, MainCorpus.class);
|
|
168 |
EditionPanel panel = editor.getEditionPanel(0);
|
|
169 |
String[] ids = panel.getWordSelection();
|
|
170 |
//System.out.println("Words: "+Arrays.toString(ids));
|
|
171 |
if (ids[1] == null) { // only one word is selected -> using sync_mode preferences
|
|
172 |
try {
|
|
173 |
return backtoMediaFromWordSelection(cqpCorpus, text.getName(), ids, (EditorPart) editor, HandlerUtil.getActiveWorkbenchWindow(event).getShell());
|
|
174 |
}
|
|
175 |
catch (Exception e) {
|
|
176 |
// TODO Auto-generated catch block
|
|
177 |
e.printStackTrace();
|
|
178 |
}
|
|
179 |
} else { // play the current word selection
|
|
180 |
try {
|
|
181 |
CQLQuery query = new CQLQuery(NLS.bind("[id=\"{0}\" & _.text_id=\"{1}\"]", ids[0]+"|"+ids[ids.length-1], text.getName()));
|
|
182 |
QueryResult rez = cqpCorpus.query(query, "TMP", false);
|
|
183 |
if (rez.getNMatch() == 2) {
|
|
184 |
Match m = rez.getMatch(0);
|
|
185 |
Match n = rez.getMatch(1);
|
|
186 |
|
|
187 |
TXMPreferences alternative = BackToMediaPreferences.getInstance();
|
|
188 |
// try reading project specific preferences
|
|
189 |
// TODO see with SJ how to implement the "command > project > preferences >
|
|
190 |
// default preferences" preference order
|
|
191 |
CorpusCommandPreferences commandPreferences = project.getCommandPreferences("backtomedia"); //$NON-NLS-1$
|
|
192 |
String pTimeName = commandPreferences.get(BackToMediaPreferences.WORD_PROPERTY, alternative);
|
|
193 |
|
|
194 |
Property timeProperty = cqpCorpus.getProperty(pTimeName);
|
|
195 |
if (timeProperty == null) {
|
|
196 |
Log.warning(NLS.bind("No word property {0} found in corpus {1}.", pTimeName, cqpCorpus));
|
|
197 |
return null;
|
|
198 |
}
|
|
199 |
String start = m.getValueForProperty(timeProperty);
|
|
200 |
String end = n.getValueForProperty(timeProperty);
|
|
201 |
return backToMedia(cqpCorpus, text.getName(), start, end, editor, HandlerUtil.getActiveWorkbenchWindow(event).getShell());
|
|
202 |
} else {
|
|
203 |
Log.warning(NLS.bind("Fail to find words with ids={0} in text with id={1}.", ids[0]+"|"+ids[ids.length-1], text.getName()));
|
|
204 |
return null;
|
|
205 |
}
|
|
206 |
}
|
|
207 |
catch (Exception e) {
|
|
208 |
// TODO Auto-generated catch block
|
|
209 |
e.printStackTrace();
|
|
210 |
}
|
|
211 |
}
|
|
212 |
}
|
|
213 |
|
|
214 |
// no suitable parameters or selection or editor
|
|
215 |
return null;
|
|
216 |
}
|
|
217 |
|
|
218 |
/**
|
|
219 |
* Uses word ids + text + corpus to build a start-end word positions array and finally uses Media preferences
|
|
220 |
*
|
|
221 |
* @param corpus
|
|
222 |
* @param textid
|
|
223 |
* @param wordids
|
|
224 |
* @param editor
|
|
225 |
* @param shell
|
|
226 |
* @return
|
|
227 |
* @throws CqiClientException
|
|
228 |
* @throws IOException
|
|
229 |
* @throws CqiServerError
|
|
230 |
*/
|
|
231 |
public static Object backtoMediaFromWordSelection(CQPCorpus corpus, String textid, String[] wordids, IWorkbenchPart editor, Shell shell) throws CqiClientException, IOException, CqiServerError {
|
|
232 |
if (wordids == null) return null;
|
|
233 |
if (wordids.length != 2) return null;
|
|
234 |
|
|
235 |
Match m = null;
|
|
236 |
Match n = null;
|
|
237 |
|
|
238 |
if (wordids[1] != null) {
|
|
239 |
CQLQuery query = new CQLQuery(NLS.bind("[id=\"{0}\" & _.text_id=\"{1}\"]", wordids[0], textid));
|
|
240 |
QueryResult rez = corpus.query(query, "TMP", false);
|
|
241 |
|
|
242 |
if (rez.getNMatch() != 1) {
|
|
243 |
Log.warning(NLS.bind("Warning: found more than or no word for id={0} in {1}", wordids[0], textid));
|
|
244 |
return null;
|
|
245 |
}
|
|
246 |
|
|
247 |
m = rez.getMatch(0);
|
|
248 |
n = rez.getMatch(0);
|
|
249 |
} else if (wordids[0] != null && wordids[1] != null) {
|
|
250 |
CQLQuery query = new CQLQuery(NLS.bind("[id=\"{0}\" & _.text_id=\"{1}\"]", wordids[0]+"|"+wordids[1], textid));
|
|
251 |
QueryResult rez = corpus.query(query, "TMP", false);
|
|
252 |
|
|
253 |
if (rez.getNMatch() != 2) {
|
|
254 |
Log.warning(NLS.bind("Warning: found more than or no word for id={0} in {1}", wordids[0]+", "+wordids[1], textid));
|
|
255 |
return null;
|
|
256 |
}
|
|
257 |
|
|
258 |
m = rez.getMatch(0);
|
|
259 |
n = rez.getMatch(1);
|
165 |
260 |
}
|
|
261 |
|
|
262 |
if (m == null || n == null) {
|
|
263 |
Log.warning(NLS.bind("Fail to find word with id={0} in text with id={1}", Arrays.toString(wordids), textid));
|
|
264 |
return null;
|
|
265 |
} else {
|
|
266 |
return backtoMediaFromMatch(corpus, textid, m.getStart(), n.getEnd(), (EditorPart) editor, shell);
|
|
267 |
}
|
166 |
268 |
}
|
167 |
269 |
|
168 |
|
public static Object backToMedia(CQPCorpus corpus, String textid, int keywordPosition, int keywordEndPosition, String sStartTime, String sEndTime,
|
169 |
|
IWorkbenchPart editor, Shell shell) {
|
|
270 |
/**
|
|
271 |
* given a start-end word position build a segment to play using Media preferences of corpus or TXM preferences
|
|
272 |
*
|
|
273 |
* @param corpus
|
|
274 |
* @param textid
|
|
275 |
* @param keywordPosition
|
|
276 |
* @param keywordEndPosition
|
|
277 |
* @param editor
|
|
278 |
* @param shell
|
|
279 |
* @return
|
|
280 |
* @throws CqiClientException
|
|
281 |
* @throws IOException
|
|
282 |
* @throws CqiServerError
|
|
283 |
*/
|
|
284 |
public static Object backtoMediaFromMatch(CQPCorpus corpus, String textid, int keywordPosition, int keywordEndPosition, IWorkbenchPart editor, Shell shell) throws CqiClientException, IOException, CqiServerError {
|
170 |
285 |
|
171 |
286 |
TXMPreferences alternative = BackToMediaPreferences.getInstance();
|
|
287 |
String sStartTime, sEndTime;
|
172 |
288 |
|
173 |
289 |
// try reading project specific preferences
|
174 |
290 |
// TODO see with SJ how to implement the "command > project > preferences >
|
175 |
291 |
// default preferences" preference order
|
176 |
292 |
CorpusCommandPreferences commandPreferences = corpus.getProject().getCommandPreferences("backtomedia"); //$NON-NLS-1$
|
|
293 |
|
177 |
294 |
String structurePropertyName = commandPreferences.get(BackToMediaPreferences.STRUCTURE, alternative);
|
178 |
295 |
String startPropertyName = commandPreferences.get(BackToMediaPreferences.STRUCTURE_START_PROPERTY, alternative);
|
179 |
296 |
String endPropertyName = commandPreferences.get(BackToMediaPreferences.STRUCTURE_END_PROPERTY, alternative);
|
180 |
297 |
String sync_mode = commandPreferences.get(BackToMediaPreferences.SYNCMODE, alternative);
|
|
298 |
String pTimeName = commandPreferences.get(BackToMediaPreferences.WORD_PROPERTY, alternative);
|
|
299 |
int leftContext = commandPreferences.getInt(BackToMediaPreferences.WORD_CONTEXT_LEFT_DISTANCE, alternative);
|
|
300 |
int rightContext = commandPreferences.getInt(BackToMediaPreferences.WORD_CONTEXT_RIGHT_DISTANCE, alternative);
|
|
301 |
|
|
302 |
if (BackToMediaPreferences.WORDMODE.equals(sync_mode)) {
|
|
303 |
|
|
304 |
if ("".equals(pTimeName)) pTimeName = "time"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
305 |
|
|
306 |
Property timeP = corpus.getProperty(pTimeName);
|
|
307 |
if (timeP == null) {
|
|
308 |
System.out.println(MessagesMP.BackToMedia_11 + pTimeName);
|
|
309 |
return false;
|
|
310 |
}
|
|
311 |
|
|
312 |
int leftPosition = Math.max(keywordPosition - leftContext, 0);
|
|
313 |
int rightPosition = Math.min(keywordPosition + rightContext, corpus.getSize());
|
|
314 |
int[] positions = { leftPosition, rightPosition };
|
|
315 |
String[] times = CQPSearchEngine.getCqiClient().cpos2Str(timeP.getQualifiedName(), positions);
|
|
316 |
sStartTime = times[0];
|
|
317 |
sEndTime = times[1];
|
|
318 |
}
|
|
319 |
else if (BackToMediaPreferences.STRUCTUREMODE.equals(sync_mode)) {
|
|
320 |
StructuralUnit structure = corpus.getStructuralUnit(structurePropertyName);
|
|
321 |
if (structure == null) {
|
|
322 |
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_12, structurePropertyName));
|
|
323 |
return null;
|
|
324 |
}
|
|
325 |
Property startProperty = structure.getProperty(startPropertyName);
|
|
326 |
if (startProperty == null) {
|
|
327 |
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_14, startPropertyName));
|
|
328 |
return null;
|
|
329 |
}
|
|
330 |
|
|
331 |
sStartTime = Match.getValueForProperty(startProperty, keywordPosition);
|
|
332 |
Log.fine(MessagesMP.BackToMedia_16 + sStartTime);
|
|
333 |
|
|
334 |
Property endProperty = structure.getProperty(endPropertyName);
|
|
335 |
if (endProperty == null) {
|
|
336 |
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_17, endPropertyName));
|
|
337 |
return null;
|
|
338 |
}
|
|
339 |
sEndTime = Match.getValueForProperty(endProperty, keywordEndPosition);
|
|
340 |
Log.fine(MessagesMP.BackToMedia_19 + sEndTime);
|
|
341 |
}
|
|
342 |
else { // MILESTONE MODE
|
|
343 |
StructuralUnit structure = corpus.getStructuralUnit(structurePropertyName);
|
|
344 |
if (structure == null) {
|
|
345 |
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_12, structurePropertyName));
|
|
346 |
return null;
|
|
347 |
}
|
|
348 |
StructuralUnitProperty startProperty = structure.getProperty(startPropertyName);
|
|
349 |
if (startProperty == null) {
|
|
350 |
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_14, startPropertyName));
|
|
351 |
return null;
|
|
352 |
}
|
|
353 |
|
|
354 |
AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient();
|
|
355 |
int[] struc = cqiClient.cpos2Struc(startProperty.getQualifiedName(),
|
|
356 |
new int[] { keywordPosition, keywordEndPosition });
|
|
357 |
int[] struc2 = new int[] { struc[0], struc[1], struc[1] + 1 };
|
|
358 |
String[] times = cqiClient.struc2Str(startProperty.getQualifiedName(), struc2);
|
|
359 |
sStartTime = times[0];
|
|
360 |
if (times[2] != null) {
|
|
361 |
sEndTime = times[2];
|
|
362 |
}
|
|
363 |
else {
|
|
364 |
sEndTime = times[1];
|
|
365 |
}
|
|
366 |
}
|
|
367 |
|
|
368 |
return backToMedia(corpus, textid, sStartTime, sEndTime, editor, shell);
|
|
369 |
}
|
|
370 |
|
|
371 |
/**
|
|
372 |
* Play the text associated media from a start-end time position
|
|
373 |
* @param corpus
|
|
374 |
* @param textid
|
|
375 |
* @param sStartTime String in "sec.msec" or "hh:mm:ss" format
|
|
376 |
* @param sEndTime String in "sec.msec" or "hh:mm:ss" format
|
|
377 |
* @param editor
|
|
378 |
* @param shell
|
|
379 |
* @return
|
|
380 |
*/
|
|
381 |
public static Object backToMedia(CQPCorpus corpus, String textid, String sStartTime, String sEndTime, IWorkbenchPart editor, Shell shell) {
|
|
382 |
|
|
383 |
TXMPreferences alternative = BackToMediaPreferences.getInstance();
|
|
384 |
|
|
385 |
// try reading project specific preferences
|
|
386 |
// TODO see with SJ how to implement the "command > project > preferences >
|
|
387 |
// default preferences" preference order
|
|
388 |
CorpusCommandPreferences commandPreferences = corpus.getProject().getCommandPreferences("backtomedia"); //$NON-NLS-1$
|
|
389 |
|
181 |
390 |
String media_directory = commandPreferences.get(BackToMediaPreferences.MEDIA_PATH_PREFIX, alternative);
|
182 |
391 |
boolean media_auth = "true".equals(commandPreferences.get(BackToMediaPreferences.MEDIA_AUTH, alternative));
|
183 |
392 |
String secured_media_login = commandPreferences.get(BackToMediaPreferences.MEDIA_AUTH_LOGIN, alternative);
|
184 |
393 |
String secured_media_password = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD);
|
185 |
394 |
String media_format = commandPreferences.get(BackToMediaPreferences.MEDIA_EXTENSION, alternative);
|
186 |
395 |
String media_index = commandPreferences.get(BackToMediaPreferences.MEDIA_INDEX_NODE, alternative);
|
187 |
|
String pTimeName = commandPreferences.get(BackToMediaPreferences.WORD_PROPERTY, alternative);
|
188 |
|
int leftContext = commandPreferences.getInt(BackToMediaPreferences.WORD_CONTEXT_LEFT_DISTANCE, alternative);
|
189 |
|
int rightContext = commandPreferences.getInt(BackToMediaPreferences.WORD_CONTEXT_RIGHT_DISTANCE, alternative);
|
190 |
396 |
|
191 |
397 |
try {
|
192 |
398 |
|
193 |
399 |
Log.fine(MessagesMP.BackToMedia_7 + textid);
|
194 |
400 |
|
195 |
|
if (sStartTime == null || sEndTime == null) { // we need to find out the time to play
|
196 |
|
|
197 |
|
if (BackToMediaPreferences.WORDMODE.equals(sync_mode)) {
|
198 |
|
|
199 |
|
if ("".equals(pTimeName)) pTimeName = "time"; //$NON-NLS-1$ //$NON-NLS-2$
|
200 |
|
|
201 |
|
Property timeP = corpus.getProperty(pTimeName);
|
202 |
|
if (timeP == null) {
|
203 |
|
System.out.println(MessagesMP.BackToMedia_11 + pTimeName);
|
204 |
|
return false;
|
205 |
|
}
|
206 |
|
|
207 |
|
int leftPosition = Math.max(keywordPosition - leftContext, 0);
|
208 |
|
int rightPosition = Math.min(keywordPosition + rightContext, corpus.getSize());
|
209 |
|
int[] positions = { leftPosition, rightPosition };
|
210 |
|
String[] times = CQPSearchEngine.getCqiClient().cpos2Str(timeP.getQualifiedName(), positions);
|
211 |
|
sStartTime = times[0];
|
212 |
|
sEndTime = times[1];
|
213 |
|
}
|
214 |
|
else if (BackToMediaPreferences.STRUCTUREMODE.equals(sync_mode)) {
|
215 |
|
StructuralUnit structure = corpus.getStructuralUnit(structurePropertyName);
|
216 |
|
if (structure == null) {
|
217 |
|
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_12, structurePropertyName));
|
218 |
|
return null;
|
219 |
|
}
|
220 |
|
Property startProperty = structure.getProperty(startPropertyName);
|
221 |
|
if (startProperty == null) {
|
222 |
|
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_14, startPropertyName));
|
223 |
|
return null;
|
224 |
|
}
|
225 |
|
|
226 |
|
sStartTime = Match.getValueForProperty(startProperty, keywordPosition);
|
227 |
|
Log.fine(MessagesMP.BackToMedia_16 + sStartTime);
|
228 |
|
|
229 |
|
Property endProperty = structure.getProperty(endPropertyName);
|
230 |
|
if (endProperty == null) {
|
231 |
|
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_17, endPropertyName));
|
232 |
|
return null;
|
233 |
|
}
|
234 |
|
sEndTime = Match.getValueForProperty(endProperty, keywordEndPosition);
|
235 |
|
Log.fine(MessagesMP.BackToMedia_19 + sEndTime);
|
236 |
|
}
|
237 |
|
else { // MILESTONE MODE
|
238 |
|
StructuralUnit structure = corpus.getStructuralUnit(structurePropertyName);
|
239 |
|
if (structure == null) {
|
240 |
|
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_12, structurePropertyName));
|
241 |
|
return null;
|
242 |
|
}
|
243 |
|
StructuralUnitProperty startProperty = structure.getProperty(startPropertyName);
|
244 |
|
if (startProperty == null) {
|
245 |
|
System.out.println(MessagesMP.bind(MessagesMP.BackToMedia_14, startPropertyName));
|
246 |
|
return null;
|
247 |
|
}
|
248 |
|
|
249 |
|
AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient();
|
250 |
|
try {
|
251 |
|
int[] struc = cqiClient.cpos2Struc(startProperty.getQualifiedName(),
|
252 |
|
new int[] { keywordPosition, keywordEndPosition });
|
253 |
|
int[] struc2 = new int[] { struc[0], struc[1], struc[1] + 1 };
|
254 |
|
String[] times = cqiClient.struc2Str(startProperty.getQualifiedName(), struc2);
|
255 |
|
sStartTime = times[0];
|
256 |
|
if (times[2] != null) {
|
257 |
|
sEndTime = times[2];
|
258 |
|
}
|
259 |
|
else {
|
260 |
|
sEndTime = times[1];
|
261 |
|
}
|
262 |
|
|
263 |
|
}
|
264 |
|
catch (Exception e) {
|
265 |
|
return null;
|
266 |
|
}
|
267 |
|
}
|
268 |
|
}
|
269 |
|
|
270 |
401 |
File binDir = corpus.getProject().getProjectDirectory();
|
271 |
402 |
String path = null;
|
272 |
403 |
if (media_index != null && media_index.length() > 0) {
|