2

パブリケーションの WebDAV URL を取得しようとしていますが、以下は私が試みているロジックです。ページとコンポーネントの webdavurl を正常に取得していますが、パブリケーションの URL を取得するのに苦労しています。

public static string getPublicationWebDav(string partialWebdavURL, Package package, Engine engine)
{
string webDav = string.Empty;
string pubURI = string.Empty;
if (!string.IsNullOrEmpty(partialWebdavURL))
{
_log.Info("partialWebdavURL" + partialWebdavURL);

RepositoryLocalObject repLocalObject = null;

if (repLocalObject == null)
{
Item pubItem = package.GetByType(ContentType.Publication);

repLocalObject = (Publication)engine.GetObject(pubItem.GetAsSource().GetValue("ID"));
}
webDav = repLocalObject.WebDavUrl + partialWebdavURL;
}
_log.Info("webDav" + webDav);
return webDav;
}

この行は私にエラーを与えます

repLocalObject = (Publication)engine.GetObject(pubItem.GetAsSource().GetValue("ID"));

ただし、ページ オブジェクトが正常に動作するようにしようとすると、以下のコードは正常に動作します。

if (package.GetByType(ContentType.Page) != null)
{
Item pageItem = package.GetByType(ContentType.Page);
//_log.Info("pageItem" + pageItem);
repLocalObject = (Page)engine.GetObject(pageItem.GetAsSource().GetValue("ID"));
pubURI = package.GetValue("Page.Publication.ID");
}
else
{
Item component = package.GetByType(ContentType.Component);
repLocalObject = (Component)engine.GetObject(component.GetAsSource().GetValue("ID"));
pubURI = package.GetValue("Component.Publication.ID");
}

私の目的は、Publication webdavURL を取得することです。

4

1 に答える 1

4

tridion フォーラムで長い間検索した結果、以下の解決策が見つかりました。ぬのさんありがとうございます!!

// まず、レンダリングしている現在のオブジェクトを見つける必要があります

RepositoryLocalObject context;
    if (p.GetByName(Package.PageName) != null)
        context = e.GetObject(p.GetByName(Package.PageName)) as RepositoryLocalObject;
    else
        context = e.GetObject(p.GetByName(Package.ComponentName)) as RepositoryLocalObject;

Repository contextPublication = context.ContextRepository;
string webdavUrl = contextPublication.WebDavUrl;

次のコードは 2011 では機能しますが、2009 では機能しないことに注意してください (リポジトリの WebDavUrl は公開されません)。2009 年には、代わりに contextPublication.RootFolder.WebDavUrl を取得しました。

于 2011-10-12T03:46:40.890 に答える