⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actions.js

📁 Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是供中,大型企业来管理其发布在互连网
💻 JS
📖 第 1 页 / 共 4 页
字号:
        asset.commitChanges();
      });
    });
  
    uploadResults.put(j,result)   
  }
  
  // if one of the uploads failed return the failure message
  for(var k=1;k<=uploadResults.size();k++)
  { 
    if(uploadResults.containsKey(k) && uploadResults.get(k)=="false") {
      result = false;
    }
  }  
  // stop iterating over uploads
  
  return result;
  
}


function viewSource(uriPrefix, resourceId, params) {
  lastResponseStatus = "0";
  return true;
}

function previewSource(uriPrefix, resourceId, params) {
  lastResponseStatus = "0";
  return true;
}

function viewResource(uriPrefix, resourceId, params) {
  lastResponseStatus = "0";
  return true;
}


function editDocument(uriPrefix, resourceId, params) 
{
  ///*
  var globalConstants = cocoon.getComponent(InputModule.ROLE + "Selector").select("globalconstants");
  var useLocking = globalConstants.getAttribute("cms-use-locking", null, null);
  var result = true;
  if (useLocking.equals("on"))
  {
    result = handleContentModelException(function(){
      usingDocumentDo("", uriPrefix + resourceId, function(document){
        document.lockForEditing();
        //document.commitChanges();
      });
    });
  }
  //*/
  //var result = true;
  return result;
}


function editDocumentFromSearch(uriPrefix, resourceId) 
{
  var result = editDocument(uriPrefix, resourceId, new HashMap());
  cocoon.sendPage("lockresult.jx", {success:result});
}

/**
 * setProperty used for move up/down.
 * The http://hippo.nl/cms/1.0 namespace is assumed.
 *
 * @param   uri        the URI of the resource to be proppatched
 * @param   property   name of the property to be set
 * @param   value      value of the property
 *
 * @returns boolean
 */
function setProperty(uri, property, value) {
  if (cocoon.log.isDebugEnabled()) {
    cocoon.log.debug("actions.js: setProperty: uri=" + uri + " - " + property + "=" + value);
  }
  var result = handleContentModelException(function(){
    usingDocumentDo("", uri, function(document){
      document.setProperty(property, value);
      document.commitChanges();
    });
  });
  return result;
}


/**
 * Copies source to destination in the repository
 *
 * @param   source        uri of the resource to be copied
 * @param   destination   destination uri
 */
function copy() {
  var source = cocoon.parameters["source"];
  var destination = cocoon.parameters["destination"];
  var destinationCollection = cocoon.parameters["collection"];
  var uriPrefix = cocoon.parameters["uriPrefix"];
  var rename = cocoon.parameters["rename"];
  var index = nextIndex(uriPrefix, destinationCollection);
  var newCaption ="";
  if (cocoon.log.isDebugEnabled()) {
    cocoon.log.debug("actions.js: copy(): copy " + source + " to " + destinationCollection);
    cocoon.log.debug("actions.js: copy(): copy " + source + " to " + destination);
    cocoon.log.debug("actions.js: copy(): index will be " + index);
  }
  
  var resourceExists = libio.checkExists(destination);

  if (resourceExists && !rename.equals("true"))
  {
    cocoon.sendPage("copy-result", {exists:true});
    return;
  }
  
  if (resourceExists && rename.equals("true"))
  {
    var newDestinationArray = destination.split("/");
    var tmpFileName = newDestinationArray[newDestinationArray.length-1];
    var shortName = tmpFileName;
    var postfix = "";
    if (tmpFileName.lastIndexOf(".xml") == tmpFileName.length - 4) // resource is a document
    {
      shortName = tmpFileName.substring(0,tmpFileName.lastIndexOf('.'));
      postfix = ".xml";
    }
    var uriPathLocation = destination.substring(0,destination.lastIndexOf(tmpFileName));
    var ii=1;
    // check if the resource exists otherwise create version with digit behind
    while(libio.checkExists(uriPathLocation + shortName + "" + ii + postfix))
    {    
      ii++;
    }
    destination = uriPathLocation + shortName + "" + ii + postfix;
    newCaption = shortName + "" + ii;
  }

  //check if webdav pathname is longer then 255 chars
  if (destination.length > 255) {
    if (cocoon.log.isDebugEnabled()) {
      cocoon.log.debug("actions.js: copy(): Pathname is to long:" + destination);
    }
    cocoon.sendPage("copy-result", {copyStatus:'toolong'});
    return;
  }
  
  var copyStatus = WebDAVHelper.copy(source, destination, authentication.getHttpState());
  var setPropertyResult = false;

  if (copyStatus >= 200 && copyStatus < 300)
  {
    // load xml document containing uris of copied document
    var copiedDocs = libio.loadDocument("cocoon://actions/resetWorkflowIds(" + destination + ")");
  
    // walk through the list and reset each document's workflowId
    var nodeList = copiedDocs.getElementsByTagName("Document");
    for (var i = 0; i < nodeList.getLength(); i++) {
      var node = nodeList.item(i);
      if (node != null) {
        var textNode = node.getFirstChild();
        if (textNode != null) {
          var path = textNode.getNodeValue();
          
          var status = startWorkflowForExistingDocument(uriPrefix, path);
          if (!status) {
            cocoon.log.error("actions.js: copy(): copy error: destination: " + path);
          }
          
          // also delete workflow status properties and regenerate UID
          var result = handleContentModelException(function(){
            usingDocumentDo(uriPrefix, path, function(document){
              document.deleteProperty("publicationDate");
              document.deleteProperty("scheduledPublicationDate");
              document.deleteProperty("unpublicationDate");
              document.deleteProperty("requestedPublicationDate");
              document.deleteProperty("requestedUnpublicationDate");
              document.setProperty("UID", UIDGenerator.generateUID());
              document.commitChanges();
            });
          });

        }
      }
    }

    setPropertyResult = handleContentModelException(function(){
      usingDocumentDo("", destination, function(document){
        if(rename.equals("true")) {
          document.setProperty("caption", newCaption);
        }
        document.setProperty("index", index);
        document.commitChanges();
      });
    });
    
    var emanager = cocoon.getComponent(EventAwareManager.ROLE);
    // var cache = cocoon.getComponent(Store.ROLE+"/EventAware");
    // fire invalidation events
    WebdavRepository.fireEvent(emanager,source);
    // below, invalidate parent node
    WebdavRepository.fireEvent(emanager,destination,false);

  }
  else
  {
    cocoon.log.error("actions.js: copy(): copy error, status code: " + copyStatus);
  }
  cocoon.sendPage("copy-result", {copyStatus:copyStatus, setPropertyResult:setPropertyResult});
}


/**
 * Creates a new workflow for a document.
 *
 * @param   uriPrefix    webdav files URL
 * @param   resourceId   path to the document for which to create the workflow, relative to uriPrefix
 * @returns true on success, false on failure.
 */
function startWorkflowForExistingDocument(uriPrefix, resourceId) {
  var uri = uriPrefix + resourceId;
  
  if (cocoon.log.isDebugEnabled()) {
    cocoon.log.debug("actions.js: startWorkflowForExistingDocument: uri: " + uriPrefix + resourceId);
  }

  var result = handleContentModelException(function(){
    usingDocumentDo(uriPrefix, resourceId, function(document){

      // get the document's type
      var type = document.getProperty("type");

      // get the workflow name for this document type  
      var model = cocoon.getComponent(InputModule.ROLE + "Selector").select("model");
      var workflowNameToUse = model.getAttribute("/types/resources/resource[@name='" + type + "']/workflowName", null, null);
      if (workflowNameToUse == null || workflowNameToUse == "")
      {
        workflowNameToUse = defaultWorkflowName;
      }
      if (cocoon.log.isDebugEnabled()) {
        cocoon.log.debug("actions.js: startWorkflowForExistingDocument: workflowName: " + workflowNameToUse);
      }

      // initialize workflow for this document and set workflowId property
      var workflowId = workflow.createWorkflow(resourceId, workflowNameToUse, uriPrefix);
      document.setProperty("workflowId", workflowId);
      document.commitChanges();
      
    });
  });
  return result;
}


/**
 * Saves an edited document and invokes the 'save' workflow action.
 *
 * @param   uri         location to save document at
 * @param   src         the XML content to save
 & @param   uriPrefix   webdav files uri
 */
function saveDocument() {
  var uri = cocoon.parameters["uri"];
  var src = cocoon.parameters["src"];
  
  var uriPrefix = cocoon.parameters["uriPrefix"];
  if (cocoon.log.isDebugEnabled()) {
    cocoon.log.debug("actions.js: saveDocument: uri: " + uri);
  }
  var sr = null;
  var fw = null;
  var tempFile = null;
  try {
    tempFile = File.createTempFile("HippoCMSSave", ".xml");
    sr = new StringReader(cocoon.request.getParameter("src"));
    fw = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(tempFile)), "UTF-8");
    // TODO: optimize; read more than one character at a time
    var c = sr.read();
    while (c >= 0) {
      fw.write(c);
      c = sr.read();
    }
    try {
      sr.close();
    }
    catch (e) {
    }
    finally {
      sr = null;
    }
    try {
      fw.close();
    }
    catch (e) {
    }
    finally {
      fw = null;
    }

    var globalConstants = cocoon.getComponent(InputModule.ROLE + "Selector").select("globalconstants");
    var extractSharedTextOnSave = globalConstants.getAttribute("extract-shared-text-on-save", null, null);
    var sharedTextVersion = globalConstants.getAttribute("shared-text-version", null, null);

    if (extractSharedTextOnSave == "on")
    {
      //print("extractSharedTextOnSave=on");
      
      var document = libio.loadDocument(src + "(" + tempFile.getCanonicalPath() + ")");
      var textElements = document.getElementsByTagName("Text");
      for (var i = 0; i < textElements.getLength(); i++)
      {
        var element = textElements.item(i);
        var attributes = element.getAttributes();
        var sharedIdAttribute = attributes.getNamedItem("new-shared-id");
        if (sharedIdAttribute != null)
        {
          //print("found new shared text");
          var textNode = sharedIdAttribute.getFirstChild();
          if (textNode != null)
          {
            var sharedId = textNode.getNodeValue();
            //print("shared id: " + sharedId);
            var sharedTextUri = uriPrefix + sharedId;
            if (!put(sharedTextUri, "cocoon:/extract-shared-text(" + tempFile.getCanonicalPath() + "," + sharedId + ")", this.post_saveDocument, this.post_saveDocument))
            {
              cocoon.log.error("actions.js: saveDocument: put failed for " + sharedTextUri);
            }
            else
            {
              // set caption and document type
              var stop = sharedTextUri.lastIndexOf(".xml");
              var start = sharedTextUri.lastIndexOf("/")+1;
              var sharedTextCaption = sharedTextUri.substring(start, stop);
              var typeProp = new Property("cms", "http://hippo.nl/cms/1.0", "type", "text");
              var captionProp = new Property("cms", "http://hippo.nl/cms/1.0", "caption", sharedTextCaption);
              var propSet = new HashSet();
              propSet.add(typeProp);
              propSet.add(captionProp);
              if (!proppatch(sharedTextUri, propSet, null, this.post_proppatch, this.post_proppatch))
              {
                cocoon.log.error("actions.js: saveDocument: proppatch failed on " + sharedTextUri);
              } 
              
              // start workflow
              if (!startWorkflowForExistingDocument(uriPrefix, sharedId))
              {
                cocoon.log.error("actions.js: saveDocument: starting workflow for shared text document with uri " + sharedTextUri + " failed");
              }
              
              if (sharedTextVersion == "on")
              {
                // publish the shared text document to create version 1
                var uris = new ArrayList();
                uris.add(sharedId);
                var params = new ArrayList();
                var p = new HashMap();
                p.put("publicationDateMode", "now");
                p.put("unpublicationDateMode", "never");
                p.put("publicationDate", null);
                p.put("unpublicationDate", null);
                params.add(p);
                if (!workflow.invokeGroupAction(uris, "hippo.cms.publish", params, uriPrefix))
                {
                  cocoon.log.error("actions.js: saveDocument: publishing of shared text document with uri " + sharedTextUri + " failed");
                }
              }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -