Révision 2589
tmp/org.txm.rcp.feature/build.properties (revision 2589) | ||
---|---|---|
4 | 4 |
root.folder.redist/xsl=../org.txm.core/res/org/txm/xml/xsl/ |
5 | 5 |
root.folder.redist/schema=../org.txm.core/res/org/txm/xml/schema/ |
6 | 6 |
root.folder.redist/css=../org.txm.core/res/org/txm/css/ |
7 |
root.macosx.cocoa.x86_64=mac/ |
|
7 |
|
|
8 | 8 |
root=../org.txm.setups/shared/all |
9 |
|
|
9 | 10 |
root.linux.gtk.x86_64.permissions.755=jre/bin/java,plugins/org.txm.libs.cqp.linux/res/linux32/,plugins/org.txm.libs.cqp.linux/res/linux64/,plugins/org.txm.statsengine.r.core.linux/res/linux64/bin/R,plugins/org.txm.statsengine.r.core.linux/res/linux64/bin/exec/R |
10 | 11 |
root.linux.gtk.x86_64=linux/ |
12 |
|
|
11 | 13 |
root.macosx.cocoa.x86_64.permissions.755=jre/bin/java,plugins/org.txm.libs.cqp.macosx/res/macosx/,plugins/org.txm.statsengine.r.core.macosx/res/macosx/bin/R,plugins/org.txm.statsengine.r.core.macosx/res/macosx/bin/exec/R |
14 |
root.macosx.cocoa.x86_64=mac/ |
tmp/org.txm.rcp.feature/feature.xml (revision 2589) | ||
---|---|---|
281 | 281 |
<import plugin="org.txm.treetagger.core"/> |
282 | 282 |
<import plugin="org.eclipse.equinox.p2.discovery.compatibility" version="1.0.201" match="greaterOrEqual"/> |
283 | 283 |
<import plugin="org.eclipse.e4.ui.workbench.renderers.swt"/> |
284 |
<import plugin="org.txm.rcp" version="0.8.0" match="greaterOrEqual"/> |
|
285 | 284 |
<import feature="org.eclipse.babel.nls_eclipse_fr" version="4.7.0.v20190126095834"/> |
285 |
<import plugin="javax.annotation" version="1.2.0" match="greaterOrEqual"/> |
|
286 | 286 |
</requires> |
287 | 287 |
|
288 | 288 |
<plugin |
tmp/org.txm.core/src/java/org/txm/xml/StaxDomConstructor.java (revision 2589) | ||
---|---|---|
1 |
package org.txm.xml; |
|
2 |
|
|
3 |
import java.io.Reader; |
|
4 |
import java.io.StringReader; |
|
5 |
|
|
6 |
import javax.xml.parsers.ParserConfigurationException; |
|
7 |
import javax.xml.stream.XMLInputFactory; |
|
8 |
import javax.xml.stream.XMLStreamConstants; |
|
9 |
import javax.xml.stream.XMLStreamException; |
|
10 |
import javax.xml.stream.XMLStreamReader; |
|
11 |
|
|
12 |
import org.txm.utils.xml.DomUtils; |
|
13 |
import org.w3c.dom.CDATASection; |
|
14 |
import org.w3c.dom.Comment; |
|
15 |
import org.w3c.dom.Document; |
|
16 |
import org.w3c.dom.Element; |
|
17 |
import org.w3c.dom.EntityReference; |
|
18 |
import org.w3c.dom.ProcessingInstruction; |
|
19 |
import org.w3c.dom.Text; |
|
20 |
|
|
21 |
public class StaxDomConstructor { |
|
22 |
|
|
23 |
XMLStreamReader parser = null; |
|
24 |
|
|
25 |
public StaxDomConstructor(XMLStreamReader parser) { |
|
26 |
this.parser = parser; |
|
27 |
} |
|
28 |
|
|
29 |
/** |
|
30 |
* consumes the parser events to create a DOM. start consuming after the current Stax event |
|
31 |
* |
|
32 |
* stop consuming when the current parser element is closed |
|
33 |
* |
|
34 |
* @return |
|
35 |
* @throws ParserConfigurationException |
|
36 |
* @throws XMLStreamException |
|
37 |
* @throws IllegalAccessException |
|
38 |
*/ |
|
39 |
public Element getDom() throws ParserConfigurationException, XMLStreamException, IllegalAccessException { |
|
40 |
|
|
41 |
if (parser.getEventType() != XMLStreamConstants.START_ELEMENT) { |
|
42 |
throw new IllegalAccessException("The Dom constructor must be called from the XMLStreamConstants.START_ELEMENT event"); |
|
43 |
} |
|
44 |
|
|
45 |
Document doc = DomUtils.emptyDocument(); |
|
46 |
Element currentElement = null; |
|
47 |
|
|
48 |
int elements = 0; |
|
49 |
String localname = null; |
|
50 |
|
|
51 |
for (int event = parser.getEventType(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { |
|
52 |
switch (event) { |
|
53 |
case XMLStreamConstants.START_ELEMENT: |
|
54 |
localname = parser.getLocalName(); |
|
55 |
|
|
56 |
String ns = parser.getNamespaceURI(); |
|
57 |
Element e = null; |
|
58 |
if (ns != null) { |
|
59 |
e = doc.createElementNS(ns, localname); |
|
60 |
} |
|
61 |
else { |
|
62 |
e = doc.createElement(localname); |
|
63 |
} |
|
64 |
|
|
65 |
for (int i = 0; i < parser.getAttributeCount(); i++) { |
|
66 |
ns = parser.getAttributeNamespace(i); |
|
67 |
if (ns != null) { |
|
68 |
e.setAttributeNS(ns, parser.getAttributeLocalName(i), parser.getAttributeValue(i)); |
|
69 |
} |
|
70 |
else { |
|
71 |
e.setAttribute(parser.getAttributeLocalName(i), parser.getAttributeValue(i)); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
if (currentElement == null) { |
|
76 |
doc.appendChild(e); |
|
77 |
} |
|
78 |
else { |
|
79 |
currentElement.appendChild(e); |
|
80 |
} |
|
81 |
currentElement = e; |
|
82 |
elements++; |
|
83 |
break; |
|
84 |
case XMLStreamConstants.CHARACTERS: |
|
85 |
Text textNode = doc.createTextNode(parser.getText()); |
|
86 |
currentElement.appendChild(textNode); |
|
87 |
break; |
|
88 |
case XMLStreamConstants.END_ELEMENT: |
|
89 |
|
|
90 |
elements--; |
|
91 |
if (elements == 0) return doc.getDocumentElement(); |
|
92 |
|
|
93 |
currentElement = (Element) currentElement.getParentNode(); |
|
94 |
|
|
95 |
break; |
|
96 |
case XMLStreamConstants.PROCESSING_INSTRUCTION: |
|
97 |
ProcessingInstruction piNode = doc.createProcessingInstruction(parser.getPITarget(), parser.getPIData()); |
|
98 |
currentElement.appendChild(piNode); |
|
99 |
break; |
|
100 |
case XMLStreamConstants.CDATA: |
|
101 |
CDATASection cDataNode = doc.createCDATASection(parser.getText()); |
|
102 |
currentElement.appendChild(cDataNode); |
|
103 |
break; |
|
104 |
case XMLStreamConstants.COMMENT: |
|
105 |
Comment commentNode = doc.createComment(parser.getText()); |
|
106 |
currentElement.appendChild(commentNode); |
|
107 |
break; |
|
108 |
case XMLStreamConstants.END_DOCUMENT: |
|
109 |
return doc.getDocumentElement(); |
|
110 |
case XMLStreamConstants.ENTITY_REFERENCE: |
|
111 |
EntityReference entityNode = doc.createEntityReference(parser.getText()); |
|
112 |
currentElement.appendChild(entityNode); |
|
113 |
break; |
|
114 |
} |
|
115 |
} |
|
116 |
return null; |
|
117 |
} |
|
118 |
|
|
119 |
public static void main(String[] args) throws Exception { |
|
120 |
Reader inputData = new StringReader("<test><ceci><est><un></un></est></ceci></test>"); |
|
121 |
XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(inputData); |
|
122 |
parser.next(); |
|
123 |
System.out.println("E=" + parser.getLocalName()); |
|
124 |
parser.next(); |
|
125 |
System.out.println("E=" + parser.getLocalName()); |
|
126 |
System.out.println(new StaxDomConstructor(parser).getDom()); |
|
127 |
parser.close(); |
|
128 |
inputData.close(); |
|
129 |
} |
|
130 |
} |
|
0 | 131 |
tmp/org.txm.core/src/java/org/txm/xml/LocalNameHookActivator.java (revision 2589) | ||
---|---|---|
1 |
package org.txm.xml; |
|
2 |
|
|
3 |
/** |
|
4 |
* Simple Activator activated when the localname matches the localname constructor parameter |
|
5 |
* |
|
6 |
* @author mdecorde |
|
7 |
* |
|
8 |
*/ |
|
9 |
public class LocalNameHookActivator extends HookActivator { |
|
10 |
|
|
11 |
String localname; |
|
12 |
|
|
13 |
/** |
|
14 |
* @param localname the element localname to match |
|
15 |
*/ |
|
16 |
public LocalNameHookActivator(Hook hook, String localname) { |
|
17 |
this.localname = localname; |
|
18 |
} |
|
19 |
|
|
20 |
@Override |
|
21 |
public boolean mustActivate() { |
|
22 |
if (localname == null) return false; |
|
23 |
|
|
24 |
return localname.equals(hook.getLocalName()); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public void hookWasActivated() { |
|
29 |
// nothing to do |
|
30 |
} |
|
31 |
} |
|
0 | 32 |
tmp/org.txm.core/src/java/org/txm/xml/IdentityHook.java (revision 2589) | ||
---|---|---|
1 |
package org.txm.xml; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import javax.xml.stream.XMLStreamException; |
|
6 |
|
|
7 |
public abstract class IdentityHook extends Hook { |
|
8 |
|
|
9 |
public IdentityHook(String name, HookActivator activator, XMLProcessor parentParser) throws IOException, XMLStreamException { |
|
10 |
super(name, activator, parentParser); |
|
11 |
} |
|
12 |
|
|
13 |
@Override |
|
14 |
protected void processNamespace() throws XMLStreamException { |
|
15 |
parentParser.processNamespace(); |
|
16 |
} |
|
17 |
|
|
18 |
@Override |
|
19 |
protected void processStartElement() throws XMLStreamException, IOException { |
|
20 |
parentParser.processStartElement(); |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
protected void processCharacters() throws XMLStreamException { |
|
25 |
parentParser.processCharacters(); |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
protected void processProcessingInstruction() throws XMLStreamException { |
|
30 |
parentParser.processProcessingInstruction(); |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
protected void processDTD() throws XMLStreamException { |
|
35 |
parentParser.processDTD(); |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
protected void processCDATA() throws XMLStreamException { |
|
40 |
parentParser.processCDATA(); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void processComment() throws XMLStreamException { |
|
45 |
parentParser.processComment(); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void processEndElement() throws XMLStreamException { |
|
50 |
parentParser.processEndElement(); |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
protected void processEndDocument() throws XMLStreamException { |
|
55 |
parentParser.processEndDocument(); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
protected void processEntityReference() throws XMLStreamException { |
|
60 |
parentParser.processEntityReference(); |
|
61 |
} |
|
62 |
|
|
63 |
} |
|
0 | 64 |
tmp/org.txm.core/src/java/org/txm/xml/HookActivator.java (revision 2589) | ||
---|---|---|
1 |
package org.txm.xml; |
|
2 |
|
|
3 |
/** |
|
4 |
* This class is used by Hook to do the activation test. If no activator is provided no activation are done. |
|
5 |
* |
|
6 |
* @author mdecorde |
|
7 |
* |
|
8 |
*/ |
|
9 |
public abstract class HookActivator { |
|
10 |
|
|
11 |
/** |
|
12 |
* to access to current parsing informations |
|
13 |
*/ |
|
14 |
Hook hook; |
|
15 |
|
|
16 |
/** |
|
17 |
* |
|
18 |
* The Hook will be associated in the Hook constructor |
|
19 |
*/ |
|
20 |
public HookActivator() {} |
|
21 |
|
|
22 |
/** |
|
23 |
* |
|
24 |
* @return true if the hook must be activated |
|
25 |
*/ |
|
26 |
public abstract boolean mustActivate(); |
|
27 |
|
|
28 |
/** |
|
29 |
* Use this method if you need the activator to be updated when the hook was activated once |
|
30 |
*/ |
|
31 |
public abstract void hookWasActivated(); |
|
32 |
|
|
33 |
/** |
|
34 |
* Set afterward the hook |
|
35 |
* |
|
36 |
* @param hook this activators hook |
|
37 |
*/ |
|
38 |
public void setHook(Hook hook) { |
|
39 |
this.hook = hook; |
|
40 |
} |
|
41 |
} |
|
0 | 42 |
tmp/org.txm.core/src/java/org/txm/xml/ToDoListHookActivator.java (revision 2589) | ||
---|---|---|
1 |
package org.txm.xml; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import javax.xml.stream.XMLStreamException; |
|
7 |
|
|
8 |
/** |
|
9 |
* To use if you have N elements to process with a specific localname for each one |
|
10 |
* |
|
11 |
* @author mdecorde |
|
12 |
* |
|
13 |
*/ |
|
14 |
public class ToDoListHookActivator extends HookActivator { |
|
15 |
|
|
16 |
List<String> tasks; |
|
17 |
|
|
18 |
int current = 0; |
|
19 |
|
|
20 |
public ToDoListHookActivator(List<String> tasks) throws IOException, XMLStreamException { |
|
21 |
this.tasks = tasks; |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
public boolean mustActivate() { |
|
26 |
if (tasks.size() <= current) return false; |
|
27 |
|
|
28 |
return tasks.get(current).equals(hook.getLocalName()); |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public void hookWasActivated() { |
|
33 |
current++; |
|
34 |
} |
|
35 |
} |
|
0 | 36 |
tmp/org.txm.core/src/java/org/txm/xml/Hook.java (revision 2589) | ||
---|---|---|
1 | 1 |
package org.txm.xml; |
2 | 2 |
|
3 |
import java.io.BufferedOutputStream; |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileOutputStream; |
|
6 | 3 |
import java.io.IOException; |
7 |
import java.io.InputStream; |
|
8 |
import java.net.URL; |
|
9 |
import java.util.HashMap; |
|
10 |
import java.util.LinkedHashMap; |
|
11 | 4 |
|
12 |
import javax.xml.stream.XMLInputFactory; |
|
13 |
import javax.xml.stream.XMLOutputFactory; |
|
14 | 5 |
import javax.xml.stream.XMLStreamConstants; |
15 | 6 |
import javax.xml.stream.XMLStreamException; |
16 |
import javax.xml.stream.XMLStreamReader; |
|
17 |
import javax.xml.stream.XMLStreamWriter; |
|
18 | 7 |
|
19 |
import org.txm.importer.PersonalNamespaceContext;
|
|
8 |
import org.txm.utils.logger.Log;
|
|
20 | 9 |
|
21 |
public class Hook { |
|
10 |
public abstract class Hook {
|
|
22 | 11 |
|
23 |
protected StringBuilder currentXPath = new StringBuilder("");
|
|
12 |
protected XMLProcessor parentParser = null;
|
|
24 | 13 |
|
25 |
protected String localname;
|
|
14 |
protected HookActivator activator = null;
|
|
26 | 15 |
|
27 |
XMLProcessor parentParser = null; |
|
28 |
|
|
29 |
private String name; |
|
16 |
protected String name; |
|
30 | 17 |
|
18 |
private int elements = 0; |
|
19 |
|
|
31 | 20 |
/** |
32 | 21 |
* create a hook parser. When a hook parser is activated, the processXYZ methods are used instead of the parent processXTZ methods. |
33 | 22 |
* |
34 | 23 |
* The hook can be activated / deactivated by the parent using the mustActivated mustDeactivated methods |
35 | 24 |
* |
25 |
* register the hok to the XMLProcessor |
|
26 |
* |
|
36 | 27 |
* @param parentParser |
37 | 28 |
* @throws IOException |
38 | 29 |
* @throws XMLStreamException |
39 | 30 |
*/ |
40 |
public Hook(String name, XMLProcessor parentParser) throws IOException, XMLStreamException { |
|
31 |
public Hook(String name, HookActivator activator, XMLProcessor parentParser) throws IOException, XMLStreamException {
|
|
41 | 32 |
this.parentParser = parentParser; |
42 | 33 |
this.name = name; |
34 |
setActivator(activator); // set the activator |
|
35 |
parentParser.addHook(name, this); // register the hook to the XMLProcessor |
|
43 | 36 |
} |
44 | 37 |
|
38 |
public void setActivator(HookActivator activator) { |
|
39 |
this.activator = activator; |
|
40 |
if (activator != null) { |
|
41 |
activator.setHook(this); |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 | 45 |
/** |
46 | 46 |
* called when the parser is activated by its parent |
47 | 47 |
* |
48 | 48 |
* @return true if correctly activated |
49 | 49 |
*/ |
50 |
public boolean activate() { |
|
51 |
return false; |
|
50 |
public final boolean activate() { |
|
51 |
elements = 0; |
|
52 |
return _activate(); |
|
52 | 53 |
} |
53 | 54 |
|
55 |
public abstract boolean _activate(); |
|
56 |
|
|
54 | 57 |
/** |
55 | 58 |
* called when the parser is deactivated by its parent |
56 | 59 |
* |
57 | 60 |
* @return true if correctly activated |
58 | 61 |
*/ |
59 |
public boolean deactivate() { |
|
60 |
return false; |
|
61 |
} |
|
62 |
public abstract boolean deactivate(); |
|
62 | 63 |
|
63 | 64 |
/** |
64 | 65 |
* |
65 | 66 |
* @return true if this hook parser must be activated |
66 | 67 |
*/ |
67 |
public boolean mustActivate() { |
|
68 |
return false; |
|
68 |
public final boolean mustActivate() { |
|
69 |
if (activator == null) return false; |
|
70 |
return activator.mustActivate(); |
|
69 | 71 |
} |
70 | 72 |
|
73 |
public final boolean mustDeactivate() { |
|
74 |
return elements == 0; |
|
75 |
} |
|
76 |
|
|
71 | 77 |
/** |
72 |
* |
|
73 |
* @return true if this hook parser must be desactivated |
|
78 |
* if something needs to be done BEFORE XMLProcessor starts parsing |
|
74 | 79 |
*/ |
75 |
public boolean mustDeactivate() { |
|
76 |
return true; |
|
77 |
} |
|
78 |
|
|
79 |
protected void before() { |
|
80 |
|
|
81 |
} |
|
80 |
protected void before() {} |
|
82 | 81 |
|
83 |
protected void after() throws XMLStreamException, IOException { |
|
84 |
} |
|
82 |
/** |
|
83 |
* if something needs to be done AFTER XMLProcessor starts parsing |
|
84 |
*/ |
|
85 |
protected void after() {} |
|
85 | 86 |
|
86 |
protected void closeForError() throws XMLStreamException, IOException { |
|
87 |
|
|
88 |
} |
|
87 |
/** |
|
88 |
* if something needs to be done when an error occurs |
|
89 |
*/ |
|
90 |
protected void closeForError() {} |
|
89 | 91 |
|
90 |
public final static String SLASH = "/"; |
|
91 |
|
|
92 | 92 |
protected void processParserEvent(int event) throws XMLStreamException, IOException { |
93 | 93 |
switch (event) { |
94 | 94 |
case XMLStreamConstants.NAMESPACE: |
95 | 95 |
processNamespace(); |
96 | 96 |
break; |
97 | 97 |
case XMLStreamConstants.START_ELEMENT: |
98 |
localname = parentParser.parser.getLocalName(); |
|
99 |
currentXPath.append(SLASH); |
|
100 |
currentXPath.append(localname); |
|
101 |
buildCurrentAttributes(); // for easier access later |
|
102 |
|
|
98 |
elements++; |
|
103 | 99 |
processStartElement(); |
104 | 100 |
break; |
105 | 101 |
case XMLStreamConstants.CHARACTERS: |
106 | 102 |
processCharacters(); |
107 | 103 |
break; |
108 | 104 |
case XMLStreamConstants.END_ELEMENT: |
109 |
localname = parentParser.parser.getLocalName(); |
|
110 | 105 |
processEndElement(); |
111 |
currentXPath.setLength(currentXPath.length() - localname.length() - 1); |
|
106 |
elements--; |
|
107 |
if (elements < 0) { |
|
108 |
Log.severe("ERROR: Hook was not interupted on time AT " + getLocation()); |
|
109 |
} |
|
112 | 110 |
break; |
113 | 111 |
case XMLStreamConstants.PROCESSING_INSTRUCTION: |
114 | 112 |
processProcessingInstruction(); |
... | ... | |
130 | 128 |
break; |
131 | 129 |
} |
132 | 130 |
} |
133 |
|
|
131 |
|
|
134 | 132 |
public final String getLocation() { |
135 |
if (parentParser.parser != null) { |
|
136 |
return "Line: " +name+": "+ parentParser.parser.getLocation().getLineNumber() + " Col: " + parentParser.parser.getLocation().getColumnNumber(); |
|
137 |
} |
|
138 |
return null; |
|
133 |
return parentParser.getLocation(); |
|
139 | 134 |
} |
140 | 135 |
|
141 |
protected void processNamespace() throws XMLStreamException { |
|
142 |
} |
|
136 |
protected abstract void processNamespace() throws XMLStreamException; |
|
143 | 137 |
|
138 |
protected abstract void processStartElement() throws XMLStreamException, IOException; |
|
144 | 139 |
|
145 |
protected void processStartElement() throws XMLStreamException, IOException { |
|
146 |
|
|
147 |
} |
|
140 |
protected abstract void processCharacters() throws XMLStreamException; |
|
148 | 141 |
|
149 |
private HashMap<String, String> currentAttributes = new HashMap<>();
|
|
142 |
protected abstract void processProcessingInstruction() throws XMLStreamException;
|
|
150 | 143 |
|
151 |
public final void buildCurrentAttributes() throws XMLStreamException { |
|
152 |
currentAttributes.clear(); |
|
153 |
for (int i = 0; i < parentParser.parser.getAttributeCount(); i++) { |
|
154 |
currentAttributes.put(parentParser.parser.getAttributeLocalName(i), parentParser.parser.getAttributeValue(i)); |
|
155 |
} |
|
156 |
} |
|
144 |
protected abstract void processDTD() throws XMLStreamException; |
|
157 | 145 |
|
158 |
public final HashMap<String, String> getCurrentAttributes() throws XMLStreamException { |
|
159 |
return currentAttributes; |
|
160 |
} |
|
161 |
|
|
146 |
protected abstract void processCDATA() throws XMLStreamException; |
|
162 | 147 |
|
163 |
protected void processCharacters() throws XMLStreamException { |
|
164 |
} |
|
148 |
protected abstract void processComment() throws XMLStreamException; |
|
165 | 149 |
|
166 |
protected void processProcessingInstruction() throws XMLStreamException { |
|
167 |
} |
|
150 |
protected abstract void processEndElement() throws XMLStreamException; |
|
168 | 151 |
|
169 |
protected void processDTD() throws XMLStreamException { |
|
170 |
} |
|
152 |
protected abstract void processEndDocument() throws XMLStreamException; |
|
171 | 153 |
|
172 |
protected void processCDATA() throws XMLStreamException { |
|
173 |
} |
|
154 |
protected abstract void processEntityReference() throws XMLStreamException; |
|
174 | 155 |
|
175 |
protected void processComment() throws XMLStreamException { |
|
156 |
public String getCurrentPath() { |
|
157 |
return parentParser.getCurrentPath(); |
|
176 | 158 |
} |
177 | 159 |
|
178 |
protected void processEndElement() throws XMLStreamException { |
|
160 |
public String getLocalName() { |
|
161 |
return parentParser.localname; |
|
179 | 162 |
} |
180 |
|
|
181 |
protected void processEndDocument() throws XMLStreamException { |
|
182 |
} |
|
183 |
|
|
184 |
protected void processEntityReference() throws XMLStreamException { |
|
185 |
} |
|
186 |
|
|
187 |
public String getCurrentPath() { |
|
188 |
return currentXPath.toString(); |
|
189 |
} |
|
190 | 163 |
} |
tmp/org.txm.core/src/java/org/txm/xml/XMLProcessor.java (revision 2589) | ||
---|---|---|
8 | 8 |
import java.net.URL; |
9 | 9 |
import java.util.HashMap; |
10 | 10 |
import java.util.LinkedHashMap; |
11 |
import java.util.Stack; |
|
11 | 12 |
|
12 | 13 |
import javax.xml.stream.XMLInputFactory; |
13 | 14 |
import javax.xml.stream.XMLOutputFactory; |
... | ... | |
52 | 53 |
|
53 | 54 |
int processingXInclude = 0; |
54 | 55 |
|
55 |
Hook activeHook = null; |
|
56 |
|
|
57 | 56 |
LinkedHashMap<String, Hook> hooks = new LinkedHashMap<>(); |
58 | 57 |
|
58 |
private Hook activeHook = null; |
|
59 |
|
|
59 | 60 |
public XMLProcessor(File infile) throws IOException, XMLStreamException { |
60 | 61 |
this(infile.toURI().toURL()); |
61 | 62 |
} |
... | ... | |
241 | 242 |
try { |
242 | 243 |
for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) { |
243 | 244 |
|
244 |
if (hooks.size() == 0) { |
|
245 |
this.processParserEvent(event); |
|
246 |
continue; |
|
245 |
// preparing process |
|
246 |
if (event == XMLStreamConstants.START_ELEMENT) { |
|
247 |
localname = parser.getLocalName(); |
|
248 |
currentXPath.append(SLASH); |
|
249 |
currentXPath.append(localname); |
|
250 |
buildCurrentAttributes(); // for easier access later |
|
247 | 251 |
} |
248 |
else { |
|
249 |
|
|
250 |
if (activeHook != null) { |
|
251 |
|
|
252 |
if (activeHook.mustDeactivate()) { |
|
253 |
activeHook.deactivate(); |
|
254 |
activeHook = null; |
|
255 |
} |
|
256 |
else { |
|
257 |
activeHook.processParserEvent(event); |
|
258 |
continue; |
|
259 |
} |
|
252 |
else if (event == XMLStreamConstants.END_ELEMENT) { |
|
253 |
localname = parser.getLocalName(); |
|
254 |
} |
|
255 |
|
|
256 |
if (activeHook != null) { |
|
257 |
if (activeHook.mustDeactivate()) { |
|
258 |
activeHook.deactivate(); |
|
259 |
activeHook = null; |
|
260 | 260 |
} |
261 |
|
|
262 |
if (activeHook == null) { |
|
263 |
for (Hook hook : hooks.values()) { |
|
264 |
if (hook.mustActivate()) { |
|
265 |
if (hook.activate()) { |
|
266 |
activeHook = hook; |
|
267 |
activeHook.processParserEvent(event); |
|
268 |
continue; |
|
269 |
} |
|
261 |
else { |
|
262 |
activeHook.processParserEvent(event); |
|
263 |
} |
|
264 |
} |
|
265 |
|
|
266 |
if (activeHook == null && event == XMLStreamConstants.START_ELEMENT) { // only activate when starting an element (for now, thus we cannot process only text nodes) |
|
267 |
for (Hook hook : hooks.values()) { |
|
268 |
if (hook.mustActivate()) { |
|
269 |
if (hook.activate()) { |
|
270 |
activeHook = hook; |
|
271 |
|
|
272 |
hook.processParserEvent(event); |
|
273 |
break; |
|
270 | 274 |
} |
271 | 275 |
} |
272 | 276 |
} |
273 |
|
|
274 |
if (activeHook == null) { |
|
275 |
this.processParserEvent(event); |
|
276 |
} |
|
277 | 277 |
} |
278 |
|
|
279 |
if (activeHook == null) { |
|
280 |
this.processParserEvent(event); |
|
281 |
} |
|
282 |
|
|
283 |
// post-preparing process |
|
284 |
if (event == XMLStreamConstants.END_ELEMENT) { |
|
285 |
currentXPath.setLength(currentXPath.length() - localname.length() - 1); |
|
286 |
popCurrentAttributes(); |
|
287 |
} |
|
278 | 288 |
} |
279 | 289 |
} |
280 | 290 |
catch (Exception e) { |
... | ... | |
302 | 312 |
processNamespace(); |
303 | 313 |
break; |
304 | 314 |
case XMLStreamConstants.START_ELEMENT: |
305 |
localname = parser.getLocalName(); |
|
306 |
currentXPath.append(SLASH); |
|
307 |
currentXPath.append(localname); |
|
308 |
buildCurrentAttributes(); // for easier access later |
|
309 |
|
|
310 |
|
|
311 |
|
|
312 | 315 |
processStartElement(); |
313 | 316 |
break; |
314 | 317 |
case XMLStreamConstants.CHARACTERS: |
315 | 318 |
processCharacters(); |
316 | 319 |
break; |
317 | 320 |
case XMLStreamConstants.END_ELEMENT: |
318 |
localname = parser.getLocalName(); |
|
319 | 321 |
processEndElement(); |
320 |
currentXPath.setLength(currentXPath.length() - localname.length() - 1); |
|
321 | 322 |
break; |
322 | 323 |
case XMLStreamConstants.PROCESSING_INSTRUCTION: |
323 | 324 |
processProcessingInstruction(); |
... | ... | |
468 | 469 |
} |
469 | 470 |
} |
470 | 471 |
|
471 |
HashMap<String, String> currentAttributes = new HashMap<>();
|
|
472 |
private Stack<LinkedHashMap<String, String>> attributesStack = new Stack<>();
|
|
472 | 473 |
|
473 |
public void buildCurrentAttributes() throws XMLStreamException { |
|
474 |
currentAttributes.clear(); |
|
475 |
for (int i = 0; i < parser.getAttributeCount(); i++) { |
|
476 |
currentAttributes.put(parser.getAttributeLocalName(i), parser.getAttributeValue(i)); |
|
477 |
} |
|
474 |
private HashMap<String, String> popCurrentAttributes() { |
|
475 |
return attributesStack.pop(); |
|
478 | 476 |
} |
479 | 477 |
|
480 |
public HashMap<String, String> getCurrentAttributes() throws XMLStreamException {
|
|
481 |
currentAttributes.clear();
|
|
478 |
private void buildCurrentAttributes() throws XMLStreamException {
|
|
479 |
LinkedHashMap<String, String> currentAttributes = new LinkedHashMap<>(); // keep order
|
|
482 | 480 |
for (int i = 0; i < parser.getAttributeCount(); i++) { |
483 | 481 |
currentAttributes.put(parser.getAttributeLocalName(i), parser.getAttributeValue(i)); |
484 | 482 |
} |
485 |
return currentAttributes;
|
|
483 |
attributesStack.push(currentAttributes);
|
|
486 | 484 |
} |
487 | 485 |
|
486 |
public LinkedHashMap<String, String> getCurrentAttributes() { |
|
487 |
return attributesStack.lastElement(); |
|
488 |
} |
|
489 |
|
|
488 | 490 |
protected void writeAttributes() throws XMLStreamException { |
489 | 491 |
for (int i = 0; i < parser.getAttributeCount(); i++) { |
490 | 492 |
writeAttribute(parser.getAttributePrefix(i), parser.getAttributeLocalName(i), parser.getAttributeValue(i)); |
... | ... | |
571 | 573 |
|
572 | 574 |
public static void main(String[] args) { |
573 | 575 |
try { |
574 |
File input = new File(System.getProperty("user.home"), "xml/tdm80j/out.xml");
|
|
575 |
File output = new File(System.getProperty("user.home"), "TEMP/identity.xml");
|
|
576 |
File input = new File(System.getProperty("user.home"), "xml/tdm80j/tdm80j.xml");
|
|
577 |
File output = new File(System.getProperty("user.home"), "xml/tdm80j/out.xml");
|
|
576 | 578 |
if (!(input.exists() && input.canRead())) { |
577 | 579 |
System.out.println("cannot found $input"); |
578 | 580 |
return; |
... | ... | |
580 | 582 |
XMLProcessor builder; |
581 | 583 |
|
582 | 584 |
builder = new XMLProcessor(input.toURI().toURL()); |
585 |
|
|
586 |
// IdentityHook hook1 = new IdentityHook("hook1", new LocalNameHookActivator(null, "p"), builder) { |
|
587 |
// |
|
588 |
// @Override |
|
589 |
// public boolean _activate() { |
|
590 |
// System.out.println("ACTIVATING " + name + " AT " + getLocation()); |
|
591 |
// return true; |
|
592 |
// } |
|
593 |
// |
|
594 |
// @Override |
|
595 |
// public boolean deactivate() { |
|
596 |
// System.out.println("DEACTIVATING " + name + " AT " + getLocation()); |
|
597 |
// return true; |
|
598 |
// } |
|
599 |
// |
|
600 |
// @Override |
|
601 |
// public void processStartElement() throws XMLStreamException, IOException { |
|
602 |
// super.processStartElement(); |
|
603 |
// parentParser.writer.writeAttribute("hook", name); |
|
604 |
// } |
|
605 |
// }; |
|
606 |
|
|
607 |
IdentityHook hook2 = new IdentityHook("hook2", new XPathHookActivator(null, "//language[@ident='fr']"), builder) { |
|
608 |
|
|
609 |
@Override |
|
610 |
public boolean _activate() { |
|
611 |
System.out.println("ACTIVATING " + name + " AT " + getLocation()); |
|
612 |
return true; |
|
613 |
} |
|
614 |
|
|
615 |
@Override |
|
616 |
public boolean deactivate() { |
|
617 |
System.out.println("DEACTIVATING " + name + " AT " + getLocation()); |
|
618 |
return true; |
|
619 |
} |
|
620 |
|
|
621 |
@Override |
|
622 |
public void processStartElement() throws XMLStreamException, IOException { |
|
623 |
super.processStartElement(); |
|
624 |
parentParser.writer.writeAttribute("hook", name); |
|
625 |
} |
|
626 |
}; |
|
627 |
|
|
583 | 628 |
long time = System.currentTimeMillis(); |
584 | 629 |
if (builder.process(output)) { |
585 | 630 |
System.out.println("Time=" + (System.currentTimeMillis() - time)); |
... | ... | |
593 | 638 |
e.printStackTrace(); |
594 | 639 |
} |
595 | 640 |
} |
641 |
|
|
642 |
/** |
|
643 |
* |
|
644 |
* @return the actual hooks hash |
|
645 |
*/ |
|
646 |
public LinkedHashMap<String, Hook> getHooks() { |
|
647 |
return hooks; |
|
648 |
} |
|
649 |
|
|
650 |
public void addHook(String name, Hook hook) { |
|
651 |
hooks.put(name, hook); |
|
652 |
} |
|
596 | 653 |
} |
tmp/org.txm.core/src/java/org/txm/xml/XPathHookActivator.java (revision 2589) | ||
---|---|---|
1 |
package org.txm.xml; |
|
2 |
|
|
3 |
import java.util.Arrays; |
|
4 |
import java.util.LinkedHashMap; |
|
5 |
import java.util.regex.Pattern; |
|
6 |
|
|
7 |
/** |
|
8 |
* Simple "XPath without attribute selector" Activator activated when the current path matches the xpath |
|
9 |
* |
|
10 |
* supported operators : / , // , * , node() |
|
11 |
* only the last element attributes can be tested with simple equals test |
|
12 |
* |
|
13 |
* exemple: //p[name='value'] |
|
14 |
* exemple: /text/node()/p[name='value'] |
|
15 |
* |
|
16 |
* @author mdecorde |
|
17 |
* |
|
18 |
*/ |
|
19 |
public class XPathHookActivator extends HookActivator { |
|
20 |
|
|
21 |
String xpath; |
|
22 |
|
|
23 |
Pattern p; |
|
24 |
|
|
25 |
LinkedHashMap<String, String> attributesTest = null; |
|
26 |
|
|
27 |
|
|
28 |
private boolean debug = false; |
|
29 |
|
|
30 |
/** |
|
31 |
* @param localname the element localname to match |
|
32 |
*/ |
|
33 |
public XPathHookActivator(Hook hook, String xpath) { |
|
34 |
this.xpath = xpath; |
|
35 |
String regex = xpath; |
|
36 |
|
|
37 |
int attrTest = xpath.indexOf("["); // [some tests] |
|
38 |
int lastNodeTest = xpath.lastIndexOf("/"); |
|
39 |
|
|
40 |
if (attrTest > 0 && attrTest > lastNodeTest) { |
|
41 |
attributesTest = new LinkedHashMap<>(); |
|
42 |
regex = xpath.substring(0, attrTest); |
|
43 |
String tail = xpath.substring(attrTest); |
|
44 |
tail = tail.substring(1, tail.length() - 1); |
|
45 |
if (debug) System.out.println("TAIL=" + tail); |
|
46 |
String tests[] = tail.split("@"); |
|
47 |
if (debug) System.out.println("TESTS=" + Arrays.toString(tests)); |
|
48 |
for (String test : tests) { |
|
49 |
if (test.length() == 0) continue; |
|
50 |
|
|
51 |
String split2[] = test.split("=", 2); // 0 name 1 "value" |
|
52 |
if (debug) System.out.println("TEST=" + Arrays.toString(split2)); |
|
53 |
attributesTest.put(split2[0], split2[1].substring(1, split2[1].length() - 1)); |
|
54 |
} |
|
55 |
} |
|
56 |
|
|
57 |
regex = regex.replaceAll("([^.])[*]", "$1[^/]+"); |
|
58 |
if (regex.startsWith("//")) regex = "(/[^/]+)*/" + regex.substring(2); |
|
59 |
regex = regex.replace("//", "(/[^/]+)*/"); |
|
60 |
regex = regex.replace("node()", "[^/]+"); |
|
61 |
|
|
62 |
this.p = Pattern.compile(regex); |
|
63 |
// System.out.println(p); |
|
64 |
// System.out.println(attributesTest); |
|
65 |
} |
|
66 |
|
|
67 |
@Override |
|
68 |
public boolean mustActivate() { |
|
69 |
if (xpath == null) return false; |
|
70 |
|
|
71 |
// System.out.println(hook.getCurrentPath() + hook.parentParser.getCurrentAttributes()); |
|
72 |
if (attributesTest != null) { |
|
73 |
return p.matcher(hook.getCurrentPath()).find() && hook.parentParser.getCurrentAttributes().equals(attributesTest); |
|
74 |
} |
|
75 |
else { |
|
76 |
return p.matcher(hook.getCurrentPath()).find(); |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public void hookWasActivated() { |
|
82 |
// nothing to do |
|
83 |
} |
|
84 |
|
|
85 |
public static void main(String[] args) { |
|
86 |
new XPathHookActivator(null, "//*"); |
|
87 |
new XPathHookActivator(null, "//p[@name='value']"); |
|
88 |
new XPathHookActivator(null, "//text/node()/p[@name='value']"); |
|
89 |
new XPathHookActivator(null, "/TEI/text/node()/p[@name='value']"); |
|
90 |
new XPathHookActivator(null, "//text//p[@name='value']"); |
|
91 |
} |
|
92 |
} |
|
0 | 93 |
tmp/org.txm.core/src/java/org/txm/importer/ReAlignXMLTEI.java (revision 2589) | ||
---|---|---|
1 |
package org.txm.importer; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.io.InputStream; |
|
6 |
import java.net.URL; |
|
7 |
|
|
8 |
import javax.xml.stream.XMLInputFactory; |
|
9 |
import javax.xml.stream.XMLStreamException; |
|
10 |
import javax.xml.stream.XMLStreamReader; |
|
11 |
|
|
12 |
/** |
|
13 |
* Re align a XML TEI file with a TAL tool result. The TAL result might change: words boundaries, words properties, an element. |
|
14 |
* |
|
15 |
* |
|
16 |
* |
|
17 |
* @author mdecorde |
|
18 |
* |
|
19 |
*/ |
|
20 |
public class ReAlignXMLTEI extends StaxIdentityParser { |
|
21 |
|
|
22 |
String elementToPatch; |
|
23 |
|
|
24 |
protected URL patchUrl; |
|
25 |
|
|
26 |
protected InputStream patchInputData; |
|
27 |
|
|
28 |
protected XMLStreamReader patchParser; |
|
29 |
|
|
30 |
public ReAlignXMLTEI(File origFile, File patchFile, String elementToPatch) throws XMLStreamException, IOException { |
|
31 |
super(origFile); |
|
32 |
this.elementToPatch = elementToPatch; |
|
33 |
this.patchUrl = patchFile.toURI().toURL(); |
|
34 |
|
|
35 |
this.factory = XMLInputFactory.newInstance(); |
|
36 |
|
|
37 |
this.patchInputData = patchUrl.openStream(); |
|
38 |
this.patchParser = factory.createXMLStreamReader(patchInputData); |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public boolean process(File outfile) throws XMLStreamException, IOException { |
|
43 |
boolean ret = super.process(outfile); |
|
44 |
|
|
45 |
if (patchParser != null) { |
|
46 |
try { |
|
47 |
patchParser.close(); |
|
48 |
} |
|
49 |
catch (Exception e) { |
|
50 |
System.out.println("patchParser excep: " + e); |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
if (patchInputData != null) { |
|
55 |
try { |
|
56 |
patchInputData.close(); |
|
57 |
} |
|
58 |
catch (Exception e) { |
|
59 |
System.out.println("patchInputData excep: " + e); |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
return ret; |
|
64 |
} |
|
65 |
} |
|
0 | 66 |
tmp/org.txm.searchengine.cqp.rcp/plugin.xml (revision 2589) | ||
---|---|---|
160 | 160 |
</visibleWhen> |
161 | 161 |
</command> |
162 | 162 |
<command |
163 |
commandId="org.txm.searchengine.cqp.rcp.handlers.base.CreateSubCorpus" |
|
164 |
icon="icons/functions/subcorpus.png" |
|
165 |
label="Edit..." |
|
166 |
style="push"> |
|
167 |
<visibleWhen |
|
168 |
checkEnabled="false"> |
|
169 |
<reference |
|
170 |
definitionId="OneCorpusSelected"> |
|
171 |
</reference> |
|
172 |
</visibleWhen> |
|
173 |
<parameter |
|
174 |
name="edit" |
|
175 |
value="true"> |
|
176 |
</parameter> |
|
177 |
</command> |
|
178 |
<command |
|
179 | 163 |
commandId="org.txm.searchengine.cqp.rcp.handlers.base.ComputePartition" |
180 | 164 |
icon="icons/functions/partition.png" |
181 | 165 |
style="push"> |
... | ... | |
185 | 169 |
<reference |
186 | 170 |
definitionId="OneCorpusSelected"> |
187 | 171 |
</reference> |
188 |
<reference |
|
189 |
definitionId="OnePartitionSelected"> |
|
190 |
</reference> |
|
191 | 172 |
</or> |
192 | 173 |
</visibleWhen> |
193 | 174 |
</command> |
... | ... | |
318 | 299 |
id="org.txm.searchengine.cqp.rcp.preferences.CQPPreferencePage" |
319 | 300 |
name="CQP"> |
320 | 301 |
</page> |
321 |
<page |
|
322 |
category="org.txm.rcp.preferences.UserPreferencePage" |
|
323 |
class="org.txm.searchengine.cqp.rcp.preferences.SubcorpusPreferencePage" |
|
324 |
id="org.txm.searchengine.cqp.rcp.preferences.SubcorpusPreferencePage" |
|
325 |
name="Subcorpus"> |
|
326 |
</page> |
|
327 |
<page |
|
328 |
category="org.txm.rcp.preferences.UserPreferencePage" |
|
329 |
class="org.txm.searchengine.cqp.rcp.preferences.PartitionPreferencePage" |
|
330 |
id="org.txm.searchengine.cqp.rcp.preferences.PartitionPreferencePage" |
|
331 |
name="Partition"> |
|
332 |
</page> |
|
333 | 302 |
</extension> |
334 | 303 |
<extension |
335 | 304 |
point="org.eclipse.core.runtime.adapters"> |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/CQPCorpus.java (revision 2589) | ||
---|---|---|
126 | 126 |
* @return |
127 | 127 |
*/ |
128 | 128 |
synchronized public static CQPCorpus getFirstParentCorpus(TXMResult result) { |
129 |
CQPCorpus corpus = (CQPCorpus) result.getFirstParent(Subcorpus.class);
|
|
129 |
CQPCorpus corpus = result.getFirstParent(Subcorpus.class); |
|
130 | 130 |
if (corpus == null) { |
131 |
corpus = (CQPCorpus) result.getFirstParent(CQPCorpus.class);
|
|
131 |
corpus = result.getFirstParent(CQPCorpus.class); |
|
132 | 132 |
} |
133 | 133 |
if (corpus == null) { |
134 | 134 |
corpus = (CQPCorpus) getParentMainCorpus(result); |
... | ... | |
675 | 675 |
return createSubcorpus(query, subcorpusName); |
676 | 676 |
} |
677 | 677 |
|
678 |
@Override |
|
678 | 679 |
protected final boolean _compute() throws Exception { |
679 |
//reset the internal variable that store information
|
|
680 |
// reset the internal variables that store cached information
|
|
680 | 681 |
|
681 | 682 |
lexicalUnitsProperties = null; |
682 | 683 |
size = -1; |
... | ... | |
690 | 691 |
textStructuralUnit = null; |
691 | 692 |
wordProperty = null; |
692 | 693 |
|
693 |
|
|
694 | 694 |
return __compute(); |
695 | 695 |
} |
696 | 696 |
|
... | ... | |
815 | 815 |
TXMResult p = getFirstParent(Subcorpus.class); |
816 | 816 |
if (p != null) |
817 | 817 |
return (Subcorpus) p; |
818 |
return (MainCorpus) getFirstParent(MainCorpus.class);
|
|
818 |
return getFirstParent(MainCorpus.class); |
|
819 | 819 |
} |
820 | 820 |
|
821 | 821 |
@Override |
... | ... | |
920 | 920 |
if (this instanceof MainCorpus) |
921 | 921 |
return (MainCorpus) this; |
922 | 922 |
|
923 |
return (MainCorpus) getFirstParent(MainCorpus.class);
|
|
923 |
return getFirstParent(MainCorpus.class); |
|
924 | 924 |
} |
925 | 925 |
|
926 | 926 |
@Override |
... | ... | |
988 | 988 |
* @return the partitions |
989 | 989 |
*/ |
990 | 990 |
public Partition getPartition(String name) { |
991 |
List<Partition> partitions = (List<Partition>) getChildren(Partition.class);
|
|
991 |
List<Partition> partitions = getChildren(Partition.class); |
|
992 | 992 |
for (Partition p : partitions) |
993 | 993 |
if (p.getName().equals(name)) |
994 | 994 |
return p; |
... | ... | |
1001 | 1001 |
* @return the partitions |
1002 | 1002 |
*/ |
1003 | 1003 |
public List<Partition> getPartitions() { |
1004 |
return (List<Partition>) getChildren(Partition.class);
|
|
1004 |
return getChildren(Partition.class); |
|
1005 | 1005 |
} |
1006 | 1006 |
|
1007 | 1007 |
/** |
... | ... | |
1255 | 1255 |
* @return the subcorpora |
1256 | 1256 |
*/ |
1257 | 1257 |
public List<Subcorpus> getSubcorpora() { |
1258 |
return (List<Subcorpus>) getChildren(Subcorpus.class);
|
|
1258 |
return getChildren(Subcorpus.class); |
|
1259 | 1259 |
} |
1260 | 1260 |
|
1261 | 1261 |
/** |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/MainCorpus.java (revision 2589) | ||
---|---|---|
135 | 135 |
|
136 | 136 |
HashMap<String, MainCorpus> corpora = CorpusManager.getCorpusManager().getCorpora(); |
137 | 137 |
if (CorpusManager.getCorpusManager().hasCorpus(this)) { |
138 |
Log.severe(NLS.bind("** The \"{0}\" MainCorpus object in the \"{1}\" project can not be computed: another one with the same CQP identifier has already been computed.", this.pID, this |
|
139 |
.getProjectDirectory()));
|
|
140 |
return false;
|
|
138 |
// Log.severe(NLS.bind("** The \"{0}\" MainCorpus object in the \"{1}\" project can not be computed: another one with the same CQP identifier has already been computed.", this.pID, this
|
|
139 |
// .getProjectDirectory()));
|
|
140 |
return true;
|
|
141 | 141 |
} |
142 | 142 |
CorpusManager.getCorpusManager().add(this); |
143 | 143 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/Application.java (revision 2589) | ||
---|---|---|
36 | 36 |
import java.util.Map; |
37 | 37 |
import java.util.logging.Level; |
38 | 38 |
|
39 |
import org.eclipse.core.commands.ExecutionException; |
|
40 | 39 |
import org.eclipse.core.net.proxy.IProxyService; |
41 | 40 |
import org.eclipse.core.runtime.Platform; |
42 | 41 |
import org.eclipse.core.runtime.preferences.ConfigurationScope; |
... | ... | |
47 | 46 |
import org.eclipse.osgi.util.TextProcessor; |
48 | 47 |
import org.eclipse.swt.SWT; |
49 | 48 |
import org.eclipse.swt.widgets.Display; |
50 |
import org.eclipse.swt.widgets.Event; |
|
51 |
import org.eclipse.swt.widgets.Listener; |
|
52 | 49 |
import org.eclipse.swt.widgets.MessageBox; |
53 | 50 |
import org.eclipse.swt.widgets.Shell; |
54 | 51 |
import org.eclipse.ui.PlatformUI; |
... | ... | |
61 | 58 |
import org.txm.Toolbox; |
62 | 59 |
import org.txm.core.messages.TXMCoreMessages; |
63 | 60 |
import org.txm.core.preferences.TBXPreferences; |
64 |
import org.txm.rcp.commands.workspace.LoadBinaryCorpus; |
|
65 | 61 |
import org.txm.rcp.messages.TXMUIMessages; |
66 | 62 |
import org.txm.rcp.preferences.RCPPreferences; |
67 | 63 |
import org.txm.rcp.swt.dialog.CGUMessageDialog; |
... | ... | |
72 | 68 |
* This class controls all aspects of the application's execution. |
73 | 69 |
*/ |
74 | 70 |
public class Application implements IApplication { |
75 |
|
|
71 |
|
|
76 | 72 |
/** The Constant PLUGIN_ID. */ |
77 | 73 |
public static final String PLUGIN_ID = "org.txm.rcp"; //$NON-NLS-1$ |
78 |
|
|
74 |
|
|
79 | 75 |
/** The Constant FIRST_LAUNCH. */ |
80 | 76 |
public static final String FIRST_LAUNCH = "first_launch"; //$NON-NLS-1$ |
81 |
|
|
77 |
|
|
82 | 78 |
private static ApplicationWorkbenchAdvisor awa; |
83 |
|
|
84 |
//public static OpenDocumentEventProcessor openDocProcessor = new OpenDocumentEventProcessor();
|
|
79 |
|
|
80 |
// public static OpenDocumentEventProcessor openDocProcessor = new OpenDocumentEventProcessor();
|
|
85 | 81 |
/* |
86 | 82 |
* (non-Javadoc) |
87 |
* |
|
88 | 83 |
* @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object) |
89 | 84 |
*/ |
90 | 85 |
@Override |
91 | 86 |
public Object start(IApplicationContext context) throws Exception { |
92 |
|
|
87 |
|
|
93 | 88 |
Display display = PlatformUI.createDisplay(); |
94 |
|
|
95 | 89 |
|
96 |
|
|
97 |
// if (Platform.inDevelopmentMode() || Platform.inDebugMode()) { |
|
98 |
// // this can not work in development environment |
|
99 |
// // as it need to have a default workspace set to none |
|
100 |
// // see product configuration : |
|
101 |
// // osgi.instance.area=@noDefault |
|
102 |
// // ignored in development |
|
103 |
// // ------------------------------------- |
|
90 |
// if (Platform.inDevelopmentMode() || Platform.inDebugMode()) { |
|
91 |
// // this can not work in development environment |
|
92 |
// // as it need to have a default workspace set to none |
|
93 |
// // see product configuration : |
|
94 |
// // osgi.instance.area=@noDefault |
|
95 |
// // ignored in development |
|
96 |
// // ------------------------------------- |
|
104 | 97 |
// |
105 |
// } else {
|
|
98 |
// } else {
|
|
106 | 99 |
// in Release mode only : platform workspace selection on startup |
107 | 100 |
// then restart if needed (on workspace error...) |
108 |
|
|
109 |
System.out.println("instance location="+Platform.getInstanceLocation().getURL());
|
|
101 |
|
|
102 |
System.out.println("instance location=" + Platform.getInstanceLocation().getURL());
|
|
110 | 103 |
if (Platform.getInstanceLocation().getURL() == null) { |
111 |
|
|
104 |
|
|
112 | 105 |
Integer ret = openCGU(); |
113 | 106 |
if (ret == IApplication.EXIT_RESTART) { |
114 | 107 |
System.out.println("** Working directory set by user."); |
115 | 108 |
return IApplication.EXIT_RESTART; |
116 |
} else if (ret == IApplication.EXIT_OK) { |
|
109 |
} |
|
110 |
else if (ret == IApplication.EXIT_OK) { |
|
117 | 111 |
System.out.println("** Fail to open CGU or set working directory."); |
118 | 112 |
return IApplication.EXIT_OK; // an error occurred or user canceled |
119 |
} else { |
|
113 |
} |
|
114 |
else { |
|
120 | 115 |
// OK |
121 | 116 |
} |
122 | 117 |
} |
123 |
|
|
118 |
|
|
124 | 119 |
// Die if platform WS not set (user cancel) |
125 | 120 |
// --------------------------- |
126 |
|
|
121 |
|
|
127 | 122 |
if (Platform.getInstanceLocation().getURL() == null) { |
128 | 123 |
System.out.println("** Working directory not set."); |
129 | 124 |
return IApplication.EXIT_OK; |
130 | 125 |
} |
131 |
|
|
132 |
|
|
126 |
|
|
127 |
|
|
133 | 128 |
// load JVM fonts in SWT env |
134 | 129 |
if (System.getProperty("os.name").contains("Linux")) { // $NON-NLS-1$ $NON-NLS-2$ |
135 | 130 |
File javaFontsPath = new File(System.getProperty("java.home") |
136 | 131 |
+ System.getProperty("file.separator") + "lib" |
137 | 132 |
+ System.getProperty("file.separator") + "fonts" |
138 | 133 |
+ System.getProperty("file.separator")); |
139 |
|
|
134 |
|
|
140 | 135 |
String[] fontFiles = javaFontsPath.list(); |
141 | 136 |
if (fontFiles != null) { |
142 | 137 |
for (int i = 0; i < fontFiles.length; i++) { |
143 |
if(fontFiles[i].endsWith(".ttf")) { //$NON-NLS-1$
|
|
138 |
if (fontFiles[i].endsWith(".ttf")) { //$NON-NLS-1$
|
|
144 | 139 |
File fontFile = new File(javaFontsPath, fontFiles[i]); |
145 | 140 |
Log.finest("Loading Java font to SWT Device from file " + fontFile + "..."); |
146 | 141 |
// Load the font in SWT |
... | ... | |
149 | 144 |
} |
150 | 145 |
} |
151 | 146 |
} |
152 |
|
|
147 |
|
|
153 | 148 |
Map args = context.getArguments(); |
154 |
|
|
155 |
List<String> argsList = Arrays.asList((String[])(args.get("application.args"))); //$NON-NLS-1$ |
|
156 |
|
|
149 |
|
|
150 |
List<String> argsList = Arrays.asList((String[]) (args.get("application.args"))); //$NON-NLS-1$
|
|
151 |
|
|
157 | 152 |
System.out.println(TXMCoreMessages.bind(TXMUIMessages.argsColon, argsList)); |
158 |
|
|
153 |
|
|
159 | 154 |
if (argsList.contains("-log")) { //$NON-NLS-1$ |
160 | 155 |
System.out.println(TXMUIMessages.logOptionDetected); |
161 | 156 |
Log.setPrintInConsole(true); |
... | ... | |
168 | 163 |
if (argsList.contains("-run")) { //$NON-NLS-1$ |
169 | 164 |
System.out.println("Running TXM"); |
170 | 165 |
// FIXME: need to check that all has been well moved in Workspace class or build.properties |
171 |
// } else if (argsList.contains("-standalone")) { //$NON-NLS-1$ |
|
172 |
// File userhomeDirectory = new File("workspace").getAbsoluteFile(); // eclipse default workspace directory |
|
173 |
// File defaultWorkspaceFile = new File("workspace/corpora/default.xml"); |
|
174 |
// if (!defaultWorkspaceFile.exists()) { |
|
175 |
// System.out.println("Stand alone launch, creating minimal TXM user home directory in "+userhomeDirectory.getAbsolutePath()); |
|
176 |
// System.out.println("Sample corpora, scripts, import scripts and macros files are not yet installed."); |
|
177 |
// |
|
178 |
// TBXPreferences.getInstance().put(TBXPreferences.USER_TXM_HOME, userhomeDirectory.getAbsolutePath()); |
|
179 |
// TBXPreferences.getInstance().put(TBXPreferences.INSTALL_DIR, userhomeDirectory.getParentFile().getAbsolutePath()); |
|
180 |
// |
|
181 |
// File corpusworkspaceDirectory = new File(userhomeDirectory, "workspaces"); |
|
182 |
// corpusworkspaceDirectory.mkdirs(); |
|
166 |
// } else if (argsList.contains("-standalone")) { //$NON-NLS-1$ |
|
167 |
// File userhomeDirectory = new File("workspace").getAbsoluteFile(); // eclipse default workspace directory |
|
168 |
// File defaultWorkspaceFile = new File("workspace/corpora/default.xml"); |
|
169 |
// if (!defaultWorkspaceFile.exists()) { |
|
170 |
// System.out.println("Stand alone launch, creating minimal TXM user home directory in "+userhomeDirectory.getAbsolutePath()); |
|
171 |
// System.out.println("Sample corpora, scripts, import scripts and macros files are not yet installed."); |
|
183 | 172 |
// |
184 |
// String createfolders[] = { |
|
185 |
// "corpora", "clipboard", //$NON-NLS-1$ //$NON-NLS-2$ |
|
186 |
// "workspaces", "css", "scripts", "scripts/lib", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
187 |
// "scripts/macro", "scripts/user", "xsl", "samples", "schema", "R"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
173 |
// TBXPreferences.getInstance().put(TBXPreferences.USER_TXM_HOME, userhomeDirectory.getAbsolutePath()); |
|
174 |
// TBXPreferences.getInstance().put(TBXPreferences.INSTALL_DIR, userhomeDirectory.getParentFile().getAbsolutePath()); |
|
188 | 175 |
// |
189 |
// for (String folder : createfolders) { |
|
190 |
// new File(userhomeDirectory, folder).mkdir(); |
|
191 |
// } |
|
176 |
// File corpusworkspaceDirectory = new File(userhomeDirectory, "workspaces"); |
|
177 |
// corpusworkspaceDirectory.mkdirs(); |
|
192 | 178 |
// |
193 |
// Workspace.createEmptyWorkspaceDefinition(new File(corpusworkspaceDirectory, "default.xml")); //$NON-NLS-1$ |
|
194 |
// BundleUtils.copyFiles("org.txm.core", "res", "org/txm", "css", new File(userhomeDirectory, "css")); |
|
195 |
// BundleUtils.copyFiles("org.txm.core", "res", "org/txm/xml", "xsl", new File(userhomeDirectory, "xsl")); |
|
196 |
// BundleUtils.copyFiles("org.txm.core", "res", "org/txm/xml", "schema", new File(userhomeDirectory, "schema")); |
|
197 |
// File scriptsDirectory = new File(userhomeDirectory, "scripts"); |
|
198 |
// new File(scriptsDirectory, "user").mkdir(); |
|
199 |
// new File(scriptsDirectory, "import").mkdir(); |
|
200 |
// new File(scriptsDirectory, "lib").mkdir(); |
|
201 |
// new File(scriptsDirectory, "macro").mkdir(); |
|
202 |
// new File(scriptsDirectory, "samples").mkdir(); |
|
203 |
// } |
|
204 |
} else { |
|
179 |
// String createfolders[] = { |
|
180 |
// "corpora", "clipboard", //$NON-NLS-1$ //$NON-NLS-2$ |
|
181 |
// "workspaces", "css", "scripts", "scripts/lib", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
182 |
// "scripts/macro", "scripts/user", "xsl", "samples", "schema", "R"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
183 |
// |
|
184 |
// for (String folder : createfolders) { |
|
185 |
// new File(userhomeDirectory, folder).mkdir(); |
|
186 |
// } |
|
187 |
// |
|
188 |
// Workspace.createEmptyWorkspaceDefinition(new File(corpusworkspaceDirectory, "default.xml")); //$NON-NLS-1$ |
|
189 |
// BundleUtils.copyFiles("org.txm.core", "res", "org/txm", "css", new File(userhomeDirectory, "css")); |
|
190 |
// BundleUtils.copyFiles("org.txm.core", "res", "org/txm/xml", "xsl", new File(userhomeDirectory, "xsl")); |
|
191 |
// BundleUtils.copyFiles("org.txm.core", "res", "org/txm/xml", "schema", new File(userhomeDirectory, "schema")); |
|
192 |
// File scriptsDirectory = new File(userhomeDirectory, "scripts"); |
|
193 |
// new File(scriptsDirectory, "user").mkdir(); |
|
194 |
// new File(scriptsDirectory, "import").mkdir(); |
|
195 |
// new File(scriptsDirectory, "lib").mkdir(); |
|
196 |
// new File(scriptsDirectory, "macro").mkdir(); |
|
197 |
// new File(scriptsDirectory, "samples").mkdir(); |
|
198 |
// } |
|
199 |
} |
|
200 |
else { |
|
205 | 201 |
System.err.println("TXM must be launch with the argument '-run' to start."); //$NON-NLS-1$ |
206 | 202 |
System.err.println(TXMUIMessages.thisFileIsNotMeantToRunTXMPleaseConsultTXMUserManual); |
207 |
|
|
203 |
|
|
208 | 204 |
javax.swing.JOptionPane.showMessageDialog(null, TXMUIMessages.thisFileIsNotMeantToRunTXMPleaseConsultTXMUserManual); |
209 | 205 |
return IApplication.EXIT_OK; |
210 | 206 |
} |
211 | 207 |
// test if Java 1.6 is installed |
212 | 208 |
String version = System.getProperty("java.version"); //$NON-NLS-1$ |
213 | 209 |
Log.warning("java.version : " + version); //$NON-NLS-1$ |
214 |
|
|
210 |
|
|
215 | 211 |
boolean exit = false;// parseCommandLine(); |
216 | 212 |
if (exit) { |
217 | 213 |
return IApplication.EXIT_OK; |
218 | 214 |
} |
219 |
|
|
220 |
|
|
221 |
//display.addListener(SWT.OpenDocument, openDocProcessor); |
|
222 |
|
|
223 |
// //Lock the RCP workspace, thus there is only one TXM instance running
|
|
224 |
// Log.warning(TXMUIMessages.lockRCPWorkspace);
|
|
225 |
// if (!Platform.getInstanceLocation().lock()){
|
|
226 |
// //Shell shell = display.getActiveShell();
|
|
227 |
// System.out.println("TXM is already running. Exiting...");
|
|
228 |
// return IApplication.EXIT_OK;
|
|
229 |
// }
|
|
230 |
|
|
215 |
|
|
216 |
|
|
217 |
// display.addListener(SWT.OpenDocument, openDocProcessor);
|
|
218 |
|
|
219 |
// //Lock the RCP workspace, thus there is only one TXM instance running
|
|
220 |
// Log.warning(TXMUIMessages.lockRCPWorkspace);
|
|
221 |
// if (!Platform.getInstanceLocation().lock()){
|
|
222 |
// //Shell shell = display.getActiveShell();
|
|
223 |
// System.out.println("TXM is already running. Exiting...");
|
|
224 |
// return IApplication.EXIT_OK;
|
|
225 |
// }
|
|
226 |
|
|
231 | 227 |
try { |
232 | 228 |
Log.warning(TXMUIMessages.activateProxyService); |
233 | 229 |
activateProxyService(); |
234 |
} catch (Exception e) { |
|
230 |
} |
|
231 |
catch (Exception e) { |
|
235 | 232 |
Log.warning(TXMCoreMessages.bind(TXMUIMessages.couldNotStartProxyConfigurationColon, e)); |
236 | 233 |
} |
237 |
|
|
234 |
|
|
238 | 235 |
try { |
239 | 236 |
// initialization code has been put in ApplicationWorkbenchAdvisor |
240 | 237 |
// as it should |
241 |
|
|
242 |
// add listener to catch --launcher.openFile |
|
243 |
display.addListener(SWT.OpenDocument, new Listener() { |
|
244 |
|
|
245 |
@Override |
|
246 |
public void handleEvent(Event event) { |
|
247 |
if (event.text != null && event.text.endsWith(".txm")) { |
|
248 |
File f = new File(event.text); |
|
249 |
|
|
250 |
try { |
|
251 |
LoadBinaryCorpus.loadBinaryCorpusArchive(f); |
|
252 |
} catch (ExecutionException e) { |
|
253 |
// TODO Auto-generated catch block |
|
254 |
e.printStackTrace(); |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
258 |
}); |
|
259 | 238 |
|
260 |
//run the application mainloop |
|
239 |
// add listener to catch --launcher.openFile |
|
240 |
// display.addListener(SWT.OpenDocument, new Listener() { |
|
241 |
// |
|
242 |
// @Override |
|
243 |
// public void handleEvent(Event event) { |
|
244 |
// if (event.text != null && event.text.endsWith(".txm")) { |
Formats disponibles : Unified diff