repositorytarget.js
来自「Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是」· JavaScript 代码 · 共 111 行
JS
111 行
/*
* Copyright 2001-2008 Hippo (www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//defineClass("java.lang.Object");
//defineClass("org.apache.cocoon.forms.flow.javascript.ScriptableWidget");
importClass(Packages.javax.xml.parsers.DocumentBuilder);
importClass(Packages.javax.xml.parsers.DocumentBuilderFactory);
importClass(Packages.org.apache.cocoon.forms.binding.BindingException);
importClass(Packages.org.apache.cocoon.xml.XMLUtils);
importClass(Packages.nl.hippo.cms.editor.flow.FlowDocument);
function nonEmpty(value){
return (typeof value != 'undefined' && value != null && value.length > 0);
}
function RepositoryTarget(targetUri,document,docType, loadSource) {
this.targetUri = targetUri;
this.loadSource = loadSource;
this.documentUri = editorFlowContext.getFlowDocument().getValue(FlowDocument.PATH);
this.document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
this.document.appendChild(this.document.importNode(document.getDocumentElement(),true));
this.docType = docType;
}
RepositoryTarget.prototype.printXML = function(document){
var test='';
try {
test = XMLUtils.serializeNode(this.document);
} catch (e) {
}
print("Importing: "+test);
}
RepositoryTarget.prototype.getTargetUri = function(){
return this.targetUri;
}
RepositoryTarget.prototype.getDocument = function(){
return this.document;
}
RepositoryTarget.prototype.makePersistent = function(form) {
form.save(this.document);
var processedDocument = this.doPostProcessing();
var result = this.doSave(processedDocument);
var preprocessedDocument = this.doPreProcessing();
form.load(preprocessedDocument);
return result;
}
RepositoryTarget.prototype.doLoadFromSource = function(){
return loadDocument(this.loadSource+"/"+this.docType + this.documentUri);
}
RepositoryTarget.prototype.doPreProcessing = function(){
if (nonEmpty(this.loadSource)){
return this.doLoadFromSource();
} else {
var pipeutil = cocoon.createObject(Packages.org.apache.cocoon.components.flow.util.PipelineUtil);
return pipeutil.processToDOM("/editing/cf2/preprocessXML/"+this.docType + this.documentUri, null);
}
}
RepositoryTarget.prototype.doPostProcessing = function(){
var pipeutil = cocoon.createObject(Packages.org.apache.cocoon.components.flow.util.PipelineUtil);
return pipeutil.processToDOM("/editing/cf2/postprocessXML", {"xml":this.document,"doctype":this.docType,"documentUri":this.documentUri});
}
RepositoryTarget.prototype.doSave = function(document){
// this.printXML(this.document);
var result = null;
var submitId = cocoon.request.get("submitid");
if(submitId=="sendWebserviceForm")
{
var global = cocoon.getComponent(InputModule.ROLE + "Selector").select("globalconstants");
var myURL = global.getAttribute("cms-webservice-url",null,null);
var webserviceObject = global.getAttribute("cms-webservice-object",null,null);
var myPostObject = cocoon.createObject(webserviceObject+"");
var returnXML = myPostObject.postXML(myURL,document);
var finalXML = string2xml(returnXML);
result = saveDocument(finalXML, this.targetUri);
finalXML = null;
}
else
{
result = saveDocument(document, this.targetUri);
}
if (!workflow.invokeStandardUIAction(this.targetUri, "hippo.cms.save", new HashMap(), ""))
{
cocoon.log.error("RepositoryTarget: doSave: workflow action failed");
return false;
}
return result;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?