1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 19 package complex.sfx2; 20 21 import static org.junit.Assert.assertNotNull; 22 import static org.junit.Assert.assertTrue; 23 import static org.junit.Assert.fail; 24 import helper.StreamSimulator; 25 26 import lib.TestParameters; 27 28 import org.junit.After; 29 import org.junit.AfterClass; 30 import org.junit.Before; 31 import org.junit.BeforeClass; 32 import org.junit.Test; 33 import org.openoffice.test.OfficeConnection; 34 35 import com.sun.star.beans.Pair; 36 import com.sun.star.beans.PropertyValue; 37 import com.sun.star.beans.StringPair; 38 import com.sun.star.beans.XPropertySet; 39 import com.sun.star.container.XEnumeration; 40 import com.sun.star.container.XEnumerationAccess; 41 import com.sun.star.frame.XStorable; 42 import com.sun.star.io.XInputStream; 43 import com.sun.star.lang.IllegalArgumentException; 44 import com.sun.star.lang.XComponent; 45 import com.sun.star.lang.XMultiServiceFactory; 46 import com.sun.star.lang.XServiceInfo; 47 import com.sun.star.rdf.BlankNode; 48 import com.sun.star.rdf.FileFormat; 49 import com.sun.star.rdf.Literal; 50 import com.sun.star.rdf.Statement; 51 import com.sun.star.rdf.URI; 52 import com.sun.star.rdf.URIs; 53 import com.sun.star.rdf.XBlankNode; 54 import com.sun.star.rdf.XDocumentMetadataAccess; 55 import com.sun.star.rdf.XDocumentRepository; 56 import com.sun.star.rdf.XLiteral; 57 import com.sun.star.rdf.XMetadatable; 58 import com.sun.star.rdf.XNamedGraph; 59 import com.sun.star.rdf.XNode; 60 import com.sun.star.rdf.XQuerySelectResult; 61 import com.sun.star.rdf.XRepository; 62 import com.sun.star.rdf.XRepositorySupplier; 63 import com.sun.star.rdf.XURI; 64 import com.sun.star.text.XText; 65 import com.sun.star.text.XTextDocument; 66 import com.sun.star.text.XTextRange; 67 import com.sun.star.uno.UnoRuntime; 68 import com.sun.star.uno.XComponentContext; 69 import com.sun.star.util.XCloseable; 70 import complex.sfx2.tools.TestDocument; 71 72 /** 73 * Test case for interface com.sun.star.rdf.XDocumentMetadataAccess 74 * Currently, this service is implemented in 75 * sfx2/source/doc/DocumentMetadataAccess.cxx 76 * 77 * Actually, this is not a service, so we need to create a document and 78 * go from there... 79 * 80 */ 81 public class DocumentMetadataAccess 82 { 83 XMultiServiceFactory xMSF; 84 XComponentContext xContext; 85 String tempDir; 86 87 String nsRDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; 88 String nsRDFS = "http://www.w3.org/2000/01/rdf-schema#"; 89 String nsPkg="http://docs.oasis-open.org/opendocument/meta/package/common#"; 90 String nsODF ="http://docs.oasis-open.org/opendocument/meta/package/odf#"; 91 92 XURI foo; 93 XURI bar; 94 XURI baz; 95 96 static XURI rdf_type; 97 static XURI rdfs_label; 98 static XURI pkg_Document; 99 static XURI pkg_hasPart; 100 static XURI pkg_MetadataFile; 101 static XURI odf_ContentFile; 102 static XURI odf_StylesFile; 103 static XURI odf_Element; 104 static XBlankNode blank1; 105 static XBlankNode blank2; 106 static XBlankNode blank3; 107 static XBlankNode blank4; 108 static String manifestPath = "manifest.rdf"; 109 static String contentPath = "content.xml"; 110 static String stylesPath = "styles.xml"; 111 static String fooPath = "foo.rdf"; 112 static String fooBarPath = "meta/foo/bar.rdf"; 113 114 XRepository xRep; 115 XRepositorySupplier xRS; 116 XDocumentMetadataAccess xDMA; 117 118 /** 119 * The test parameters 120 */ 121 private static TestParameters param = null; 122 before()123 @Before public void before() throws Exception 124 { 125 xMSF = getMSF(); 126 param = new TestParameters(); 127 param.put("ServiceFactory", xMSF); // important for param.getMSF() 128 129 assertNotNull("could not create MultiServiceFactory.", xMSF); 130 XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xMSF); 131 Object defaultCtx = xPropertySet.getPropertyValue("DefaultContext"); 132 xContext = UnoRuntime.queryInterface(XComponentContext.class, defaultCtx); 133 assertNotNull("could not get component context.", xContext); 134 135 tempDir = util.utils.getOfficeTemp/*Dir*/(xMSF); 136 System.out.println("tempdir: " + tempDir); 137 138 foo = URI.create(xContext, "uri:foo"); 139 assertNotNull("foo", foo); 140 bar = URI.create(xContext, "uri:bar"); 141 assertNotNull("bar", bar); 142 baz = URI.create(xContext, "uri:baz"); 143 assertNotNull("baz", baz); 144 145 blank1 = BlankNode.create(xContext, "_:1"); 146 assertNotNull("blank1", blank1); 147 blank2 = BlankNode.create(xContext, "_:2"); 148 assertNotNull("blank2", blank2); 149 blank3 = BlankNode.create(xContext, "_:3"); 150 assertNotNull("blank3", blank3); 151 blank4 = BlankNode.create(xContext, "_:4"); 152 assertNotNull("blank4", blank4); 153 rdf_type = URI.createKnown(xContext, URIs.RDF_TYPE); 154 assertNotNull("rdf_type", rdf_type); 155 rdfs_label = URI.createKnown(xContext, URIs.RDFS_LABEL); 156 assertNotNull("rdfs_label", rdfs_label); 157 pkg_Document = URI.createKnown(xContext, URIs.PKG_DOCUMENT); 158 assertNotNull("pkg_Document", pkg_Document); 159 pkg_hasPart = URI.createKnown(xContext, URIs.PKG_HASPART); 160 assertNotNull("pkg_hasPart", pkg_hasPart); 161 pkg_MetadataFile = URI.createKnown(xContext, URIs.PKG_METADATAFILE); 162 assertNotNull("pkg_MetadataFile", pkg_MetadataFile); 163 odf_ContentFile = URI.createKnown(xContext, URIs.ODF_CONTENTFILE); 164 assertNotNull("odf_ContentFile", odf_ContentFile); 165 odf_StylesFile = URI.createKnown(xContext, URIs.ODF_STYLESFILE); 166 assertNotNull("odf_StylesFile", odf_StylesFile); 167 odf_Element = URI.createKnown(xContext, URIs.ODF_ELEMENT); 168 assertNotNull("odf_Element", odf_Element); 169 } 170 after()171 @After public void after() 172 { 173 xRep = null; 174 xRS = null; 175 xDMA = null; 176 } 177 check()178 @Test public void check() throws Exception 179 { 180 XComponent xComp = null; 181 XComponent xComp2 = null; 182 try { 183 XEnumeration xStmtsEnum; 184 XNamedGraph xManifest; 185 186 System.out.println("Creating document with Repository..."); 187 188 // we cannot create a XDMA directly, we must create 189 // a document and get it from there :( 190 // create document 191 PropertyValue[] loadProps = new PropertyValue[1]; 192 loadProps[0] = new PropertyValue(); 193 loadProps[0].Name = "Hidden"; 194 loadProps[0].Value = true; 195 xComp = util.DesktopTools.openNewDoc(xMSF, "swriter", loadProps); 196 XTextDocument xText = UnoRuntime.queryInterface(XTextDocument.class, xComp); 197 198 XRepositorySupplier xRepoSupplier = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp); 199 assertNotNull("xRS null", xRepoSupplier); 200 XDocumentMetadataAccess xDocMDAccess = UnoRuntime.queryInterface(XDocumentMetadataAccess.class, xRepoSupplier); 201 assertNotNull("xDMA null", xDocMDAccess); 202 xRep = xRepoSupplier.getRDFRepository(); 203 assertNotNull("xRep null", xRep); 204 205 System.out.println("...done"); 206 207 System.out.println("Checking that new repository is initialized..."); 208 209 XURI xBaseURI = xDocMDAccess; 210 String baseURI = xBaseURI.getStringValue(); 211 assertNotNull("new: baseURI", xBaseURI ); 212 assertTrue("new: baseURI", !xBaseURI.getStringValue().equals("")); 213 214 assertTrue("new: # graphs", 1 == xRep.getGraphNames().length); 215 XURI manifest = URI.createNS(xContext, xBaseURI.getStringValue(), 216 manifestPath); 217 xManifest = xRep.getGraph(manifest); 218 assertTrue("new: manifest graph", null != xManifest); 219 220 Statement[] manifestStmts = getManifestStmts(xBaseURI); 221 xStmtsEnum = xRep.getStatements(null, null, null); 222 assertTrue("new: manifest graph", eq(xStmtsEnum, manifestStmts)); 223 224 System.out.println("...done"); 225 226 System.out.println("Checking some invalid args..."); 227 228 String content = "behold, for I am the content."; 229 new TestRange(content); 230 231 try { 232 xDocMDAccess.getElementByURI(null); 233 fail("getElementByURI: null allowed"); 234 } catch (IllegalArgumentException e) { 235 // ignore 236 } 237 try { 238 xDocMDAccess.getMetadataGraphsWithType(null); 239 fail("getMetadataGraphsWithType: null URI allowed"); 240 } catch (IllegalArgumentException e) { 241 // ignore 242 } 243 try { 244 xDocMDAccess.addMetadataFile("", new XURI[0]); 245 fail("addMetadataFile: empty filename allowed"); 246 } catch (IllegalArgumentException e) { 247 // ignore 248 } 249 try { 250 xDocMDAccess.addMetadataFile("/foo", new XURI[0]); 251 fail("addMetadataFile: absolute filename allowed"); 252 } catch (IllegalArgumentException e) { 253 // ignore 254 } 255 try { 256 xDocMDAccess.addMetadataFile("fo\"o", new XURI[0]); 257 fail("addMetadataFile: invalid filename allowed"); 258 } catch (IllegalArgumentException e) { 259 // ignore 260 } 261 try { 262 xDocMDAccess.addMetadataFile("../foo", new XURI[0]); 263 fail("addMetadataFile: filename with .. allowed"); 264 } catch (IllegalArgumentException e) { 265 // ignore 266 } 267 try { 268 xDocMDAccess.addMetadataFile("foo/../../bar", new XURI[0]); 269 fail("addMetadataFile: filename with nest .. allowed"); 270 } catch (IllegalArgumentException e) { 271 // ignore 272 } 273 try { 274 xDocMDAccess.addMetadataFile("foo/././bar", new XURI[0]); 275 fail("addMetadataFile: filename with nest . allowed"); 276 } catch (IllegalArgumentException e) { 277 // ignore 278 } 279 try { 280 xDocMDAccess.addMetadataFile("content.xml", new XURI[0]); 281 fail("addMetadataFile: content.xml allowed"); 282 } catch (IllegalArgumentException e) { 283 // ignore 284 } 285 try { 286 xDocMDAccess.addMetadataFile("styles.xml", new XURI[0]); 287 fail("addMetadataFile: styles.xml allowed"); 288 } catch (IllegalArgumentException e) { 289 // ignore 290 } 291 try { 292 xDocMDAccess.addMetadataFile("meta.xml", new XURI[0]); 293 fail("addMetadataFile: meta.xml allowed"); 294 } catch (IllegalArgumentException e) { 295 // ignore 296 } 297 try { 298 xDocMDAccess.addMetadataFile("settings.xml", new XURI[0]); 299 fail("addMetadataFile: settings.xml allowed"); 300 } catch (IllegalArgumentException e) { 301 // ignore 302 } 303 try { 304 xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, null, "foo", 305 foo, new XURI[0]); 306 fail("importMetadataFile: null stream allowed"); 307 } catch (IllegalArgumentException e) { 308 // ignore 309 } 310 311 final String sEmptyRDF = TestDocument.getUrl("empty.rdf"); 312 try { 313 XInputStream xFooIn = new StreamSimulator(sEmptyRDF, true, param); 314 xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, xFooIn, "", 315 foo, new XURI[0]); 316 fail("importMetadataFile: empty filename allowed"); 317 } catch (IllegalArgumentException e) { 318 // ignore 319 } 320 try { 321 XInputStream xFooIn = 322 new StreamSimulator(sEmptyRDF, true, param); 323 xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, xFooIn, "meta.xml", 324 foo, new XURI[0]); 325 fail("importMetadataFile: meta.xml filename allowed"); 326 } catch (IllegalArgumentException e) { 327 // ignore 328 } 329 try { 330 XInputStream xFooIn = 331 new StreamSimulator(sEmptyRDF, true, param); 332 xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, 333 xFooIn, "foo", null, new XURI[0]); 334 fail("importMetadataFile: null base URI allowed"); 335 } catch (IllegalArgumentException e) { 336 // ignore 337 } 338 try { 339 XInputStream xFooIn = 340 new StreamSimulator(sEmptyRDF, true, param); 341 xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, 342 xFooIn, "foo", rdf_type, new XURI[0]); 343 fail("importMetadataFile: non-absolute base URI allowed"); 344 } catch (IllegalArgumentException e) { 345 // ignore 346 } 347 try { 348 xDocMDAccess.removeMetadataFile(null); 349 fail("removeMetadataFile: null URI allowed"); 350 } catch (IllegalArgumentException e) { 351 // ignore 352 } 353 try { 354 xDocMDAccess.addContentOrStylesFile(""); 355 fail("addContentOrStylesFile: empty filename allowed"); 356 } catch (IllegalArgumentException e) { 357 // ignore 358 } 359 try { 360 xDocMDAccess.addContentOrStylesFile("/content.xml"); 361 fail("addContentOrStylesFile: absolute filename allowed"); 362 } catch (IllegalArgumentException e) { 363 // ignore 364 } 365 try { 366 xDocMDAccess.addContentOrStylesFile("foo.rdf"); 367 fail("addContentOrStylesFile: invalid filename allowed"); 368 } catch (IllegalArgumentException e) { 369 // ignore 370 } 371 try { 372 xDocMDAccess.removeContentOrStylesFile(""); 373 fail("removeContentOrStylesFile: empty filename allowed"); 374 } catch (IllegalArgumentException e) { 375 // ignore 376 } 377 try { 378 xDocMDAccess.loadMetadataFromStorage(null, foo, null); 379 fail("loadMetadataFromStorage: null storage allowed"); 380 } catch (IllegalArgumentException e) { 381 // ignore 382 } 383 try { 384 xDocMDAccess.storeMetadataToStorage(null/*, base*/); 385 fail("storeMetadataToStorage: null storage allowed"); 386 } catch (IllegalArgumentException e) { 387 // ignore 388 } 389 try { 390 xDocMDAccess.loadMetadataFromMedium(new PropertyValue[0]); 391 fail("loadMetadataFromMedium: empty medium allowed"); 392 } catch (IllegalArgumentException e) { 393 // ignore 394 } 395 try { 396 xDocMDAccess.storeMetadataToMedium(new PropertyValue[0]); 397 fail("storeMetadataToMedium: empty medium allowed"); 398 } catch (IllegalArgumentException e) { 399 // ignore 400 } 401 402 System.out.println("...done"); 403 404 System.out.println("Checking file addition/removal..."); 405 406 xDocMDAccess.removeContentOrStylesFile(contentPath); 407 xStmtsEnum = xManifest.getStatements(null, null, null); 408 assertTrue("removeContentOrStylesFile (content)", 409 eq(xStmtsEnum, new Statement[] { 410 manifestStmts[0], manifestStmts[2], manifestStmts[4] 411 })); 412 413 xDocMDAccess.addContentOrStylesFile(contentPath); 414 xStmtsEnum = xManifest.getStatements(null, null, null); 415 assertTrue("addContentOrStylesFile (content)", 416 eq(xStmtsEnum, manifestStmts)); 417 418 xDocMDAccess.removeContentOrStylesFile(stylesPath); 419 xStmtsEnum = xManifest.getStatements(null, null, null); 420 assertTrue("removeContentOrStylesFile (styles)", 421 eq(xStmtsEnum, new Statement[] { 422 manifestStmts[0], manifestStmts[1], manifestStmts[3] 423 })); 424 425 xDocMDAccess.addContentOrStylesFile(stylesPath); 426 xStmtsEnum = xManifest.getStatements(null, null, null); 427 assertTrue("addContentOrStylesFile (styles)", 428 eq(xStmtsEnum, manifestStmts)); 429 430 XURI xFoo = URI.createNS(xContext, xBaseURI.getStringValue(), 431 fooPath); 432 Statement xM_BaseHaspartFoo = 433 new Statement(xBaseURI, pkg_hasPart, xFoo, manifest); 434 Statement xM_FooTypeMetadata = 435 new Statement(xFoo, rdf_type, pkg_MetadataFile, manifest); 436 Statement xM_FooTypeBar = 437 new Statement(xFoo, rdf_type, bar, manifest); 438 xDocMDAccess.addMetadataFile(fooPath, new XURI[] { bar }); 439 xStmtsEnum = xManifest.getStatements(null, null, null); 440 assertTrue("addMetadataFile", 441 eq(xStmtsEnum, merge(manifestStmts, new Statement[] { 442 xM_BaseHaspartFoo, xM_FooTypeMetadata, xM_FooTypeBar 443 }))); 444 445 XURI[] graphsBar = xDocMDAccess.getMetadataGraphsWithType(bar); 446 assertTrue("getMetadataGraphsWithType", 447 graphsBar.length == 1 && eq(graphsBar[0], xFoo)); 448 449 450 xDocMDAccess.removeMetadataFile(xFoo); 451 xStmtsEnum = xManifest.getStatements(null, null, null); 452 assertTrue("removeMetadataFile", 453 eq(xStmtsEnum, manifestStmts)); 454 455 System.out.println("...done"); 456 457 System.out.println("Checking mapping..."); 458 459 XEnumerationAccess xTextEnum = UnoRuntime.queryInterface(XEnumerationAccess.class, xText.getText()); 460 Object o = xTextEnum.createEnumeration().nextElement(); 461 XMetadatable xMeta1 = UnoRuntime.queryInterface(XMetadatable.class, o); 462 463 XMetadatable xMeta; 464 xMeta = xDocMDAccess.getElementByURI(xMeta1); 465 assertTrue("getElementByURI: null", null != xMeta); 466 String XmlId = xMeta.getMetadataReference().Second; 467 String XmlId1 = xMeta1.getMetadataReference().Second; 468 assertTrue("getElementByURI: no xml id", !XmlId.equals("")); 469 assertTrue("getElementByURI: different xml id", XmlId.equals(XmlId1)); 470 471 System.out.println("...done"); 472 473 System.out.println("Checking storing and loading..."); 474 475 XURI xFoobar = URI.createNS(xContext, xBaseURI.getStringValue(), 476 fooBarPath); 477 Statement[] metadataStmts = getMetadataFileStmts(xBaseURI, 478 fooBarPath); 479 xDocMDAccess.addMetadataFile(fooBarPath, new XURI[0]); 480 xStmtsEnum = xRep.getStatements(null, null, null); 481 assertTrue("addMetadataFile", 482 eq(xStmtsEnum, merge(manifestStmts, metadataStmts ))); 483 484 Statement xFoobar_FooBarFoo = 485 new Statement(foo, bar, foo, xFoobar); 486 xRep.getGraph(xFoobar).addStatement(foo, bar, foo); 487 xStmtsEnum = xRep.getStatements(null, null, null); 488 assertTrue("addStatement", 489 eq(xStmtsEnum, merge(manifestStmts, merge(metadataStmts, 490 new Statement[] { xFoobar_FooBarFoo })))); 491 492 PropertyValue noMDNoContentFile = new PropertyValue(); 493 noMDNoContentFile.Name = "URL"; 494 noMDNoContentFile.Value = TestDocument.getUrl("CUSTOM.odt"); 495 PropertyValue noMDFile = new PropertyValue(); 496 noMDFile.Name = "URL"; 497 noMDFile.Value = TestDocument.getUrl("TEST.odt"); 498 PropertyValue file = new PropertyValue(); 499 file.Name = "URL"; 500 file.Value = tempDir + "TESTDMA.odt"; 501 PropertyValue mimetype = new PropertyValue(); 502 mimetype.Name = "MediaType"; 503 mimetype.Value = "application/vnd.oasis.opendocument.text"; 504 PropertyValue[] argsEmptyNoContent = { mimetype, noMDNoContentFile}; 505 PropertyValue[] argsEmpty = { mimetype, noMDFile }; 506 PropertyValue[] args = { mimetype, file }; 507 508 xStmtsEnum = xRep.getStatements(null, null, null); 509 XURI[] graphs = xRep.getGraphNames(); 510 511 xDocMDAccess.storeMetadataToMedium(args); 512 513 // this should re-init 514 xDocMDAccess.loadMetadataFromMedium(argsEmptyNoContent); 515 xRep = xRepoSupplier.getRDFRepository(); 516 assertTrue("xRep null", null != xRep); 517 assertTrue("baseURI still tdoc?", 518 !baseURI.equals(xDocMDAccess.getStringValue())); 519 Statement[] manifestStmts2 = getManifestStmts(xDocMDAccess); 520 xStmtsEnum = xRep.getStatements(null, null, null); 521 // there is no content or styles file in here, so we have just 522 // the package stmt 523 assertTrue("loadMetadataFromMedium (no metadata, no content)", 524 eq(xStmtsEnum, new Statement[] { manifestStmts2[0] })); 525 526 // this should re-init 527 xDocMDAccess.loadMetadataFromMedium(argsEmpty); 528 xRep = xRepoSupplier.getRDFRepository(); 529 assertTrue("xRep null", null != xRep); 530 assertTrue("baseURI still tdoc?", 531 !baseURI.equals(xDocMDAccess.getStringValue())); 532 Statement[] manifestStmts3 = getManifestStmts(xDocMDAccess); 533 534 xStmtsEnum = xRep.getStatements(null, null, null); 535 assertTrue("loadMetadataFromMedium (no metadata)", 536 eq(xStmtsEnum, manifestStmts3)); 537 538 xDocMDAccess.loadMetadataFromMedium(args); 539 xRep = xRepoSupplier.getRDFRepository(); 540 assertTrue("xRep null", null != xRep); 541 Statement[] manifestStmts4 = getManifestStmts(xDocMDAccess); 542 Statement[] metadataStmts4 = getMetadataFileStmts(xDocMDAccess, 543 fooBarPath); 544 545 xStmtsEnum = xRep.getStatements(null, null, null); 546 assertTrue("some graph(s) not reloaded", 547 graphs.length == xRep.getGraphNames().length); 548 549 XURI xFoobar4 = URI.createNS(xContext, xDocMDAccess.getStringValue(), 550 fooBarPath); 551 Statement xFoobar_FooBarFoo4 = 552 new Statement(foo, bar, foo, xFoobar4); 553 assertTrue("loadMetadataFromMedium (re-load)", 554 eq(xStmtsEnum, merge(manifestStmts4, merge(metadataStmts4, 555 new Statement[] { xFoobar_FooBarFoo4 })))); 556 557 System.out.println("...done"); 558 559 System.out.println("Checking storing and loading via model..."); 560 561 String f = tempDir + "TESTPARA.odt"; 562 563 XStorable xStor = UnoRuntime.queryInterface(XStorable.class, xRepoSupplier); 564 565 xStor.storeToURL(f, new PropertyValue[0]); 566 567 xComp2 = util.DesktopTools.loadDoc(xMSF, f, loadProps); 568 569 XDocumentMetadataAccess xDMA2 = UnoRuntime.queryInterface(XDocumentMetadataAccess.class, xComp2); 570 assertTrue("xDMA2 null", null != xDMA2); 571 572 XRepositorySupplier xRS2 = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp2); 573 assertTrue("xRS2 null", null != xRS2); 574 575 XRepository xRep2 = xRS2.getRDFRepository(); 576 assertTrue("xRep2 null", null != xRep2); 577 578 Statement[] manifestStmts5 = getManifestStmts(xDMA2); 579 Statement[] metadataStmts5 = getMetadataFileStmts(xDMA2, 580 fooBarPath); 581 XURI xFoobar5 = URI.createNS(xContext, xDMA2.getStringValue(), 582 fooBarPath); 583 Statement xFoobar_FooBarFoo5 = 584 new Statement(foo, bar, foo, xFoobar5); 585 xStmtsEnum = xRep.getStatements(null, null, null); 586 XEnumeration xStmtsEnum2 = xRep2.getStatements(null, null, null); 587 assertTrue("load: repository differs", 588 eq(xStmtsEnum2, merge(manifestStmts5, merge(metadataStmts5, 589 new Statement[] { xFoobar_FooBarFoo5 })))); 590 591 System.out.println("...done"); 592 593 } finally { 594 close(xComp); 595 close(xComp2); 596 } 597 } 598 checkRDFa()599 @Test public void checkRDFa() throws Exception 600 { 601 XComponent xComp = null; 602 try { 603 final String file = TestDocument.getUrl("TESTRDFA.odt"); 604 xComp = loadRDFa(file); 605 if (xComp != null) 606 { 607 final String sNewFile = tempDir + "TESTRDFA.odt"; 608 storeRDFa(xComp, sNewFile); 609 close(xComp); 610 611 xComp = loadRDFa(sNewFile); 612 } 613 } finally { 614 close(xComp); 615 } 616 } 617 618 @Test checkTdf123293()619 public void checkTdf123293() throws Exception 620 { 621 XComponent xComp = null; 622 try { 623 xComp = util.DesktopTools.loadDocUsingStream(xMSF, TestDocument.getPath("TESTRDFA.odt")); 624 625 // Metadata was discarded when loading from stream, make sure it's there now 626 XRepositorySupplier xRepoSupplier = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp); 627 assertNotNull("No metadata loaded", xRepoSupplier); 628 } finally { 629 close(xComp); 630 } 631 } 632 storeRDFa(XComponent xComp, String file)633 private void storeRDFa(XComponent xComp, String file) throws com.sun.star.io.IOException 634 { 635 System.out.println("Storing test document..."); 636 637 XStorable xStor = UnoRuntime.queryInterface(XStorable.class, xComp); 638 639 xStor.storeToURL(file, new PropertyValue[0]); 640 641 System.out.println("...done"); 642 } 643 loadRDFa(String file)644 private XComponent loadRDFa(String file) throws Exception 645 { 646 XComponent xComp = null; 647 648 System.out.println("Loading test document..."); 649 650 PropertyValue[] loadProps = new PropertyValue[1]; 651 loadProps[0] = new PropertyValue(); 652 loadProps[0].Name = "Hidden"; 653 loadProps[0].Value = true; 654 655 656 657 xComp = util.DesktopTools.loadDoc(xMSF, file, loadProps); 658 659 XRepositorySupplier xRepoSupplier = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp); 660 assertTrue("xRS null", null != xRepoSupplier); 661 662 XDocumentRepository xDocRepository = UnoRuntime.queryInterface(XDocumentRepository.class, xRepoSupplier.getRDFRepository()); 663 assertTrue("xRep null", null != xDocRepository); 664 665 XTextDocument xTextDoc = UnoRuntime.queryInterface(XTextDocument.class, xComp); 666 667 XText xText = xTextDoc.getText(); 668 669 XEnumerationAccess xEA = UnoRuntime.queryInterface(XEnumerationAccess.class, xText); 670 XEnumeration xEnum = xEA.createEnumeration(); 671 672 System.out.println("...done"); 673 674 System.out.println("Checking RDFa in loaded test document..."); 675 676 XMetadatable xPara; 677 Pair<Statement[], Boolean> result; 678 679 Statement x_FooBarLit1 = new Statement(foo, bar, mkLit("1"), null); 680 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 681 result = xDocRepository.getStatementRDFa(xPara); 682 assertTrue("RDFa: 1", 683 !result.Second && 684 eq(result.First, new Statement[] { 685 x_FooBarLit1 686 })); 687 688 Statement x_FooBarLit2 = new Statement(foo, bar, mkLit("2"), null); 689 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 690 result = xDocRepository.getStatementRDFa(xPara); 691 assertTrue("RDFa: 2", 692 !result.Second && 693 eq(result.First, new Statement[] { 694 x_FooBarLit2 695 })); 696 697 Statement x_BlankBarLit3 = 698 new Statement(blank1, bar, mkLit("3"), null); 699 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 700 result = xDocRepository.getStatementRDFa(xPara); 701 assertTrue("RDFa: 3", 702 !result.Second && 703 eq(result.First, new Statement[] { 704 x_BlankBarLit3 705 })); 706 XBlankNode b3 = UnoRuntime.queryInterface(XBlankNode.class, result.First[0].Subject); 707 708 Statement x_BlankBarLit4 = 709 new Statement(blank2, bar, mkLit("4"), null); 710 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 711 result = xDocRepository.getStatementRDFa(xPara); 712 assertTrue("RDFa: 4", 713 !result.Second && 714 eq(result.First, new Statement[] { 715 x_BlankBarLit4 716 })); 717 XBlankNode b4 = UnoRuntime.queryInterface(XBlankNode.class, result.First[0].Subject); 718 719 Statement x_BlankBarLit5 = 720 new Statement(blank1, bar, mkLit("5"), null); 721 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 722 result = xDocRepository.getStatementRDFa(xPara); 723 assertTrue("RDFa: 5", 724 !result.Second && 725 eq(result.First, new Statement[] { 726 x_BlankBarLit5 727 })); 728 XBlankNode b5 = UnoRuntime.queryInterface(XBlankNode.class, result.First[0].Subject); 729 730 assertTrue("RDFa: 3 != 4", 731 !b3.getStringValue().equals(b4.getStringValue())); 732 assertTrue("RDFa: 3 == 5", 733 b3.getStringValue().equals(b5.getStringValue())); 734 735 Statement x_FooBarLit6 = new Statement(foo, bar, mkLit("6"), null); 736 Statement x_FooBazLit6 = new Statement(foo, baz, mkLit("6"), null); 737 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 738 result = xDocRepository.getStatementRDFa(xPara); 739 assertTrue("RDFa: 6", 740 !result.Second && 741 eq(result.First, new Statement[] { 742 x_FooBarLit6, x_FooBazLit6 743 })); 744 745 Statement x_FooBarLit7 = new Statement(foo, bar, mkLit("7"), null); 746 Statement x_FooBazLit7 = new Statement(foo, baz, mkLit("7"), null); 747 Statement x_FooFooLit7 = new Statement(foo, foo, mkLit("7"), null); 748 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 749 result = xDocRepository.getStatementRDFa(xPara); 750 assertTrue("RDFa: 7", 751 !result.Second && 752 eq(result.First, new Statement[] { 753 x_FooBarLit7, x_FooBazLit7, x_FooFooLit7 754 })); 755 756 XNode lit = mkLit("a fooish bar"); 757 XNode lit_type= mkLit("a fooish bar", bar); 758 Statement x_FooBarLit = new Statement(foo, bar, lit, null); 759 Statement x_FooBarLittype = new Statement(foo, bar, lit_type, null); 760 761 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 762 result = xDocRepository.getStatementRDFa(xPara); 763 assertTrue("RDFa: 8", 764 result.Second && 765 eq(result.First, new Statement[] { 766 x_FooBarLit 767 })); 768 769 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 770 result = xDocRepository.getStatementRDFa(xPara); 771 assertTrue("RDFa: 9", 772 result.Second && 773 eq(result.First, new Statement[] { 774 x_FooBarLit 775 })); 776 777 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 778 result = xDocRepository.getStatementRDFa(xPara); 779 assertTrue("RDFa: 10", 780 result.Second && 781 eq(result.First, new Statement[] { 782 x_FooBarLittype 783 })); 784 785 Statement x_FooBarLit11 786 = new Statement(foo, bar, mkLit("11", bar), null); 787 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 788 result = xDocRepository.getStatementRDFa(xPara); 789 assertTrue("RDFa: 11", 790 !result.Second && 791 eq(result.First, new Statement[] { 792 x_FooBarLit11 793 })); 794 795 XURI xFile = URI.createNS(xContext, file, "/" + contentPath); 796 Statement x_FileBarLit12 = 797 new Statement(xFile, bar, mkLit("12"), null); 798 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 799 result = xDocRepository.getStatementRDFa(xPara); 800 assertTrue("RDFa: 12", 801 !result.Second && 802 eq(result.First, new Statement[] { 803 x_FileBarLit12 804 })); 805 806 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 807 result = xDocRepository.getStatementRDFa(xPara); 808 assertTrue("RDFa: 13", 809 result.Second && 810 eq(result.First, new Statement[] { 811 x_FooBarLit 812 })); 813 814 new Statement(foo, rdfs_label, mkLit("14"), null); 815 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 816 result = xDocRepository.getStatementRDFa(xPara); 817 assertTrue("RDFa: 14", 818 result.Second && 819 eq(result.First, new Statement[] { 820 /* x_FooLabelLit14 */ x_FooBarLit 821 })); 822 823 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 824 result = xDocRepository.getStatementRDFa(xPara); 825 assertTrue("RDFa: 15", eq(result.First, new Statement[] { } )); 826 827 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 828 result = xDocRepository.getStatementRDFa(xPara); 829 assertTrue("RDFa: 16", eq(result.First, new Statement[] { } )); 830 831 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 832 result = xDocRepository.getStatementRDFa(xPara); 833 assertTrue("RDFa: 17", eq(result.First, new Statement[] { } )); 834 835 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 836 result = xDocRepository.getStatementRDFa(xPara); 837 assertTrue("RDFa: 18", eq(result.First, new Statement[] { } )); 838 839 xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement()); 840 result = xDocRepository.getStatementRDFa(xPara); 841 assertTrue("RDFa: 19", eq(result.First, new Statement[] { } )); 842 843 xPara = UnoRuntime.queryInterface( 844 XMetadatable.class, xEnum.nextElement()); 845 result = xDocRepository.getStatementRDFa(xPara); 846 assertTrue("RDFa: 20", eq(result.First, new Statement[] { } )); 847 848 xPara = UnoRuntime.queryInterface( 849 XMetadatable.class, xEnum.nextElement()); 850 result = xDocRepository.getStatementRDFa(xPara); 851 assertTrue("RDFa: 21", eq(result.First, new Statement[] { } )); 852 853 System.out.println("...done"); 854 855 return xComp; 856 } 857 858 859 // utilities ------------------------------------------------------------- 860 close(XComponent i_comp)861 static void close(XComponent i_comp) 862 { 863 try { 864 XCloseable xClos = UnoRuntime.queryInterface(XCloseable.class, i_comp); 865 if (xClos != null) 866 { 867 xClos.close(true); 868 } 869 } catch (Exception e) { 870 } 871 } 872 mkLit(String i_content)873 XLiteral mkLit(String i_content) 874 { 875 return Literal.create(xContext, i_content); 876 } 877 mkLit(String i_content, XURI i_uri)878 XLiteral mkLit(String i_content, XURI i_uri) 879 { 880 return Literal.createWithType(xContext, i_content, i_uri); 881 } 882 merge(Statement[] i_A1, Statement[] i_A2)883 static Statement[] merge(Statement[] i_A1, Statement[] i_A2) 884 { 885 // bah, java sucks... 886 Statement[] ret = new Statement[i_A1.length + i_A2.length]; 887 for (int i = 0; i < i_A1.length; ++i) { 888 ret[i] = i_A1[i]; 889 } 890 for (int i = 0; i < i_A2.length; ++i) { 891 ret[i+i_A1.length] = i_A2[i]; 892 } 893 return ret; 894 } 895 toS(XNode n)896 public static String toS(XNode n) { 897 if (null == n) 898 { 899 return "< null >"; 900 } 901 return n.getStringValue(); 902 } 903 isBlank(XNode i_node)904 static boolean isBlank(XNode i_node) 905 { 906 XBlankNode blank = UnoRuntime.queryInterface(XBlankNode.class, i_node); 907 return blank != null; 908 } 909 910 toSeq(XEnumeration i_Enum)911 static Statement[] toSeq(XEnumeration i_Enum) throws Exception 912 { 913 java.util.Collection<Statement> c = new java.util.ArrayList<Statement>(); 914 while (i_Enum.hasMoreElements()) { 915 Statement s = (Statement) i_Enum.nextElement(); 916 c.add(s); 917 } 918 // java sucks 919 Object[] arr = c.toArray(); 920 Statement[] ret = new Statement[arr.length]; 921 for (int i = 0; i < arr.length; ++i) { 922 ret[i] = (Statement) arr[i]; 923 } 924 return ret; 925 } 926 toSeqs(XEnumeration i_Enum)927 static XNode[][] toSeqs(XEnumeration i_Enum) throws Exception 928 { 929 java.util.Collection<XNode[]> c = new java.util.ArrayList<XNode[]>(); 930 while (i_Enum.hasMoreElements()) { 931 XNode[] s = (XNode[]) i_Enum.nextElement(); 932 c.add(s); 933 } 934 Object[] arr = c.toArray(); 935 XNode[][] ret = new XNode[arr.length][]; 936 for (int i = 0; i < arr.length; ++i) { 937 ret[i] = (XNode[]) arr[i]; 938 } 939 return ret; 940 } 941 942 private static class BindingComp implements java.util.Comparator<XNode[]> 943 { compare(XNode[] left, XNode[] right)944 public int compare(XNode[] left, XNode[] right) 945 { 946 if (left.length != right.length) 947 { 948 throw new RuntimeException(); 949 } 950 for (int i = 0; i < left.length; ++i) { 951 int eq = (left[i].getStringValue().compareTo( 952 right[i].getStringValue())); 953 if (eq != 0) 954 { 955 return eq; 956 } 957 } 958 return 0; 959 } 960 } 961 962 private static class StmtComp implements java.util.Comparator<Statement> 963 { compare(Statement left, Statement right)964 public int compare(Statement left, Statement right) 965 { 966 int eq; 967 if ((eq = cmp(left.Graph, right.Graph )) != 0) return eq; 968 if ((eq = cmp(left.Subject, right.Subject )) != 0) return eq; 969 if ((eq = cmp(left.Predicate, right.Predicate)) != 0) return eq; 970 if ((eq = cmp(left.Object, right.Object )) != 0) return eq; 971 return 0; 972 } 973 cmp(XNode i_Left, XNode i_Right)974 private int cmp(XNode i_Left, XNode i_Right) 975 { 976 if (isBlank(i_Left)) { 977 return isBlank(i_Right) ? 0 : 1; 978 } else { 979 if (isBlank(i_Right)) { 980 return -1; 981 } else { 982 return toS(i_Left).compareTo(toS(i_Right)); 983 } 984 } 985 } 986 } 987 eq(Statement i_Left, Statement i_Right)988 static boolean eq(Statement i_Left, Statement i_Right) 989 { 990 XURI lG = i_Left.Graph; 991 XURI rG = i_Right.Graph; 992 if (!eq(lG, rG)) { 993 System.out.println("Graphs differ: " + toS(lG) + " != " + toS(rG)); 994 return false; 995 } 996 if (!eq(i_Left.Subject, i_Right.Subject)) { 997 System.out.println("Subjects differ: " + 998 i_Left.Subject.getStringValue() + " != " + 999 i_Right.Subject.getStringValue()); 1000 return false; 1001 } 1002 if (!eq(i_Left.Predicate, i_Right.Predicate)) { 1003 System.out.println("Predicates differ: " + 1004 i_Left.Predicate.getStringValue() + " != " + 1005 i_Right.Predicate.getStringValue()); 1006 return false; 1007 } 1008 if (!eq(i_Left.Object, i_Right.Object)) { 1009 System.out.println("Objects differ: " + 1010 i_Left.Object.getStringValue() + " != " + 1011 i_Right.Object.getStringValue()); 1012 return false; 1013 } 1014 return true; 1015 } 1016 eq(Statement[] i_Result, Statement[] i_Expected)1017 static boolean eq(Statement[] i_Result, Statement[] i_Expected) 1018 { 1019 if (i_Result.length != i_Expected.length) { 1020 System.out.println("eq: different lengths: " + i_Result.length + " " + 1021 i_Expected.length); 1022 return false; 1023 } 1024 Statement[] expected = i_Expected.clone(); 1025 java.util.Arrays.sort(i_Result, new StmtComp()); 1026 java.util.Arrays.sort(expected, new StmtComp()); 1027 for (int i = 0; i < expected.length; ++i) 1028 { 1029 // This is better for debug! 1030 final Statement a = i_Result[i]; 1031 final Statement b = expected[i]; 1032 final boolean cond = eq(a, b); 1033 if (!cond) return false; 1034 } 1035 return true; 1036 } 1037 eq(XEnumeration i_Enum, Statement[] i_Expected)1038 static boolean eq(XEnumeration i_Enum, Statement[] i_Expected) 1039 throws Exception 1040 { 1041 Statement[] current = toSeq(i_Enum); 1042 return eq(current, i_Expected); 1043 } 1044 eq(XNode i_Left, XNode i_Right)1045 static boolean eq(XNode i_Left, XNode i_Right) 1046 { 1047 if (i_Left == null) { 1048 return (i_Right == null); 1049 } else { 1050 return (i_Right != null) && 1051 (i_Left.getStringValue().equals(i_Right.getStringValue()) 1052 // FIXME: hack: blank nodes considered equal 1053 || (isBlank(i_Left) && isBlank(i_Right))); 1054 } 1055 } 1056 eq(XQuerySelectResult i_Result, String[] i_Vars, XNode[][] i_Bindings)1057 static boolean eq(XQuerySelectResult i_Result, 1058 String[] i_Vars, XNode[][] i_Bindings) throws Exception 1059 { 1060 String[] vars = i_Result.getBindingNames(); 1061 XEnumeration iter = i_Result; 1062 XNode[][] bindings = toSeqs(iter); 1063 if (vars.length != i_Vars.length) { 1064 System.out.println("var lengths differ"); 1065 return false; 1066 } 1067 if (bindings.length != i_Bindings.length) { 1068 System.out.println("binding lengths differ: " + i_Bindings.length + 1069 " vs " + bindings.length ); 1070 return false; 1071 } 1072 java.util.Arrays.sort(bindings, new BindingComp()); 1073 java.util.Arrays.sort(i_Bindings, new BindingComp()); 1074 for (int i = 0; i < i_Bindings.length; ++i) { 1075 if (i_Bindings[i].length != i_Vars.length) { 1076 System.out.println("TEST ERROR!"); 1077 throw new Exception(); 1078 } 1079 if (bindings[i].length != i_Vars.length) { 1080 System.out.println("binding length and var length differ"); 1081 return false; 1082 } 1083 for (int j = 0; j < i_Vars.length; ++j) { 1084 if (!eq(bindings[i][j], i_Bindings[i][j])) { 1085 System.out.println("bindings differ: " + 1086 toS(bindings[i][j]) + " != " + toS(i_Bindings[i][j])); 1087 return false; 1088 } 1089 } 1090 } 1091 for (int i = 0; i < i_Vars.length; ++i) { 1092 if (!vars[i].equals(i_Vars[i])) { 1093 System.out.println("variable names differ: " + 1094 vars[i] + " != " + i_Vars[i]); 1095 return false; 1096 } 1097 } 1098 return true; 1099 } 1100 eq(StringPair i_Left, StringPair i_Right)1101 static boolean eq(StringPair i_Left, StringPair i_Right) 1102 { 1103 return ((i_Left.First).equals(i_Right.First)) && 1104 ((i_Left.Second).equals(i_Right.Second)); 1105 } 1106 mkNamespace(String i_prefix, String i_namespace)1107 static String mkNamespace(String i_prefix, String i_namespace) 1108 { 1109 return "PREFIX " + i_prefix + ": <" + i_namespace + ">\n"; 1110 } 1111 mkNss()1112 static String mkNss() 1113 { 1114 String namespaces = mkNamespace("rdf", 1115 "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); 1116 namespaces += mkNamespace("pkg", 1117 "http://docs.oasis-open.org/opendocument/meta/package/common#"); 1118 namespaces += mkNamespace("odf", 1119 "http://docs.oasis-open.org/opendocument/meta/package/odf#"); 1120 return namespaces; 1121 } 1122 getManifestStmts(XURI xBaseURI)1123 Statement[] getManifestStmts(XURI xBaseURI) throws Exception 1124 { 1125 XURI xManifest = URI.createNS(xContext, xBaseURI.getStringValue(), 1126 manifestPath); 1127 XURI xContent = URI.createNS(xContext, xBaseURI.getStringValue(), 1128 contentPath); 1129 XURI xStyles = URI.createNS(xContext, xBaseURI.getStringValue(), 1130 stylesPath); 1131 Statement xM_BaseTypeDoc = 1132 new Statement(xBaseURI, rdf_type, pkg_Document, xManifest); 1133 Statement xM_BaseHaspartContent = 1134 new Statement(xBaseURI, pkg_hasPart, xContent, xManifest); 1135 Statement xM_BaseHaspartStyles = 1136 new Statement(xBaseURI, pkg_hasPart, xStyles, xManifest); 1137 Statement xM_ContentTypeContent = 1138 new Statement(xContent, rdf_type, odf_ContentFile, xManifest); 1139 Statement xM_StylesTypeStyles = 1140 new Statement(xStyles, rdf_type, odf_StylesFile, xManifest); 1141 return new Statement[] { 1142 xM_BaseTypeDoc, xM_BaseHaspartContent, xM_BaseHaspartStyles, 1143 xM_ContentTypeContent, xM_StylesTypeStyles 1144 }; 1145 } 1146 getMetadataFileStmts(XURI xBaseURI, String Path)1147 Statement[] getMetadataFileStmts(XURI xBaseURI, String Path) 1148 throws Exception 1149 { 1150 XURI xManifest = URI.createNS(xContext, xBaseURI.getStringValue(), 1151 manifestPath); 1152 XURI xGraph = URI.createNS(xContext, xBaseURI.getStringValue(), Path); 1153 Statement xM_BaseHaspartGraph = 1154 new Statement(xBaseURI, pkg_hasPart, xGraph, xManifest); 1155 Statement xM_GraphTypeMetadata = 1156 new Statement(xGraph, rdf_type, pkg_MetadataFile, xManifest); 1157 return new Statement[] { xM_BaseHaspartGraph, xM_GraphTypeMetadata }; 1158 } 1159 1160 class TestRange implements XTextRange, XMetadatable, XServiceInfo 1161 { 1162 String m_Stream; 1163 String m_XmlId; 1164 String m_Text; TestRange(String i_Str)1165 TestRange(String i_Str) { m_Text = i_Str; } 1166 getStringValue()1167 public String getStringValue() { return ""; } getNamespace()1168 public String getNamespace() { return ""; } getLocalName()1169 public String getLocalName() { return ""; } 1170 getMetadataReference()1171 public StringPair getMetadataReference() 1172 { 1173 return new StringPair(m_Stream, m_XmlId); 1174 } setMetadataReference(StringPair i_Ref)1175 public void setMetadataReference(StringPair i_Ref) 1176 throws IllegalArgumentException 1177 { 1178 m_Stream = i_Ref.First; 1179 m_XmlId = i_Ref.Second; 1180 } ensureMetadataReference()1181 public void ensureMetadataReference() 1182 { 1183 m_Stream = "content.xml"; 1184 m_XmlId = "42"; 1185 } 1186 getImplementationName()1187 public String getImplementationName() { return null; } getSupportedServiceNames()1188 public String[] getSupportedServiceNames() { return null; } supportsService(String i_Svc)1189 public boolean supportsService(String i_Svc) 1190 { 1191 return i_Svc.equals("com.sun.star.text.Paragraph"); 1192 } 1193 getText()1194 public XText getText() { return null; } getStart()1195 public XTextRange getStart() { return null; } getEnd()1196 public XTextRange getEnd() { return null; } getString()1197 public String getString() { return m_Text; } setString(String i_Str)1198 public void setString(String i_Str) { m_Text = i_Str; } 1199 } 1200 1201 1202 getMSF()1203 private XMultiServiceFactory getMSF() 1204 { 1205 return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); 1206 } 1207 1208 // setup and close connections setUpConnection()1209 @BeforeClass public static void setUpConnection() throws Exception { 1210 System.out.println( "------------------------------------------------------------" ); 1211 System.out.println( "starting class: " + DocumentMetadataAccess.class.getName() ); 1212 System.out.println( "------------------------------------------------------------" ); 1213 connection.setUp(); 1214 } 1215 tearDownConnection()1216 @AfterClass public static void tearDownConnection() 1217 throws InterruptedException, com.sun.star.uno.Exception 1218 { 1219 System.out.println( "------------------------------------------------------------" ); 1220 System.out.println( "finishing class: " + DocumentMetadataAccess.class.getName() ); 1221 System.out.println( "------------------------------------------------------------" ); 1222 connection.tearDown(); 1223 } 1224 1225 private static final OfficeConnection connection = new OfficeConnection(); 1226 1227 } 1228 1229