コード例 #1
0
ファイル: SystemImport.java プロジェクト: BillVelasquez/exist
  public void restore(
      RestoreListener listener,
      String username,
      Object credentials,
      String newCredentials,
      File f,
      String uri)
      throws XMLDBException, FileNotFoundException, IOException, SAXException,
          ParserConfigurationException, URISyntaxException, AuthenticationException,
          ConfigurationException, PermissionDeniedException {

    // login
    final DBBroker broker = db.authenticate(username, credentials);
    try {
      // set the new password
      setAdminCredentials(broker, newCredentials);

      // get the backup descriptors, can be more than one if it was an incremental backup
      final Stack<BackupDescriptor> descriptors = getBackupDescriptors(f);

      final SAXParserFactory saxFactory = SAXParserFactory.newInstance();
      saxFactory.setNamespaceAware(true);
      saxFactory.setValidating(false);
      final SAXParser sax = saxFactory.newSAXParser();
      final XMLReader reader = sax.getXMLReader();

      try {
        listener.restoreStarting();

        while (!descriptors.isEmpty()) {
          final BackupDescriptor descriptor = descriptors.pop();
          final EXistInputSource is = descriptor.getInputSource();
          is.setEncoding("UTF-8");

          final SystemImportHandler handler =
              new SystemImportHandler(broker, listener, uri, descriptor);

          reader.setContentHandler(handler);
          reader.parse(is);
        }
      } finally {
        listener.restoreFinished();
      }
    } finally {
      db.release(broker);
    }
  }
コード例 #2
0
ファイル: SystemImport.java プロジェクト: BillVelasquez/exist
  private Stack<BackupDescriptor> getBackupDescriptors(File contents)
      throws XMLDBException, IOException {

    final Stack<BackupDescriptor> descriptors = new Stack<BackupDescriptor>();

    do {
      final BackupDescriptor bd = getBackupDescriptor(contents);

      descriptors.push(bd);

      // check if the system collection is in the backup. This should be processed first
      final BackupDescriptor sysDescriptor =
          bd.getChildBackupDescriptor(XmldbURI.SYSTEM_COLLECTION_NAME);

      // check if the system/security collection is in the backup, this must be the first system
      // collection processed
      if (sysDescriptor != null) {
        descriptors.push(sysDescriptor);

        final BackupDescriptor secDescriptor = sysDescriptor.getChildBackupDescriptor("security");
        if (secDescriptor != null) {
          descriptors.push(secDescriptor);
        }
      }

      contents = null;

      final Properties properties = bd.getProperties();
      if ((properties != null) && "yes".equals(properties.getProperty("incremental", "no"))) {
        final String previous = properties.getProperty("previous", "");

        if (previous.length() > 0) {
          contents = new File(bd.getParentDir(), previous);

          if (!contents.canRead()) {
            throw new XMLDBException(
                ErrorCodes.PERMISSION_DENIED,
                "Required part of incremental backup not found: " + contents.getAbsolutePath());
          }
        }
      }
    } while (contents != null);

    return descriptors;
  }