

![]() ![]() ![]() ![]() ![]() ![]() | ![]() |
![]() |
|
|
|
|
![]() |
|
|
|
![]() |
第10章
この章では、カスタムWebDAVクライアントを開発するためのexteNd Director WebDAVサービスに付属のAPIについて説明します。WebDAVクライアントでは、exteNd Director Content Management (CM)サブシステムの特別な機能を利用し、コンテンツを作成、管理します。
この章では、次のトピックについて説明します。
WebDAVクライアントAPIは、Jakarta Slideコンテンツ管理フレームワークに基いており、exteNd Director CMサブシステムで機能するように設計されています。Slideは、WebDAVプロトコルを使用してさまざまなデータストアのバイナリコンテンツを操作するための一貫したインタフェースの開発に使用できる低レベルのフレームワークです。
Javaクライアントアプリケーションでは、次のような分野でWebDAVメソッドおよび低レベルのその他の論理を実装するJavaクラスのセットを使用して、Slideコンテンツ管理フレームワークに直接アクセスできます。
SlideクライアントAPIの前後にラッパクラスを指定すると、exteNd Director WebDAVクライアントAPIにより抽象レベルが追加されます。これらのクラスにはヘルパメソッドおよびユーティリティメソッドが含まれています。これらのメソッドは、低レベルのSlideメソッドをカプセル化し、exteNd Director CMサブシステムの特別な機能と密接に統合する論理を追加します。たとえば、ドキュメントにカテゴリを割り当て、カスタムメタデータをコンテンツに関連付けて、CMサブシステムで定義された「ドキュメントタイプ」と呼ばれるカスタムテンプレートを使用してコンテンツを作成するWebDAVクライアントを構築することができます。
Slideの詳細については、Jakarta SlideプロジェクトのWebサイトを参照してください。この章の発行時点では、次のURLが使用されています。
http://jakarta.apache.org/slide/
市販およびオープンソースのWebDAVクライアントアプリケーションは現在多数存在しており、入手できるアプリケーションは今後さらに増えることが予想されます。それにもかかわらず、exteNd Director CMサブシステムで機能する独自のWebDAVクライアントを作成する理由について、次に説明します。
主な理由としては、exteNd Director CMサブシステムを使用して、コンテンツの作成、更新、および管理に関する固有なオーサリングニーズに合わせてアプリケーションをカスタマイズするためです。この目的を念頭に置くと、WebDAVクライアントAPIを使用することにより、次のような点で、ほとんどの市販およびオープンソースのWebDAVクライアントよりもさらに強力なアプリケーションを開発できます。
「WebDAVクライアントAPIを使用する」には、次のJARファイルをプロジェクトクラスパスに追加する必要があります。
|
JARファイル |
説明 |
|---|---|
|
WebDAV_slide.jar |
関連するSlideクライアントAPIクラスを含みます。 |
|
WebDAVClient.jar |
exteNd Director WebDAVクライアントAPIクラスを含みます。 |
これらのJARファイルは、exteNd Directorインストールディレクトリの次の場所に、exteNd Directorとともにインストールされます。
eXtendDirector\utilities\Client
「WebDAVクライアントを実行する」には、ランタイム時に次のJARファイルをクライアントのクラスパスに追加する必要があります。
たとえば、次のとおりです。 getDocumentsというWebDAV Javaクライアントプログラムを実行するには、次のコマンドを入力し、独自のインストールディレクトリパスで置き換えます。
>set classpath=D:\\Director_install\\eXtendDirector\\utilities\\Client\\WebDAVClient.jar;D:\\Director_install\\eXtendDirector\\utilities\\Client\\WebDAV_slide.jar;.;D:\\Director_install\\eXtendDirector\\lib\\xerces.jar;D:\\Director_install\\eXtendDirector\\lib\\xalan.jar;D:\\Director_install\\eXtendDirector\\lib\\FrameworkService.jar;d:\\Director_install\\eXtendServer\\lib\\servlet.jar >java -cp %classpath% getDocuments
コンテンツの共同操作を管理するためにexteNd Director CMサブシステムへのWebDAVアクセスを持つカスタムオーサリングツールを設計するには、WebDAVクライアントAPIを使用します。
独自のユーザインタフェースを作成する必要がありますが、クライアントから次の重要なCM機能を呼び出す論理的基盤がAPIにより提供されます。
WebDAVクライアントAPIでは、WebDAV要求を送信することによって、CM機能を呼び出すメソッドを提供します。各要求の結果は、成功または失敗の理由を示すステータスコードを含むWebDAV応答として返されます。
WebDAV要求は、ヘッダと本文から構成されます。要求ヘッダには、メソッド、ターゲットリソース、HTTPバージョン、およびメソッドのパラメータを含むキーと値のペアのシーケンスが含まれています。要求の本文では、必要に応じて追加の(そして、さらに複雑な可能性のある)パラメータが定義されます。
同様に、WebDAV応答も、ヘッダおよびオプションの本文から構成されます。応答ヘッダには、サーバで使用されるHTTPバージョンなどの応答に関する情報が、ステータスコードおよびメッセージとともに含まれます。 通常、応答の本文には、ドキュメントなどのメソッド実行の結果が含まれます。
WebDAVクライアントAPIのクラスは、特定のWebDAV要求を簡単に作成、送信し、応答を処理するためのメソッドを提供します。
WebDAVの詳細については、Webサイトでrfc2518 (WebDAVの仕様)を検索してください。
分散型Webオーサリングの情報要素で説明されているように、WebDAV要求は、Webリソース、コレクション、およびプロパティで動作します。WebDAV要求を発行する場合は、目的の要素に参照を渡す必要があります。この参照は、要素のサーバに相対的な、次の形式のURIでなければなりません。
/database name/WebDAVService/main/path relative to default (root) folder
たとえば、exteNd DirectorデータベースがDirectorだとします。MyDocumentというドキュメントがTestというデフォルト(ルート)フォルダに存在する場合、URIは次のようになります。
/Director/WebDAVService/main/Test/MyDocument
WebDAVクライアントAPIは、次の主要なクラスから構成されます。
|
クラス |
説明 |
|---|---|
|
WebDAV要求を構成し、WebDAV応答を取得します。 |
|
|
EboDAVException |
WebDAV例外を定義します。 |
|
EboDAVStatus |
WebDAV例外に関連付けられているステータスコードを示します。 |
中心であるEboDAVSwitch EboDAVSwitchオブジェクトはWebDAVクライアントAPIの中心で、CMサブシステムと通信する機能性のほとんどが含まれています。EboDAVSwitchでは、WebDAVの要求と応答を転送する場合に必要な低レベルのSlideコードの多くをカプセル化するヘルパメソッドおよびユーティリティメソッドを提供します。
EboDAVSwitchオブジェクトでは、WebDAV要求を構成するヘルパメソッドのセットを提供します。各ヘルパメソッドを使用すると、1行のコードで完全な要求を送信できます。
サポートされているWebDAV要求で、ヘルパメソッドが関連付けられているものは、次のとおりです。表のリンクをクリックすると、Javaクライアントプログラムで特定のWebDAV要求をコード化する方法の詳細が表示されます。
WebDAV要求の一部は、ヘルプメソッドが関連付けられていないため、Slideクラスおよび\x83 \x86 \x81 [\x83 e\x83 B\x83 \x8a \x83 e\x83 B\x83 \x81 \x83 \\x83 b\x83 hを使用することによってのみ発行されます(次で説明します)。
WebDAVクライアントアプリケーションでこれらのヘルパメソッドを使用する方法については、ヘルパメソッドを使用したプログラミング練習を参照してください。
すべてのWebDAV要求は、ユーティリティメソッドを使用して呼び出すことができます。ヘルパメソッドに比べると、ユーティリティメソッドでは、より多くのSlide APIを発行しています。Slide APIにより提供される追加の機能性にアクセスできる一方、WebDAV要求を送信するためにより多くのコード行を記述しなければならないというマイナス面があります。
また、ユーティリティメソッドにより、ヘルパメソッドが関連付けられていないWebDAV要求を発行するメカニズムも提供されます。
WebDAV要求を作成、発行するためのSlide機能をラップするユーティリティメソッドで、一般的に使用されるものは次のとおりです。
WebDAVクライアントアプリケーションでこれらのユーティリティメソッドを使用する方法の詳細については、ユーティリティメソッドを使用したプログラミング練習を参照してください。
ユーティリティメソッドを操作する場合は、複数のSlide APIクラスを使用する必要があります。
これらのクラスの詳細については、Slide WebDAVクライアントJavaDOCを次のURLで参照してください(この章の発行時点では、次のURLが使用されています)。
http://jakarta.apache.org/slide/clientjavadoc/index.html
exteNd Directorヘルパメソッドが関連付けられていないWebDAV要求のリストは、次のとおりです。これらは、SlideクラスおよびexteNd Directorユーティリティメソッドを使用することによってのみ実装できます。表のリンクをクリックすると、JavaクライアントプログラムでこれらのWebDAV要求をコード化する方法の詳細が表示されます。
|
WebDAV要求 |
関連付けられているWebDAVメソッド |
|---|---|
|
GET |
|
|
HEAD |
|
|
OPTIONS |
|
|
PROPFIND |
この節では、カスタムJavaクライアントプログラムでWebDAV要求を発行してWebDAV応答を処理するためにクライアントAPIを使用する場合の最適な練習について説明します。論理は、ヘルパメソッドまたはユーティリティメソッドのどちらを使用するかによって異なります。
WebDAV要求を発行するためにヘルパメソッドを使用する場合の手順は次のとおりです。
次は、ヘルプメソッドdeleteDocument()をWebDAVクライアントで使用する方法を示すサンプルコードです。この例では、サーバURL=localhost、ポート=80です。削除するドキュメントは、引数としてメソッドに渡されます。
EboDAVStatusオブジェクトはインスタンス化されることにも注意してください。このオブジェクトは、要求のステータスを確認し、ユーザに成功または失敗したことを通知するために使用されます。
/**
deleteADocument
*/
import com.sssw.webdav.client.*;
public class deleteADocument {
private static boolean m_debug = false;
public void deleteADocument (String document)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
try
{
//Lock document before trying to delete
statuscode = dav.lockDocument(user, password, realm, document);
if (statuscode==EboDAVStatus.SC_NO_CONTENT)
System.out.println(迭equest succeeded:The document is now locked・;
else
System.out.println(迭equest failed:・+ status.getStatusText(statuscode));
//Send the WebDAV request to delete document
statuscode = dav.deleteDocument(user, password, realm, document);
if (statuscode==EboDAVStatus.SC_OK)
System.out.println("Request succeeded:The document was deleted.");
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e) {
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
//End session
dav.endSession();
}
}
ユーティリティメソッドを使用して同じWebDAV要求を発行する方法を学習するには、コード例:ユーティリティメソッドを使用したドキュメントの削除を参照してください。
WebDAV要求を発行するためにユーティリティメソッドを使用する場合の手順は次のとおりです。
WebDAV Proppatchメソッドは、次のようなさまざまなWebDAV要求を発行するために、exteNd Directorユーティリティメソッドとともに使用されます。
これらの各要求に対しては、SlideのPropPatchMethodオブジェクトをインスタンス化し、次の署名を使用してPropPatchMethodオブジェクトでaddPropertyToSet()メソッドを呼び出す必要があります。
addPropertyToSet( String property name, String property value, String namespace-abbr, String namespace )
addPropertyToSet()に対する引数の説明は次のとおりです。
標準フィールドの値の設定 WebDAV Proppatchメソッドを使用すると、タイトルや作成者などのドキュメントの標準フィールドの値を設定することもできます。このような場合は、namespace-abbr引数やnamespace引数なしでaddPropertyToSet()を呼び出します。
次は、ドキュメントを削除する要求を送信するために、WebDAVクライアントでSlideクラスのあるユーティリティメソッドを使用する方法を示したサンプルコードです。この例では、サーバURL=localhost、ポート=80です。この例では、次のSlideクラスが使用されています。
/**
deleteTheDocument
*/
import com.sssw.webdav.client.*;
import org.apache.webdav.lib.*;
import org.apache.webdav.lib.methods.*;
public class deleteTheDocument
{
private static boolean m_debug = false;
public void deleteTheDocument (String document)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Get and set credentials
Credentials credentials = dav.createCredentials(user, password);
dav.setCredentials(credentials);
//Get and set state and authentication realm
State state = dav.getState();
state.setAuthenticateToken(realm);
dav.setState(state);
try
{
//Create the WebDAV method object LockMethod
LockMethod lm = (LockMethod)dav.createWebdavMethod(dav.LOCK_METHOD,document);
//Set the owner
lm.setOwner(user);
//Execute LockMethod
dav.executeCommand(lm);
statuscode = lm.getStatusCode();
if (statuscode == (EboDAVStatus.SC_NO_CONTENT))
System.out.println(迭equest succeeded:The document was locked.・;
else
System.out.println(迭equest failed:・+ status.getStatusText(statuscode));
//Create the WebDAV method object DeleteMethod
DeleteMethod dm = (DeleteMethod)dav.createWebdavMethod(dav.DELETE_METHOD,document);
//Execute DeleteMethod (send the WebDAV request to delete document)
dav.executeCommand(dm);
statuscode = dm.getStatusCode();
if (statuscode == (EboDAVStatus.SC_OK))
System.out.println("Request succeeded:The document was deleted.");
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
catch (java.net.MalformedURLException murle)
{
if (m_debug)
murle.printStackTrace();
else
System.out.println(murle.getMessage());
}
catch (java.io.IOException ioe)
{
if (m_debug)
ioe.printStackTrace();
else
System.out.println(ioe.getMessage());
}
//End session
dav.endSession();
}
}
ヘルパメソッドを使用して同じWebDAV要求を発行する方法を学習するには、コード例:ヘルパメソッドを使用したドキュメントの削除を参照してください。
この節では、JavaクライアントアプリケーションからWebDAV要求を発行する方法について説明します。説明されている機能は、次のとおりです。
次のコード例では、ドキュメントにカテゴリ参照を追加する方法を示します。カテゴリは、CMサブシステムで論理的にドキュメントをグループ化する場合に使用される、わかりやすい名前です。
この例では、ヘルパメソッドaddCategoryToDocument()を使用します。
/**
addCategoryReferenceToDocument
*/
import com.sssw.webdav.client.*;
public class addCategoryReferenceToDocument {
private static boolean m_debug = false;
public void addCategoryReferenceToDocument (String document, String categoryUUID)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
try
{
//Lock the document
statuscode = dav.lockDocument(user, password, realm, document);
if (statuscode == EboDAVStatus.SC_NO_CONTENT)
System.out.println(迭equest succeeded:The category was added to ・+ document);
else
System.out.println(迭equest failed:・+ status.getStatusText(statuscode));
//Send the WebDAV request to add a category reference
statuscode = dav.addCategoryToDocument(user, password, realm, document, categoryUUID);
if (statuscode==EboDAVStatus.SC_MULTI_STATUS)
System.out.println("Request succeeded:The category was added to " + document);
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
//Unlock the document
statuscode = dav.unlockDocument(user, password, realm, document);
if (statuscode == EboDAVStatus.SC_NO_CONTENT)
System.out.println(迭equest succeeded:The document was unlocked.・;
else
System.out.println(迭equest failed:・+ status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
//End session
dav.endSession();
}
}
この例では、SlideのPropPatchMethodクラスと、exteNd DirectorユーティリティメソッドのstartSession()、createCredentials()、setCredentials()、getState()、setState()、およびcreateWebDAVMethod()を使用します。
カテゴリ参照を追加するメソッドはaddPropertyToSet()で、PropPatchMethodオブジェクトで呼び出されます。カテゴリUUIDは、最初の引数であるproperty nameとして渡されるため、2番目の引数であるproperty valueはnullです。addPropertyToSet()およびその引数の詳細については、Proppatchを使用するWebDAV要求の作成を参照してください。
/**
addCategoryReference
*/
import com.sssw.webdav.client.*;
import com.sssw.webdav.common.EboWebdavConstants;
import org.apache.webdav.lib.*;
import org.apache.webdav.lib.methods.*;
public class addCategoryReference
{
private static boolean m_debug = false;
public void addCategoryReference (String document, String categoryUUID)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
String namespace-abbr = "AC";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Get and set credentials
Credentials credentials = dav.createCredentials(user, password);
dav.setCredentials(credentials);
//Get and set state and authentication realm
State state = dav.getState();
state.setAuthenticateToken(realm);
dav.setState(state);
try
{
//Lock the document
//Create the WebDAV method object LockMethod
LockMethod lm = (LockMethod)dav.createWebdavMethod(dav.LOCK_METHOD,document);
//Set the owner
lm.setOwner(user);
//Execute the command
dav.executeCommand(lm);
statuscode = lm.getStatusCode();
if (statuscode == (EboDAVStatus.SC_NO_CONTENT))
System.out.println(迭equest succeeded:The document was locked.・;
else
System.out.println(迭equest failed:・+ status.getStatusText(statuscode));
//Create the WebDAV method object PropPatchMethod
PropPatchMethod ppm = (PropPatchMethod)dav.createWebdavMethod(dav.PROPPATCH_METHOD,document);
ppm.addPropertyToSet( categoryUUID, null, namespace-abbr, EboWebdavConstants.PROPPATCH_ADDCATEGORY);
//Execute PropPatchMethod (send the WebDAV request to add category reference)
dav.executeCommand(ppm);
statuscode = ppm.getStatusCode();
if (statuscode == (EboDAVStatus.SC_MULTI_STATUS))
System.out.println("Request succeeded:The category was added to " + document + ".");
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
//Create the WebDAV method object UnlockMethod
UnlockMethod ulm = (UnlockMethod)dav.createWebdavMethod(dav.UNLOCK_METHOD,document);
//Execute UnlockMethod
dav.executeCommand(ulm);
statuscode = ulm.getStatusCode();
if (statuscode == (EboDAVStatus.SC_NO_CONTENT))
System.out.println(迭equest succeeded:The document was unlocked.・;
else
System.out.println(迭equest failed:・+ status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
catch (java.net.MalformedURLException murle)
{
if (m_debug)
murle.printStackTrace();
else
System.out.println(murle.getMessage());
}
catch (java.io.IOException ioe)
{
if (m_debug)
ioe.printStackTrace();
else
System.out.println(ioe.getMessage());
}
//End session
dav.endSession();
}
}
次のコードでは、ソースパスからコピー先のパスへドキュメントをコピーする方法を示します。この場合、ソースパスはドキュメントを指します。他のタイプのリソースまたはコレクションをコピーするには、ソースパスが目的の要素を指していることを確認します。
この例では、ヘルパメソッドcopyElement()を使用します。
/**
copyADocument
*/
import com.sssw.webdav.client.*;
public class copyADocument {
private static boolean m_debug = false;
public void copyADocument (String docsourcepath, String docdestinationpath)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
boolean overwrite = true; //Overwrite an existing document of the same name in the docdestinationpath
boolean autogen = true; //Generate folders in the docdestinationpath if they don\qt exist
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Send the WebDAV request to copy document
try
{
statuscode = dav.copyElement(user, password, realm, docsourcepath, docdestinationpath, overwrite, autogen);
if (statuscode==EboDAVStatus.SC_CREATED)
System.out.println("Request succeeded:The document " + docsourcepath + "was copied to " + docdestinationpath);
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
//End session
dav.endSession();
}
}
SlideのCopyMethodクラスとexteNd Directorユーティリティメソッドを使用して、リソースまたはコレクションをコピーすることもできます。ユーティリティメソッドを使用したプログラミング練習を参照してください。
次のコードでは、新しいコレクションの作成方法を示します。コレクションとは、他のリソースやコレクションのコンテナです。フォルダは、コレクションの一例です。
この例では、ヘルパメソッドmakeCollection()を使用します。
/**
makeACollection
*/
import com.sssw.webdav.client.*;
public class makeACollection {
private static boolean m_debug = false;
public void makeACollection (String parent_folder, String folder_name)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Send the WebDAV request to make a collection
try
{
statuscode = dav.makeCollection(user, password, realm, parent_folder, folder_name, true);
if (statuscode==EboDAVStatus.SC_CREATED)
System.out.println("Request succeeded:The collection " + parent_folder + "/" + folder_name + "was created.");
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
//End session
dav.endSession();
}
}
SlideのMkcolMethodクラスとexteNd Directorユーティリティメソッドを使用して、新しいコレクションを作成することもできます。ユーティリティメソッドを使用したプログラミング練習を参照してください。
次のコードでは、カスタムテンプレートから新しいドキュメントを作成する方法を示します。カスタムテンプレートとは、CM APIまたはCMS管理コンソールを使用してexteNd Director CMサブシステムで定義するドキュメントタイプです。
作成されるドキュメントには、このドキュメントタイプで定義されたカスタムフィールドの他に、コンテンツ「Hello world!」が含まれます。
この例では、ヘルパメソッドcreateNewDocument()を使用します。ドキュメントタイプは、ユーザ名、パスワード、領域、格納フォルダ、およびコンテンツとともに、createNewDocumentに引数として渡されます。
/**
createADocument
*/
import com.sssw.webdav.client.*;
public class createADocument {
private static boolean m_debug = false;
public void createADocument (String document, String folder, String documentType)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
String sourcetext = "Hello world!";
byte [] content = sourcetext.getBytes();
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Send the WebDAV request to create a document
try
{
statuscode = dav.createNewDocument(user, password, realm, folder, document, documentType, content);
if (statuscode==EboDAVStatus.SC_CREATED)
System.out.println("Request succeeded:The document " + document + "was created.");
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
//End session
dav.endSession();
}
}
WebDAVクライアントからドキュメントを削除する例については、コード例:ヘルパメソッドを使用したドキュメントの削除およびコード例:ユーティリティメソッドを使用したドキュメントの削除を参照してください。
次のコードでは、CMサブシステムに保存されているドキュメントのコンテンツを取得する方法を示します。ドキュメントは、createWebDAVMethod()ユーティリティメソッドの2番目の引数として参照されます。他のタイプのリソースまたはコレクションを取得するには、目的の要素を指すようにこの引数を変更します。
この例では、SlideのGetMethodクラスと、exteNd DirectorユーティリティメソッドのstartSession()、createCredentials()、setCredentials()、getState()、setState()、およびcreateWebDAVMethod()を使用します。
GetMethodクラスでgetDataAsString()メソッドを呼び出すと、クライアントアプリケーションにより、ドキュメントのコンテンツがHTML形式で取得されます。
リソースまたはコレクションを取得するためのヘルパメソッドはありません。
/**
getTheDocument
*/
import com.sssw.webdav.client.*;
import org.apache.webdav.lib.*;
import org.apache.webdav.lib.methods.*;
public class getTheDocument
{
private static boolean m_debug = false;
public void getTheDocument (String document)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Get and set credentials
Credentials credentials = dav.createCredentials(user, password);
dav.setCredentials(credentials);
//Get and set state and authentication realm
State state = dav.getState();
state.setAuthenticateToken(realm);
dav.setState(state);
//Create the WebDAV method object GetMethod
GetMethod gm = (GetMethod)dav.createWebdavMethod(dav.GET_METHOD,document);
//Execute GetMethod (send the WebDAV request to get document)
try
{
dav.executeCommand(gm);
statuscode = gm.getStatusCode();
if (statuscode == (EboDAVStatus.SC_OK))
{
String html = gm.getDataAsString();
System.out.println("Request succeeded:Got the document and its content as html.");
}
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
catch (java.net.MalformedURLException murle)
{
if (m_debug)
murle.printStackTrace();
else
System.out.println(murle.getMessage());
}
catch (java.io.IOException ioe)
{
if (m_debug)
ioe.printStackTrace();
else
System.out.println(ioe.getMessage());
}
//End session
dav.endSession();
}
}
リソースまたはコレクションを取得するためのexteNd Directorヘルパメソッドはありません。
次のコードでは、CMサブシステムに保存されているドキュメントのヘッダ情報を取得する方法を示します。ドキュメントは、createWebDAVMethod()ユーティリティメソッドの2番目の引数として参照されます。他のタイプのリソースまたはコレクションを取得するには、目的の要素を指すようにこの引数を変更します。
この例では、SlideのHeadMethodクラスと、exteNd DirectorユーティリティメソッドのstartSession()、createCredentials()、setCredentials()、getState()、setState()、およびcreateWebDAVMethod()を使用します。
リソースまたはコレクションを取得するためのヘルパメソッドはありません。
/**
getDocumentHeader
*/
import com.sssw.webdav.client.*;
import org.apache.webdav.lib.*;
import org.apache.webdav.lib.methods.*;
public class getDocumentHeader
{
private static boolean m_debug = false;
public void getDocumentHeader (String document)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
String authtype = 涛;
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Get and set credentials
Credentials credentials = dav.createCredentials(user, password);
dav.setCredentials(credentials);
//Get and set state and authentication realm
State state = dav.getState();
state.setAuthenticateToken(realm);
dav.setState(state);
//Create the WebDAV method object HeadMethod
HeadMethod hm = (HeadMethod)dav.createWebdavMethod(dav.HEAD_METHOD,document);
//Execute HeadMethod (send the WebDAV request to get document header)
try
{
dav.executeCommand(hm);
statuscode = hm.getStatusCode();
if (statuscode == (EboDAVStatus.SC_OK))
{
//Get authorization type from header
authtype = hm.getHeader (殿uthorization・.toString();
System.out.println("Request succeeded:Got the document header.Authorization type is ・+ authtype);
}
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
catch (java.net.MalformedURLException murle)
{
if (m_debug)
murle.printStackTrace();
else
System.out.println(murle.getMessage());
}
catch (java.io.IOException ioe)
{
if (m_debug)
ioe.printStackTrace();
else
System.out.println(ioe.getMessage());
}
//End session
dav.endSession();
}
}
リソースまたはコレクションからヘッダ情報を取得するためのexteNd Directorヘルパメソッドはありません。
次のコードでは、CMサブシステムに保存されているドキュメントで呼び出すことができるメソッドを取得する方法を示します。ドキュメントは、createWebDAVMethod()ユーティリティメソッドの2番目の引数として参照されます。他のタイプのリソースまたはコレクションを取得するには、目的の要素を指すようにこの引数を変更します。
この例では、SlideのOptionsMethodクラスと、exteNd DirectorユーティリティメソッドのstartSession()、createCredentials()、setCredentials()、getState()、setState()、およびcreateWebDAVMethod()を使用します。
リソースまたはコレクションで許可メソッドを取得するためのヘルパメソッドはありません。
/**
getAllowedMethods
*/
import com.sssw.webdav.client.*;
import org.apache.webdav.lib.*;
import org.apache.webdav.lib.methods.*;
import java.util.*;
public class getAllowedMethods
{
private static boolean m_debug = false;
public void getAllowedMethods (String document)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Get and set credentials
Credentials credentials = dav.createCredentials(user, password);
dav.setCredentials(credentials);
//Get and set state and authentication realm
State state = dav.getState();
state.setAuthenticateToken(realm);
dav.setState(state);
//Create the WebDAV method object HeadMethod
OptionsMethod om = (OptionsMethod)dav.createWebdavMethod(dav.OPTIONS,document);
//Execute OptionsMethod (send the WebDAV request to get the allowed methods on
//the document)
try
{
dav.executeCommand(om);
statuscode = om.getStatusCode();
if (statuscode == (EboDAVStatus.SC_OK))
{
System.out.println("Request succeeded:Got the document header.\n");
System.out.println("The allowed methods on " + document + " are:\n");
Enumeration methods = om.getAllowedMethods();
while (methods.hasMoreElements()) {
System.out.println( methods.nextElement().toString() + "\n" );
}
}
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
catch (java.net.MalformedURLException murle)
{
if (m_debug)
murle.printStackTrace();
else
System.out.println(murle.getMessage());
}
catch (java.io.IOException ioe)
{
if (m_debug)
ioe.printStackTrace();
else
System.out.println(ioe.getMessage());
}
//End session
dav.endSession();
}
}
リソースまたはコレクションで呼び出すことができるメソッドを取得するためのexteNd Directorヘルパメソッドはありません。
次のコードでは、CMサブシステムに保存されているドキュメントで定義されたプロパティを取得する方法を示します。ドキュメントは、createWebDAVMethod()ユーティリティメソッドの2番目の引数として参照されます。他のタイプのリソースまたはコレクションを取得するには、目的の要素を指すようにこの引数を変更します。
この例では、SlideのPropFindMethodクラスと、exteNd DirectorユーティリティメソッドのstartSession()、createCredentials()、setCredentials()、getState()、setState()、およびcreateWebDAVMethod()を使用します。
リソースまたはコレクションで定義されたプロパティを取得するためのヘルパメソッドはありません。
/**
getProperties
*/
import com.sssw.webdav.client.*;
import org.apache.webdav.lib.*;
import org.apache.webdav.lib.methods.*;
import java.util.*;
public class getProperties
{
private static boolean m_debug = false;
public void getProperties (String document)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Get and set credentials
Credentials credentials = dav.createCredentials(user, password);
dav.setCredentials(credentials);
//Get and set state and authentication realm
State state = dav.getState();
state.setAuthenticateToken(realm);
dav.setState(state);
//Create the WebDAV method object PropFindMethod
PropFindMethod pfm = (PropFindMethod)dav.createWebdavMethod(dav.PROPFIND_METHOD,document);
//Execute PropFindMethod (send the WebDAV request to get the properties defined on
//the document)
try
{
dav.executeCommand(pfm);
statuscode = pfm.getStatusCode();
if (statuscode == (EboDAVStatus.SC_MULTI_STATUS))
{
System.out.println("Request succeeded:Got the properties.\n");
System.out.println("The properties defined on " + document + " are:\n");
Enumeration props = pfm.getResponseProperties(document);
while (props.hasMoreElements()) {
System.out.println( props.nextElement().toString() + "\n" );
}
}
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
catch (java.net.MalformedURLException murle)
{
if (m_debug)
murle.printStackTrace();
else
System.out.println(murle.getMessage());
}
catch (java.io.IOException ioe)
{
if (m_debug)
ioe.printStackTrace();
else
System.out.println(ioe.getMessage());
}
//End session
dav.endSession();
}
}
リソースまたはコレクションで呼び出すことができるメソッドを取得するためのexteNd Directorヘルパメソッドはありません。
次のコードでは、共同環境で排他的アクセスに対してドキュメントをロックする方法を示します。この機能は、ユーザがドキュメントをチェックアウトする際にWebDAVクライアントアプリケーションで呼び出すことができます。
この例では、ヘルパメソッドlockDocument()を使用します。目的のドキュメントがすでにロックされている場合は、このメソッドにより例外がスローされます。この状況をはっきりと確認するために、コードではcheckLockToken()メソッドを呼び出します。
/**
lockADocument
*/
import com.sssw.webdav.client.*;
public class lockADocument {
private static boolean m_debug = false;
public void lockADocument (String document)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
try
{
//If document not already locked, send the WebDAV request to lock the document
if ( dav.checkLockToken(document) == null)
{
statuscode = dav.lockDocument(user, password, realm, document);
if (statuscode==EboDAVStatus.SC_NO_CONTENT)
System.out.println("Request succeeded:The document " + document + "was locked.");
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
else
System.out.println(泥ocument is already locked.・;
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
//End session
dav.endSession();
}
}
SlideのLockMethodクラスとexteNd Directorユーティリティメソッドを使用して、ドキュメントをロックすることもできます。ユーティリティメソッドを使用したプログラミング練習を参照してください。
次のコードでは、ソースパスから移動先のパスへフォルダを移動する方法を示します。この場合、ソースパスはフォルダを指します。他のタイプのリソースまたはコレクションを移動するには、ソースパスが目的の要素を指定していることを確認します。
この例では、ヘルパメソッドmoveElement()を使用します。
/**
moveAFolder
*/
import com.sssw.webdav.client.*;
public class moveAFolder {
private static boolean m_debug = false;
public void moveAFolder (String foldersourcepath, String folderdestinationpath)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
boolean autogen = true; //Generate folders in the folderdestinationpath if they don\qt exist
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Send the WebDAV request to move folder
try
{
statuscode = dav.moveElement(user, password, realm, foldersourcepath, folderdestinationpath, autogen);
if (statuscode==EboDAVStatus.SC_CREATED)
System.out.println("Request succeeded:The folder " + foldersourcepath + "was moved to " + folderdestinationpath);
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
//End session
dav.endSession();
}
}
SlideのMoveMethodクラスとexteNd Directorユーティリティメソッドを使用して、リソースまたはコレクションを移動することもできます。ユーティリティメソッドを使用したプログラミング練習を参照してください。
次のコード例では、ドキュメントからカテゴリ参照を削除する方法を示します。カテゴリは、CMサブシステムで論理的にドキュメントをグループ化する場合に使用される、わかりやすい名前です。
この例では、ヘルパメソッドremoveCategoryFromDocument()を使用します。
/**
removeCategoryReferenceFromDocument
*/
import com.sssw.webdav.client.*;
public class removeCategoryReferenceFromDocument {
private static boolean m_debug = false;
public void removeCategoryReferenceFromDocument (String document, String categoryUUID)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Send the WebDAV request to remove a category reference
try
{
statuscode = dav.removeCategoryFromDocument(user, password, realm, document, categoryUUID);
if (statuscode==EboDAVStatus.SC_MULTI_STATUS)
System.out.println("Request succeeded:The category was removed from " + document);
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
//End session
dav.endSession();
}
}
この例では、SlideのPropPatchMethodクラスと、exteNd DirectorユーティリティメソッドのstartSession()、createCredentials()、setCredentials()、getState()、setState()、およびcreateWebDAVMethod()を使用します。
カテゴリ参照を削除するメソッドはaddPropertyToSet()で、PropPatchMethodオブジェクトで呼び出されます。カテゴリUUIDは、最初の引数であるproperty nameとして渡されるため、2番目の引数であるproperty valueはnullです。addPropertyToSet()およびその引数の詳細については、Proppatchを使用するWebDAV要求の作成を参照してください。
/**
removeCategoryReference
*/
import com.sssw.webdav.client.*;
import com.sssw.webdav.common.EboWebdavConstants;
import org.apache.webdav.lib.*;
import org.apache.webdav.lib.methods.*;
public class removeCategoryReference
{
private static boolean m_debug = false;
public void removeCategoryReference (String document, String categoryUUID)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
String namespace-abbr = "RC";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Get and set credentials
Credentials credentials = dav.createCredentials(user, password);
dav.setCredentials(credentials);
//Get and set state and authentication realm
State state = dav.getState();
state.setAuthenticateToken(realm);
dav.setState(state);
//Create the WebDAV method object PropPatchMethod
PropPatchMethod ppm = (PropPatchMethod)dav.createWebdavMethod(dav.PROPPATCH_METHOD,document);
ppm.addPropertyToSet( categoryUUID, null, namespace-abbr, EboWebdavConstants.PROPPATCH_REMOVECATEGORY);
//Execute PropPatchMethod (send the WebDAV request to remove category reference)
try
{
dav.executeCommand(ppm);
statuscode = ppm.getStatusCode();
if (statuscode == (EboDAVStatus.MULTI_STATUS))
System.out.println("Request succeeded:The category was removed from " + document + ".");
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
catch (java.net.MalformedURLException murle)
{
if (m_debug)
murle.printStackTrace();
else
System.out.println(murle.getMessage());
}
catch (java.io.IOException ioe)
{
if (m_debug)
ioe.printStackTrace();
else
System.out.println(ioe.getMessage());
}
//End session
dav.endSession();
}
}
次のコード例では、ドキュメントからすべてのカテゴリ参照を削除する方法を示します。カテゴリは、CMサブシステムで論理的にドキュメントをグループ化する場合に使用される、わかりやすい名前です。
この例では、ヘルパメソッドremoveAllCategoriesFromDocument()を使用します。
/**
removeAllCategoryReferencesFromDocument
*/
import com.sssw.webdav.client.*;
public class removeAllCategoryReferencesFromDocument {
private static boolean m_debug = false;
public void removeAllCategoryReferencesFromDocument (String document)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Send the WebDAV request to remove all category references from the document
try
{
statuscode = dav.removeAllCategoriesFromDocument(user, password, realm, document);
if (statuscode==EboDAVStatus.MULTI_STATUS)
System.out.println("Request succeeded:All categories were removed from " + document);
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
//End session
dav.endSession();
}
}
この例では、SlideのPropPatchMethodクラスと、exteNd DirectorユーティリティメソッドのstartSession()、createCredentials()、setCredentials()、getState()、setState()、およびcreateWebDAVMethod()を使用します。
すべてのカテゴリ参照を削除するメソッドはaddPropertyToSet()で、PropPatchMethodオブジェクトで呼び出されます。ドキュメントUUIDは、最初の引数であるproperty nameとして渡されるため、2番目の引数であるproperty valueはnullです。addPropertyToSet()およびその引数の詳細については、Proppatchを使用するWebDAV要求の作成を参照してください。
/**
removeAllCategoryReferences
*/
import com.sssw.webdav.client.*;
import com.sssw.webdav.common.EboWebdavConstants;
import org.apache.webdav.lib.*;
import org.apache.webdav.lib.methods.*;
public class removeAllCategoryReferences
{
private static boolean m_debug = false;
public void removeAllCategoryReferences (String documentUUID)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
String namespace-abbr = "RAC";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Get and set credentials
Credentials credentials = dav.createCredentials(user, password);
dav.setCredentials(credentials);
//Get and set state and authentication realm
State state = dav.getState();
state.setAuthenticateToken(realm);
dav.setState(state);
//Create the WebDAV method object PropPatchMethod
PropPatchMethod ppm = (PropPatchMethod)dav.createWebdavMethod(dav.PROPPATCH_METHOD,document);
ppm.addPropertyToSet( documentUUID, null, namespace-abbr, EboWebdavConstants.PROPPATCH_REMOVEALLCATEGORIES);
//Execute PropPatchMethod (send the WebDAV request to remove all category references)
try
{
dav.executeCommand(ppm);
statuscode = ppm.getStatusCode();
if (statuscode == (EboDAVStatus.SC_OK))
System.out.println("Request succeeded:All categories were removed.");
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
catch (java.net.MalformedURLException murle)
{
if (m_debug)
murle.printStackTrace();
else
System.out.println(murle.getMessage());
}
catch (java.io.IOException ioe)
{
if (m_debug)
ioe.printStackTrace();
else
System.out.println(ioe.getMessage());
}
//End session
dav.endSession();
}
}
次のコードでは、ドキュメントの名前を変更する方法を示します。この場合、ソースパスはドキュメントを指します。対象のパスは、別のドキュメント名である場合を除き、ソースパスと同一です。
他のタイプのリソースまたはコレクションの名前を変更するには、ソースパスが目的の要素を指しており、対象のパスが別の名前の同じ要素を指していることを確認します。
この例では、ヘルパメソッドmoveElement()を使用します。
//**
renameADocument
*/
import com.sssw.webdav.client.*;
public class renameADocument {
private static boolean m_debug = false;
public void renameADocument (String docsourcepath, String docdestinationpath)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
boolean autogen = false; //Do not generate folders in the docdestinationpath if they don\qt exist
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Send the WebDAV request to rename the document
try
{
statuscode = dav.moveElement(user, password, realm, docsourcepath, docdestinationpath, autogen);
if (statuscode==EboDAVStatus.SC_CREATED)
System.out.println("Request succeeded:The document " + docsourcepath + "was renamed to " + docdestinationpath);
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
//End session
dav.endSession();
}
}
SlideのMoveMethodクラスとexteNd Directorユーティリティメソッドを使用して、リソースまたはコレクションの名前を変更することもできます。ユーティリティメソッドを使用したプログラミング練習を参照してください。
次のコード例では、カスタムフィールドの値を設定することによってドキュメントのカスタムメタデータを更新する方法を示します。カスタムフィールドとは、CM APIまたはCMS管理コンソールを使用してCMサブシステムで作成されるカスタムドキュメントタイプの一部として定義するフィールドです。
ドキュメントで標準のメタデータを更新するには、Proppatchを使用するWebDAV要求の作成の説明に従って、ProppatchメソッドオブジェクトでaddPropertyToSet()メソッドを使用します。
この例では、ヘルパメソッドsetFieldValueForDocument()を使用します。このメソッドは、カスタムフィールドの既存の値を上書きします。
/**
setFieldValueOfADocument
*/
import com.sssw.webdav.client.*;
public class setFieldValueOfADocument {
private static boolean m_debug = false;
public void setFieldValueOfADocument (String document, String field_name, String field_value)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Send the WebDAV request to update the custom field
try
{
statuscode = dav.setFieldValueForDocument(user, password, realm, document, field_name, field_value);
if (statuscode==EboDAVStatus.SC_MULTI_STATUS)
System.out.println("Request succeeded:The field " + field_name + " of document " + document + "was changed to " + field_value);
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
//End session
dav.endSession();
}
}
この例では、SlideのPropPatchMethodクラスと、exteNd DirectorユーティリティメソッドのstartSession()、createCredentials()、setCredentials()、getState()、setState()、およびcreateWebDAVMethod()を使用します。
/**
setTheFieldValue
*/
import com.sssw.webdav.client.*;
import com.sssw.webdav.common.EboWebdavConstants;
import org.apache.webdav.lib.*;
import org.apache.webdav.lib.methods.*;
public class setTheFieldValue
{
private static boolean m_debug = false;
public void setTheFieldValue (String document)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
String fieldname = "Department";
String fieldvalue = "Human Resources";
String namespace-abbr = "SFV";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Get and set credentials
Credentials credentials = dav.createCredentials(user, password);
dav.setCredentials(credentials);
//Get and set state and authentication realm
State state = dav.getState();
state.setAuthenticateToken(realm);
dav.setState(state);
//Create the WebDAV method object PropPatchMethod
PropPatchMethod ppm = (PropPatchMethod)dav.createWebdavMethod(dav.PROPPATCH_METHOD,document);
ppm.addPropertyToSet( fieldname, fieldvalue, namespace-abbr, EboWebdavConstants.PROPPATCH_SETFIELDVALUE);
//Execute PropPatchMethod (send the WebDAV request to set field value)
try
{
dav.executeCommand(ppm);
statuscode = ppm.getStatusCode();
if (statuscode == (EboDAVStatus.SC_MULTI_STATUS))
System.out.println("Request succeeded:The field " + fieldname + " was set to " + fieldvalue + ".");
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
catch (java.net.MalformedURLException murle)
{
if (m_debug)
murle.printStackTrace();
else
System.out.println(murle.getMessage());
}
catch (java.io.IOException ioe)
{
if (m_debug)
ioe.printStackTrace();
else
System.out.println(ioe.getMessage());
}
//End session
dav.endSession();
}
}
次のコードでは、共同環境で他の作成者が使用できるようにドキュメントのロックを解除する方法を示します。この機能は、ユーザがドキュメントをチェックインする際にWebDAVクライアントアプリケーションで呼び出すことができます。
この例では、ヘルパメソッドunlockDocument()を使用します。目的のドキュメントがすでにロック解除されている場合は、このメソッドにより例外がスローされます。この状況をはっきりと確認するために、コードではcheckLockToken()メソッドを呼び出します。
/**
unlockADocument
*/
import com.sssw.webdav.client.*;
public class unlockADocument {
private static boolean m_debug = false;
public void unlockADocument (String document)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
try
{
//If document is locked, unlock it
if (dav.checkLockToken(document) != null)
{
//Send the WebDAV request to unlock the document
statuscode = dav.unlockDocument(user, password, realm, document);
if (statuscode==EboDAVStatus.SC_NO_CONTENT)
System.out.println("Request succeeded:The document " + document + "was unlocked.");
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
else
{
System.out.println(典he document is already unlocked.・;
}
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
}
//End session
dav.endSession();
}
}
SlideのUnlockMethodクラスとexteNd Directorユーティリティメソッドを使用して、ドキュメントをロック解除することもできます。ユーティリティメソッドを使用したプログラミング練習を参照してください。
次のコードでは、ドキュメントのコンテンツを更新する方法を示します。
この例では、ヘルパメソッドputDocument()を使用します。このメソッドは、新しいバージョンを作成して発行することにより、ドキュメントのメタデータではなくコンテンツを更新します。ドキュメントのメタデータを更新するには、ドキュメントでのカスタムフィールド値の設定を参照してください。
/**
updateADocument
*/
import com.sssw.webdav.client.*;
public class updateADocument {
private static boolean m_debug = false;
public void updateADocument (String document)
{
//Define variables
int statuscode = 0;
String user = "contentadmin";
String password = "contentadmin";
String realm = "Basic realm = \"SSSW_WEBDAV_AUTHENTICATION\"";
String updatetext = "Hello earth!";
byte [] newcontent = updatetext.getBytes();
//Instantiate an EboDAVSwitch object
EboDAVSwitch dav = new EboDAVSwitch();
//Instantiate an EboDAVStatus object
EboDAVStatus status = new EboDAVStatus();
//Start a session
dav.startSession("localhost", 80);
//Send the WebDAV request to update the document
try
{
statuscode = dav.putDocument(user, password, realm, document, newcontent);
if (statuscode==EboDAVStatus.SC_OK)
System.out.println("Request succeeded:The document " + document + "was updated.");
else
System.out.println("Request failed:" + status.getStatusText(statuscode));
}
catch (EboDAVException e)
{
if (m_debug)
e.printStackTrace();
else
System.out.println(e.getMessage());
}
//End session
dav.endSession();
}
}
SlideのPutMethodクラスとexteNd Directorユーティリティメソッドを使用して、ドキュメントを更新したり、新しいドキュメントを作成したりすることもできます。ユーティリティメソッドを使用したプログラミング練習を参照してください。
Copyright © 2004 Novell, Inc. All rights reserved. Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved. more ...