简体   繁体   English

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

[英]Creating an Ektron Smart Form Definition via the API

I've been trying to create a smart form definition from another application. 我一直在尝试从另一个应用程序创建智能表单定义。 The app successfully creates the smart form, but I'm unable to get the FieldList, DisplayXSLT or Schema fields to populate. 该应用程序成功创建了智能表单,但是无法填充FieldList,DisplayXSLT或Schema字段。

This leaves me with a blank smart form definition (less that ideal). 这给我留下了空白的智能表单定义(不那么理想)。

Here's the code I have to perform the action. 这是我必须执行操作的代码。 Any ideas? 有任何想法吗?

// 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);

Update: 更新:

I heard back from Ektron Support on this issue. 我从Ektron支持小组收到有关此问题的回复。 It's not so much a "bug" per-se... It's more a case of this API class looking very similar to the ContentManager but not behaving like it. 本身并不是一个“ bug”……更多的是,该API类看起来与ContentManager非常相似,但是行为却不一样。 I expected that since it looked so similar to ContentManager and many of the other classes, I would be able to call Add() and it would just magically work. 我期望,因为它看起来与ContentManager和许多其他类非常相似,所以我可以调用Add() ,并且可以神奇地工作。 It turns out the solution is a little more complicated. 事实证明,解决方案要复杂一些。

Adding a smartform is a two-step process: first Add() , then Update() . 添加智能表单的过程分为两步:首先是Add() ,然后是Update()

The Add method doesn't set all of the fields and in fact passes in NULL for a few of the parameters on the stored procedure that creates the entry in xml_collection_tbl . Add方法不会设置所有字段,实际上,对于在xml_collection_tbl中创建条目的存储过程中的一些参数, xml_collection_tbl

The real fun comes in step 2. Basically, you start with the SmartForm's HTML -- the stuff you see when you're in the "Data Design" view for editing the smart form definition and you click that <> button ("HTML") at the bottom of the editor. 真正的乐趣来自第2步。基本上,您从SmartForm的HTML开始-当您在“数据设计”视图中编辑智能表单定义并单击<>按钮(“ HTML” )在编辑器底部。 You run that through a whole bunch of XSLTs that are burried in the WorkArea folder to construct the missing fields, and then you call update. 您通过将整个XSLT埋入WorkArea文件夹中以构造缺少的字段来进行操作,然后调用update。 Here's the code that worked for me: 这是对我有用的代码:

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);

I extracted the HTML for my existing smart form and saved in the root of my site as NewsArticleSmartForm.html. 我为现有的智能表单提取了HTML,并将其另存为NewsArticleSmartForm.html保存在网站的根目录中。 Here's what my file looked like: 这是我的文件的样子:

<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>

Good luck! 祝好运!

Original Answer: 原始答案:

Creating a copy of a SmartForm configuration should be fairly straight-forward. 创建SmartForm配置的副本应该相当简单。 The SmartFormConfigurationData object has a Clone() method on it which makes it really easy to create a copy of an existing SmartForm. SmartFormConfigurationData对象上具有Clone()方法,这使创建现有SmartForm的副本非常容易。 I say "should be" because it doesn't work. 我说“应该是”,因为它不起作用。

I had an answer all typed out ready to post; 我有一个答案,所有答案都可以输入。 I tried some code and it appeared to work. 我尝试了一些代码,它似乎起作用了。 The new smartform was listed in the workarea, but when I clicked on that new smartform to view its details, I realized something was wrong. 新的智能表单已在工作区中列出,但是当我单击该新的智能表单以查看其详细信息时,我意识到出了点问题。

I tried the following code: 我尝试了以下代码:

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

if (config == null) return;

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

sfManager.Add(newSmartForm);

Here are the details from the original smartform: 以下是原始smartform的详细信息: 原始smartform,“属性”选项卡原始智能表格,“显示信息”选项卡

And here's what the new smartform looked like -- the one I created with the frameworkAPI: 这就是新的智能表单的样子-我用frameworkAPI创建的智能表单: api生成的smartform,“属性”选项卡api生成的smartform,“显示信息”选项卡

I did find one API method that successfully created a copy of an existing smartform: 我确实找到了一种成功创建现有智能表单副本的API方法:

var sfApi = new Ektron.Cms.ContentAPI();
var newId = sfApi.ReplicateXmlConfiguration(7, "copied sf title");

The problem with that method is that the smartform must exist on your system and you can only change the title. 该方法的问题在于,智能表单必须存在于您的系统上,并且您只能更改标题。 So, I went digging into the database to see what was happening. 因此,我进入数据库以了解发生了什么。 It turns out that after calling this ReplicateXmlConfiguration() method, the two database records are identical (except for the expected LastUpdated type of fields). 事实证明,在调用此ReplicateXmlConfiguration()方法之后,两个数据库记录是相同的(除了期望的LastUpdated类型的字段)。

调用ReplicateXmlConfiguration()之后的源和目标数据库记录

After calling the frameworkAPI's Update() method (same holds true when calling Add() ), the "updated" record is clearly different. 调用frameworkAPI的Update()方法(调用Add()时也是如此)之后,“更新”记录明显不同。

在框架api中调用Update()之后,源和目标数据库记录

I think we've got a genuine bug here. 我认为我们这里有一个真正的错误。 This happens both in v8.7 sp2 and v9.0 sp1. 在v8.7 sp2和v9.0 sp1中都会发生这种情况。 I've opened a case with Ektron support, and I'll update my answer as I hear back. 我在Ektron支持下打开了一个案例,我将在回听时更新答案。 They have always been very responsive when I've dealt with them in the past. 我过去与他们打交道时,他们总是反应灵敏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM