-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTM_solas_api.php
248 lines (206 loc) · 7.57 KB
/
TM_solas_api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html>
<html>
<head>
<title>Solas API TM Checker Page</title>
<!--
Creation Date: 21 February 2012
Author: Ian O'Keeffe
Modification History:
--------------------------
21-02-2012
This page is a template for creating new components that interact with locConnect via PEAR and the locConnect API
It performs the following:
* Sets IP address for LocConnect
* Sets Component Name
* First step, call LocConnect to fetch a list of available jobs for this component, ComponentName
$jobs = $solasApi->solas_fetch_jobs($componentName, $locConnect);
* Parse returned XML/XLIFF list for status, and possible jobs
* Any error messages?
* Any jobs?
* If yes, Tell locConnect I will process this jobId
$response = $solasApi->solas_set_status_processing($componentName, $jobId, $locConnect);
* Get job
$file = $solasApi->solas_get_job($componentName, $jobId, $locConnect);
* Do stuff to the XLIFF file
* Send the updated XLIFF file back to locConnect
$response = $solasApi->solas_send_output($componentName, $jobId, $data, $locConnect);
* Say what you did to the XLIFF file
$response = $solasApi->solas_send_feedback($componentName, $jobId, 'did stuff to XLIFF file', $locConnect);
*
* If no, jobId is not set, so wait until called again
*
--------------------------
-->
</head>
<body>
<br>
<b>TM Checker API page is being called at: </b>
<?php
echo strftime('%c');
echo '<br>';
// Set IP address for LocConnect (better if this is all in a config.ini file)
$locConnect='http://193.1.97.50/locconnect/';
// Set Component Name here
$componentName='ComponentName';
// LocConnect uses Pear for its calls
require_once 'HTTP\Request2.php';
//If Request2.php is not found, and you get:
// Warning: require_once(HTTP/Request2.php) [function.require-once]: failed to open stream: No such file or directory in E:\www\ct\1.php on line 2
// Fatal error: require_once() [function.require]: Failed opening required 'HTTP/Request2.php' (include_path='.;C:\php5\pear') in E:\www\ct\1.php on line 2
//you should type:
// pear install http_request2
//at the # prompt
require 'SolasAPI.class.php';
require 'checkTM.php';
$solasApi = new SolasAPI; // set up SolasAPI class for function calling
//First step, call LocConnect to fetch a list of available jobs for this component, ComponentName
$jobs = $solasApi->solas_fetch_jobs($componentName, $locConnect);
echo '<br> $jobs: '.$jobs; //IOK for testing
//Now parse returned XML/XLIFF list for status, and possible jobs
$doc = new DOMDocument();
$doc->loadXML($jobs);
$xpath = new DOMXPath($doc);
//Any error messages?
$solas_errors = $doc->getElementsByTagName("error");
foreach ($solas_errors as $solas_error) {
echo '<br> Tag: '.$solas_error->nodeName.' - '.$solas_error->nodeValue; //IOK for testing
$solas_msgs = $solas_error->getElementsByTagName("msg");
foreach($solas_msgs as $solas_msg) {
echo '<br> Tag: '.$solas_msg->nodeName.' - '.$solas_msg->nodeValue; //IOK for testing
}
}
//Any jobs?
$solas_alljobs = $doc->getElementsByTagName("jobs");
foreach ($solas_alljobs as $solas_alljob) {
echo '<br> Tag: '.$solas_alljob->nodeName.' - '.$solas_alljob->nodeValue; //IOK for testing
$solas_jobs = $solas_alljob->getElementsByTagName("job");
foreach($solas_jobs as $solas_job) { //list all jobs - not strictly necessary!
echo '<br> Tag: '.$solas_job->nodeName.' - '.$solas_job->nodeValue; //IOK for testing
}
$jobId = $solas_jobs->item(0)->nodeValue; // select the jobId of the first job in the list (may be the only job in the list!)
echo '<br> Job ID to be processed: '.$jobId; //IOK for testing
//Tell locConnect I will process this jobId
$response = $solasApi->solas_set_status_processing($componentName, $jobId, $locConnect);
echo '<br> solas_set_status_processing Response: '.$response; //IOK for testing
//may need to insert error handling here in case solas_set_status is unsuccessful
}
//IOK create $data in XML format for test purposes
$tmxFile = "<tmx version=\"1.4b\">\r\n".
"<header creationtool=\"XYZTool\" creationtoolversion=\"1.01-023\"\r\n".
" datatype=\"PlainText\" segtype=\"sentence\"\r\n".
" adminlang=\"EN-US\" srclang=\"EN-US\"\r\n".
" o-tmf=\"ABCTransMem\">\r\n".
"</header>\r\n".
"<body>\r\n".
" <tu>\r\n".
" <tuv lang=\"EN-US\">\r\n".
" <seg>Fart.</seg>\r\n".
" </tuv>\r\n".
" <tuv lang=\"DE-DE\">\r\n".
" <seg>Farten.</seg>\r\n".
" </tuv>\r\n".
" </tu>\r\n".
" <tu>\r\n".
" <tuv lang=\"EN-US\">\r\n".
" <seg>Sneeze.</seg>\r\n".
" </tuv>\r\n".
" <tuv lang=\"DE-DE\">\r\n".
" <seg>Bigennosenblowenoffen.</seg>\r\n".
" </tuv>\r\n".
" </tu>\r\n".
" <tu>\r\n".
" <tuv lang=\"EN-US\">\r\n".
" <seg>Burp.</seg>\r\n".
" </tuv>\r\n".
" <tuv lang=\"DE-DE\">\r\n".
" <seg>Burpen.</seg>\r\n".
" </tuv>\r\n".
" </tu>\r\n".
" <tu>\r\n".
" <tuv lang=\"EN-US\">\r\n".
" <seg>Belch.</seg>\r\n".
" </tuv>\r\n".
" <tuv lang=\"DE-DE\">\r\n".
" <seg>Burpen.</seg>\r\n".
" </tuv>\r\n".
" </tu>\r\n".
" <tu>\r\n".
" <tuv lang=\"EN-US\">\r\n".
" <seg>Fart.</seg>\r\n".
" </tuv>\r\n".
" <tuv lang=\"DE-DE\">\r\n".
" <seg>Stinkenbum.</seg>\r\n".
" </tuv>\r\n".
" </tu>\r\n".
" <tu>\r\n".
" <tuv lang=\"EN-US\">\r\n".
" <seg>Fart.</seg>\r\n".
" </tuv>\r\n".
" <tuv lang=\"DE-DE\">\r\n".
" <seg>Farten.</seg>\r\n".
" </tuv>\r\n".
" </tu>\r\n".
" <tu>\r\n".
" <tuv lang=\"EN-US\">\r\n".
" <seg>Cough.</seg>\r\n".
" </tuv>\r\n".
" <tuv lang=\"DE-DE\">\r\n".
" <seg>Coffen.</seg>\r\n".
" </tuv>\r\n".
" </tu>\r\n".
" <tu>\r\n".
" <tuv lang=\"EN-US\">\r\n".
" <seg>Cough.</seg>\r\n".
" </tuv>\r\n".
" <tuv lang=\"DE-DE\">\r\n".
" <seg>Coffen.</seg>\r\n".
" </tuv>\r\n".
" </tu>\r\n".
" <tu>\r\n".
" <tuv lang=\"EN-US\">\r\n".
" <seg>Belch.</seg>\r\n".
" </tuv>\r\n".
" <tuv lang=\"DE-DE\">\r\n".
" <seg>Burpen.</seg>\r\n".
" </tuv>\r\n".
" </tu>\r\n".
" <tu>\r\n".
" <tuv lang=\"EN-US\">\r\n".
" <seg>Belch.</seg>\r\n".
" </tuv>\r\n".
" <tuv lang=\"DE-DE\">\r\n".
" <seg>Belchen.</seg>\r\n".
" </tuv>\r\n".
" </tu>\r\n".
"</body>\r\n".
"</tmx>";
// echo '<br> $tmxFile: '.$tmxFile; //IOK for testing
//Do stuff to the XLIFF file
$results = checkTM_TMX($tmxFile);
echo '<br><br><br><h2> Results: </h2>'.$results; //IOK for testing
//Get job if jobId is set
if(isset($jobId)) {
$file = $solasApi->solas_get_job($componentName, $jobId, $locConnect); // $file now contains the XLIFF file to be processed
//IOK create $data in XML format for test purposes
$xliffFile = "<methodCall>\r\n".
" <methodName>foo.bar</methodName>\r\n".
" <params>\r\n".
" <param><value><string>Hello, locConnect!</string></value></param>\r\n".
" <param><value><int>123</int></value></param>\r\n".
" </params>\r\n".
"</methodCall>";
//Do stuff to the XLIFF file
$updatedXliffFile = doStuffToXLIFF($xliffFile);
echo '<br> $updatedXliffFile: '.$updatedXliffFile; //IOK for testing
//Send the updated XLIFF file back to locConnect
$response = $solasApi->solas_send_output($componentName, $jobId, $data, $locConnect);
echo '<br> solas_send_output Response: '.$response; //IOK for testing
//Say what you did to the XLIFF file
$response = $solasApi->solas_send_feedback($componentName, $jobId, 'did stuff to XLIFF file', $locConnect);
echo '<br> solas_send_feedback Response: '.$response; //IOK for testing
} else { //jobId is not set, so wait until called again
echo '<br> Waiting for a job for '.$componentName; //IOK for testing
}
?>
</body>
</html>