Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是供中,大型企业来管理其发布在互连网

源代码在线查看: wizard.js

软件大小: 29397 K
上传用户: devilgaze
关键词: Hippo CMS 开源 大型
下载地址: 免注册下载 普通下载 VIP

相关代码

				cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");
				cocoon.load("site:/actions/flow/actions.js");
				cocoon.load("site:/spring/spring.js");
				
				importClass(Packages.nl.hippo.cms.contentmodel.WebdavRepository);
				importClass(Packages.nl.hippo.cms.contentmodel.Document);
				//importClass(Packages.nl.hippo.cms.wizard.i18n.I18NHelper);
				importClass(Packages.nl.hippo.cocoon.repository.RepositoryManager);
				
				importClass(Packages.java.util.HashMap);
				importClass(Packages.java.io.ByteArrayOutputStream);
				importClass(Packages.javax.xml.parsers.DocumentBuilder);
				importClass(Packages.javax.xml.parsers.DocumentBuilderFactory);
				importClass(Packages.org.springframework.web.context.WebApplicationContext);
				importClass(Packages.nl.hippo.cms.wizard.NewDocumentWizard);
				importClass(Packages.nl.hippo.cms.wizard.WizardConfigurationContentHandler);
				importClass(Packages.nl.hippo.cms.wizard.WizardResult);
				//importClass(Packages.nl.hippo.cms.wizard.Constants);
				
				function do_wizardChooser() {
				    var tpl = 'display-form/wizard/tpl.xml';
					var def = 'forms/wizard/def.xml';
					var bnd = 'forms/wizard/bnd.xml';
					var repo = cocoon.parameters["repository-prefix"];
					var config = "configuration";
						
					var pu = cocoon.createObject(Packages.org.apache.cocoon.components.flow.util.PipelineUtil);
				
				    var wizard = null;
				    var aspects = null;
				    if(cocoon.session.getAttribute("cms-wizard") != null) {
				        wizard  = cocoon.session.getAttribute("cms-wizard").wizard;
				        aspects = cocoon.session.getAttribute("cms-wizard").aspects;
				    } else {
				        var contentHandler = new WizardConfigurationContentHandler();	
				        pu.processToSAX(config,{}, contentHandler);
				        wizard  = contentHandler.getWizard();
				        aspects = contentHandler.getAspects();
				    }
				
				    //debug
				    //cocoon.sendPage('forms/wizard/def.xml', {'wizard': wizard});
				    //cocoon.sendPage('forms/wizard/bnd.xml', {'wizard': wizard});
				
				    //Create the form
				    var modelDOM = pu.processToDOM(def, {'wizard': wizard});
				    var form = new Form(modelDOM.getDocumentElement());
				    var bindingDOM = pu.processToDOM(bnd, {'wizard': wizard});
				    form.createBinding(bindingDOM.getDocumentElement());
				
				    form.load({'wizard':wizard});
				    form.showForm(tpl, {'wizard': wizard});
				    form.save({'wizard':wizard});
				
				    //Wizard model is filled and valid, let's get the new document info  
				    var result = new WizardResult()
				    wizard.fillResult(result, spring.getWebApplicationContext());
				    result.handleAspects(aspects);
				
				    //result.debug();
				
				    //Check if doc exists
				    //the ugly way	
				    var docExists = false;
				    var cmresult = handleContentModelException(function() {
				        usingRepositoryDo(function(repository) {
				            try {
				                var doc = repository.lookupDocument(repo + result.getDocumentURI());
				                docExists = doc!=null;
				            } catch(e) {
				                //print("Document " + result.getDocumentURI() + " doesn't esxist: " + e);
				            }
				        });
				    });
				    
				    if(docExists) {
				        //return a document exists action
				        result.setResultAction("exists");
				    } else {
				        //create params for newDocument() in actions.js
				        var params = new HashMap;
				        params.put("name",result.getName());
				        params.put("type",result.getType());
				        params.put("xml",result.getSourceURI());
				        params.put("workflowName",result.getWorkflowName());
				
				        //create document
				        checkAncestorCollectionsExist(repo, result.getDocumentURI());
				        
				        if(newDocument(repo, result.getPath(), params)) {
				            //TODO: implement result handling
				            //patch document
				            patchProperties(repo, result.getDocumentURI(), result.getProperties());
				            
				            //xpath document
				            injectContent(repo, result.getDocumentURI(), result.getXpaths());
				
					        if (libio.checkExists("extensions://wizard/flow/customactions.js"))
					        {
					            cocoon.load("extensions://wizard/flow/customactions.js");
					            performCustomWizardActions(repo, result);          
					        }
				
				            wizard.reset();
				        } else {
				            result.setResultAction("not-allowed");
				        }
				    }
					
				    //user convenience
				    cocoon.session.setAttribute("cms-wizard", {'wizard' : wizard, 'aspects': aspects});
				
				    //store the result in the session for processing after the redirect.
				    cocoon.session.setAttribute("result", result);
				    cocoon.redirectTo("/wizard/wizard");
				}
				
				function patchProperties(repo, source, properties) {
				    if(properties.size() > 0){
				        var result = handleContentModelException(function(){
				            usingRepositoryDo(function(repository){
				                var doc = repository.lookupResource(repo + source);
				                var it = properties.iterator();
				                while(it.hasNext()) {
				                    var prop = it.next();
				                    doc.setProperty(prop.getNameSpace(), prop.getName(), prop.getValue());
				                }
				                doc.commitChanges();
				            });
				        });
				    }
				}
				
				function injectContent(repo, source, xpaths) {
				    if(xpaths.size() > 0) {
				        //try-catch?	
				        var pu = cocoon.createObject(Packages.org.apache.cocoon.components.flow.util.PipelineUtil);
				        var enhancedDocument = pu.processToDOM('addContent' + source, {'xpaths': xpaths});
				        var enhancementResult = handleContentModelException(function() {
				            usingRepositoryDo(function(repository) {
				                var doc = repository.lookupDocument(repo + source);
				                doc.setContents(enhancedDocument);
				                doc.commitChanges();
				            });
				        });
				        //return enhancedDocument && enhancementResult;
				    }
				}
				
				function checkAncestorCollectionsExist(m_baseUri,location) {
				    var NOT_FOUND_INDEX = -1;
				    var lastIndexOfSlash = location.lastIndexOf('/');
				    
				    if (lastIndexOfSlash != NOT_FOUND_INDEX) {
				        var parentPath = "" + location.substring(0, lastIndexOfSlash);
				        var pPlength = parentPath.length;
				
				        if (pPlength > 0) {      
				            checkAncestorCollectionsExist(m_baseUri,parentPath);
				            var mkcolResult = WebDAVHelper.mkcol(m_baseUri + parentPath, cocoon.session.httpstate);
				            if (mkcolResult != 201) {
				                //print("failure making: " + m_baseUri + parentPath + ": " + mkcolResult);
				                // TODO: handle result
				            }
				        }
				    }
				}			

相关资源