eXist-db の特定のコレクションにファイルをアップロードできるアプリケーションを作成しています。このアプリケーションは、eXist Web サイトで見つけたコードに基づいています。
残念ながら、コードが機能していないようです - テストするとエラーメッセージが表示されます
usage: StoreExample collection-path document
URI xmldb:exist://localhost:8080/exist/xmlrpcをhttp://localhost:8080/exist/admin/admin.xql;jsessionid=1fkd05vvfv6kqに変更し、コレクションを/db/col1に変更すると、次のエラーが発生します発生します:
Exception in thread "main" org.xmldb.api.base.XMLDBException:
at org.xmldb.api.DatabaseManager.getDatabase(Unknown Source)
at org.xmldb.api.DatabaseManager.getCollection(Unknown Source)
at org.xmldb.api.DatabaseManager.getCollection(Unknown Source)
at addingfiletest.exp.main(exp.java:44)
ligne 44 ==> Collection col =DatabaseManager.getCollection(URI + collection);
これが私のコードです:
import java.io.File;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.Database;
import org.xmldb.api.base.*;
import org.xmldb.api.modules.CollectionManagementService;
import org.xmldb.api.modules.XMLResource;
public class exp {
public final static String URI = "http://localhost:8080/exist/admin/admin.xql;jsessionid=1fkd05vvfv6kq";
public static void main(String args[]) throws Exception {
String collection = "/db/col1", file = "D:/PFE/lien.txt";
// initialisation du driver
String driver = "org.exist.xmldb.DatabaseImpl";
Class cl = Class.forName(driver);
Database database = (Database) cl.newInstance();
DatabaseManager.registerDatabase(database);
// Accès à la collection
Collection col = DatabaseManager.getCollection(URI + collection);
// créer une nouvelle XMLResource; un id sera affecté à la nouvelle
// ressource
XMLResource document = (XMLResource) col.createResource(null,
"XMLResource");
File f = new File(file);
if (!f.canRead()) {
System.out.println("cannot read file " + file);
return;
}
document.setContent(f);
System.out.print("storing document " + document.getId() + "...");
col.storeResource(document);
System.out.println("ok.");
}
}
すべての助けに感謝します、ありがとう。