在 Alfresco 中使用代码创建站点 All in one project with Eclipse IDE

Create site using code in Alfresco All in one project with Eclipse IDE

如何在一个项目中使用 Alfresco All 中的代码创建网站。

我正在使用 Eclipse IDE。

我将构建和部署 war 文件。

但是在部署 war 之后,我希望自动创建一个站点或逻辑分区。意味着我们不需要由任何特定用户手动创建它。所有的事情都应该只通过代码来完成。

任何人都可以告诉我这需要哪些文件,以及我需要将它放在露天的什么地方 All in one project?

提前致谢..

         var site = siteService.createSite("site-dashboard", "gamma-site", "Gamma Site", "A site description", siteService.PUBLIC_SITE, "st:site");

这可能会帮助您在存储库级别创建站点。这将 return 具有指定参数的已创建网站的 Site 对象。

如果您想使用 CMIS,请参考下面的代码 API

      package com.kayne.cmis.webscript;
      import org.apache.commons.httpclient.HttpClient;
      import org.apache.commons.httpclient.HttpStatus;
      import org.apache.commons.httpclient.UsernamePasswordCredentials;
      import org.apache.commons.httpclient.auth.AuthScope;
      import org.apache.commons.httpclient.methods.PostMethod;
      import org.apache.commons.httpclient.methods.StringRequestEntity;
      import org.json.JSONObject;
      public class CreateSiteTest {   
      public static void main(String[] args){

  HttpClient client = new HttpClient();
  client.getState().setCredentials(                
   new AuthScope("localhost", 8080, "Alfresco"),           
     new UsernamePasswordCredentials("admin", "admin"));   
   String apiurl ="http://localhost:8080/alfresco/service/api/sites";
  PostMethod post = new PostMethod(apiurl);
  try {
     JSONObject site = new JSONObject();
     site.put("shortName", "kaynezhang");
     site.put("visibility", "PUBLIC");
      site.put("sitePreset", "site-dashboard");


     System.out.println(site.toString());
     post.setDoAuthentication(true);
     post.setRequestHeader("Content-Type", "application/json");
     post.setRequestEntity(new StringRequestEntity(site.toString(), "application/json",  "UTF-8"));


     int status = client.executeMethod(post);
         if (status != HttpStatus.SC_OK) {
            System.err.println("Method failed: " + post.getStatusLine());
             } 
     String resultString = post.getResponseBodyAsString();
     System.out.println(resultString);
  } catch (Exception e) {
     e.printStackTrace();
  } finally {
     post.releaseConnection();
  }   } }

您可以在 CMIS REST API 中了解有关该主题的更多信息。

希望对您有所帮助。