私はeXist-dbの特定のコレクションにファイルをアップロードできるアプリケーションを作成しています。私はこのアプリケーションをcode I found on the eXist web siteから外しています。Javaを使用してファイルをeXist-dbにアップロード
残念ながら、コードが動作するようには思えない - 私はそれをテストするとき、私はURI XMLDB変更するとエラーメッセージが
usage: StoreExample collection-path document
を表示されます:存在:// localhostを:に8080 /存在/ XMLRPCをにhttp:// localhost:8080 /に存在する/管理/ 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.");
}
}
ありがとう、ありがとう、ありがとう。