| 52 | | } |
| 53 | | |
| 54 | | } |
| 55 | | |
| 56 | | /** |
| 57 | | * Returns a list of localized strings from a list of simple strings |
| 58 | | * and a given language. |
| 59 | | * @param x The list of strings. |
| 60 | | * @param lang The language of the list. |
| | 100 | } |
| | 101 | res.setCheckedby(or.getCheckedby()); |
| | 102 | res.setPassed(or.getPassed()); |
| | 103 | res.setUri(or.getUri()); |
| | 104 | res.setVersion(or.getVersion()); |
| | 105 | |
| | 106 | org.w3.unicorn.observationresponse.ResultDocument.Result result = or |
| | 107 | .getResult(); |
| | 108 | |
| | 109 | // Fill res.result |
| | 110 | |
| | 111 | if (result != null) { |
| | 112 | org.w3.unicorn.observationresponse.WarningsDocument.Warnings warnings = result |
| | 113 | .getWarnings(); |
| | 114 | if (warnings != null && warnings.getWarninglistArray() != null) { |
| | 115 | for (org.w3.unicorn.observationresponse.WarninglistDocument.Warninglist wl : warnings |
| | 116 | .getWarninglistArray()) { |
| | 117 | String lang = warnings.getLang(); |
| | 118 | Result r = new Result(lang, wl.getUri()); |
| | 119 | for (org.w3.unicorn.observationresponse.WarningDocument.Warning w : wl |
| | 120 | .getWarningArray()) { |
| | 121 | r.getWarnings().add(swap(w, lang)); |
| | 122 | } |
| | 123 | res.addResult(r); |
| | 124 | } |
| | 125 | } |
| | 126 | |
| | 127 | org.w3.unicorn.observationresponse.ErrorsDocument.Errors errors = result |
| | 128 | .getErrors(); |
| | 129 | if (errors != null && errors.getErrorlistArray() != null) { |
| | 130 | for (org.w3.unicorn.observationresponse.ErrorlistDocument.Errorlist el : errors |
| | 131 | .getErrorlistArray()) { |
| | 132 | String lang = errors.getLang(); |
| | 133 | Result r = new Result(errors.getLang(), el.getUri()); |
| | 134 | for (org.w3.unicorn.observationresponse.ErrorDocument.Error e : el |
| | 135 | .getErrorArray()) { |
| | 136 | r.getErrors().add(swap(e, lang)); |
| | 137 | } |
| | 138 | res.addResult(r); |
| | 139 | } |
| | 140 | } |
| | 141 | |
| | 142 | org.w3.unicorn.observationresponse.InformationsDocument.Informations informations = result |
| | 143 | .getInformations(); |
| | 144 | if (informations != null && informations.getInfolistArray() != null) { |
| | 145 | String lang = informations.getLang(); |
| | 146 | for (org.w3.unicorn.observationresponse.InfolistDocument.Infolist il : informations |
| | 147 | .getInfolistArray()) { |
| | 148 | Result r = new Result(informations.getLang(), il.getUri()); |
| | 149 | for (org.w3.unicorn.observationresponse.InfoDocument.Info i : il |
| | 150 | .getInfoArray()) { |
| | 151 | r.getInfos().add(swap(i, lang)); |
| | 152 | } |
| | 153 | res.addResult(r); |
| | 154 | } |
| | 155 | } |
| | 156 | } |
| | 157 | |
| | 158 | return res; |
| | 159 | |
| | 160 | } |
| | 161 | |
| | 162 | /** |
| | 163 | * Creates and fills a Warning object from a warning in a response. |
| | 164 | * |
| | 165 | * @param x |
| | 166 | * The warning from the document. |
| | 167 | * @param lang |
| | 168 | * The language of the warning. |
| | 169 | * @return The resulting Warning object. |
| | 170 | */ |
| | 171 | private Warning swap( |
| | 172 | org.w3.unicorn.observationresponse.WarningDocument.Warning x, |
| | 173 | String lang) { |
| | 174 | Warning y = new Warning(); |
| | 175 | y.setLine(x.getLine()); |
| | 176 | y.setColumn(x.getColumn()); |
| | 177 | y.setContext(x.getContext()); |
| | 178 | y.setLevel(x.getLevel()); |
| | 179 | y.setMessage(swapListMessage(x.getMessageArray(), lang)); |
| | 180 | y.setLongmessage(swapListLongmessage(x.getLongmessageArray(), lang)); |
| | 181 | return y; |
| | 182 | } |
| | 183 | |
| | 184 | /** |
| | 185 | * Creates and fills a Error object from an error in a response. |
| | 186 | * |
| | 187 | * @param x |
| | 188 | * The error from the document. |
| | 189 | * @param lang |
| | 190 | * The language of the Error. |
| | 191 | * @return The resulting Error object. |
| | 192 | */ |
| | 193 | private Error swap( |
| | 194 | org.w3.unicorn.observationresponse.ErrorDocument.Error x, |
| | 195 | String lang) { |
| | 196 | Error y = new Error(); |
| | 197 | y.setLine(x.getLine()); |
| | 198 | y.setColumn(x.getColumn()); |
| | 199 | y.setErrortype(x.getErrortype()); |
| | 200 | y.setContext(x.getContext()); |
| | 201 | y.setMessage(swapListMessage(x.getMessageArray(), lang)); |
| | 202 | y.setLongmessage(swapListLongmessage(x.getLongmessageArray(), lang)); |
| | 203 | return y; |
| | 204 | } |
| | 205 | |
| | 206 | /** |
| | 207 | * Creates and fills a Info object from an info in a response. |
| | 208 | * |
| | 209 | * @param x |
| | 210 | * The info from the document. |
| | 211 | * @param lang |
| | 212 | * The language of the Info. |
| | 213 | * @return The resulting Info object. |
| | 214 | */ |
| | 215 | private Info swap(org.w3.unicorn.observationresponse.InfoDocument.Info x, |
| | 216 | String lang) { |
| | 217 | Info y = new Info(); |
| | 218 | y.setLine(x.getLine()); |
| | 219 | y.setColumn(x.getColumn()); |
| | 220 | y.setContext(x.getContext()); |
| | 221 | y.setMessage(swapListMessage(x.getMessageArray(), lang)); |
| | 222 | y.setLongmessage(swapListLongmessage(x.getLongmessageArray(), lang)); |
| | 223 | return y; |
| | 224 | } |
| | 225 | |
| | 226 | /** |
| | 227 | * Returns a list of localized strings from a list of simple strings. and a |
| | 228 | * given language. |
| | 229 | * |
| | 230 | * @param x |
| | 231 | * The list of strings. |
| | 232 | * @param lang |
| | 233 | * The language of the list. |
| 74 | | * Returns a list of localized objects from a list of simple objects |
| 75 | | * and a given language. |
| 76 | | * @param x The initial list of objects. |
| 77 | | * @param lang The language of the list. |
| 78 | | * @return The new list of localized objects. |
| 79 | | */ |
| 80 | | private List<Object> swap(List<Object> x, String lang) { |
| 81 | | List<Object> y = new ArrayList<Object>(); |
| 82 | | for (Object ox : x) { |
| 83 | | if (ox instanceof String) { |
| 84 | | String cox = (String) ox; |
| 85 | | LocalizedString coy = new LocalizedString(cox, lang); |
| 86 | | y.add(coy); |
| 87 | | } else if (ox instanceof org.w3.unicorn.observationresponse.ADocument.A) { |
| 88 | | org.w3.unicorn.observationresponse.ADocument.A cox = (org.w3.unicorn.observationresponse.ADocument.A) ox; |
| 89 | | A coy = new A(); |
| 90 | | coy.setHref(cox.getHref()); |
| 91 | | |
| 92 | | |
| 93 | | XmlCursor cursor=cox.newCursor(); |
| 94 | | //System.err.println("Debut"); |
| 95 | | //System.err.println(cursor.xmlText()); |
| 96 | | |
| 97 | | ArrayList<Object> listObj = new ArrayList<Object>(); |
| 98 | | |
| 99 | | while (cursor.hasNextToken()) { |
| 100 | | cursor.toNextToken(); |
| 101 | | //System.err.println(cursor.currentTokenType().intValue()==TokenType.INT_END); |
| 102 | | Object current = cursor.getObject(); |
| 103 | | if(current!=null) { |
| 104 | | //System.err.println(current.getClass()); |
| 105 | | |
| 106 | | if (current.getClass()== |
| 107 | | org.w3.unicorn.observationresponse.impl.LongmessageDocumentImpl.LongmessageImpl.class) { |
| 108 | | break; |
| 109 | | } |
| 110 | | // Case : A |
| 111 | | if (current.getClass()== |
| 112 | | org.w3.unicorn.observationresponse.impl.ADocumentImpl.AImpl.class) { |
| 113 | | org.w3.unicorn.observationresponse.ADocument.A |
| 114 | | a = (org.w3.unicorn.observationresponse.ADocument.A) current; |
| 115 | | listObj.add(a); |
| 116 | | //We skip 3 tokens to forget about the inner text in the A tag. |
| 117 | | //We don't want it in the object list |
| 118 | | cursor.toNextToken(); |
| 119 | | cursor.toNextToken(); |
| 120 | | cursor.toNextToken(); |
| 121 | | } |
| 122 | | // Case : Code |
| 123 | | if (current.getClass()== |
| 124 | | org.w3.unicorn.observationresponse.impl.CodeDocumentImpl.CodeImpl.class) { |
| 125 | | org.w3.unicorn.observationresponse.CodeDocument.Code code=(org.w3.unicorn.observationresponse.CodeDocument.Code) current; |
| 126 | | |
| 127 | | listObj.add(code); |
| 128 | | } |
| 129 | | // Case : Img |
| 130 | | if (current.getClass()== |
| 131 | | org.w3.unicorn.observationresponse.impl.ImgDocumentImpl.ImgImpl.class) { |
| 132 | | org.w3.unicorn.observationresponse.ImgDocument.Img |
| 133 | | img = (org.w3.unicorn.observationresponse.ImgDocument.Img) current; |
| 134 | | listObj.add(img); |
| 135 | | } |
| 136 | | } |
| 137 | | else if(cursor.isText()){ |
| 138 | | listObj.add(cursor.getTextValue()); |
| 139 | | } |
| 140 | | |
| 141 | | } |
| 142 | | coy.setContent(swap(listObj, lang)); |
| 143 | | y.add(coy); |
| 144 | | |
| 145 | | } else if (ox instanceof org.w3.unicorn.observationresponse.CodeDocument.Code) { |
| 146 | | org.w3.unicorn.observationresponse.CodeDocument.Code cox = (org.w3.unicorn.observationresponse.CodeDocument.Code) ox; |
| 147 | | Code coy = new Code(); |
| 148 | | |
| 149 | | |
| 150 | | XmlCursor cursor=cox.newCursor(); |
| 151 | | //System.err.println("Debut"); |
| 152 | | //System.err.println(cursor.xmlText()); |
| 153 | | |
| 154 | | ArrayList<Object> listObj = new ArrayList<Object>(); |
| 155 | | |
| 156 | | while (cursor.hasNextToken()) { |
| 157 | | cursor.toNextToken(); |
| 158 | | //System.err.println(cursor.currentTokenType().intValue()==TokenType.INT_END); |
| 159 | | Object current = cursor.getObject(); |
| 160 | | if(current!=null) { |
| 161 | | //System.err.println(current.getClass()); |
| 162 | | |
| 163 | | if (current.getClass()== |
| 164 | | org.w3.unicorn.observationresponse.impl.LongmessageDocumentImpl.LongmessageImpl.class) { |
| 165 | | break; |
| 166 | | } |
| 167 | | // Case : A |
| 168 | | if (current.getClass()== |
| 169 | | org.w3.unicorn.observationresponse.impl.ADocumentImpl.AImpl.class) { |
| 170 | | org.w3.unicorn.observationresponse.ADocument.A |
| 171 | | a = (org.w3.unicorn.observationresponse.ADocument.A) current; |
| 172 | | listObj.add(a); |
| 173 | | // We skip 3 tokens to forget about the inner text in the A tag. |
| 174 | | //We don't want it in the object list |
| 175 | | cursor.toNextToken(); |
| 176 | | cursor.toNextToken(); |
| 177 | | cursor.toNextToken(); |
| 178 | | } |
| 179 | | // Case : Code |
| 180 | | if (current.getClass()== |
| 181 | | org.w3.unicorn.observationresponse.impl.CodeDocumentImpl.CodeImpl.class) { |
| 182 | | org.w3.unicorn.observationresponse.CodeDocument.Code code=(org.w3.unicorn.observationresponse.CodeDocument.Code) current; |
| 183 | | |
| 184 | | listObj.add(code); |
| 185 | | } |
| 186 | | // Case : Img |
| 187 | | if (current.getClass()== |
| 188 | | org.w3.unicorn.observationresponse.impl.ImgDocumentImpl.ImgImpl.class) { |
| 189 | | org.w3.unicorn.observationresponse.ImgDocument.Img |
| 190 | | img = (org.w3.unicorn.observationresponse.ImgDocument.Img) current; |
| 191 | | listObj.add(img); |
| 192 | | } |
| 193 | | } |
| 194 | | else if(cursor.isText()){ |
| 195 | | listObj.add(cursor.getTextValue()); |
| 196 | | } |
| 197 | | |
| 198 | | } |
| 199 | | |
| 200 | | |
| 201 | | coy.setContent(swap(listObj, lang)); |
| 202 | | y.add(coy); |
| 203 | | } else if (ox instanceof org.w3.unicorn.observationresponse.ImgDocument.Img) { |
| 204 | | org.w3.unicorn.observationresponse.ImgDocument.Img cox = (org.w3.unicorn.observationresponse.ImgDocument.Img) ox; |
| 205 | | Img coy = new Img(); |
| 206 | | coy.setAlt(cox.getAlt()); |
| 207 | | coy.setHeight(cox.getHeight()); |
| 208 | | coy.setLongdesc(cox.getLongdesc()); |
| 209 | | coy.setName(cox.getName()); |
| 210 | | coy.setSrc(cox.getSrc()); |
| 211 | | coy.setWidth(cox.getWidth()); |
| 212 | | y.add(coy); |
| 213 | | } |
| 214 | | } |
| 215 | | return y; |
| 216 | | } |
| 217 | | |
| 218 | | /** |
| 219 | | * Swaps a message : returns the result with the corresponding language. |
| 220 | | * @param x The message to swap. |
| 221 | | * @param lang The language of the message. |
| 222 | | * @return The swapped message. |
| 223 | | */ |
| 224 | | private Longmessage swap( |
| 225 | | org.w3.unicorn.observationresponse.LongmessageDocument.Longmessage x, |
| 226 | | String lang) { |
| 227 | | Longmessage y = new Longmessage(); |
| 228 | | XmlCursor cursor=x.newCursor(); |
| 229 | | //System.err.println("Debut"); |
| 230 | | //System.err.println(cursor.xmlText()); |
| 231 | | |
| 232 | | ArrayList<Object> listObj = new ArrayList<Object>(); |
| 233 | | |
| 234 | | while (cursor.hasNextToken()) { |
| 235 | | cursor.toNextToken(); |
| 236 | | //System.err.println(cursor.currentTokenType().intValue()==TokenType.INT_END); |
| 237 | | Object current = cursor.getObject(); |
| 238 | | if(current!=null) { |
| 239 | | //System.err.println(current.getClass()); |
| 240 | | |
| 241 | | if (current.getClass()== |
| 242 | | org.w3.unicorn.observationresponse.impl.LongmessageDocumentImpl.LongmessageImpl.class) { |
| 243 | | break; |
| 244 | | } |
| 245 | | // Case : A |
| 246 | | if (current.getClass()== |
| 247 | | org.w3.unicorn.observationresponse.impl.ADocumentImpl.AImpl.class) { |
| 248 | | org.w3.unicorn.observationresponse.ADocument.A |
| 249 | | a = (org.w3.unicorn.observationresponse.ADocument.A) current; |
| 250 | | listObj.add(a); |
| 251 | | //We skip 3 tokens to forget about the inner text in the A tag. |
| 252 | | //We don't want it in the object list |
| 253 | | cursor.toNextToken(); |
| 254 | | cursor.toNextToken(); |
| 255 | | cursor.toNextToken(); |
| 256 | | } |
| 257 | | // Case : Code |
| 258 | | if (current.getClass()== |
| 259 | | org.w3.unicorn.observationresponse.impl.CodeDocumentImpl.CodeImpl.class) { |
| 260 | | org.w3.unicorn.observationresponse.CodeDocument.Code code=(org.w3.unicorn.observationresponse.CodeDocument.Code) current; |
| 261 | | |
| 262 | | listObj.add(code); |
| 263 | | } |
| 264 | | // Case : Img |
| 265 | | if (current.getClass()== |
| 266 | | org.w3.unicorn.observationresponse.impl.ImgDocumentImpl.ImgImpl.class) { |
| 267 | | org.w3.unicorn.observationresponse.ImgDocument.Img |
| 268 | | img = (org.w3.unicorn.observationresponse.ImgDocument.Img) current; |
| 269 | | listObj.add(img); |
| 270 | | } |
| 271 | | } |
| 272 | | else if(cursor.isText()){ |
| 273 | | listObj.add(cursor.getTextValue()); |
| 274 | | } |
| 275 | | |
| 276 | | } |
| 277 | | |
| 278 | | //System.err.println("List : " + listObj); |
| 279 | | //System.err.println("Fin"); |
| 280 | | |
| 281 | | y.setContent(swap(listObj, lang)); |
| 282 | | return y; |
| 283 | | } |
| 284 | | |
| 285 | | /** |
| 286 | | * Returns a list of localized messages from a list of simple messages |
| 287 | | * and a given language. |
| 288 | | * @param x The list of messages. |
| 289 | | * @param lang The language of the list. |
| 290 | | * @return The new list of localized messages. |
| | 247 | * Returns a list of Longmessage objects from a list of longmessage in a |
| | 248 | * response. and a given language. |
| | 249 | * |
| | 250 | * @param x |
| | 251 | * The list of longmessage. |
| | 252 | * @param lang |
| | 253 | * The language of the list. |
| | 254 | * @return The list of Longmessage objects. |
| 305 | | * Swaps a warning : returns the result with the corresponding language. |
| 306 | | * @param x The warning to swap. |
| 307 | | * @param lang The language of the warning. |
| 308 | | * @return The swapped warning. |
| 309 | | */ |
| 310 | | private Warning swap( |
| 311 | | org.w3.unicorn.observationresponse.WarningDocument.Warning x, String lang) { |
| 312 | | Warning y = new Warning(); |
| 313 | | y.setLine(x.getLine()); |
| 314 | | y.setColumn(x.getColumn()); |
| 315 | | y.setContext(x.getContext()); |
| 316 | | y.setLevel(x.getLevel()); |
| 317 | | y.setMessage(swapListMessage(x.getMessageArray(), lang)); |
| 318 | | y.setLongmessage(swapListLongmessage(x.getLongmessageArray(), lang)); |
| 319 | | return y; |
| 320 | | } |
| 321 | | |
| 322 | | /** |
| 323 | | * Swaps an error : returns the result with the corresponding language. |
| 324 | | * @param x The error to swap. |
| 325 | | * @param lang The language of the error. |
| 326 | | * @return The swapped error. |
| 327 | | */ |
| 328 | | private Error swap(org.w3.unicorn.observationresponse.ErrorDocument.Error x, |
| | 269 | * Creates and fills a Longmessage object from a longmessage in a response. |
| | 270 | * |
| | 271 | * @param x |
| | 272 | * The info document. |
| | 273 | * @param lang |
| | 274 | * The language of the Info. |
| | 275 | * @return The resulting Info object. |
| | 276 | */ |
| | 277 | private Longmessage swap( |
| | 278 | org.w3.unicorn.observationresponse.LongmessageDocument.Longmessage x, |
| 330 | | Error y = new Error(); |
| 331 | | y.setLine(x.getLine()); |
| 332 | | y.setColumn(x.getColumn()); |
| 333 | | y.setErrortype(x.getErrortype()); |
| 334 | | y.setContext(x.getContext()); |
| 335 | | y.setMessage(swapListMessage(x.getMessageArray(), lang)); |
| 336 | | y.setLongmessage(swapListLongmessage(x.getLongmessageArray(), lang)); |
| 337 | | return y; |
| 338 | | } |
| 339 | | |
| 340 | | /** |
| 341 | | * Swaps an info : returns the result with the corresponding language. |
| 342 | | * @param x The info to swap. |
| 343 | | * @param lang The language of the info. |
| 344 | | * @return The swapped info. |
| 345 | | */ |
| 346 | | private Info swap(org.w3.unicorn.observationresponse.InfoDocument.Info x, |
| 347 | | String lang) { |
| 348 | | Info y = new Info(); |
| 349 | | y.setLine(x.getLine()); |
| 350 | | y.setColumn(x.getColumn()); |
| 351 | | y.setContext(x.getContext()); |
| 352 | | y.setMessage(swapListMessage(x.getMessageArray(), lang)); |
| 353 | | y.setLongmessage(swapListLongmessage(x.getLongmessageArray(), lang)); |
| 354 | | return y; |
| 355 | | } |
| 356 | | |
| 357 | | /** |
| 358 | | * Swaps a response : returns the result with the corresponding language. |
| 359 | | * @param x The response to swap. |
| 360 | | * @param lang The language of the response. |
| 361 | | * @return The swapped response. |
| 362 | | */ |
| 363 | | private Response swap(org.w3.unicorn.observationresponse.ObservationresponseDocument ord) { |
| 364 | | Response res = new Response(); |
| 365 | | org.w3.unicorn.observationresponse.ObservationresponseDocument.Observationresponse or=ord.getObservationresponse(); |
| 366 | | res.setUri(or.getUri()); |
| 367 | | res.setCheckedby(or.getCheckedby()); |
| 368 | | res.setVersion(or.getVersion()); |
| 369 | | XMLGregorianCalendar xmlGregorianCalendar; |
| 370 | | if (or.getDate()!=null) |
| 371 | | try { |
| 372 | | xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar((GregorianCalendar)or.getDate()); |
| 373 | | or.setDate(Calendar.getInstance()); |
| 374 | | res.setDate(xmlGregorianCalendar); |
| 375 | | } catch (DatatypeConfigurationException e) { |
| 376 | | e.printStackTrace(); |
| 377 | | logger.error("DatatypeConfigurationException erreur de date : " + e.getMessage(), e); |
| 378 | | return null; |
| | 280 | Longmessage y = new Longmessage(); |
| | 281 | y.setLang(lang); |
| | 282 | List<Object> list = new ArrayList<Object>(); |
| | 283 | list = swapObj(x, lang); |
| | 284 | y.setContent(list); |
| | 285 | return y; |
| | 286 | |
| | 287 | } |
| | 288 | |
| | 289 | /** |
| | 290 | * Parses an Xml extract corresponding to an object and returns its content. |
| | 291 | * |
| | 292 | * @param obj The xml extract. |
| | 293 | * @param lang The language of the document. |
| | 294 | * @return The content of the XmlObject. |
| | 295 | */ |
| | 296 | private List<Object> swapObj(XmlObject obj, String lang) { |
| | 297 | List<Object> list = new ArrayList<Object>(); |
| | 298 | XmlCursor cursor = obj.newCursor(); |
| | 299 | int count = 0; |
| | 300 | cursor.toNextToken(); |
| | 301 | |
| | 302 | while (cursor.hasNextToken()) { |
| | 303 | |
| | 304 | if (cursor.isStart()) { |
| | 305 | System.out.println("start"); |
| | 306 | count++; |
| | 307 | XmlObject current = cursor.getObject(); |
| | 308 | |
| | 309 | // Should be useless |
| | 310 | if (current instanceof org.w3.unicorn.observationresponse.impl.LongmessageDocumentImpl.LongmessageImpl |
| | 311 | || current instanceof org.w3.unicorn.observationresponse.impl.InfoDocumentImpl.InfoImpl) { |
| | 312 | |
| | 313 | break; |
| | 314 | } |
| | 315 | |
| | 316 | // Case : A |
| | 317 | else if (current instanceof org.w3.unicorn.observationresponse.impl.ADocumentImpl.AImpl) { |
| | 318 | org.w3.unicorn.observationresponse.ADocument.A a = (org.w3.unicorn.observationresponse.ADocument.A) current; |
| | 319 | |
| | 320 | A coy = new A(); |
| | 321 | List<Object> content = new ArrayList<Object>(); |
| | 322 | |
| | 323 | coy.setHref(a.getHref()); |
| | 324 | |
| | 325 | content = swapObj(current, lang); |
| | 326 | coy.setContent(content); |
| | 327 | list.add(coy); |
| | 328 | |
| | 329 | for (Object o : content) { |
| | 330 | if (o instanceof Inline) |
| | 331 | count++; |
| | 332 | } |
| | 333 | |
| | 334 | cursor.toEndToken(); |
| | 335 | |
| | 336 | } |
| | 337 | // Case : Code |
| | 338 | else if (current instanceof org.w3.unicorn.observationresponse.impl.CodeDocumentImpl.CodeImpl) { |
| | 339 | org.w3.unicorn.observationresponse.CodeDocument.Code code = (org.w3.unicorn.observationresponse.CodeDocument.Code) current; |
| | 340 | Code coy = new Code(); |
| | 341 | List<Object> content = new ArrayList<Object>(); |
| | 342 | content = swapObj(current, lang); |
| | 343 | coy.setContent(content); |
| | 344 | list.add(coy); |
| | 345 | for (Object o : content) { |
| | 346 | if (o instanceof Inline) |
| | 347 | count++; |
| | 348 | } |
| | 349 | cursor.toEndToken(); |
| | 350 | |
| | 351 | } |
| | 352 | // Case : Img |
| | 353 | else if (current instanceof org.w3.unicorn.observationresponse.impl.ImgDocumentImpl.ImgImpl) { |
| | 354 | org.w3.unicorn.observationresponse.ImgDocument.Img img = (org.w3.unicorn.observationresponse.ImgDocument.Img) current; |
| | 355 | Img coy = new Img(); |
| | 356 | coy.setAlt(img.getAlt()); |
| | 357 | coy.setHeight(img.getHeight()); |
| | 358 | coy.setLongdesc(img.getLongdesc()); |
| | 359 | coy.setName(img.getName()); |
| | 360 | coy.setSrc(img.getSrc()); |
| | 361 | coy.setWidth(img.getWidth()); |
| | 362 | list.add(coy); |
| | 363 | |
| | 364 | cursor.toEndToken(); |
| | 365 | |
| | 366 | } |
| | 367 | |
| | 368 | // If the class is not recognized, we check the name |
| | 369 | |
| | 370 | // Case : A |
| | 371 | else if (cursor.getName().toString().equals( |
| | 372 | "{http://www.w3.org/unicorn/observationresponse}a")) { |
| | 373 | A coy = new A(); |
| | 374 | |
| | 375 | List<Object> content = new ArrayList<Object>(); |
| | 376 | |
| | 377 | cursor.toNextToken(); |
| | 378 | coy.setHref(cursor.getTextValue()); |
| | 379 | cursor.toPrevToken(); |
| | 380 | cursor.toNextAttribute(); |
| | 381 | content = swapObj(current, lang); |
| | 382 | coy.setContent(content); |
| | 383 | list.add(coy); |
| | 384 | |
| | 385 | for (Object o : content) { |
| | 386 | if (o instanceof Inline) |
| | 387 | count++; |
| | 388 | } |
| | 389 | |
| | 390 | cursor.toEndToken(); |
| | 391 | |
| | 392 | |
| | 393 | } |
| | 394 | |
| | 395 | // Case : Code |
| | 396 | else if (cursor.getName().toString().equals( |
| | 397 | "{http://www.w3.org/unicorn/observationresponse}code")) { |
| | 398 | Code coy = new Code(); |
| | 399 | List<Object> content = new ArrayList<Object>(); |
| | 400 | content = swapObj(current, lang); |
| | 401 | coy.setContent(content); |
| | 402 | list.add(coy); |
| | 403 | for (Object o : content) { |
| | 404 | if (o instanceof Inline) |
| | 405 | count++; |
| | 406 | } |
| | 407 | cursor.toEndToken(); |
| | 408 | } |
| | 409 | |
| | 410 | // Case : Img |
| | 411 | else if (cursor.getName().toString().equals( |
| | 412 | "{http://www.w3.org/unicorn/observationresponse}img")) { |
| | 413 | org.w3.unicorn.observationresponse.ImgDocument.Img img = (org.w3.unicorn.observationresponse.ImgDocument.Img) current; |
| | 414 | Img coy = new Img(); |
| | 415 | coy.setAlt(img.getAlt()); |
| | 416 | coy.setHeight(img.getHeight()); |
| | 417 | coy.setLongdesc(img.getLongdesc()); |
| | 418 | coy.setName(img.getName()); |
| | 419 | coy.setSrc(img.getSrc()); |
| | 420 | coy.setWidth(img.getWidth()); |
| | 421 | list.add(coy); |
| | 422 | |
| | 423 | cursor.toEndToken(); |
| | 424 | } |
| | 425 | |
| | 426 | |
| | 427 | // We still want to append what's inside a block even if the block's unknown |
| | 428 | else { |
| | 429 | list.addAll(swapObj(current,lang)); |
| | 430 | cursor.toEndToken(); |
| | 431 | } |
| | 432 | } |
| | 433 | |
| | 434 | else if (cursor.isText()) { |
| | 435 | LocalizedString ls = new LocalizedString(cursor.getChars(), |
| | 436 | lang); |
| | 437 | list.add(ls); |
| | 438 | } |
| | 439 | |
| | 440 | else if (cursor.isEnd()) { |
| | 441 | count--; |
| | 442 | if (count < 0) |
| | 443 | break; |
| | 444 | } |
| | 445 | |
| | 446 | cursor.toNextToken(); |
| 380 | | |
| 381 | | res.setPassed(or.getPassed()); |
| 382 | | |
| 383 | | // Fill res.result |
| 384 | | org.w3.unicorn.observationresponse.ResultDocument.Result rrr = or.getResult(); |
| 385 | | if (rrr != null) { |
| 386 | | org.w3.unicorn.observationresponse.WarningsDocument.Warnings warnings = rrr.getWarnings(); |
| 387 | | if (warnings != null && warnings.getWarninglistArray() != null) { |
| 388 | | for (org.w3.unicorn.observationresponse.WarninglistDocument.Warninglist wl : warnings.getWarninglistArray()) { |
| 389 | | String lang = warnings.getLang(); |
| 390 | | Result r = new Result(lang, wl.getUri()); |
| 391 | | for (org.w3.unicorn.observationresponse.WarningDocument.Warning w : wl.getWarningArray()) { |
| 392 | | r.getWarnings().add(swap(w, lang)); |
| 393 | | } |
| 394 | | res.addResult(r); |
| 395 | | } |
| 396 | | } |
| 397 | | |
| 398 | | org.w3.unicorn.observationresponse.ErrorsDocument.Errors errors = rrr.getErrors(); |
| 399 | | if (errors != null && errors.getErrorlistArray() != null) { |
| 400 | | for (org.w3.unicorn.observationresponse.ErrorlistDocument.Errorlist wl : errors.getErrorlistArray()) { |
| 401 | | String lang = errors.getLang(); |
| 402 | | Result r = new Result(errors.getLang(), wl.getUri()); |
| 403 | | for (org.w3.unicorn.observationresponse.ErrorDocument.Error w : wl |
| 404 | | .getErrorArray()) { |
| 405 | | r.getErrors().add(swap(w, lang)); |
| 406 | | } |
| 407 | | res.addResult(r); |
| 408 | | } |
| 409 | | } |
| 410 | | |
| 411 | | org.w3.unicorn.observationresponse.InformationsDocument.Informations informations = rrr.getInformations(); |
| 412 | | if (informations != null && informations.getInfolistArray() != null) { |
| 413 | | String lang = informations.getLang(); |
| 414 | | for (org.w3.unicorn.observationresponse.InfolistDocument.Infolist wl : informations.getInfolistArray()) { |
| 415 | | Result r = new Result(informations.getLang(), wl.getUri()); |
| 416 | | for (org.w3.unicorn.observationresponse.InfoDocument.Info w : wl |
| 417 | | .getInfoArray()) { |
| 418 | | r.getInfos().add(swap(w, lang)); |
| 419 | | } |
| 420 | | res.addResult(r); |
| 421 | | } |
| 422 | | } |
| 423 | | } |
| 424 | | |
| 425 | | return res; |
| | 448 | |
| | 449 | cursor.dispose(); |
| | 450 | return list; |