예제 #1
0
 Statement[] getMetadataFileStmts(XURI xBaseURI, String Path) throws Exception {
   XURI xManifest = URI.createNS(xContext, xBaseURI.getStringValue(), manifestPath);
   XURI xGraph = URI.createNS(xContext, xBaseURI.getStringValue(), Path);
   Statement xM_BaseHaspartGraph = new Statement(xBaseURI, pkg_hasPart, xGraph, xManifest);
   Statement xM_GraphTypeMetadata = new Statement(xGraph, rdf_type, pkg_MetadataFile, xManifest);
   return new Statement[] {xM_BaseHaspartGraph, xM_GraphTypeMetadata};
 }
예제 #2
0
 Statement[] getManifestStmts(XURI xBaseURI) throws Exception {
   XURI xManifest = URI.createNS(xContext, xBaseURI.getStringValue(), manifestPath);
   XURI xContent = URI.createNS(xContext, xBaseURI.getStringValue(), contentPath);
   XURI xStyles = URI.createNS(xContext, xBaseURI.getStringValue(), stylesPath);
   Statement xM_BaseTypeDoc = new Statement(xBaseURI, rdf_type, pkg_Document, xManifest);
   Statement xM_BaseHaspartContent = new Statement(xBaseURI, pkg_hasPart, xContent, xManifest);
   Statement xM_BaseHaspartStyles = new Statement(xBaseURI, pkg_hasPart, xStyles, xManifest);
   Statement xM_ContentTypeContent = new Statement(xContent, rdf_type, odf_ContentFile, xManifest);
   Statement xM_StylesTypeStyles = new Statement(xStyles, rdf_type, odf_StylesFile, xManifest);
   return new Statement[] {
     xM_BaseTypeDoc,
     xM_BaseHaspartContent,
     xM_BaseHaspartStyles,
     xM_ContentTypeContent,
     xM_StylesTypeStyles
   };
 }
예제 #3
0
  private XComponent loadRDFa(String file) throws Exception {
    XComponent xComp = null;

    System.out.println("Loading test document...");

    PropertyValue[] loadProps = new PropertyValue[1];
    loadProps[0] = new PropertyValue();
    loadProps[0].Name = "Hidden";
    loadProps[0].Value = true;

    xComp = util.DesktopTools.loadDoc(xMSF, file, loadProps);

    XRepositorySupplier xRepoSupplier = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp);
    assertTrue("xRS null", null != xRepoSupplier);

    XDocumentRepository xDocRepository =
        UnoRuntime.queryInterface(XDocumentRepository.class, xRepoSupplier.getRDFRepository());
    assertTrue("xRep null", null != xDocRepository);

    XTextDocument xTextDoc = UnoRuntime.queryInterface(XTextDocument.class, xComp);

    XText xText = xTextDoc.getText();

    XEnumerationAccess xEA = UnoRuntime.queryInterface(XEnumerationAccess.class, xText);
    XEnumeration xEnum = xEA.createEnumeration();

    System.out.println("...done");

    System.out.println("Checking RDFa in loaded test document...");

    XMetadatable xPara;
    Pair<Statement[], Boolean> result;

    Statement x_FooBarLit1 = new Statement(foo, bar, mkLit("1"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 1", !result.Second && eq(result.First, new Statement[] {x_FooBarLit1}));

    Statement x_FooBarLit2 = new Statement(foo, bar, mkLit("2"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 2", !result.Second && eq(result.First, new Statement[] {x_FooBarLit2}));

    Statement x_BlankBarLit3 = new Statement(blank1, bar, mkLit("3"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 3", !result.Second && eq(result.First, new Statement[] {x_BlankBarLit3}));
    XBlankNode b3 = UnoRuntime.queryInterface(XBlankNode.class, result.First[0].Subject);

    Statement x_BlankBarLit4 = new Statement(blank2, bar, mkLit("4"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 4", !result.Second && eq(result.First, new Statement[] {x_BlankBarLit4}));
    XBlankNode b4 = UnoRuntime.queryInterface(XBlankNode.class, result.First[0].Subject);

    Statement x_BlankBarLit5 = new Statement(blank1, bar, mkLit("5"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 5", !result.Second && eq(result.First, new Statement[] {x_BlankBarLit5}));
    XBlankNode b5 = UnoRuntime.queryInterface(XBlankNode.class, result.First[0].Subject);

    assertTrue("RDFa: 3 != 4", !b3.getStringValue().equals(b4.getStringValue()));
    assertTrue("RDFa: 3 == 5", b3.getStringValue().equals(b5.getStringValue()));

    Statement x_FooBarLit6 = new Statement(foo, bar, mkLit("6"), null);
    Statement x_FooBazLit6 = new Statement(foo, baz, mkLit("6"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue(
        "RDFa: 6",
        !result.Second && eq(result.First, new Statement[] {x_FooBarLit6, x_FooBazLit6}));

    Statement x_FooBarLit7 = new Statement(foo, bar, mkLit("7"), null);
    Statement x_FooBazLit7 = new Statement(foo, baz, mkLit("7"), null);
    Statement x_FooFooLit7 = new Statement(foo, foo, mkLit("7"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue(
        "RDFa: 7",
        !result.Second
            && eq(result.First, new Statement[] {x_FooBarLit7, x_FooBazLit7, x_FooFooLit7}));

    XNode lit = mkLit("a fooish bar");
    XNode lit_type = mkLit("a fooish bar", bar);
    Statement x_FooBarLit = new Statement(foo, bar, lit, null);
    Statement x_FooBarLittype = new Statement(foo, bar, lit_type, null);

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 8", result.Second && eq(result.First, new Statement[] {x_FooBarLit}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 9", result.Second && eq(result.First, new Statement[] {x_FooBarLit}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 10", result.Second && eq(result.First, new Statement[] {x_FooBarLittype}));

    Statement x_FooBarLit11 = new Statement(foo, bar, mkLit("11", bar), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 11", !result.Second && eq(result.First, new Statement[] {x_FooBarLit11}));

    XURI xFile = URI.createNS(xContext, file, "/" + contentPath);
    Statement x_FileBarLit12 = new Statement(xFile, bar, mkLit("12"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 12", !result.Second && eq(result.First, new Statement[] {x_FileBarLit12}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 13", result.Second && eq(result.First, new Statement[] {x_FooBarLit}));

    new Statement(foo, rdfs_label, mkLit("14"), null);
    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue(
        "RDFa: 14",
        result.Second && eq(result.First, new Statement[] {/* x_FooLabelLit14 */ x_FooBarLit}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 15", eq(result.First, new Statement[] {}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 16", eq(result.First, new Statement[] {}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 17", eq(result.First, new Statement[] {}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 18", eq(result.First, new Statement[] {}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 19", eq(result.First, new Statement[] {}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 20", eq(result.First, new Statement[] {}));

    xPara = UnoRuntime.queryInterface(XMetadatable.class, xEnum.nextElement());
    result = xDocRepository.getStatementRDFa(xPara);
    assertTrue("RDFa: 21", eq(result.First, new Statement[] {}));

    System.out.println("...done");

    return xComp;
  }
예제 #4
0
  @Test
  public void check() throws Exception {
    XComponent xComp = null;
    XComponent xComp2 = null;
    try {
      XEnumeration xStmtsEnum;
      XNamedGraph xManifest;

      System.out.println("Creating document with Repository...");

      // we cannot create a XDMA directly, we must create
      // a document and get it from there :(
      // create document
      PropertyValue[] loadProps = new PropertyValue[1];
      loadProps[0] = new PropertyValue();
      loadProps[0].Name = "Hidden";
      loadProps[0].Value = true;
      xComp = util.DesktopTools.openNewDoc(xMSF, "swriter", loadProps);
      XTextDocument xText = UnoRuntime.queryInterface(XTextDocument.class, xComp);

      XRepositorySupplier xRepoSupplier =
          UnoRuntime.queryInterface(XRepositorySupplier.class, xComp);
      assertNotNull("xRS null", xRepoSupplier);
      XDocumentMetadataAccess xDocMDAccess =
          UnoRuntime.queryInterface(XDocumentMetadataAccess.class, xRepoSupplier);
      assertNotNull("xDMA null", xDocMDAccess);
      xRep = xRepoSupplier.getRDFRepository();
      assertNotNull("xRep null", xRep);

      System.out.println("...done");

      System.out.println("Checking that new repository is initialized...");

      XURI xBaseURI = xDocMDAccess;
      String baseURI = xBaseURI.getStringValue();
      assertNotNull("new: baseURI", xBaseURI);
      assertTrue("new: baseURI", !xBaseURI.getStringValue().equals(""));

      assertTrue("new: # graphs", 1 == xRep.getGraphNames().length);
      XURI manifest = URI.createNS(xContext, xBaseURI.getStringValue(), manifestPath);
      xManifest = xRep.getGraph(manifest);
      assertTrue("new: manifest graph", null != xManifest);

      Statement[] manifestStmts = getManifestStmts(xBaseURI);
      xStmtsEnum = xRep.getStatements(null, null, null);
      assertTrue("new: manifest graph", eq(xStmtsEnum, manifestStmts));

      System.out.println("...done");

      System.out.println("Checking some invalid args...");

      String content = "behold, for I am the content.";
      new TestRange(content);

      try {
        xDocMDAccess.getElementByURI(null);
        fail("getElementByURI: null allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.getMetadataGraphsWithType(null);
        fail("getMetadataGraphsWithType: null URI allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("", new XURI[0]);
        fail("addMetadataFile: empty filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("/foo", new XURI[0]);
        fail("addMetadataFile: absolute filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("fo\"o", new XURI[0]);
        fail("addMetadataFile: invalid filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("../foo", new XURI[0]);
        fail("addMetadataFile: filename with .. allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("foo/../../bar", new XURI[0]);
        fail("addMetadataFile: filename with nest .. allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("foo/././bar", new XURI[0]);
        fail("addMetadataFile: filename with nest . allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("content.xml", new XURI[0]);
        fail("addMetadataFile: content.xml allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("styles.xml", new XURI[0]);
        fail("addMetadataFile: styles.xml allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("meta.xml", new XURI[0]);
        fail("addMetadataFile: meta.xml allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addMetadataFile("settings.xml", new XURI[0]);
        fail("addMetadataFile: settings.xml allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, null, "foo", foo, new XURI[0]);
        fail("importMetadataFile: null stream allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }

      final String sEmptyRDF = TestDocument.getUrl("empty.rdf");
      try {
        XInputStream xFooIn = new StreamSimulator(sEmptyRDF, true, param);
        xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, xFooIn, "", foo, new XURI[0]);
        fail("importMetadataFile: empty filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        XInputStream xFooIn = new StreamSimulator(sEmptyRDF, true, param);
        xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, xFooIn, "meta.xml", foo, new XURI[0]);
        fail("importMetadataFile: meta.xml filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        XInputStream xFooIn = new StreamSimulator(sEmptyRDF, true, param);
        xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, xFooIn, "foo", null, new XURI[0]);
        fail("importMetadataFile: null base URI allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        XInputStream xFooIn = new StreamSimulator(sEmptyRDF, true, param);
        xDocMDAccess.importMetadataFile(FileFormat.RDF_XML, xFooIn, "foo", rdf_type, new XURI[0]);
        fail("importMetadataFile: non-absolute base URI allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.removeMetadataFile(null);
        fail("removeMetadataFile: null URI allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addContentOrStylesFile("");
        fail("addContentOrStylesFile: empty filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addContentOrStylesFile("/content.xml");
        fail("addContentOrStylesFile: absolute filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.addContentOrStylesFile("foo.rdf");
        fail("addContentOrStylesFile: invalid filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.removeContentOrStylesFile("");
        fail("removeContentOrStylesFile: empty filename allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.loadMetadataFromStorage(null, foo, null);
        fail("loadMetadataFromStorage: null storage allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.storeMetadataToStorage(null /*, base*/);
        fail("storeMetadataToStorage: null storage allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.loadMetadataFromMedium(new PropertyValue[0]);
        fail("loadMetadataFromMedium: empty medium allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }
      try {
        xDocMDAccess.storeMetadataToMedium(new PropertyValue[0]);
        fail("storeMetadataToMedium: empty medium allowed");
      } catch (IllegalArgumentException e) {
        // ignore
      }

      System.out.println("...done");

      System.out.println("Checking file addition/removal...");

      xDocMDAccess.removeContentOrStylesFile(contentPath);
      xStmtsEnum = xManifest.getStatements(null, null, null);
      assertTrue(
          "removeContentOrStylesFile (content)",
          eq(xStmtsEnum, new Statement[] {manifestStmts[0], manifestStmts[2], manifestStmts[4]}));

      xDocMDAccess.addContentOrStylesFile(contentPath);
      xStmtsEnum = xManifest.getStatements(null, null, null);
      assertTrue("addContentOrStylesFile (content)", eq(xStmtsEnum, manifestStmts));

      xDocMDAccess.removeContentOrStylesFile(stylesPath);
      xStmtsEnum = xManifest.getStatements(null, null, null);
      assertTrue(
          "removeContentOrStylesFile (styles)",
          eq(xStmtsEnum, new Statement[] {manifestStmts[0], manifestStmts[1], manifestStmts[3]}));

      xDocMDAccess.addContentOrStylesFile(stylesPath);
      xStmtsEnum = xManifest.getStatements(null, null, null);
      assertTrue("addContentOrStylesFile (styles)", eq(xStmtsEnum, manifestStmts));

      XURI xFoo = URI.createNS(xContext, xBaseURI.getStringValue(), fooPath);
      Statement xM_BaseHaspartFoo = new Statement(xBaseURI, pkg_hasPart, xFoo, manifest);
      Statement xM_FooTypeMetadata = new Statement(xFoo, rdf_type, pkg_MetadataFile, manifest);
      Statement xM_FooTypeBar = new Statement(xFoo, rdf_type, bar, manifest);
      xDocMDAccess.addMetadataFile(fooPath, new XURI[] {bar});
      xStmtsEnum = xManifest.getStatements(null, null, null);
      assertTrue(
          "addMetadataFile",
          eq(
              xStmtsEnum,
              merge(
                  manifestStmts,
                  new Statement[] {xM_BaseHaspartFoo, xM_FooTypeMetadata, xM_FooTypeBar})));

      XURI[] graphsBar = xDocMDAccess.getMetadataGraphsWithType(bar);
      assertTrue("getMetadataGraphsWithType", graphsBar.length == 1 && eq(graphsBar[0], xFoo));

      xDocMDAccess.removeMetadataFile(xFoo);
      xStmtsEnum = xManifest.getStatements(null, null, null);
      assertTrue("removeMetadataFile", eq(xStmtsEnum, manifestStmts));

      System.out.println("...done");

      System.out.println("Checking mapping...");

      XEnumerationAccess xTextEnum =
          UnoRuntime.queryInterface(XEnumerationAccess.class, xText.getText());
      Object o = xTextEnum.createEnumeration().nextElement();
      XMetadatable xMeta1 = UnoRuntime.queryInterface(XMetadatable.class, o);

      XMetadatable xMeta;
      xMeta = xDocMDAccess.getElementByURI(xMeta1);
      assertTrue("getElementByURI: null", null != xMeta);
      String XmlId = xMeta.getMetadataReference().Second;
      String XmlId1 = xMeta1.getMetadataReference().Second;
      assertTrue("getElementByURI: no xml id", !XmlId.equals(""));
      assertTrue("getElementByURI: different xml id", XmlId.equals(XmlId1));

      System.out.println("...done");

      System.out.println("Checking storing and loading...");

      XURI xFoobar = URI.createNS(xContext, xBaseURI.getStringValue(), fooBarPath);
      Statement[] metadataStmts = getMetadataFileStmts(xBaseURI, fooBarPath);
      xDocMDAccess.addMetadataFile(fooBarPath, new XURI[0]);
      xStmtsEnum = xRep.getStatements(null, null, null);
      assertTrue("addMetadataFile", eq(xStmtsEnum, merge(manifestStmts, metadataStmts)));

      Statement xFoobar_FooBarFoo = new Statement(foo, bar, foo, xFoobar);
      xRep.getGraph(xFoobar).addStatement(foo, bar, foo);
      xStmtsEnum = xRep.getStatements(null, null, null);
      assertTrue(
          "addStatement",
          eq(
              xStmtsEnum,
              merge(manifestStmts, merge(metadataStmts, new Statement[] {xFoobar_FooBarFoo}))));

      PropertyValue noMDNoContentFile = new PropertyValue();
      noMDNoContentFile.Name = "URL";
      noMDNoContentFile.Value = TestDocument.getUrl("CUSTOM.odt");
      PropertyValue noMDFile = new PropertyValue();
      noMDFile.Name = "URL";
      noMDFile.Value = TestDocument.getUrl("TEST.odt");
      PropertyValue file = new PropertyValue();
      file.Name = "URL";
      file.Value = tempDir + "TESTDMA.odt";
      PropertyValue mimetype = new PropertyValue();
      mimetype.Name = "MediaType";
      mimetype.Value = "application/vnd.oasis.opendocument.text";
      PropertyValue[] argsEmptyNoContent = {mimetype, noMDNoContentFile};
      PropertyValue[] argsEmpty = {mimetype, noMDFile};
      PropertyValue[] args = {mimetype, file};

      xStmtsEnum = xRep.getStatements(null, null, null);
      XURI[] graphs = xRep.getGraphNames();

      xDocMDAccess.storeMetadataToMedium(args);

      // this should re-init
      xDocMDAccess.loadMetadataFromMedium(argsEmptyNoContent);
      xRep = xRepoSupplier.getRDFRepository();
      assertTrue("xRep null", null != xRep);
      assertTrue("baseURI still tdoc?", !baseURI.equals(xDocMDAccess.getStringValue()));
      Statement[] manifestStmts2 = getManifestStmts(xDocMDAccess);
      xStmtsEnum = xRep.getStatements(null, null, null);
      // there is no content or styles file in here, so we have just
      // the package stmt
      assertTrue(
          "loadMetadataFromMedium (no metadata, no content)",
          eq(xStmtsEnum, new Statement[] {manifestStmts2[0]}));

      // this should re-init
      xDocMDAccess.loadMetadataFromMedium(argsEmpty);
      xRep = xRepoSupplier.getRDFRepository();
      assertTrue("xRep null", null != xRep);
      assertTrue("baseURI still tdoc?", !baseURI.equals(xDocMDAccess.getStringValue()));
      Statement[] manifestStmts3 = getManifestStmts(xDocMDAccess);

      xStmtsEnum = xRep.getStatements(null, null, null);
      assertTrue("loadMetadataFromMedium (no metadata)", eq(xStmtsEnum, manifestStmts3));

      xDocMDAccess.loadMetadataFromMedium(args);
      xRep = xRepoSupplier.getRDFRepository();
      assertTrue("xRep null", null != xRep);
      Statement[] manifestStmts4 = getManifestStmts(xDocMDAccess);
      Statement[] metadataStmts4 = getMetadataFileStmts(xDocMDAccess, fooBarPath);

      xStmtsEnum = xRep.getStatements(null, null, null);
      assertTrue("some graph(s) not reloaded", graphs.length == xRep.getGraphNames().length);

      XURI xFoobar4 = URI.createNS(xContext, xDocMDAccess.getStringValue(), fooBarPath);
      Statement xFoobar_FooBarFoo4 = new Statement(foo, bar, foo, xFoobar4);
      assertTrue(
          "loadMetadataFromMedium (re-load)",
          eq(
              xStmtsEnum,
              merge(manifestStmts4, merge(metadataStmts4, new Statement[] {xFoobar_FooBarFoo4}))));

      System.out.println("...done");

      System.out.println("Checking storing and loading via model...");

      String f = tempDir + "TESTPARA.odt";

      XStorable xStor = UnoRuntime.queryInterface(XStorable.class, xRepoSupplier);

      xStor.storeToURL(f, new PropertyValue[0]);

      xComp2 = util.DesktopTools.loadDoc(xMSF, f, loadProps);

      XDocumentMetadataAccess xDMA2 =
          UnoRuntime.queryInterface(XDocumentMetadataAccess.class, xComp2);
      assertTrue("xDMA2 null", null != xDMA2);

      XRepositorySupplier xRS2 = UnoRuntime.queryInterface(XRepositorySupplier.class, xComp2);
      assertTrue("xRS2 null", null != xRS2);

      XRepository xRep2 = xRS2.getRDFRepository();
      assertTrue("xRep2 null", null != xRep2);

      Statement[] manifestStmts5 = getManifestStmts(xDMA2);
      Statement[] metadataStmts5 = getMetadataFileStmts(xDMA2, fooBarPath);
      XURI xFoobar5 = URI.createNS(xContext, xDMA2.getStringValue(), fooBarPath);
      Statement xFoobar_FooBarFoo5 = new Statement(foo, bar, foo, xFoobar5);
      xStmtsEnum = xRep.getStatements(null, null, null);
      XEnumeration xStmtsEnum2 = xRep2.getStatements(null, null, null);
      assertTrue(
          "load: repository differs",
          eq(
              xStmtsEnum2,
              merge(manifestStmts5, merge(metadataStmts5, new Statement[] {xFoobar_FooBarFoo5}))));

      System.out.println("...done");

    } finally {
      close(xComp);
      close(xComp2);
    }
  }
예제 #5
0
  @Before
  public void before() throws Exception {
    xMSF = getMSF();
    param = new TestParameters();
    param.put("ServiceFactory", xMSF); // important for param.getMSF()

    assertNotNull("could not create MultiServiceFactory.", xMSF);
    XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xMSF);
    Object defaultCtx = xPropertySet.getPropertyValue("DefaultContext");
    xContext = UnoRuntime.queryInterface(XComponentContext.class, defaultCtx);
    assertNotNull("could not get component context.", xContext);

    tempDir = util.utils.getOfficeTemp /*Dir*/(xMSF);
    System.out.println("tempdir: " + tempDir);

    foo = URI.create(xContext, "uri:foo");
    assertNotNull("foo", foo);
    bar = URI.create(xContext, "uri:bar");
    assertNotNull("bar", bar);
    baz = URI.create(xContext, "uri:baz");
    assertNotNull("baz", baz);

    blank1 = BlankNode.create(xContext, "_:1");
    assertNotNull("blank1", blank1);
    blank2 = BlankNode.create(xContext, "_:2");
    assertNotNull("blank2", blank2);
    blank3 = BlankNode.create(xContext, "_:3");
    assertNotNull("blank3", blank3);
    blank4 = BlankNode.create(xContext, "_:4");
    assertNotNull("blank4", blank4);
    rdf_type = URI.createKnown(xContext, URIs.RDF_TYPE);
    assertNotNull("rdf_type", rdf_type);
    rdfs_label = URI.createKnown(xContext, URIs.RDFS_LABEL);
    assertNotNull("rdfs_label", rdfs_label);
    pkg_Document = URI.createKnown(xContext, URIs.PKG_DOCUMENT);
    assertNotNull("pkg_Document", pkg_Document);
    pkg_hasPart = URI.createKnown(xContext, URIs.PKG_HASPART);
    assertNotNull("pkg_hasPart", pkg_hasPart);
    pkg_MetadataFile = URI.createKnown(xContext, URIs.PKG_METADATAFILE);
    assertNotNull("pkg_MetadataFile", pkg_MetadataFile);
    odf_ContentFile = URI.createKnown(xContext, URIs.ODF_CONTENTFILE);
    assertNotNull("odf_ContentFile", odf_ContentFile);
    odf_StylesFile = URI.createKnown(xContext, URIs.ODF_STYLESFILE);
    assertNotNull("odf_StylesFile", odf_StylesFile);
    odf_Element = URI.createKnown(xContext, URIs.ODF_ELEMENT);
    assertNotNull("odf_Element", odf_Element);
  }