Esempio n. 1
0
 public void openIdlDescription(String _sIDLUrl, String _sClassName, String _sAnchor) {
   try {
     String sIDLUrl = _sIDLUrl;
     String sAnchor = ""; // TODO find out how the Anchor may be set at the html file;  //_sAnchor;
     boolean bExists = Introspector.getIntrospector().getXSimpleFileAccess().exists(sIDLUrl);
     if (sIDLUrl.equals("") || (!bExists)) {
       sIDLUrl = "http://api.libreoffice.org/" + Inspector.sIDLDOCUMENTSUBFOLDER;
     }
     if (!sIDLUrl.endsWith("/")) {
       sIDLUrl += "/";
     }
     if (_sClassName.equals("")) {
       sIDLUrl += "index";
       sAnchor = "";
     } else {
       sIDLUrl += _sClassName.replace(".", "_1_1");
     }
     sIDLUrl += ".html";
     if (sAnchor != null) {
       if (!sAnchor.equals("")) {
         sIDLUrl += "#" + sAnchor;
       }
     }
     URL openHyperlink = getDispatchURL(".uno:OpenHyperlink");
     PropertyValue pv = new PropertyValue();
     pv.Name = "URL";
     pv.Value = sIDLUrl;
     getXDispatcher(openHyperlink).dispatch(openHyperlink, new PropertyValue[] {pv});
   } catch (Exception exception) {
     exception.printStackTrace(System.err);
   }
 }
Esempio n. 2
0
  /**
   * calls <CODE>createTestEnvironment()</CODE> from it's super class
   *
   * @param Param the test parameter
   * @param log the log writer
   * @return lib.TestEnvironment
   */
  @Override
  protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws Exception {
    TestEnvironment tEnv = super.createTestEnvironment(Param, log);
    tEnv.addObjRelation("DataAwareControlModel.NewFieldName", DBTools.TST_INT_F);
    PropertyValue prop = new PropertyValue();
    prop.Name = "HelpText";
    prop.Value = "new Help Text since XPropertyAccess";
    tEnv.addObjRelation("XPropertyAccess.propertyToChange", prop);
    tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "HelpText");

    return tEnv;
  }
  /** Create a specified read-only configuration view */
  protected Object createConfigurationReadOnlyView(String sPath) throws com.sun.star.uno.Exception {
    // XMultiServiceFactory xProvider = getProvider();

    // The service name: Need only read access:
    final String sReadOnlyView = "com.sun.star.configuration.ConfigurationAccess";

    // creation arguments: nodepath
    com.sun.star.beans.PropertyValue aPathArgument = new com.sun.star.beans.PropertyValue();
    aPathArgument.Name = "nodepath";
    aPathArgument.Value = sPath;

    Object[] aArguments = new Object[1];
    aArguments[0] = aPathArgument;

    Object xViewRoot = m_ConfProvider.createInstanceWithArguments(sReadOnlyView, aArguments);
    return xViewRoot;
  }
  /** Create a specified updatable configuration view using default synchronicity */
  protected Object createConfigurationReadWriteView(String sPath)
      throws com.sun.star.uno.Exception {
    // The service name: Need update access:
    final String cUpdatableView = "com.sun.star.configuration.ConfigurationUpdateAccess";

    // creation arguments: nodepath
    com.sun.star.beans.PropertyValue aPathArgument = new com.sun.star.beans.PropertyValue();
    aPathArgument.Name = "nodepath";
    aPathArgument.Value = sPath;
    // creation arguments: commit mode - write-through or write-back
    com.sun.star.beans.PropertyValue aModeArgument = new com.sun.star.beans.PropertyValue();
    aModeArgument.Name = "enableasync";
    aModeArgument.Value = new Boolean(false);

    Object[] aArguments = new Object[2];
    aArguments[0] = aPathArgument;
    aArguments[1] = aModeArgument;

    // create the view
    Object xViewRoot = m_ConfProvider.createInstanceWithArguments(cUpdatableView, aArguments);
    return xViewRoot;
  }
Esempio n. 5
0
 private PropertyValue[] loadArgs(String url) {
   PropertyValue pv = new PropertyValue();
   pv.Name = "URL";
   pv.Value = url;
   return new PropertyValue[] {pv};
 }
  /** * creating a Testenvironment for the interfaces to be tested */
  protected synchronized TestEnvironment createTestEnvironment(
      TestParameters Param, PrintWriter log) {
    if (xTextDoc != null) {
      try {
        XCloseable closer = UnoRuntime.queryInterface(XCloseable.class, xTextDoc);
        closer.close(true);
      } catch (com.sun.star.util.CloseVetoException e) {
        log.println("couldn't close document");
      } catch (com.sun.star.lang.DisposedException e) {
        log.println("couldn't close document");
      }

      log.println("Existing document disposed");
    }

    log.println("creating a text document");
    xTextDoc = WriterTools.createTextDoc(((XMultiServiceFactory) Param.getMSF()));

    // initialize test table
    if (isMySQLDB) {
      try {
        dbTools.initTestTableUsingJDBC(tableName, srcInf);
      } catch (java.sql.SQLException e) {
        e.printStackTrace(log);
        throw new StatusException(Status.failed("Couldn't " + " init test table. SQLException..."));
      } catch (java.lang.ClassNotFoundException e) {
        throw new StatusException(Status.failed("Couldn't " + "register mysql driver"));
      }
    }

    XInterface oObj = null;
    XShapes oShapes = null;
    XInterface oInstance = null;
    XConnection connection = null;

    // creation of testobject here
    // first we write what we are intend to do to log file
    log.println("creating a test environment");

    XNameContainer forms = FormTools.getForms(WriterTools.getDrawPage(xTextDoc));

    try {
      String[] formNames = forms.getElementNames();

      for (int i = 0; i < formNames.length; i++) {
        log.println("Removing form '" + formNames[i] + "' ...");
        forms.removeByName(formNames[i]);
      }
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
    } catch (com.sun.star.container.NoSuchElementException e) {
      e.printStackTrace(log);
    }

    String[] formNames = forms.getElementNames();
    FormTools.insertForm(xTextDoc, forms, "MyForm");
    formNames = forms.getElementNames();

    XLoadable formLoader = null;

    try {
      formLoader = FormTools.bindForm(xTextDoc, "MyForm", dbSourceName, tableName);
    } catch (com.sun.star.uno.Exception e) {
      log.println(
          "Cann't bind the form to source '" + dbSourceName + "', table '" + tableName + "' :");
      e.printStackTrace(log);
      throw new StatusException("Cann't bind a form", e);
    }

    // DEBUG
    log.println("Forms before adding controls : ");
    formNames = forms.getElementNames();

    for (int i = 0; i < formNames.length; i++) {
      log.println("    '" + formNames[i] + "'");
    }

    XControlShape shape1 = null;
    XControlShape shape2 = null;

    try {

      log.println("Elements in the 'MyForm' :");

      XIndexAccess formElements1 =
          UnoRuntime.queryInterface(XIndexAccess.class, forms.getByName("MyForm"));

      for (int i = 0; i < formElements1.getCount(); i++) {
        XNamed elemName = UnoRuntime.queryInterface(XNamed.class, formElements1.getByIndex(i));
        log.println("   '" + elemName.getName() + "'");
      }

      // END DEBUG
      // put something on the drawpage
      log.println("inserting some ControlShapes");
      oShapes = DrawTools.getShapes(WriterTools.getDrawPage(xTextDoc));
      shape1 = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000, 1000, "CommandButton");
      shape2 = FormTools.createControlShape(xTextDoc, 5000, 3500, 7500, 5000, "TextField");

      XControlShape shape3 =
          FormTools.createControlShape(xTextDoc, 2000, 1500, 1000, 1000, "CheckBox");
      oShapes.add(shape1);
      oShapes.add(shape2);
      oShapes.add(shape3);
    } catch (Exception e) {
      e.printStackTrace(log);
    }

    log.println("Forms after adding controls : ");
    formNames = forms.getElementNames();

    for (int i = 0; i < formNames.length; i++) {
      log.println("    '" + formNames[i] + "'");
    }

    try {
      log.println("Elements in the 'MyForm' :");

      XIndexAccess formElements1 =
          UnoRuntime.queryInterface(XIndexAccess.class, forms.getByName("MyForm"));

      for (int i = 0; i < formElements1.getCount(); i++) {
        XNamed elemName = UnoRuntime.queryInterface(XNamed.class, formElements1.getByIndex(i));
        log.println("   '" + elemName.getName() + "'");
      }
    } catch (Exception e) {
      e.printStackTrace(log);
    }

    formLoader.load();

    try {
      oObj =
          (XForm)
              AnyConverter.toObject(
                  new Type(XForm.class),
                  (FormTools.getForms(WriterTools.getDrawPage(xTextDoc))).getByName("MyForm"));

      XPropertySet xSetProp = UnoRuntime.queryInterface(XPropertySet.class, oObj);
      connection =
          (XConnection)
              AnyConverter.toObject(
                  new Type(XConnection.class), xSetProp.getPropertyValue("ActiveConnection"));
    } catch (com.sun.star.uno.Exception e) {
      log.println("Couldn't get Form");
      e.printStackTrace(log);
    }

    // get a control
    oInstance = FormTools.createControl(xTextDoc, "TextField");

    log.println("creating a new environment for drawpage object");

    TestEnvironment tEnv = new TestEnvironment(oObj);

    // adding relation for closing connection while environment disposing.
    this.conn = connection;

    // adding relation for XSubmit
    XControlModel the_Model = shape2.getControl();
    XControlAccess the_access =
        UnoRuntime.queryInterface(XControlAccess.class, xTextDoc.getCurrentController());
    XControl cntrl = null;

    // now get the OEditControl
    try {
      cntrl = the_access.getControl(the_Model);
      log.println(cntrl.getClass().getName());
    } catch (com.sun.star.container.NoSuchElementException e) {
      log.println("Couldn't get OEditControl");
      e.printStackTrace(log);
      throw new StatusException("Couldn't get OEditControl", e);
    }

    XResultSet the_set = UnoRuntime.queryInterface(XResultSet.class, oObj);

    try {
      the_set.first();
    } catch (SQLException e) {
      log.println("Cann't move cursor to the first row.");
      e.printStackTrace();
      throw new StatusException("Can't move cursor to the first row.", e);
    }

    tEnv.addObjRelation("Model1", shape1.getControl());
    tEnv.addObjRelation("Model2", shape2.getControl());

    // adding an object for XNameReplace testing
    log.println("adding oInstace as obj relation to environment");
    tEnv.addObjRelation("INSTANCE", oInstance);

    // INDEX : _XNameContainer
    log.println("adding INDEX as obj relation to environment");
    tEnv.addObjRelation("INDEX", "0");

    // INDEX : _XNameReplace
    log.println("adding NameReplaceIndex as obj relation to environment");
    tEnv.addObjRelation("XNameReplaceINDEX", "2");

    // INSTANCEn : _XNameContainer; _XNameReplace
    log.println("adding INSTANCEn as obj relation to environment");

    // XComponent xComp = (XComponent)
    //    UnoRuntime.queryInterface(XComponent.class, xDrawDoc);
    String tc = (String) Param.get("THRCNT");
    int THRCNT = 1;

    if (tc != null) {
      THRCNT = Integer.parseInt(tc);
    }

    for (int n = 1; n < (2 * (THRCNT + 1)); n++) {
      log.println("adding INSTANCE" + n + " as obj relation to environment");
      tEnv.addObjRelation("INSTANCE" + n, FormTools.createControl(xTextDoc, "CheckBox"));
    }

    // adding relation for XNameContainer
    tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());

    // adding relation for XPersistObject
    tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component.Form");

    if (the_set != null) {
      log.println("The Form has a not empty ResultSet");
    }

    // Adding obj relation for XRowSetApproveBroadcaster test
    final XResultSet xResSet = UnoRuntime.queryInterface(XResultSet.class, oObj);
    final XResultSetUpdate xResSetUpdate = UnoRuntime.queryInterface(XResultSetUpdate.class, oObj);
    final XRowSet xRowSet = UnoRuntime.queryInterface(XRowSet.class, oObj);
    final PrintWriter logF = log;
    tEnv.addObjRelation(
        "XRowSetApproveBroadcaster.ApproveChecker",
        new ifc.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker() {
          public void moveCursor() {
            try {
              xResSet.beforeFirst();
              xResSet.afterLast();
            } catch (com.sun.star.sdbc.SQLException e) {
              logF.println(
                  "### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.moveCursor() :");
              e.printStackTrace(logF);
            }
          }

          public RowChangeEvent changeRow() {
            try {
              xResSet.first();

              XRowUpdate row = UnoRuntime.queryInterface(XRowUpdate.class, xResSet);
              row.updateString(1, "1");
              xResSetUpdate.updateRow();
            } catch (com.sun.star.sdbc.SQLException e) {
              logF.println(
                  "### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRow() :");
              e.printStackTrace(logF);
            }

            RowChangeEvent ev = new RowChangeEvent();
            ev.Action = com.sun.star.sdb.RowChangeAction.UPDATE;
            ev.Rows = 1;

            return ev;
          }

          public void changeRowSet() {
            try {
              xRowSet.execute();
            } catch (com.sun.star.sdbc.SQLException e) {
              logF.println(
                  "### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRowSet() :");
              e.printStackTrace(logF);
            }
          }
        });

    // Adding relation for XColumnLocate test
    tEnv.addObjRelation("XColumnLocate.ColumnName", DBTools.TST_STRING_F);

    // Adding relation for XParameters ifc test
    ArrayList<Object> params = new ArrayList<Object>();

    /** *** statement parameter types and their initial values must be added here as relation. */
    params.add("SAU99");
    params.add(new Boolean(false));
    params.add(new Byte((byte) 123));
    params.add(new Short((short) 234));
    params.add(new Integer(12345));
    params.add(new Long(23456));
    params.add(new Float(1.234));
    params.add(new Double(2.345));
    params.add(new byte[] {1, 2, 3});
    Date d = new Date();
    d.Day = 26;
    d.Month = 1;
    d.Year = 2001;
    params.add(d);
    Time t = new Time();
    t.Hours = 1;
    t.NanoSeconds = 123456789;
    t.Minutes = 25;
    t.Seconds = 14;
    params.add(t);
    DateTime dt = new DateTime();
    dt.Day = 26;
    dt.Month = 1;
    dt.Year = 2001;
    dt.Hours = 1;
    dt.NanoSeconds = 123456789;
    dt.Minutes = 25;
    dt.Seconds = 14;
    params.add(dt);
    tEnv.addObjRelation("XParameters.ParamValues", params);

    // Adding relation for XCompletedExecution
    tEnv.addObjRelation("InteractionHandlerChecker", new InteractionHandlerImpl());

    // Adding for XWarningSupplier
    tEnv.addObjRelation("CheckWarningsSupplier", new Boolean(isMySQLDB));

    // Adding relation for XDatabaseParameterBroadcaster
    tEnv.addObjRelation("ParameterListenerChecker", new ODatabaseForm.ParameterListenerImpl());
    XPropertySet xSetProp = UnoRuntime.queryInterface(XPropertySet.class, oObj);
    try {
      xSetProp.setPropertyValue("DataSourceName", dbSourceName);
      if (isMySQLDB) {
        xSetProp.setPropertyValue(
            "Command", "SELECT Column0  FROM soffice_test_table  WHERE ( (  Column0 = :param1 ) )");
      } else {
        xSetProp.setPropertyValue(
            "Command",
            "SELECT \"_TEXT\" FROM \"ODatabaseForm_tmp0\" WHERE ( ( \"_TEXT\" = :param1 ) )");
      }

      xSetProp.setPropertyValue("CommandType", new Integer(CommandType.COMMAND));
    } catch (Exception e) {
    }

    // Adding relation for XResultSetUpdate
    final XRowUpdate xRowUpdate = UnoRuntime.queryInterface(XRowUpdate.class, oObj);
    final XRow xRow = UnoRuntime.queryInterface(XRow.class, oObj);

    tEnv.addObjRelation(
        "XResultSetUpdate.UpdateTester",
        new ifc.sdbc._XResultSetUpdate.UpdateTester() {
          String lastUpdate = null;

          public int rowCount() throws SQLException {
            int prevPos = xResSet.getRow();
            xResSet.last();

            int count = xResSet.getRow();
            xResSet.absolute(prevPos);

            return count;
          }

          public void update() throws SQLException {
            lastUpdate = xRow.getString(1);
            lastUpdate += "_";
            xRowUpdate.updateString(1, lastUpdate);
          }

          public boolean wasUpdated() throws SQLException {
            String getStr = xRow.getString(1);

            return lastUpdate.equals(getStr);
          }

          public int currentRow() throws SQLException {
            return xResSet.getRow();
          }
        });

    // Adding relations for XRow as a Vector with all data
    // of current row of RowSet.

    ArrayList<Object> rowData = new ArrayList<Object>();

    for (int i = 0; i < DBTools.TST_TABLE_VALUES[0].length; i++) {
      rowData.add(DBTools.TST_TABLE_VALUES[0][i]);
    }

    tEnv.addObjRelation("CurrentRowData", rowData);

    // Adding relation for XRowUpdate
    XRow row = UnoRuntime.queryInterface(XRow.class, oObj);
    tEnv.addObjRelation("XRowUpdate.XRow", row);

    tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "Cycle");

    PropertyValue propVal = new PropertyValue();
    propVal.Name = "Name";
    propVal.Value = "Text since XPropertyAccess";

    tEnv.addObjRelation("XPropertyAccess.propertyToChange", propVal);

    return tEnv;
  } // finish method getTestEnvironment
  @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);
    }
  }