flow.js
来自「Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是」· JavaScript 代码 · 共 209 行
JS
209 行
/*
* Copyright 2001-2007 Hippo (www.hippo.nl)
*
* 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.
*/
// cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");
importClass(Packages.javax.xml.parsers.DocumentBuilder);
importClass(Packages.javax.xml.parsers.DocumentBuilderFactory);
importClass(Packages.nl.hippo.cms.editor.flow.FlowContext);
importClass(Packages.nl.hippo.cms.editor.flow.Configuration);
importClass(Packages.nl.hippo.cms.editor.flow.FlowHelper);
importClass(Packages.nl.hippo.cocoon.forms.HippoFormHelper);
importClass(Packages.nl.hippo.cocoon.forms.HippoFormProcessor);
cocoon.load("site:/login/login.js");
cocoon.load("site:/util/flow/lib-io.js");
cocoon.load("site:/actions/flow/contentmodel.js");
// optionally load custom actions flowscript from extensions
if (libio.checkExists("extensions://editing/cf2/flow/customflow.js"))
{
cocoon.load("extensions://editing/cf2/flow/customflow.js");
}
var targetURI = "site://editing/cf2/resources/test.xml";
var editorFlowContext;
function getCurrentJavaDate(){
var cal= new java.util.GregorianCalendar();
cal.setTime(new java.util.Date());
return cal;
}
function editCform(form) {
var loadSource = cocoon.parameters["loadSource"];
var documentURI = cocoon.parameters["documentURI"];
var uriPrefix = cocoon.parameters["uriPrefix"];
var schema = cocoon.parameters["schema"];
var resourceId = documentURI;
var targetURI ="";
var lastResponseStatus = "";
if(documentURI !="")
{
targetURI = uriPrefix + documentURI;
}
var document = null;
try
{
if (loadSource != null && loadSource.indexOf("cocoon:/") >= 0){
document = loadDocument(loadSource+"/"+schema+documentURI);
} else {
document = loadDocument("cocoon://editing/cf2/preprocessXML/"+schema+documentURI);
}
}
catch (e)
{
if (e instanceof Packages.org.apache.excalibur.source.SourceNotFoundException)
{
// a SourceNotFoundException is thrown/catched but probably the user has insufficient rights
lastResponseStatus = "404";
}
else
{
lastResponseStatus = "405";
}
var actionSuccess = "failure";
var actionEvent = "editDocumentForbidden";
cocoon.sendPage("/explorer/action" + actionSuccess + "?resourceId=" + resourceId,
{status: lastResponseStatus, action: actionEvent});
return;
}
// flow object editorFlowContext; can be referenced from e.g. source pipelines specified
// in your business logic files.
var flowHelper = cocoon.getComponent(FlowHelper.ROLE);
var editorConfig = new Configuration(resourceId, uriPrefix, schema);
editorFlowContext = new FlowContext(editorConfig, flowHelper);
var target1 = new RepositoryTarget(targetURI,document,schema,loadSource);
form.load(document);
var resultHandler = new FormResultHandler([target1]);
form.setFormName("site.editing.cf2.flow.flow.editCform"+cocoon.session);
form.setUseUniqueContinuations(true);
form.showForm("form/"+schema, resultHandler, {"document":resourceId,'doctype':schema,'editorFlowContext':editorFlowContext,'editorHelper':new EditorHelper()});
cocoon.sendPage("/explorer/action" + actionSuccess + "?resourceId=" + resourceId + "&additional=" + additional,
{status: lastResponseStatus, actionEvent: actionEvent, actionName: actionEvent});
}
/*
* Convenience method; can be used to develop backend templates
*
*/
function contextualize() {
var uriPrefix = cocoon.parameters["uriPrefix"];
var path = cocoon.parameters["path"];
var type = cocoon.parameters["type"];
var pipeline = cocoon.parameters["pipeline"];
var flowHelper = cocoon.getComponent(FlowHelper.ROLE);
var editorConfig = new Configuration(path, uriPrefix, type);
var editorFlowContext = new FlowContext(editorConfig, flowHelper);
cocoon.sendPage(pipeline,{'editorFlowContext':editorFlowContext,'doctype':type,'editorHlpr':new EditorHelper()});
}
function string2xml(content)
{
var builder = null;
var factory = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();
try
{
builder = factory.newDocumentBuilder();
}
catch (e)
{
print("Problem getting a parser");
}
var dom = builder.parse(new Packages.org.xml.sax.InputSource(new Packages.java.io.StringReader(content)));
return dom;
}
/**
* returns a DOM object representing the XML document at location @uri
*/
function loadDocument(uri) {
var parser = null;
var source = null;
var resolver = null;
try {
parser = cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
resolver = cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
source = resolver.resolveURI(uri);
var is = new Packages.org.xml.sax.InputSource(source.getInputStream());
is.setSystemId(source.getURI());
return parser.parseDocument(is);
}
finally {
if (source != null)
resolver.release(source);
cocoon.releaseComponent(parser);
cocoon.releaseComponent(resolver);
}
}
function saveDocument(documentTree, uri)
{
if (uri.indexOf("?") > 0)
{
uri = uri.substr(0, uri.indexOf("?"));
}
var result = true;
try
{
usingDocumentDo("", uri, function(document){
document.setContents(documentTree);
document.commitChanges();
});
}
catch (e)
{
result = false;
if (e instanceof ContentModelException)
{
print(e);
cocoon.log.error(e);
if (e.hasInfo())
{
print(e.getInfo());
}
}
else
{
print("other exception....");
throw e;
}
}
return result;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?