通过API创建Ektron智能表单定义

时间:2013-05-28 15:25:14

标签: c# api ektron

我一直在尝试从其他应用程序创建智能表单定义。该应用程序成功创建了智能表单,但我无法填充FieldList,DisplayXSLT或Schema字段。

这给我留下了一个空白的智能表单定义(不那么理想)。

这是我必须执行操作的代码。有什么想法吗?

// form is a simple POCO with values copied from an existing SmartForm Definition
var config = new SmartFormConfigurationData();

config.SmartformTitle = form.Name;            
config.SmartformDescription = form.Description;
config.XmlSchema = form.Schema;
config.PackageDisplayXslt = form.Xslt;
config.FieldList = form.FieldList;
config.Type = EkEnumeration.XmlConfigType.Content;

var api = new SmartFormConfigurationManager(ApiAccessMode.Admin);
api.RequestInformation.ServicesPath = this.EktronServiceHost;
api.RequestInformation.AuthenticationToken = this.GetAdminAuthToken();

api.Add(config);

1 个答案:

答案 0 :(得分:0)

更新

我在此问题上听到了Ektron支持部门的回复。它本身并不是一个“bug”......更多的是这个API类看起来与ContentManager非常相似,但表现不像它。我预计,因为它看起来与ContentManager和许多其他类很相似,所以我可以调用Add(),它只会神奇地工作。事实证明解决方案有点复杂。

添加智能表单分为两个步骤:首先Add(),然后Update()

Add方法不会设置所有字段,实际上会为在xml_collection_tbl中创建条目的存储过程中的一些参数传递NULL。

真正的乐趣来自第2步。基本上,您从SmartForm的HTML开始 - 当您在“数据设计”视图中编辑智能表单定义时,您看到的内容并单击{{1}编辑器底部的按钮(“HTML”)。您通过在WorkArea文件夹中隐藏的一大堆XSLT来构建缺少的字段,然后调用update。这是适用于我的代码:

<>

我为现有的智能表单提取了HTML,并将其保存在我的网站的根目录中,作为NewsArticleSmartForm.html。这是我的文件的样子:

var sfManager = new SmartFormConfigurationManager();
var data = sfManager.GetItem(12);

if (data == null) return;

var sfcData = new SmartFormConfigurationData();
sfcData.Type = EkEnumeration.XmlConfigType.Content;
sfcData.SmartformTitle = "SmartForm12 copy";
sfcData.SmartformDescription = "SmartForm12 copy";
sfcData.XmlSchema = "";
sfcData.PackageDisplayXslt = data.PackageDisplayXslt;
sfcData.FieldList = data.FieldList;

sfcData = sfManager.Add(sfcData);

Response.Write("SmartForm added with id: " + sfcData.Id);

var design = System.IO.File.ReadAllText(Server.MapPath("~/NewsArticleSmartForm.html"));
var contentApi = new ContentAPI();

var schema = contentApi.TransformXsltPackage(design, Server.MapPath("~/WorkArea/ContentDesigner/DesignToSchema.xslt"), true);
var fieldList = contentApi.TransformXsltPackage(design, Server.MapPath("~/WorkArea/ContentDesigner/DesignToFieldList.xslt"), true);
var viewEntryXslt = contentApi.TransformXsltPackage(design, Server.MapPath("~/WorkArea/ContentDesigner/DesignToEntryXSLT.xslt"), true);

var xsltArgs = new XsltArgumentList();
xsltArgs.AddParam("srcPath", "", "/WorkArea/ContentDesigner/");

var viewXsltSource = string.Concat("<root>", design, "<ektdesignpackage_list>", fieldList, "</ektdesignpackage_list></root>");
var viewXslt = contentApi.XSLTransform(viewXsltSource, Server.MapPath("~/WorkArea/ContentDesigner/DesignToViewXSLT.xslt"), true, false, xsltArgs, false);
var initialDocument = contentApi.TransformXsltPackage(design, Server.MapPath("~/WorkArea/ContentDesigner/PresentationToData.xslt"), true);

var sbPackage = new StringBuilder("<ektdesignpackage_forms><ektdesignpackage_form><ektdesignpackage_designs><ektdesignpackage_design>");
sbPackage.Append(design);
sbPackage.Append("</ektdesignpackage_design></ektdesignpackage_designs><ektdesignpackage_schemas><ektdesignpackage_schema>");
sbPackage.Append(schema);
sbPackage.Append("</ektdesignpackage_schema></ektdesignpackage_schemas><ektdesignpackage_lists><ektdesignpackage_list>");
sbPackage.Append(fieldList);
sbPackage.Append("</ektdesignpackage_list></ektdesignpackage_lists><ektdesignpackage_views><ektdesignpackage_view>");
sbPackage.Append(viewEntryXslt);
sbPackage.Append("</ektdesignpackage_view><ektdesignpackage_view>");
sbPackage.Append(viewXslt);
sbPackage.Append("</ektdesignpackage_view></ektdesignpackage_views><ektdesignpackage_initialDocuments><ektdesignpackage_initialDocument>");
sbPackage.Append(initialDocument);
sbPackage.Append("</ektdesignpackage_initialDocument></ektdesignpackage_initialDocuments></ektdesignpackage_form></ektdesignpackage_forms>");

sfcData.PackageXslt = sbPackage.ToString();
sfcData.FieldList = fieldList;

var baseFilename = "SmartForm" + sfcData.Id;
var schemaFilename = "/" + baseFilename + "Schema.xsd";
var xsltFilename = "/" + baseFilename + "Xslt.xslt";

sfcData.XmlSchema = schemaFilename;  // The file will be prefixed with /XmlFiles

var unPackDisplayXslt = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:output method=\"xml\" version=\"1.0\" encoding=\"UTF-8\" indent=\"yes\"/><xsl:template match=\"/\"><xsl:choose><xsl:when test=\"ektdesignpackage_forms/ektdesignpackage_form[1]/ektdesignpackage_views/ektdesignpackage_view[2]\"><xsl:copy-of select=\"ektdesignpackage_forms/ektdesignpackage_form[1]/ektdesignpackage_views/ektdesignpackage_view[2]/node()\"/></xsl:when><xsl:otherwise><xsl:copy-of select=\"ektdesignpackage_forms/ektdesignpackage_form[1]/ektdesignpackage_views/ektdesignpackage_view[1]/node()\"/></xsl:otherwise></xsl:choose></xsl:template></xsl:stylesheet>";

var displayXslt = contentApi.TransformXsltPackage(sbPackage.ToString(), unPackDisplayXslt, false);
System.IO.File.WriteAllText(Server.MapPath("~/XmlFiles" + xsltFilename), displayXslt);

sfcData.Xslt1 = xsltFilename;  // The file will be prefixed with /XmlFiles
sfcData.DefaultXslt = 1;

sfManager.Update(sfcData);
祝你好运!

原始答案:

创建SmartForm配置的副本应该非常简单。 <p>Author:&#160;<input type="text" name="Author" id="Author" ektdesignns_caption="Author" ektdesignns_name="Author" title="Author" ektdesignns_indexed="false" ektdesignns_nodetype="element" size="24" class="design_textfield" /></p> <p>&#160;</p> <p>Article Summary:&#160;<textarea name="Summary" id="Summary" ektdesignns_caption="Summary" ektdesignns_name="Summary" title="Summary" ektdesignns_indexed="false" ektdesignns_nodetype="element" cols="40" rows="3" class="design_textfield"></textarea> </p> <p>&#160;</p> <p>Article Body:</p> <p>&#160;</p> <ektdesignns_richarea id="Body" name="Body" ektdesignns_caption="Body" ektdesignns_name="Body" title="Body" ektdesignns_indexed="false" ektdesignns_nodetype="element">&#160;</ektdesignns_richarea> <p>&#160;</p> 对象上有一个SmartFormConfigurationData方法,这使得创建现有SmartForm的副本变得非常容易。我说“应该”因为它不起作用。

我有一个所有打字的答案准备发布;我尝试了一些代码,它似乎工作。新的smartform被列在工作区,但当我点击新的smartform查看其详细信息时,我意识到出了问题。

我尝试了以下代码:

Clone()

以下是原始smartform的详细信息: original smartform, properties tab original smartform, Display Information tab

这就是新smartform的样子 - 我用frameworkAPI创建的那个: api-generated smartform, properties tab api-generated smartform, Display Information tab

我找到了一个成功创建现有smartform副本的API方法:

var sfManager = new SmartFormConfigurationManager();
var config = sfManager.GetItem(7);

if (config == null) return;

var newSmartForm = config.Clone();
newSmartForm.SmartformTitle += " copy";

sfManager.Add(newSmartForm);

该方法的问题在于智能形式必须存在于您的系统上,并且您只能更改标题。所以,我深入挖掘数据库,看看发生了什么。事实证明,在调用此var sfApi = new Ektron.Cms.ContentAPI(); var newId = sfApi.ReplicateXmlConfiguration(7, "copied sf title"); 方法之后,两个数据库记录是相同的(除了预期的LastUpdated类型的字段)。

source and target database records after calling ReplicateXmlConfiguration()

在调用frameworkAPI的ReplicateXmlConfiguration()方法后(调用Update()时也是如此),“更新”记录明显不同。

source and target database records after calling Update() in framework api

我想我们这里有一个真正的错误。在v8.7 sp2和v9.0 sp1中都会发生这种情况。我已经开启了Ektron支持的案例,我会在收到回复后更新我的答案。当我过去处理它们时,它们总是非常敏感。