Révision 527
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/corpora/CorporaView.java (revision 527) | ||
---|---|---|
43 | 43 |
import org.eclipse.jface.viewers.StructuredSelection; |
44 | 44 |
import org.eclipse.jface.viewers.TreeSelection; |
45 | 45 |
import org.eclipse.jface.viewers.TreeViewer; |
46 |
import org.eclipse.jface.viewers.Viewer; |
|
47 |
import org.eclipse.jface.viewers.ViewerFilter; |
|
46 | 48 |
import org.eclipse.swt.SWT; |
47 | 49 |
import org.eclipse.swt.events.KeyAdapter; |
48 | 50 |
import org.eclipse.swt.events.KeyEvent; |
... | ... | |
64 | 66 |
import org.txm.Toolbox; |
65 | 67 |
import org.txm.core.results.TXMResult; |
66 | 68 |
import org.txm.objects.Project; |
69 |
import org.txm.objects.SavedQuery; |
|
70 |
import org.txm.objects.Text; |
|
67 | 71 |
import org.txm.objects.Workspace; |
68 | 72 |
import org.txm.rcp.RCPMessages; |
69 | 73 |
import org.txm.rcp.StatusLine; |
... | ... | |
108 | 112 |
*/ |
109 | 113 |
private static HashMap<Class, Class> managedDoubleClickClasses = new HashMap<Class, Class>(); |
110 | 114 |
|
115 |
public static HashMap<Class, Class> getManagedDoubleClickClasses() { |
|
116 |
return managedDoubleClickClasses; |
|
117 |
} |
|
118 |
|
|
119 |
|
|
111 | 120 |
/** |
112 | 121 |
* Gets the single instance of CorporaView. |
113 | 122 |
* |
... | ... | |
147 | 156 |
public void _reload() { |
148 | 157 |
if (Toolbox.isInitialized()) { |
149 | 158 |
//System.out.println("__Reload corpora view"); |
150 |
treeViewer.setContentProvider(new TXMResultContentProvider()); |
|
159 |
|
|
160 |
treeViewer.setContentProvider(new TXMResultContentProvider(this)); |
|
151 | 161 |
//treeViewer.setLabelProvider(new TextometrieLabelProvider()); |
152 | 162 |
treeViewer.setLabelProvider( |
153 | 163 |
new DecoratingLabelProvider(new TXMResultLabelProvider(), |
... | ... | |
155 | 165 |
Workspace w = Toolbox.workspace; |
156 | 166 |
if (w == null) return; |
157 | 167 |
Project p = w.getProject("default"); //$NON-NLS-1$ |
158 |
if( p == null) return; |
|
159 | 168 |
treeViewer.setInput(p); |
160 | 169 |
treeViewer.refresh(); |
161 | 170 |
} |
... | ... | |
173 | 182 |
PlatformUI.getWorkbench().getHelpSystem().setHelp( |
174 | 183 |
treeViewer.getControl(), RCPMessages.CorporaView_0); |
175 | 184 |
getSite().setSelectionProvider(treeViewer); |
176 |
|
|
177 |
treeViewer.setContentProvider(new TXMResultContentProvider()); |
|
185 |
treeViewer.addFilter(new ViewerFilter() { |
|
186 |
@Override |
|
187 |
public boolean select(Viewer viewer, Object parentElement, Object element) { |
|
188 |
if (element instanceof Text) return false; |
|
189 |
if (element instanceof SavedQuery) return false; |
|
190 |
return true; |
|
191 |
} |
|
192 |
}); |
|
193 |
treeViewer.setContentProvider(new TXMResultContentProvider(this)); |
|
178 | 194 |
//treeViewer.setLabelProvider(new TextometrieLabelProvider()); |
179 | 195 |
treeViewer.setLabelProvider( |
180 | 196 |
new DecoratingLabelProvider(new TXMResultLabelProvider(), |
... | ... | |
213 | 229 |
Object selectedItem = selection.getFirstElement(); |
214 | 230 |
|
215 | 231 |
// FIXME: define here what to display |
216 |
if (selectedItem instanceof TXMResult) { |
|
217 |
StatusLine.setMessage(((TXMResult)selectedItem).getSimpleDetails()); |
|
218 |
} else { |
|
219 |
StatusLine.setMessage(selectedItem.toString()); |
|
220 |
} |
|
232 |
String mess = ((TXMResult)selectedItem).getSimpleDetails(); |
|
233 |
if (mess == null) mess = selectedItem.toString(); |
|
234 |
|
|
235 |
StatusLine.setMessage(mess); |
|
221 | 236 |
// FIXME: Debug: |
222 | 237 |
// System.err.println("CorporaView.createPartControl(...).new SelectionListener() {...}.widgetSelected(): ********************************************************************************"); |
223 | 238 |
// System.err.println("CorporaView.createPartControl(...).new SelectionListener() {...}.widgetSelected(): selected object = " + selectedItem); |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/corpora/TXMResultLabelProvider.java (revision 527) | ||
---|---|---|
95 | 95 |
*/ |
96 | 96 |
@Override |
97 | 97 |
public final String getText(Object element) { |
98 |
if (element instanceof TXMResult) |
|
99 |
return ((TXMResult)element).getSimpleName(); |
|
100 | 98 |
|
101 | 99 |
IWorkbenchAdapter adapter = getAdapter(element); |
102 |
if (adapter == null) {
|
|
103 |
return ""; //$NON-NLS-1$
|
|
100 |
if (adapter != null) {
|
|
101 |
return adapter.getLabel(element);
|
|
104 | 102 |
} |
105 |
return adapter.getLabel(element); |
|
103 |
|
|
104 |
if (element instanceof TXMResult) |
|
105 |
return ((TXMResult)element).getSimpleName(); |
|
106 |
else |
|
107 |
return element.toString(); |
|
106 | 108 |
} |
107 | 109 |
|
108 | 110 |
/* (non-Javadoc) |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/corpora/TXMResultContentProvider.java (revision 527) | ||
---|---|---|
31 | 31 |
import java.util.Arrays; |
32 | 32 |
import java.util.Collections; |
33 | 33 |
import java.util.Comparator; |
34 |
import java.util.HashMap; |
|
34 | 35 |
|
35 | 36 |
import org.eclipse.core.runtime.IAdaptable; |
36 | 37 |
import org.eclipse.core.runtime.Platform; |
... | ... | |
49 | 50 |
* @author mdecorde. |
50 | 51 |
*/ |
51 | 52 |
public class TXMResultContentProvider implements ITreeContentProvider { |
52 |
|
|
53 |
|
|
54 |
private CorporaView view; |
|
55 |
|
|
56 |
public TXMResultContentProvider(CorporaView view) { |
|
57 |
this.view = view; |
|
58 |
} |
|
59 |
|
|
53 | 60 |
/** |
54 | 61 |
* Gets the adapter. |
55 | 62 |
* |
... | ... | |
60 | 67 |
IWorkbenchAdapter adapter = null; |
61 | 68 |
if (element instanceof IAdaptable) |
62 | 69 |
adapter = (IWorkbenchAdapter) ((IAdaptable) element) |
63 |
.getAdapter(IWorkbenchAdapter.class);
|
|
70 |
.getAdapter(IWorkbenchAdapter.class); |
|
64 | 71 |
if (element != null && adapter == null) |
65 | 72 |
adapter = (IWorkbenchAdapter) Platform.getAdapterManager() |
66 |
.loadAdapter(element, IWorkbenchAdapter.class.getName());
|
|
73 |
.loadAdapter(element, IWorkbenchAdapter.class.getName()); |
|
67 | 74 |
return adapter; |
68 | 75 |
} |
69 | 76 |
|
... | ... | |
72 | 79 |
*/ |
73 | 80 |
@Override |
74 | 81 |
public Object[] getChildren(Object element) { |
75 |
|
|
82 |
HashMap<Class, Class> managed = CorporaView.getManagedDoubleClickClasses(); |
|
76 | 83 |
IWorkbenchAdapter adapter = getAdapter(element); |
77 | 84 |
if (adapter != null) { |
78 | 85 |
Object[] children = adapter.getChildren(element); |
79 |
|
|
86 |
// ArrayList<Object> managedChildrenList = new ArrayList<Object>(); |
|
87 |
// for (Object child : children) { |
|
88 |
// if (managed.containsKey(child.getClass())) { |
|
89 |
// managedChildrenList.add(child); |
|
90 |
// } |
|
91 |
// } |
|
92 |
// Object[] managedChildren = managedChildrenList.toArray(); |
|
93 |
|
|
94 |
|
|
80 | 95 |
// FIXME: sort here the TXM result according to current sorting preference order, eg. getWeight(), getDate(), getName(), getClass() |
81 |
|
|
82 |
// Arrays.sort(children, new Comparator<Object>() { |
|
83 |
// @Override |
|
84 |
// public int compare(Object o1, Object o2) { |
|
85 |
// if (o1 == null) return -1; |
|
86 |
// if (o2 == null) return 1; |
|
87 |
// return o1.toString().compareTo(o2.toString()); |
|
88 |
// } |
|
89 |
// }); |
|
96 |
|
|
97 |
// Arrays.sort(children, new Comparator<Object>() {
|
|
98 |
// @Override
|
|
99 |
// public int compare(Object o1, Object o2) {
|
|
100 |
// if (o1 == null) return -1;
|
|
101 |
// if (o2 == null) return 1;
|
|
102 |
// return o1.toString().compareTo(o2.toString());
|
|
103 |
// }
|
|
104 |
// });
|
|
90 | 105 |
return children; |
91 | 106 |
} |
107 |
|
|
108 |
if (element instanceof TXMResult) { |
|
109 |
return ((TXMResult)element).getResults().toArray(); |
|
110 |
} |
|
92 | 111 |
return new Object[0]; |
93 | 112 |
} |
94 | 113 |
|
... | ... | |
100 | 119 |
if (element instanceof Project) { |
101 | 120 |
ArrayList<MainCorpus> elements = new ArrayList<MainCorpus>(); |
102 | 121 |
Project p = (Project) element; |
103 |
|
|
122 |
|
|
104 | 123 |
for (Base b : p.getBases()) { |
105 | 124 |
for (TXMResult o : b.getResults(MainCorpus.class)) { |
106 | 125 |
elements.add((MainCorpus)o); |
... | ... | |
108 | 127 |
} |
109 | 128 |
//System.out.println("get elements: "+elements); |
110 | 129 |
Collections.sort(elements, new Comparator<MainCorpus>() { |
111 |
|
|
130 |
|
|
112 | 131 |
@Override |
113 | 132 |
public int compare(MainCorpus o1, MainCorpus o2) { |
114 | 133 |
if (o1 == null) return -1; |
... | ... | |
118 | 137 |
}); |
119 | 138 |
//System.out.println("corpora view content: "+elements); |
120 | 139 |
return elements.toArray(); |
140 |
} else if (element instanceof TXMResult) { |
|
141 |
return ((TXMResult)element).getResults().toArray(); |
|
121 | 142 |
} |
122 | 143 |
return new Object[0]; |
123 | 144 |
} |
... | ... | |
130 | 151 |
IWorkbenchAdapter adapter = getAdapter(element); |
131 | 152 |
if (adapter != null) { |
132 | 153 |
return adapter.getParent(element); |
154 |
} else if (element instanceof TXMResult) { |
|
155 |
return ((TXMResult)element).getParent(); |
|
133 | 156 |
} |
134 | 157 |
return null; |
135 | 158 |
} |
... | ... | |
139 | 162 |
*/ |
140 | 163 |
@Override |
141 | 164 |
public boolean hasChildren(Object element) { |
142 |
int n = getChildren(element).length; |
|
143 |
return n > 0; |
|
165 |
if (element instanceof TXMResult) { |
|
166 |
return ((TXMResult)element).hasResults(); |
|
167 |
} else { |
|
168 |
int n = getChildren(element).length; |
|
169 |
return n > 0; |
|
170 |
} |
|
144 | 171 |
} |
145 | 172 |
|
146 | 173 |
/* (non-Javadoc) |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/RCPMessages.java (revision 527) | ||
---|---|---|
1 | 1 |
|
2 | 2 |
package org.txm.rcp; |
3 | 3 |
|
4 |
import org.eclipse.osgi.util.NLS; |
|
5 |
import org.txm.utils.messages.Utf8NLS; |
|
4 |
import org.txm.utils.messages.TXMNLS; |
|
6 | 5 |
|
7 |
public class RCPMessages extends NLS { |
|
6 |
public class RCPMessages extends TXMNLS {
|
|
8 | 7 |
|
9 | 8 |
// The Constant BUNDLE_NAME. |
10 | 9 |
private static final String BUNDLE_NAME = "org.txm.rcp.messages"; //$NON-NLS-1$ |
... | ... | |
165 | 164 |
public static String AssistedQueryWidget_0; |
166 | 165 |
public static String BackToText_0; |
167 | 166 |
public static String CANT_CREATE_GRAPHIC; |
168 |
public static String CQPPreferenceInitializer_0; |
|
169 |
public static String CQPPreferenceInitializer_1; |
|
170 |
public static String CQPPreferencePage_0; |
|
171 |
public static String CQPPreferencePage_1; |
|
172 |
public static String CQPPreferencePage_10; |
|
173 |
public static String CQPPreferencePage_11; |
|
174 |
public static String CQPPreferencePage_12; |
|
175 |
public static String CQPPreferencePage_13; |
|
176 |
public static String CQPPreferencePage_14; |
|
177 |
public static String CQPPreferencePage_15; |
|
178 |
public static String CQPPreferencePage_16; |
|
179 |
public static String CQPPreferencePage_17; |
|
180 |
public static String CQPPreferencePage_18; |
|
167 |
|
|
181 | 168 |
public static String CaEditor_0; |
182 | 169 |
|
183 | 170 |
public static String Cannot_ask_simple_when_advance; |
... | ... | |
1006 | 993 |
|
1007 | 994 |
static { |
1008 | 995 |
// initialize resource bundle |
1009 |
Utf8NLS.initializeMessages(BUNDLE_NAME, RCPMessages.class);
|
|
996 |
TXMNLS.initializeMessages(BUNDLE_NAME, RCPMessages.class);
|
|
1010 | 997 |
//NLS.initializeMessages(BUNDLE_NAME, Messages.class); |
1011 | 998 |
} |
1012 | 999 |
|
tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 527) | ||
---|---|---|
34 | 34 |
* Unique ID of the object built with : class + date + number |
35 | 35 |
*/ |
36 | 36 |
protected String uniqueID; |
37 |
protected String path; |
|
37 | 38 |
public static final DateFormat ID_TIME_FORMAT = new SimpleDateFormat("YYYYMMDD"); |
39 |
|
|
38 | 40 |
/** |
39 | 41 |
* The weight, essentially used for sorting purpose. |
40 | 42 |
*/ |
... | ... | |
48 | 50 |
public boolean isDirty() { return dirty;} |
49 | 51 |
|
50 | 52 |
/** |
51 |
* Force the result state to dirty and will be recomputed
|
|
53 |
* Mark the result has dirty so editors or others will know to recompute the TXMResult
|
|
52 | 54 |
*/ |
53 | 55 |
public void setDirty() { |
54 | 56 |
dirty = true; |
55 | 57 |
} |
56 | 58 |
|
57 | 59 |
/** |
58 |
* Parent.
|
|
60 |
* The result Parent. should not be null except for roots TXMResult
|
|
59 | 61 |
*/ |
60 | 62 |
protected TXMResult parent; |
61 | 63 |
|
... | ... | |
84 | 86 |
this(parent, null); |
85 | 87 |
} |
86 | 88 |
|
89 |
public boolean hasResults() { |
|
90 |
return children.size() > 0; |
|
91 |
} |
|
92 |
|
|
87 | 93 |
/** |
88 | 94 |
* |
89 | 95 |
* @param parent |
... | ... | |
605 | 611 |
public abstract boolean validateParameters() throws Exception; |
606 | 612 |
|
607 | 613 |
public String getSimpleDetails() { |
608 |
return this.getDetails().replace("\n", " "); |
|
614 |
String mess = this.getDetails(); |
|
615 |
if (mess != null) return mess.replace("\n", " "); |
|
616 |
|
|
617 |
return this.toString(); |
|
609 | 618 |
} |
610 | 619 |
|
611 | 620 |
/** |
tmp/org.txm.core/src/java/org/txm/objects/SavedQuery.java (revision 527) | ||
---|---|---|
98 | 98 |
} |
99 | 99 |
|
100 | 100 |
/* (non-Javadoc) |
101 |
* @see org.txm.objects.TxmObject#getChildren() |
|
102 |
*/ |
|
103 |
public List<? extends TxmObject> getChildren() { |
|
104 |
return new ArrayList<TxmObject>(); |
|
105 |
} |
|
106 |
|
|
107 |
/* (non-Javadoc) |
|
108 |
* @see org.txm.objects.TxmObject#getParent() |
|
109 |
*/ |
|
110 |
@Override |
|
111 |
public TxmObject getParent() { |
|
112 |
return corpus; |
|
113 |
} |
|
114 |
|
|
115 |
/* (non-Javadoc) |
|
116 |
* @see org.txm.objects.TxmObject#hasChildren(org.txm.objects.TxmObject) |
|
117 |
*/ |
|
118 |
public boolean hasChildren(TxmObject children) { |
|
119 |
return false; |
|
120 |
} |
|
121 |
|
|
122 |
/* (non-Javadoc) |
|
123 | 101 |
* @see org.txm.objects.TxmObject#load() |
124 | 102 |
*/ |
125 | 103 |
@Override |
... | ... | |
138 | 116 |
} |
139 | 117 |
|
140 | 118 |
/* (non-Javadoc) |
141 |
* @see org.txm.objects.TxmObject#removeChildren(org.txm.objects.TxmObject) |
|
142 |
*/ |
|
143 |
public TxmObject removeChildren(TxmObject children) { |
|
144 |
return null; |
|
145 |
} |
|
146 |
|
|
147 |
/* (non-Javadoc) |
|
148 | 119 |
* @see org.txm.objects.TxmObject#save() |
149 | 120 |
*/ |
150 | 121 |
@Override |
... | ... | |
175 | 146 |
*/ |
176 | 147 |
@Override |
177 | 148 |
public String toString() { |
178 |
return this.name ;//+ " >> " + this.examples; |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public String getSimpleName() { |
|
183 |
// TODO Auto-generated method stub |
|
184 |
return null; |
|
185 |
} |
|
186 |
|
|
187 |
@Override |
|
188 |
public String getDetails() { |
|
189 |
// TODO Auto-generated method stub |
|
190 |
return null; |
|
191 |
} |
|
192 |
|
|
193 |
@Override |
|
194 |
public void clean() { |
|
195 |
// TODO Auto-generated method stub |
|
196 |
|
|
197 |
} |
|
198 |
|
|
199 |
@Override |
|
200 |
public boolean validateParameters() { |
|
201 |
// TODO Auto-generated method stub |
|
202 |
return false; |
|
149 |
return this.name+"="+this.value;//+ " >> " + this.examples; |
|
203 | 150 |
} |
204 | 151 |
} |
tmp/org.txm.core/src/java/org/txm/objects/CorpusParameters.java (revision 527) | ||
---|---|---|
10 | 10 |
import org.w3c.dom.Element; |
11 | 11 |
import org.w3c.dom.NodeList; |
12 | 12 |
|
13 |
/** |
|
14 |
* Try of corpus parameter container, used during the parallel corpus developpement session and portal corpus configurations |
|
15 |
* |
|
16 |
* @author mdecorde |
|
17 |
* |
|
18 |
*/ |
|
13 | 19 |
public class CorpusParameters implements IParameters { |
14 | 20 |
|
15 | 21 |
/** The importmetadatas. */ |
... | ... | |
231 | 237 |
if (alignNodes.getLength() > 0) { |
232 | 238 |
Element alignNode = (Element) alignNodes.item(0); |
233 | 239 |
NodeList linkNodes = alignNode.getElementsByTagName("link"); |
234 |
for(int i = 0 ; i < linkNodes.getLength() ; i++) |
|
235 |
{ |
|
240 |
for (int i = 0 ; i < linkNodes.getLength() ; i++) { |
|
236 | 241 |
Element link = (Element)linkNodes.item(i); |
237 | 242 |
|
238 | 243 |
String target = link.getAttribute("target"); |
239 | 244 |
String[] split = target.split("#"); |
240 |
if(split.length != 3) |
|
241 |
{ |
|
245 |
if (split.length != 3) { |
|
242 | 246 |
System.out.println("Error: linkGrp/link/@target malformed: "+target); |
243 | 247 |
continue; |
244 | 248 |
} |
... | ... | |
258 | 262 |
|
259 | 263 |
//default surcorpus and partition |
260 | 264 |
NodeList corporaNodes = root.getElementsByTagName("corpora"); |
261 |
if (corporaNodes.getLength() > 0) |
|
262 |
{ |
|
265 |
if (corporaNodes.getLength() > 0) { |
|
263 | 266 |
Element corporaNode = (Element) corporaNodes.item(0); |
264 | 267 |
NodeList corpusNodes = corporaNode.getElementsByTagName("corpus"); |
265 |
for(int i = 0 ; i < corpusNodes.getLength() ; i++) |
|
266 |
{ |
|
268 |
for (int i = 0 ; i < corpusNodes.getLength() ; i++) { |
|
267 | 269 |
Element corpus = (Element)corpusNodes.item(i); |
268 | 270 |
/*String id = biblio.getAttribute("id"); |
269 | 271 |
String url = biblio.getTextContent(); |
... | ... | |
274 | 276 |
} |
275 | 277 |
return true; |
276 | 278 |
} |
277 |
|
|
278 | 279 |
} |
tmp/org.txm.core/src/java/org/txm/objects/TxmObject.java (revision 527) | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 | 31 |
import java.io.Serializable; |
32 |
import java.util.ArrayList; |
|
32 | 33 |
import java.util.HashMap; |
34 |
import java.util.List; |
|
33 | 35 |
import java.util.Map; |
34 | 36 |
|
35 | 37 |
import org.txm.core.messages.TXMCoreMessages; |
... | ... | |
49 | 51 |
|
50 | 52 |
/** The name. */ |
51 | 53 |
protected String name; |
52 |
|
|
54 |
|
|
53 | 55 |
/** The self element. */ |
54 | 56 |
private Element selfElement; |
55 |
|
|
57 |
|
|
56 | 58 |
/** The metadatas. */ |
57 | 59 |
protected Map<String, Property> metadatas; |
58 |
|
|
60 |
|
|
59 | 61 |
/** The object path from the object root to it. */ |
60 | 62 |
private String path; |
61 | 63 |
|
... | ... | |
67 | 69 |
super(parent); |
68 | 70 |
metadatas = new HashMap<String, Property>(); |
69 | 71 |
} |
70 |
|
|
72 |
|
|
71 | 73 |
/** |
72 | 74 |
* Gets the name. |
73 | 75 |
* |
... | ... | |
100 | 102 |
*/ |
101 | 103 |
public abstract boolean save(); |
102 | 104 |
|
103 |
// /** |
|
104 |
// * Delete. |
|
105 |
// * |
|
106 |
// * @return true, if successful |
|
107 |
// */ |
|
108 |
// public boolean delete() { |
|
109 |
// if (this.getTXMObjectParent() != null) { |
|
110 |
// if (this.getTXMObjectParent().removeChildren(this) != null) { |
|
111 |
// return true; |
|
112 |
// } |
|
113 |
// } else |
|
114 |
// System.out.println(Messages.TxmObject_1); |
|
115 |
// return false; |
|
116 |
// } |
|
105 |
// /**
|
|
106 |
// * Delete.
|
|
107 |
// *
|
|
108 |
// * @return true, if successful
|
|
109 |
// */
|
|
110 |
// public boolean delete() {
|
|
111 |
// if (this.getTXMObjectParent() != null) {
|
|
112 |
// if (this.getTXMObjectParent().removeChildren(this) != null) {
|
|
113 |
// return true;
|
|
114 |
// }
|
|
115 |
// } else
|
|
116 |
// System.out.println(Messages.TxmObject_1);
|
|
117 |
// return false;
|
|
118 |
// }
|
|
117 | 119 |
|
118 | 120 |
/** |
119 | 121 |
* Sets the path. |
... | ... | |
145 | 147 |
|
146 | 148 |
for (TXMResult o : getResults()) { |
147 | 149 |
TxmObject typeObject = (TxmObject) o; |
148 |
|
|
150 |
|
|
149 | 151 |
if (!typeObject.metadatas.containsKey(key)) { |
150 | 152 |
typeObject.setAttribute(key, value); |
151 | 153 |
} |
... | ... | |
161 | 163 |
public void setAttribute(String key, Serializable value) { |
162 | 164 |
try |
163 | 165 |
{ |
164 |
Document doc = getSelfElement().getOwnerDocument(); |
|
165 |
Element prop = doc.createElement("prop"); //$NON-NLS-1$ |
|
166 |
prop.setAttribute("key", key); //$NON-NLS-1$ |
|
167 |
prop.setAttribute("type", "String"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
168 |
prop.setTextContent(value.toString()); |
|
169 |
getSelfElement().appendChild(prop); |
|
170 |
getSelfElement().appendChild(prop); |
|
171 |
metadatas.put(key, new Property(key, value, "String", prop)); //$NON-NLS-1$ |
|
172 |
} |
|
173 |
catch(Exception e){ |
|
166 |
Document doc = getSelfElement().getOwnerDocument(); |
|
167 |
Element prop = doc.createElement("prop"); //$NON-NLS-1$ |
|
168 |
prop.setAttribute("key", key); //$NON-NLS-1$ |
|
169 |
prop.setAttribute("type", "String"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
170 |
prop.setTextContent(value.toString()); |
|
171 |
getSelfElement().appendChild(prop); |
|
172 |
getSelfElement().appendChild(prop); |
|
173 |
metadatas.put(key, new Property(key, value, "String", prop)); //$NON-NLS-1$ |
|
174 |
} catch(Exception e){ |
|
174 | 175 |
System.out.println(TXMCoreMessages.TxmObject_2+key+":"+value); //$NON-NLS-1$ |
175 | 176 |
org.txm.utils.logger.Log.printStackTrace(e); |
176 | 177 |
} |
... | ... | |
242 | 243 |
public void setSelfElement(Element selfElement) { |
243 | 244 |
this.selfElement = selfElement; |
244 | 245 |
} |
245 |
|
|
246 |
|
|
246 | 247 |
@Override |
247 | 248 |
public boolean setParameters(TXMParameters parameters) { |
248 | 249 |
return false; |
249 | 250 |
} |
250 |
|
|
251 |
|
|
251 | 252 |
@Override |
252 | 253 |
public String getSimpleName() { |
253 |
// TODO Auto-generated method stub |
|
254 |
return null; |
|
254 |
return name; |
|
255 | 255 |
} |
256 | 256 |
|
257 | 257 |
@Override |
258 | 258 |
public String getDetails() { |
259 |
// TODO Auto-generated method stub |
|
260 |
return null; |
|
259 |
return this.path; |
|
261 | 260 |
} |
262 | 261 |
|
263 | 262 |
@Override |
264 | 263 |
public void clean() { |
265 | 264 |
// TODO Auto-generated method stub |
266 |
|
|
265 |
|
|
267 | 266 |
} |
268 | 267 |
|
269 | 268 |
@Override |
... | ... | |
283 | 282 |
// TODO Auto-generated method stub |
284 | 283 |
return false; |
285 | 284 |
} |
285 |
|
|
286 |
/* (non-Javadoc) |
|
287 |
* @see org.txm.objects.TxmObject#removeChildren(org.txm.objects.TxmObject) |
|
288 |
*/ |
|
289 |
public TxmObject removeChildren(TxmObject o) { |
|
290 |
if (super.removeResult(o)) { |
|
291 |
getSelfElement().removeChild(o.getSelfElement()); |
|
292 |
} |
|
293 |
return o; |
|
294 |
} |
|
295 |
|
|
296 |
/* (non-Javadoc) |
|
297 |
* @see org.txm.objects.TxmObject#hasChildren(org.txm.objects.TxmObject) |
|
298 |
*/ |
|
299 |
public boolean hasChildren(TxmObject o) { |
|
300 |
return this.getResults(TxmObject.class).contains(o); |
|
301 |
} |
|
302 |
|
|
286 | 303 |
} |
tmp/org.txm.core/src/java/org/txm/objects/Script.java (revision 527) | ||
---|---|---|
116 | 116 |
*/ |
117 | 117 |
@Override |
118 | 118 |
public boolean save() { |
119 |
|
|
120 | 119 |
return false; |
121 | 120 |
} |
122 | 121 |
|
... | ... | |
137 | 136 |
public String getType() { |
138 | 137 |
return this.type; |
139 | 138 |
} |
140 |
|
|
141 |
/* (non-Javadoc) |
|
142 |
* @see org.txm.objects.TxmObject#getChildren() |
|
143 |
*/ |
|
144 |
public List<TxmObject> getChildren() { |
|
145 |
List<TxmObject> rez = new ArrayList<TxmObject>(); |
|
146 |
return rez; |
|
147 |
} |
|
148 |
|
|
149 |
/* (non-Javadoc) |
|
150 |
* @see org.txm.objects.TxmObject#removeChildren(org.txm.objects.TxmObject) |
|
151 |
*/ |
|
152 |
public TxmObject removeChildren(TxmObject o) { |
|
153 |
return null; |
|
154 |
} |
|
155 |
|
|
156 |
/* (non-Javadoc) |
|
157 |
* @see org.txm.objects.TxmObject#hasChildren(org.txm.objects.TxmObject) |
|
158 |
*/ |
|
159 |
public boolean hasChildren(TxmObject o) { |
|
160 |
return false; |
|
161 |
} |
|
162 |
|
|
163 |
/* (non-Javadoc) |
|
164 |
* @see org.txm.objects.TxmObject#getParent() |
|
165 |
*/ |
|
166 |
@Override |
|
167 |
public TxmObject getParent() { |
|
168 |
return getBase(); |
|
169 |
} |
|
170 |
|
|
171 |
@Override |
|
172 |
public String getSimpleName() { |
|
173 |
// TODO Auto-generated method stub |
|
174 |
return null; |
|
175 |
} |
|
176 |
|
|
177 |
@Override |
|
178 |
public String getDetails() { |
|
179 |
// TODO Auto-generated method stub |
|
180 |
return null; |
|
181 |
} |
|
182 |
|
|
183 |
@Override |
|
184 |
public void clean() { |
|
185 |
// TODO Auto-generated method stub |
|
186 |
|
|
187 |
} |
|
188 |
|
|
189 |
@Override |
|
190 |
public boolean validateParameters() { |
|
191 |
// TODO Auto-generated method stub |
|
192 |
return false; |
|
193 |
} |
|
194 | 139 |
} |
tmp/org.txm.core/src/java/org/txm/objects/Corpus.java (revision 527) | ||
---|---|---|
298 | 298 |
*/ |
299 | 299 |
@Override |
300 | 300 |
public boolean load() { |
301 |
|
|
301 | 302 |
this.name = getSelfElement().getAttribute(NAME); |
302 | 303 |
this.lang = getSelfElement().getAttribute(LANG); |
303 | 304 |
// System.out.println("LOAD BASE "+this.name); |
tmp/org.txm.core/src/java/org/txm/objects/Text.java (revision 527) | ||
---|---|---|
212 | 212 |
return true; |
213 | 213 |
} |
214 | 214 |
|
215 |
/* (non-Javadoc) |
|
216 |
* @see org.txm.objects.TxmObject#getChildren() |
|
217 |
*/ |
|
218 |
public List<TxmObject> getChildren() { |
|
219 |
List<TxmObject> rez = new ArrayList<TxmObject>(); |
|
220 |
rez.addAll(this.getEditions()); |
|
221 |
return rez; |
|
222 |
} |
|
223 |
|
|
224 |
/* (non-Javadoc) |
|
225 |
* @see org.txm.objects.TxmObject#removeChildren(org.txm.objects.TxmObject) |
|
226 |
*/ |
|
227 |
public TxmObject removeChildren(TxmObject o) { |
|
228 |
if (o == null) |
|
229 |
return null; |
|
230 |
if (o instanceof Edition) { |
|
231 |
getSelfElement().removeChild(o.getSelfElement()); |
|
232 |
return editions.remove(((Edition) o).getName()); |
|
233 |
} |
|
234 |
return null; |
|
235 |
} |
|
236 |
|
|
237 |
/* (non-Javadoc) |
|
238 |
* @see org.txm.objects.TxmObject#hasChildren(org.txm.objects.TxmObject) |
|
239 |
*/ |
|
240 |
public boolean hasChildren(TxmObject o) { |
|
241 |
if (o == null) |
|
242 |
return false; |
|
243 |
if (o instanceof Edition) |
|
244 |
return editions.containsKey(((Edition) o).getName()); |
|
245 |
return false; |
|
246 |
} |
|
247 |
|
|
248 |
/* (non-Javadoc) |
|
249 |
* @see org.txm.objects.TxmObject#getParent() |
|
250 |
*/ |
|
251 |
@Override |
|
252 |
public TxmObject getParent() { |
|
253 |
return getCorpus(); |
|
254 |
} |
|
255 |
|
|
256 | 215 |
/** |
257 | 216 |
* Gets the biblio. |
258 | 217 |
* |
... | ... | |
274 | 233 |
this.biblio = url; |
275 | 234 |
return true; |
276 | 235 |
} |
277 |
|
|
278 |
@Override |
|
279 |
public String getSimpleName() { |
|
280 |
// TODO Auto-generated method stub |
|
281 |
return null; |
|
282 |
} |
|
283 |
|
|
284 |
@Override |
|
285 |
public String getDetails() { |
|
286 |
// TODO Auto-generated method stub |
|
287 |
return null; |
|
288 |
} |
|
289 |
|
|
290 |
@Override |
|
291 |
public void clean() { |
|
292 |
// TODO Auto-generated method stub |
|
293 |
|
|
294 |
} |
|
295 |
|
|
296 |
@Override |
|
297 |
public boolean validateParameters() { |
|
298 |
// TODO Auto-generated method stub |
|
299 |
return false; |
|
300 |
} |
|
301 | 236 |
} |
tmp/org.txm.utils/src/org/txm/utils/messages/Utf8NLS.java (revision 527) | ||
---|---|---|
1 | 1 |
package org.txm.utils.messages; |
2 | 2 |
|
3 | 3 |
import java.lang.reflect.Field; |
4 |
import java.lang.reflect.Modifier; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.Map; |
|
4 | 7 |
|
5 | 8 |
import org.eclipse.osgi.util.NLS; |
6 | 9 |
|
... | ... | |
12 | 15 |
*/ |
13 | 16 |
public class Utf8NLS extends NLS { |
14 | 17 |
|
18 |
private static final int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC; |
|
19 |
private static final int MOD_MASK = MOD_EXPECTED | Modifier.FINAL; |
|
15 | 20 |
|
16 | 21 |
/** |
17 | 22 |
* Initializes messages using UTF-8 encoding. |
... | ... | |
22 | 27 |
// initialize resource bundle |
23 | 28 |
NLS.initializeMessages(baseName, clazz); |
24 | 29 |
|
25 |
// reencode the fields |
|
30 |
// re-encode the fields
|
|
26 | 31 |
final Field[] fieldArray = clazz.getDeclaredFields(); |
27 | 32 |
final int len = fieldArray.length; |
28 | 33 |
for(int i = 0; i < len; i++) { |
29 | 34 |
final Field field = (Field) fieldArray[i]; |
30 |
if(field.getType() == java.lang.String.class) { |
|
31 |
if(!field.isAccessible()) |
|
32 |
field.setAccessible(true); |
|
33 |
try { |
|
34 |
final String rawValue = (String) field.get(null); |
|
35 |
field.set(null, new String(rawValue.getBytes("ISO-8859-1"), "UTF-8")); |
|
36 |
} |
|
37 |
catch(Exception e) { |
|
35 |
|
|
36 |
if ((field.getModifiers() & MOD_MASK) != MOD_EXPECTED) // only init public static fields |
|
37 |
continue; |
|
38 |
|
|
39 |
if(field.getType() != java.lang.String.class) |
|
40 |
continue; |
|
41 |
|
|
42 |
if(!field.isAccessible()) |
|
43 |
field.setAccessible(true); |
|
44 |
try { |
|
45 |
final String rawValue = (String) field.get(null); |
|
46 |
field.set(null, new String(rawValue.getBytes("ISO-8859-1"), "UTF-8")); |
|
47 |
} |
|
48 |
catch(Exception e) { |
|
38 | 49 |
// e.printStackTrace(); |
39 |
} |
|
40 | 50 |
} |
51 |
|
|
41 | 52 |
} |
42 | 53 |
} |
43 | 54 |
|
44 |
|
|
45 |
|
|
55 |
|
|
56 |
|
|
46 | 57 |
} |
tmp/org.txm.utils/src/org/txm/utils/messages/TXMNLS.java (revision 527) | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* Copyright (c) 2005, 2014 IBM Corporation and others. |
|
3 |
* All rights reserved. This program and the accompanying materials |
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|
5 |
* which accompanies this distribution, and is available at |
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
|
7 |
* |
|
8 |
* Contributors: |
|
9 |
* IBM - Initial API and implementation |
|
10 |
*******************************************************************************/ |
|
11 |
package org.txm.utils.messages; |
|
12 |
|
|
13 |
import java.io.IOException; |
|
14 |
import java.io.InputStream; |
|
15 |
import java.lang.reflect.Field; |
|
16 |
import java.lang.reflect.Modifier; |
|
17 |
import java.security.AccessController; |
|
18 |
import java.security.PrivilegedAction; |
|
19 |
import java.util.*; |
|
20 |
|
|
21 |
import org.eclipse.osgi.framework.log.FrameworkLog; |
|
22 |
import org.eclipse.osgi.framework.log.FrameworkLogEntry; |
|
23 |
|
|
24 |
/** |
|
25 |
* Common superclass for all message bundle classes. Provides convenience |
|
26 |
* methods for manipulating messages. |
|
27 |
* <p> |
|
28 |
* The <code>#bind</code> methods perform string substitution and should be considered a |
|
29 |
* convenience and <em>not</em> a full substitute replacement for <code>MessageFormat#format</code> |
|
30 |
* method calls. |
|
31 |
* </p> |
|
32 |
* <p> |
|
33 |
* Text appearing within curly braces in the given message, will be interpreted |
|
34 |
* as a numeric index to the corresponding substitution object in the given array. Calling |
|
35 |
* the <code>#bind</code> methods with text that does not map to an integer will result in an |
|
36 |
* {@link IllegalArgumentException}. |
|
37 |
* </p> |
|
38 |
* <p> |
|
39 |
* Text appearing within single quotes is treated as a literal. A single quote is escaped by |
|
40 |
* a preceeding single quote. |
|
41 |
* </p> |
|
42 |
* <p> |
|
43 |
* Clients who wish to use the full substitution power of the <code>MessageFormat</code> class should |
|
44 |
* call that class directly and not use these <code>#bind</code> methods. |
|
45 |
* </p> |
|
46 |
* <p> |
|
47 |
* Clients may subclass this type. |
|
48 |
* </p> |
|
49 |
* |
|
50 |
* @since 3.1 |
|
51 |
*/ |
|
52 |
public abstract class TXMNLS { |
|
53 |
|
|
54 |
private static final Object[] EMPTY_ARGS = new Object[0]; |
|
55 |
private static final String EXTENSION = ".properties"; //$NON-NLS-1$ |
|
56 |
private static String[] nlSuffixes; |
|
57 |
private static final String PROP_WARNINGS = "osgi.nls.warnings"; //$NON-NLS-1$ |
|
58 |
private static final String IGNORE = "ignore"; //$NON-NLS-1$ |
|
59 |
private static final boolean ignoreWarnings = AccessController.doPrivileged(new PrivilegedAction<Boolean>() { |
|
60 |
public Boolean run() { |
|
61 |
return IGNORE.equals(System.getProperty(PROP_WARNINGS)); |
|
62 |
} |
|
63 |
}); |
|
64 |
|
|
65 |
/* |
|
66 |
* NOTE do not change the name of this field; it is set by the Framework using reflection |
|
67 |
*/ |
|
68 |
private static FrameworkLog frameworkLog; |
|
69 |
|
|
70 |
static final int SEVERITY_ERROR = 0x04; |
|
71 |
static final int SEVERITY_WARNING = 0x02; |
|
72 |
/* |
|
73 |
* This object is assigned to the value of a field map to indicate |
|
74 |
* that a translated message has already been assigned to that field. |
|
75 |
*/ |
|
76 |
static final Object ASSIGNED = new Object(); |
|
77 |
public static final boolean STATIC_DEBUG_MESSAGE_BUNDLES = false; |
|
78 |
|
|
79 |
/** |
|
80 |
* Creates a new NLS instance. |
|
81 |
*/ |
|
82 |
protected TXMNLS() { |
|
83 |
super(); |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* Bind the given message's substitution locations with the given string value. |
|
88 |
* |
|
89 |
* @param message the message to be manipulated |
|
90 |
* @param binding the object to be inserted into the message |
|
91 |
* @return the manipulated String |
|
92 |
* @throws IllegalArgumentException if the text appearing within curly braces in the given message does not map to an integer |
|
93 |
*/ |
|
94 |
public static String bind(String message, Object binding) { |
|
95 |
return internalBind(message, null, String.valueOf(binding), null); |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* Bind the given message's substitution locations with the given string values. |
|
100 |
* |
|
101 |
* @param message the message to be manipulated |
|
102 |
* @param binding1 An object to be inserted into the message |
|
103 |
* @param binding2 A second object to be inserted into the message |
|
104 |
* @return the manipulated String |
|
105 |
* @throws IllegalArgumentException if the text appearing within curly braces in the given message does not map to an integer |
|
106 |
*/ |
|
107 |
public static String bind(String message, Object binding1, Object binding2) { |
|
108 |
return internalBind(message, null, String.valueOf(binding1), String.valueOf(binding2)); |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Bind the given message's substitution locations with the given string values. |
|
113 |
* |
|
114 |
* @param message the message to be manipulated |
|
115 |
* @param bindings An array of objects to be inserted into the message |
|
116 |
* @return the manipulated String |
|
117 |
* @throws IllegalArgumentException if the text appearing within curly braces in the given message does not map to an integer |
|
118 |
*/ |
|
119 |
public static String bind(String message, Object[] bindings) { |
|
120 |
return internalBind(message, bindings, null, null); |
|
121 |
} |
|
122 |
|
|
123 |
|
|
124 |
/** |
|
125 |
* Shortcut method to initialize messages if the baseName is the clazz package |
|
126 |
* |
|
127 |
* @param clazz |
|
128 |
*/ |
|
129 |
public static void initializeMessages(final Class<?> clazz) { |
|
130 |
final String baseName = clazz.getPackage().getName()+".messages"; |
|
131 |
initializeMessages(baseName, clazz); |
|
132 |
} |
|
133 |
|
|
134 |
public static void initializeMessages(final String baseName, final Class<?> clazz) { |
|
135 |
|
|
136 |
if (System.getSecurityManager() == null) { |
|
137 |
load(baseName, clazz); |
|
138 |
fixEncodingToUTF8(baseName, clazz); // fix encoding to UTF-8 |
|
139 |
return; |
|
140 |
} |
|
141 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
|
142 |
public Void run() { |
|
143 |
load(baseName, clazz); |
|
144 |
fixEncodingToUTF8(baseName, clazz); |
|
145 |
return null; |
|
146 |
} |
|
147 |
}); |
|
148 |
} |
|
149 |
|
|
150 |
/** |
|
151 |
* Initialize the given class with the values from the message properties specified by the |
|
152 |
* base name. The base name specifies a fully qualified base name to a message properties file, |
|
153 |
* including the package where the message properties file is located. The class loader of the |
|
154 |
* specified class will be used to load the message properties resources. |
|
155 |
* <p> |
|
156 |
* For example, if the locale is set to en_US and <code>org.eclipse.example.nls.messages</code> |
|
157 |
* is used as the base name then the following resources will be searched using the class |
|
158 |
* loader of the specified class: |
|
159 |
* <pre> |
|
160 |
* org/eclipse/example/nls/messages_en_US.properties |
|
161 |
* org/eclipse/example/nls/messages_en.properties |
|
162 |
* org/eclipse/example/nls/messages.properties |
|
163 |
* </pre> |
|
164 |
* |
|
165 |
* TXM change: |
|
166 |
* - the ASSIGNED test has been commented, so this method should always reset the String values |
|
167 |
* - the properties String are re-encoded to UTF-8 |
|
168 |
* </p> |
|
169 |
* |
|
170 |
* @param baseName the base name of a fully qualified message properties file. |
|
171 |
* @param clazz the class where the constants will exist |
|
172 |
*/ |
|
173 |
protected static void fixEncodingToUTF8(final String baseName, final Class<?> clazz) { |
|
174 |
// re-encode the fields |
|
175 |
final Field[] fieldArray = clazz.getDeclaredFields(); |
|
176 |
final int len = fieldArray.length; |
|
177 |
for (int i = 0; i < len; i++) { |
|
178 |
final Field field = (Field) fieldArray[i]; |
|
179 |
|
|
180 |
if (field.getType() != java.lang.String.class) |
|
181 |
continue; |
|
182 |
|
|
183 |
if (!field.isAccessible()) |
|
184 |
field.setAccessible(true); |
|
185 |
try { |
|
186 |
final String rawValue = (String) field.get(null); |
|
187 |
field.set(null, new String(rawValue.getBytes("ISO-8859-1"), "UTF-8")); |
|
188 |
} |
|
189 |
catch(Exception e) { |
|
190 |
// e.printStackTrace(); |
|
191 |
} |
|
192 |
} |
|
193 |
} |
|
194 |
|
|
195 |
/* |
|
196 |
* Perform the string substitution on the given message with the specified args. |
|
197 |
* See the class comment for exact details. |
|
198 |
*/ |
|
199 |
private static String internalBind(String message, Object[] args, String argZero, String argOne) { |
|
200 |
if (message == null) |
|
201 |
return "No message available."; //$NON-NLS-1$ |
|
202 |
if (args == null || args.length == 0) |
|
203 |
args = EMPTY_ARGS; |
|
204 |
|
|
205 |
int length = message.length(); |
|
206 |
//estimate correct size of string buffer to avoid growth |
|
207 |
int bufLen = length + (args.length * 5); |
|
208 |
if (argZero != null) |
|
209 |
bufLen += argZero.length() - 3; |
|
210 |
if (argOne != null) |
|
211 |
bufLen += argOne.length() - 3; |
|
212 |
StringBuffer buffer = new StringBuffer(bufLen < 0 ? 0 : bufLen); |
|
213 |
for (int i = 0; i < length; i++) { |
|
214 |
char c = message.charAt(i); |
|
215 |
switch (c) { |
|
216 |
case '{' : |
|
217 |
int index = message.indexOf('}', i); |
|
218 |
// if we don't have a matching closing brace then... |
|
219 |
if (index == -1) { |
|
220 |
buffer.append(c); |
|
221 |
break; |
|
222 |
} |
|
223 |
i++; |
|
224 |
if (i >= length) { |
|
225 |
buffer.append(c); |
|
226 |
break; |
|
227 |
} |
|
228 |
// look for a substitution |
|
229 |
int number = -1; |
|
230 |
try { |
|
231 |
number = Integer.parseInt(message.substring(i, index)); |
|
232 |
} catch (NumberFormatException e) { |
|
233 |
throw (IllegalArgumentException) new IllegalArgumentException().initCause(e); |
|
234 |
} |
|
235 |
if (number == 0 && argZero != null) |
|
236 |
buffer.append(argZero); |
|
237 |
else if (number == 1 && argOne != null) |
|
238 |
buffer.append(argOne); |
|
239 |
else { |
|
240 |
if (number >= args.length || number < 0) { |
|
241 |
buffer.append("<missing argument>"); //$NON-NLS-1$ |
|
242 |
i = index; |
|
243 |
break; |
|
244 |
} |
|
245 |
buffer.append(args[number]); |
|
246 |
} |
|
247 |
i = index; |
|
248 |
break; |
|
249 |
case '\'' : |
|
250 |
// if a single quote is the last char on the line then skip it |
|
251 |
int nextIndex = i + 1; |
|
252 |
if (nextIndex >= length) { |
|
253 |
buffer.append(c); |
|
254 |
break; |
|
255 |
} |
|
256 |
char next = message.charAt(nextIndex); |
|
257 |
// if the next char is another single quote then write out one |
|
258 |
if (next == '\'') { |
|
259 |
i++; |
|
260 |
buffer.append(c); |
|
261 |
break; |
|
262 |
} |
|
263 |
// otherwise we want to read until we get to the next single quote |
|
264 |
index = message.indexOf('\'', nextIndex); |
|
265 |
// if there are no more in the string, then skip it |
|
266 |
if (index == -1) { |
|
267 |
buffer.append(c); |
|
268 |
break; |
|
269 |
} |
|
270 |
// otherwise write out the chars inside the quotes |
|
271 |
buffer.append(message.substring(nextIndex, index)); |
|
272 |
i = index; |
|
273 |
break; |
|
274 |
default : |
|
275 |
buffer.append(c); |
|
276 |
} |
|
277 |
} |
|
278 |
return buffer.toString(); |
|
279 |
} |
|
280 |
|
|
281 |
/* |
|
282 |
* Build an array of property files to search. The returned array contains |
|
283 |
* the property fields in order from most specific to most generic. |
|
284 |
* So, in the FR_fr locale, it will return file_fr_FR.properties, then |
|
285 |
* file_fr.properties, and finally file.properties. |
|
286 |
*/ |
|
287 |
private static String[] buildVariants(String root) { |
|
288 |
if (nlSuffixes == null) { |
|
289 |
//build list of suffixes for loading resource bundles |
|
290 |
String nl = Locale.getDefault().toString(); |
|
291 |
List<String> result = new ArrayList<String>(4); |
|
292 |
int lastSeparator; |
|
293 |
while (true) { |
|
294 |
result.add('_' + nl + EXTENSION); |
|
295 |
lastSeparator = nl.lastIndexOf('_'); |
|
296 |
if (lastSeparator == -1) |
|
297 |
break; |
|
298 |
nl = nl.substring(0, lastSeparator); |
|
299 |
} |
|
300 |
//add the empty suffix last (most general) |
|
301 |
result.add(EXTENSION); |
|
302 |
nlSuffixes = result.toArray(new String[result.size()]); |
|
303 |
} |
|
304 |
root = root.replace('.', '/'); |
|
305 |
String[] variants = new String[nlSuffixes.length]; |
|
306 |
for (int i = 0; i < variants.length; i++) |
|
307 |
variants[i] = root + nlSuffixes[i]; |
|
308 |
return variants; |
|
309 |
} |
|
310 |
|
|
311 |
private static void computeMissingMessages(String bundleName, Class<?> clazz, Map<Object, Object> fieldMap, Field[] fieldArray, boolean isAccessible) { |
|
312 |
// iterate over the fields in the class to make sure that there aren't any empty ones |
|
313 |
final int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC; |
|
314 |
final int MOD_MASK = MOD_EXPECTED | Modifier.FINAL; |
|
315 |
final int numFields = fieldArray.length; |
|
316 |
for (int i = 0; i < numFields; i++) { |
|
317 |
Field field = fieldArray[i]; |
|
318 |
if ((field.getModifiers() & MOD_MASK) != MOD_EXPECTED) |
|
319 |
continue; |
|
320 |
//if the field has a a value assigned, there is nothing to do |
|
321 |
// changed ASSIGNED to null because assigned key are now removed from the fieldMap == the fields members of the MessagesProperties objects == fieldArray of the load method |
|
322 |
if (fieldMap.get(field.getName()) == null) continue; |
|
323 |
|
|
324 |
try { |
|
325 |
// Set a value for this empty field. We should never get an exception here because |
|
326 |
// we know we have a public static non-final field. If we do get an exception, silently |
|
327 |
// log it and continue. This means that the field will (most likely) be un-initialized and |
|
328 |
// will fail later in the code and if so then we will see both the NPE and this error. |
|
329 |
String value = "NLS missing message: " + field.getName() + " in: " + bundleName; //$NON-NLS-1$ //$NON-NLS-2$ |
|
330 |
if (STATIC_DEBUG_MESSAGE_BUNDLES) |
|
331 |
System.out.println(value); |
|
332 |
log(SEVERITY_WARNING, value, null); |
|
333 |
if (!isAccessible) |
|
334 |
field.setAccessible(true); |
|
335 |
field.set(null, value); |
|
336 |
} catch (Exception e) { |
|
337 |
log(SEVERITY_ERROR, "Error setting the missing message value for: " + field.getName(), e); //$NON-NLS-1$ |
|
338 |
} |
|
339 |
} |
|
340 |
} |
|
341 |
|
|
342 |
/* |
|
343 |
* Load the given resource bundle using the specified class loader. |
|
344 |
*/ |
|
345 |
static void load(final String bundleName, Class<?> clazz) { |
|
346 |
long start = System.currentTimeMillis(); |
|
347 |
final Field[] fieldArray = clazz.getDeclaredFields(); |
|
348 |
ClassLoader loader = clazz.getClassLoader(); |
|
349 |
|
|
350 |
boolean isAccessible = (clazz.getModifiers() & Modifier.PUBLIC) != 0; |
|
351 |
|
|
352 |
//build a map of field names to Field objects |
|
353 |
final int len = fieldArray.length; |
|
354 |
Map<Object, Object> fields = new HashMap<Object, Object>(len * 2); |
|
355 |
for (int i = 0; i < len; i++) |
|
356 |
fields.put(fieldArray[i].getName(), fieldArray[i]); |
|
357 |
|
|
358 |
// search the variants from most specific to most general, since |
|
359 |
// the MessagesProperties.put method will mark assigned fields |
|
360 |
// to prevent them from being assigned twice |
|
361 |
final String[] variants = buildVariants(bundleName); |
|
362 |
for (int i = 0; i < variants.length; i++) { |
|
363 |
// loader==null if we're launched off the Java boot classpath |
|
364 |
final InputStream input = loader == null ? ClassLoader.getSystemResourceAsStream(variants[i]) : loader.getResourceAsStream(variants[i]); |
|
365 |
if (input == null) |
|
366 |
continue; |
|
367 |
try { |
|
368 |
final MessagesProperties properties = new MessagesProperties(fields, bundleName, variants[i], isAccessible); |
|
369 |
properties.load(input); |
|
370 |
} catch (IOException e) { |
|
371 |
log(SEVERITY_ERROR, "Error loading " + variants[i], e); //$NON-NLS-1$ |
|
372 |
} finally { |
|
373 |
if (input != null) |
|
374 |
try { |
|
375 |
input.close(); |
|
376 |
} catch (IOException e) { |
|
377 |
// ignore |
|
378 |
} |
|
379 |
} |
|
380 |
} |
|
381 |
computeMissingMessages(bundleName, clazz, fields, fieldArray, isAccessible); |
|
382 |
if (STATIC_DEBUG_MESSAGE_BUNDLES) |
|
383 |
System.out.println("Time to load message bundle: " + bundleName + " was " + (System.currentTimeMillis() - start) + "ms."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
384 |
} |
|
385 |
|
|
386 |
/* |
|
387 |
* The method adds a log entry based on the error message and exception. |
|
388 |
* The output is written to the System.err. |
|
389 |
* |
|
390 |
* This method is only expected to be called if there is a problem in |
|
391 |
* the NLS mechanism. As a result, translation facility is not available |
|
392 |
* here and messages coming out of this log are generally not translated. |
|
393 |
* |
|
394 |
* @param severity - severity of the message (SEVERITY_ERROR or SEVERITY_WARNING) |
|
395 |
* @param message - message to log |
|
396 |
* @param e - exception to log |
|
397 |
*/ |
|
398 |
static void log(int severity, String message, Exception e) { |
|
399 |
if (severity == SEVERITY_WARNING && ignoreWarnings) |
|
400 |
return; // ignoring warnings; bug 292980 |
|
401 |
if (frameworkLog != null) { |
|
402 |
frameworkLog.log(new FrameworkLogEntry("org.eclipse.osgi", severity, 1, message, 0, e, null)); //$NON-NLS-1$ |
|
403 |
return; |
|
404 |
} |
|
405 |
String statusMsg; |
|
406 |
switch (severity) { |
|
407 |
case SEVERITY_ERROR : |
|
408 |
statusMsg = "Error: "; //$NON-NLS-1$ |
|
409 |
break; |
|
410 |
case SEVERITY_WARNING : |
|
411 |
// intentionally fall through: |
|
412 |
default : |
|
413 |
statusMsg = "Warning: "; //$NON-NLS-1$ |
|
414 |
} |
|
415 |
if (message != null) |
|
416 |
statusMsg += message; |
|
417 |
if (e != null) |
|
418 |
statusMsg += ": " + e.getMessage(); //$NON-NLS-1$ |
|
419 |
System.err.println(statusMsg); |
|
420 |
if (e != null) |
|
421 |
e.printStackTrace(); |
|
422 |
} |
|
423 |
|
|
424 |
/* |
|
425 |
* Class which sub-classes java.util.Properties and uses the #put method |
|
426 |
* to set field values rather than storing the values in the table. |
|
427 |
*/ |
|
428 |
private static class MessagesProperties extends Properties { |
|
429 |
|
|
430 |
private static final int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC; |
|
431 |
private static final int MOD_MASK = MOD_EXPECTED | Modifier.FINAL; |
|
432 |
private static final long serialVersionUID = 1L; |
|
433 |
|
|
434 |
private final String bundleName; |
|
435 |
private final Map<Object, Object> fields; |
|
436 |
private final boolean isAccessible; |
|
437 |
private final String variant; |
|
438 |
|
|
439 |
public MessagesProperties(Map<Object, Object> fieldMap, String bundleName, String variant, boolean isAccessible) { |
|
440 |
super(); |
|
441 |
this.fields = fieldMap; |
|
442 |
this.bundleName = bundleName; |
|
443 |
this.isAccessible = isAccessible; |
|
444 |
this.variant = variant; |
|
445 |
} |
|
446 |
|
|
447 |
/* (non-Javadoc) |
|
448 |
* @see java.util.Hashtable#put(java.lang.Object, java.lang.Object) |
|
449 |
*/ |
|
450 |
public synchronized Object put(Object key, Object value) { |
|
451 |
|
|
452 |
//Object fieldObject = fields.put(key, ASSIGNED); |
|
453 |
|
|
454 |
Object fieldObject = fields.remove(key); |
|
455 |
|
|
456 |
// if already assigned, there is nothing to do |
|
457 |
if (fieldObject == ASSIGNED) { |
|
458 |
//System.out.println(variant+ " DAOL MESSAGE "+key+"="+value); |
|
459 |
return null; |
|
460 |
} |
|
461 |
//System.out.println(variant+" LOAD MESSAGE "+key+"="+value+" in "+fieldObject); |
|
462 |
if (fieldObject == null) { |
|
463 |
final String msg = "NLS unused message: " + key + " in: " + bundleName;//$NON-NLS-1$ //$NON-NLS-2$ |
|
464 |
if (STATIC_DEBUG_MESSAGE_BUNDLES) |
|
465 |
System.out.println(msg); |
|
466 |
// keys with '.' are ignored by design (bug 433424) |
|
467 |
if (key instanceof String && ((String) key).indexOf('.') < 0) { |
|
468 |
log(SEVERITY_WARNING, msg, null); |
|
469 |
} |
|
470 |
return null; |
|
471 |
} |
|
472 |
final Field field = (Field) fieldObject; |
|
473 |
//can only set value of public static non-final fields |
|
474 |
if ((field.getModifiers() & MOD_MASK) != MOD_EXPECTED) |
|
475 |
return null; |
|
476 |
try { |
|
477 |
// Check to see if we are allowed to modify the field. If we aren't (for instance |
|
478 |
// if the class is not public) then change the accessible attribute of the field |
|
479 |
// before trying to set the value. |
|
480 |
if (!isAccessible) |
|
481 |
field.setAccessible(true); |
|
482 |
// Set the value into the field. We should never get an exception here because |
|
483 |
// we know we have a public static non-final field. If we do get an exception, silently |
|
484 |
// log it and continue. This means that the field will (most likely) be un-initialized and |
|
485 |
// will fail later in the code and if so then we will see both the NPE and this error. |
|
486 |
|
|
487 |
// Extra care is taken to be sure we create a String with its own backing char[] (bug 287183) |
|
488 |
// This is to ensure we do not keep the key chars in memory. |
|
489 |
field.set(null, new String(((String) value).toCharArray())); |
|
490 |
} catch (Exception e) { |
|
491 |
log(SEVERITY_ERROR, "Exception setting field value.", e); //$NON-NLS-1$ |
|
492 |
} |
|
493 |
return null; |
|
494 |
} |
|
495 |
} |
|
496 |
} |
|
0 | 497 |
tmp/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/preferences/CQPPreferencePage.java (revision 527) | ||
---|---|---|
38 | 38 |
import org.eclipse.ui.IWorkbench; |
39 | 39 |
import org.osgi.service.prefs.Preferences; |
40 | 40 |
import org.txm.rcp.Application; |
41 |
import org.txm.rcp.RCPMessages; |
|
42 | 41 |
import org.txm.rcp.preferences.TXMPreferencePage; |
43 | 42 |
import org.txm.rcp.preferences.TXMPreferenceStore; |
44 | 43 |
import org.txm.searchengine.cqp.CQPPreferences; |
44 |
import org.txm.searchengine.cqp.rcp.*; |
|
45 |
|
|
45 | 46 |
// TODO: Auto-generated Javadoc |
46 | 47 |
/** |
47 | 48 |
* This class represents a preference page that is contributed to the |
... | ... | |
103 | 104 |
public void createFieldEditors() { |
104 | 105 |
|
105 | 106 |
cqi_use_network = new BooleanFieldEditor(CQPPreferences.CQI_NETWORK_MODE, |
106 |
RCPMessages.CQPPreferencePage_1,
|
|
107 |
Messages.CQPPreferencePage_1, |
|
107 | 108 |
BooleanFieldEditor.DEFAULT, getFieldEditorParent()); |
108 | 109 |
cqi_server_path_to_cqplib = new DirectoryFieldEditor( |
109 |
CQPPreferences.CQI_SERVER_PATH_TO_CQPLIB, RCPMessages.CQPPreferencePage_0,
|
|
110 |
CQPPreferences.CQI_SERVER_PATH_TO_CQPLIB, Messages.CQPPreferencePage_0, |
|
110 | 111 |
getFieldEditorParent()); |
111 | 112 |
cqi_server_is_remote = new BooleanFieldEditor(CQPPreferences.CQI_SERVER_IS_REMOTE, |
112 |
RCPMessages.CQPPreferencePage_10,
|
|
113 |
Messages.CQPPreferencePage_10, |
|
113 | 114 |
BooleanFieldEditor.DEFAULT, getFieldEditorParent()); |
114 | 115 |
cqi_server_host = new StringFieldEditor(CQPPreferences.CQI_SERVER_HOST, |
115 |
RCPMessages.CQPPreferencePage_11, getFieldEditorParent());
|
|
116 |
Messages.CQPPreferencePage_11, getFieldEditorParent()); |
|
116 | 117 |
|
117 | 118 |
cqi_server_port = new IntegerFieldEditor(CQPPreferences.CQI_SERVER_PORT, |
118 |
RCPMessages.CQPPreferencePage_12, getFieldEditorParent());
|
|
119 |
Messages.CQPPreferencePage_12, getFieldEditorParent()); |
|
119 | 120 |
|
120 | 121 |
cqi_server_user = new StringFieldEditor(CQPPreferences.CQI_SERVER_LOGIN, |
121 |
RCPMessages.CQPPreferencePage_13, getFieldEditorParent());
|
|
122 |
Messages.CQPPreferencePage_13, getFieldEditorParent()); |
|
122 | 123 |
|
123 | 124 |
cqi_server_password = new StringFieldEditor(CQPPreferences.CQI_SERVER_PASSWORD, |
124 |
RCPMessages.CQPPreferencePage_14, getFieldEditorParent());
|
|
125 |
Messages.CQPPreferencePage_14, getFieldEditorParent()); |
|
125 | 126 |
|
126 | 127 |
cqi_server_path_to_executable = new FileFieldEditor( |
127 |
CQPPreferences.CQI_SERVER_PATH_TO_EXECUTABLE, RCPMessages.CQPPreferencePage_15,
|
|
128 |
CQPPreferences.CQI_SERVER_PATH_TO_EXECUTABLE, Messages.CQPPreferencePage_15, |
|
128 | 129 |
getFieldEditorParent()); |
129 | 130 |
|
130 | 131 |
// cqi_server_path_to_registry = new DirectoryFieldEditor( |
131 | 132 |
// CQI_SERVER_PATH_TO_REGISTRY, Messages.CQPPreferencePage_16, |
132 | 133 |
// getFieldEditorParent()); |
133 | 134 |
cqi_server_path_to_init_file = new FileFieldEditor( |
134 |
CQPPreferences.CQI_SERVER_PATH_TO_INIT_FILE, RCPMessages.CQPPreferencePage_17,
|
|
135 |
CQPPreferences.CQI_SERVER_PATH_TO_INIT_FILE, Messages.CQPPreferencePage_17, |
|
135 | 136 |
getFieldEditorParent()); |
136 | 137 |
cqi_server_additional_options = new StringFieldEditor( |
137 |
CQPPreferences.CQI_SERVER_ADDITIONAL_OPTIONS, RCPMessages.CQPPreferencePage_18,
|
|
138 |
CQPPreferences.CQI_SERVER_ADDITIONAL_OPTIONS, Messages.CQPPreferencePage_18, |
|
138 | 139 |
getFieldEditorParent()); |
139 | 140 |
|
140 | 141 |
addField(cqi_use_network); |
tmp/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/messages.properties (revision 527) | ||
---|---|---|
1 |
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/) |
|
2 |
#Eclipse modern messages class |
|
3 |
#Mon Feb 10 11:04:14 CET 2014 |
|
4 |
|
|
5 |
OK=OK |
|
6 |
REFRESH=Refresh |
|
7 |
CGU_TITLE=Terms of service |
|
8 |
CGU_MESSAGE=<p>TXM is published under the GNU GPL 2 license <<a href="https://www.gnu.org/licenses/gpl-2.0.en.html">https://www.gnu.org/licenses/gpl-2.0.en.html</a>>. |
|
9 |
CGU_CHECKMESSAGE=I accept the licence and I undertake to cite TXM for acknowledging my use of TXM in my research work \n(see the Citation section of the <http://textometrie.ens-lyon.fr/spip.php?rubrique61> page). |
|
10 |
|
|
11 |
|
|
12 |
About_Menu_Label = About TXM... |
|
13 |
|
|
14 |
AdapterFactory_0 = ** Warning: the corpus {0} is corrupted. Some commands won''t work correctly. |
|
15 |
|
|
16 |
AddBase_1 = New corpus: {0}. |
|
17 |
AddBase_10 = TXM is ready. |
|
18 |
AddBase_16 = ** Cannot set the 'LANG' property from the 'txmcorpus' structure: |
|
19 |
AddBase_17 = ** Cannot read the file {0} |
|
20 |
AddBase_19 = Warning |
|
21 |
AddBase_2 = ** Failed to load corpus from directory: {0}.\nWe cannot find the necessary components |
|
22 |
AddBase_20 = The {0} corpus directory already exists. Do you want to replace it ? |
|
23 |
AddBase_22 = This file is not a TXM file: {0} |
|
24 |
AddBase_23 = The corpus {0} has no ''LANG'' set in ''txmcorpus'' |
|
25 |
AddBase_24 = ** Failed to load corpus {0} |
|
26 |
AddBase_25 = A binary corpus is a TXM file (extension .txm or .zip) |
|
27 |
AddBase_27 = Loading binary corpus |
|
28 |
AddBase_28 = Extracting binary corpus |
|
29 |
AddBase_29 = Extracting {0} in {1} |
|
30 |
AddBase_31 = ** Could not unzip binary corpus: |
|
31 |
AddBase_32 = Loading the corpus in the platform |
|
32 |
AddBase_33 = Restarting the platform |
|
33 |
AddBase_34 = TXM workspace is not initialized, please restart TXM. |
|
34 |
AddBase_4 = ** Failed to load binary corpus (null error). |
|
35 |
AddBase_7 = ** Failed to create binary corpus. |
|
36 |
|
|
37 |
AddProject_3 = Enter project name |
|
38 |
|
|
39 |
AdvancePreferencePage_0 = Print the stacktrace |
|
40 |
AdvancePreferencePage_1 = TXM Install directory |
Formats disponibles : Unified diff