adalm pluto_Apache Pluto和Jackrabbit集成示例教程

adalm pluto

According for multiple sources and standards, you may be able of defining the Content Repository as a store of digital content (Structured/Unstructured) with an associated set of facilities like data management, full-text search, versioning, transactions and access methods allowing application-independent access the content.

根据多种来源和标准,您可以将Content Repository定义为数字内容存储(结构化/非结构化),并具有一组相关的设施,如数据管理,全文搜索,版本控制,事务和允许应用程序的访问方法-独立访问内容。

Accessing these content has become important matter as this should be done through using of a well-defined, common standard and organized way. This actually will help you getting acquired a lot of features, most important one of them is Swap-ability.

访问这些内容已变得很重要,因为这应该通过使用定义明确,通用的标准和有组织的方式来完成。 实际上,这将帮助您获得许多功能,其中最重要的一项是可交换性

This exactly means that when it comes to modify your Content Engine, you don’t wast a lot of time/efforts acquiring/learning practices & information to get this new Content Repository integrated into your infrastructure.

这恰恰意味着,在修改Content Engine时,您无需花费很多时间/精力来获取/学习实践和信息,就可以将此新的Content Repository集成到您的基础架构中。

As the importance of the Portal has increased the need for the integration with Content Repository is also got increased and especially when you know that a very famous Portal like WebLogic Portal has become self-integrated with one of the most robust content management system which was known as a Stellent-UCM (Currently know as oracle Stellent-UCM).

随着门户网站重要性的增加,与内容库集成的需求也越来越大,尤其是当您知道像WebLogic Portal这样非常著名的门户网站已与最强大的内容管理系统之一进行自我集成时作为Stellent-UCM(当前称为oracle Stellent-UCM)。

Even though a Stellent UCM has already provided a separate API to get integrated with, however Oracle has integrated through controls built in using JCR/JSR 170

尽管Stellent UCM已经提供了单独的API进行集成,但是Oracle通过使用JCR / JSR 170内置的控件进行了集成。

Numerous kinds of content repositories are provided these days, some of them are Open source like Apache Jackrabbit while others are still closed source and you may find something restricted like Alfresco.

如今,提供了许多种类的内容存储库,其中一些是开源的,例如Apache Jackrabbit,而另一些仍是封闭的,您可能会发现某些限制,例如Alfresco。

This restriction comes in terms of availability for a community copy but if you want more powerful support you may need to buy a license.

此限制来自社区副本的可用性,但是如果您想获得更强大的支持,则可能需要购买许可证。

This tutorial is a solid trial that aim to provide you tangible perspective for the Content Repository concept and how can you use that JCR standard API to get integrated with as well as provide you other options that you may need to communicate with other repositories that may or may not provide you a standard way to communicate with.

本教程是一个可靠的试用版,旨在为您提供有关内容存​​储库概念的切实见解,以及如何使用该JCR标准API进行集成,并为您提供与可能需要或可能与其他存储库进行通信的其他选项。可能无法为您提供一种标准的交流方式。

将Jackrabbit运行到Apache (Running Jackrabbit Into Apache)

Defining of Apache Jackrabbit isn’t separated from defining of the JCR itself, JCR is stands for Java Content Repository or Content Repository API for Java, it’s a specification for Java platform to access content repositories in a uniform manner.

Apache Jackrabbit的定义与JCR本身的定义并没有分开,JCR表示Java Content Repository或Java的Content Repository API,它是Java平台以统一方式访问内容存储库的规范。

Apache Jackrabbit content repository is a complete, and fully complaint implementation of the Content Repository API for Java Technology API (JCR – Java Content Repository) and therefore its primary API is defined by JCR.

Apache Jackrabbit内容存储库是针对Java技术API的内容存储库API(JCR – Java内容存储库)的完整且完全受投诉的实现,因此,其主要API由JCR定义。

Jackrabbit supports all JCR specifications, practically, Jackrabbit 2.8 supports JCR 2.0 while last version of Jackrabbit that supports JCR 1.0 was Jackrabbit 1.6.

Jackrabbit支持所有JCR规范,实际上,Jackrabbit 2.8支持JCR 2.0,而最后一个支持JCR 1.0的Jackrabbit版本是Jackrabbit 1.6。

To get started using of Jackrabbit content repository and communicating with it through using of standard JCR 2.0, just follow below steps:

要开始使用Jackrabbit内容存储库并通过使用标准JCR 2.0与之通信,只需执行以下步骤:

  • Download Jackrabbit from Apache official site.

    从Apache官方网站下载Jackrabbit
  • Unzip Jackrabbit into your directory. We assumed that you did that on D:\Jackrabbit\jackrabbit-2.8.0.

    将Jackrabbit解压缩到您的目录中。 我们假设您在D:\Jackrabbit\jackrabbit-2.8.0
  • Open your jackrabbit-webapp and modify populate.jsp there to be look like below:

    打开您的jackrabbit-webapp并修改populate.jsp ,如下所示:

populate.jsp

populate.jsp

<%--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You 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

       https://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.
--%><%@ page import="java.io.FilterInputStream,
                     java.io.IOException,
                     java.io.InputStream,
                     java.io.InputStreamReader,
                     java.net.URL,
                     java.net.URLConnection,
                     java.net.URLDecoder,
                     java.net.URLEncoder,
                     java.util.ArrayList,
                     java.util.Arrays,
                     java.util.Calendar,
                     java.util.Collections,
                     java.util.Iterator,
                     java.util.List,
                     javax.jcr.Node,
                     javax.jcr.Repository,
                     javax.jcr.Session,
                     javax.jcr.SimpleCredentials,
                     org.apache.jackrabbit.j2ee.RepositoryAccessServlet,
                     org.apache.jackrabbit.util.Text,
                     org.json.simple.JSONArray,
                     org.json.simple.JSONObject,
                     org.json.simple.JSONValue"
 %><%@ page contentType="text/html;charset=UTF-8" %><%
    Repository rep;
    Session jcrSession;
    String wspName;
    try {
        rep = RepositoryAccessServlet.getRepository(pageContext.getServletContext());
        jcrSession = rep.login(new SimpleCredentials("admin", "admin".toCharArray()));
        wspName = jcrSession.getWorkspace().getName();
    } catch (Throwable e) {
        %>Error while accessing the repository: <font color="red"><%= Text.encodeIllegalXMLCharacters(e.getMessage()) %></font><br><%
        %>Check the configuration or use the <a href="admin/">easy setup</a> wizard.<%
        return;
    }
    try {
        String seedWord = request.getParameter("seed");
        if (seedWord != null) {
            seedWord = new String(seedWord.getBytes("ISO-8859-1"), "UTF-8");
        }
        int numDocs = 0;
        List filetypes = new ArrayList();
        if (request.getParameter("num") != null) {
            try {
                numDocs = Integer.parseInt(request.getParameter("num"));
            } catch (NumberFormatException e) {
                // ignore
            }
        }
        String[] types = request.getParameterValues("filetype");
        if (types != null) {
            filetypes.addAll(Arrays.asList(types));
        } else {
            filetypes = DEFAULT_TYPES;
        }

if (seedWord != null && numDocs > 0 && filetypes.size() > 0) { %>
<html>
<head>
<title>Welcome to Apache Jackrabbit - Populate workspace: <%= Text.encodeIllegalXMLCharacters(wspName) %></title>
<link rel="shortcut icon" href="<%= Text.encodeIllegalXMLCharacters(request.getContextPath()) %>/images/favicon.ico" type="image/vnd.microsoft.icon">
<style type="text/css" media="all">
      @import url("<%= Text.encodeIllegalXMLCharacters(request.getContextPath()) %>/css/default.css");
</style>
<script><!--
function draw() {
	// draw the bar
        document.write('<table cellspacing="0" cellpadding="0" style="border-color:' + this.borderColor + '; border-width:' + this.borderWidth + '; border-style:' + this.borderStyle + '">');
        document.write('<tr><td>');
        document.write('<table border="0" cellspacing="0" cellpadding="0" style="">');
        document.write('<tr><td style="background-color:' + this.barColor +'"><img src="<%= Text.encodeIllegalXMLCharacters(request.getContextPath()) %>/images/0.gif" id="' + this.id + 'barFG" width="0" height="' + this.height + '"/></td>');
        document.write('<td><img src="<%= Text.encodeIllegalXMLCharacters(request.getContextPath()) %>/images/0.gif" id="' + this.id + 'barBG" width="' + this.width + '" height="' + this.height + '"/></td></tr>');
        document.write('</table>');
        document.write('</tr></td>');
        document.write('</table>');
        document.write('<table>');
        document.write('<tr><td><img src="<%= Text.encodeIllegalXMLCharacters(request.getContextPath()) %>/images/0.gif" width="' + this.width + '" height="0"/></td></tr>');
        document.write('<tr><td align="center"><span id="' + this.id + 'barValue">0%</span></td></tr>');
        document.write('<tr><td align="center"><span id="' + this.id + 'barInfo"> </span></td></tr>');
        document.write('</table>');

	this.barFG = document.getElementById(this.id + 'barFG');
	this.barBG = document.getElementById(this.id + 'barBG');
	this.barValue = document.getElementById(this.id + 'barValue').firstChild;
	this.barInfo = document.getElementById(this.id + 'barInfo').firstChild;
}

// informs the progress bar about the current value
function inform(value, info) {
	var barWidth = Math.floor(this.width * value / this.maxValue);
	var spaceWidth = this.width - barWidth;
	var perCent = Math.floor(100 * value / this.maxValue);
	this.barFG.width = barWidth;
	this.barBG.width = spaceWidth;
	this.barValue.nodeValue = perCent + '%';
	this.barInfo.nodeValue = info;
}

// constructor
function ProgressBar(maxValue, width, height) {
	this.maxValue = maxValue;
	this.width = width;
	this.height = height;
	this.id = '' + Math.round(Math.random() * 10000);
	this.inform = inform;
	this.draw = draw;
}

// default values
ProgressBar.prototype.barColor = "green";
ProgressBar.prototype.borderColor = "grey";
ProgressBar.prototype.borderStyle = "groove";
ProgressBar.prototype.borderWidth = "2px";

// -->
</script>
</head>
  <body>
  <div style="background: white; border: 1px solid black; padding: 50px; width: 510px; margin: 50px auto;">
  <h2>Populate workspace: "<%= Text.encodeIllegalXMLCharacters(wspName) %>"</h2><br>
    <p>Overall progress</p>
    <script>var pb = new ProgressBar(<%= numDocs %>, 500, 30);pb.draw();</script>

    <p>Downloading document</p>
    <script>var dp = new ProgressBar(1000, 500, 30);dp.draw();</script>
    <%
            Node root = jcrSession.getRootNode();
            int n = 0;
            for (int typeIdx = 0; typeIdx < filetypes.size(); typeIdx++) {
                String type = (String) filetypes.get(typeIdx);
                int offset = 0;
                while (n < numDocs * (typeIdx + 1) / filetypes.size()) {
                    final URL[] urls = new Search(type, seedWord, offset).getURLs();
                    if (urls.length == 0) {
                        break;
                    }
                    for (int i = 0; i < urls.length; i++) {
                        final URL currentURL = urls[i];
                        String path = urls[i].getPath();
                        if (path.startsWith("/")) {
                            path = path.substring(1);
                        }
                        final String host = urls[i].getHost();
                        List folderNames = new ArrayList();
                        folderNames.addAll(Arrays.asList(host.split("\\.")));
                        Collections.reverse(folderNames);
                        folderNames.addAll(Arrays.asList(path.split("/", 0)));
                        final String fileName = URLDecoder.decode((String) folderNames.remove(folderNames.size() - 1), "UTF-8").replaceAll(":", "_");
                        Node node = root;
                        for (Iterator fn = folderNames.iterator(); fn.hasNext(); ) {
                            String name = URLDecoder.decode((String) fn.next(), "UTF-8");
                            name = name.replaceAll(":", "_");
                            if (name.length() == 0) {
                                continue;
                            }
                            if (!node.hasNode(name)) {
                                node.addNode(name, "nt:folder");
                            }
                            node = node.getNode(name);
                        }
                        if (!node.hasNode(fileName)) {
                            final JspWriter fOut = out;
                            Node file = node.addNode(fileName, "nt:file");
                            final Node resource = file.addNode("jcr:content", "nt:resource");
                            final Exception[] ex = new Exception[1];
                            Thread t = new Thread(new Runnable() {
                                public void run() {
                                    try {
                                        String info = fileName + " (" + host + ")";
                                        URLConnection con = currentURL.openConnection();
                                        InputStream in = con.getInputStream();
                                        try {
                                            synchronized (fOut) {
                                                fOut.println("<script>dp.inform(0, '" + Text.encodeIllegalXMLCharacters(info) + "')</script>");
                                                fOut.flush();
                                            }
                                            int length = con.getContentLength();
                                            if (length != -1) {
                                                in = new ProgressInputStream(in, length, info, "dp", fOut);
                                            }
                                            resource.setProperty("jcr:data", in);
                                            String mimeType = URLConnection.guessContentTypeFromName(fileName);
                                            if (mimeType == null) {
                                                if (fileName.endsWith(".doc")) {
                                                    mimeType = "application/msword";
                                                } else if (fileName.endsWith(".xls")) {
                                                    mimeType = "application/vnd.ms-excel";
                                                } else if (fileName.endsWith(".ppt")) {
                                                    mimeType = "application/mspowerpoint";
                                                } else {
                                                    mimeType = "application/octet-stream";
                                                }
                                            }
                                            resource.setProperty("jcr:mimeType", mimeType);
                                            Calendar lastModified = Calendar.getInstance();
                                            lastModified.setTimeInMillis(con.getLastModified());
                                            resource.setProperty("jcr:lastModified", lastModified);
                                        } finally {
                                            in.close();
                                        }
                                    } catch (Exception e) {
                                        ex[0] = e;
                                    }
                                }
                            });
                            t.start();
                            for (int s = 0; t.isAlive(); s++) {
                                Thread.sleep(100);
                                if (s % 10 == 0) {
                                    synchronized (fOut) {
                                        fOut.println("<script>pb.inform(" + n + ", '')</script>");
                                        fOut.flush();
                                    }
                                }
                            }
                            if (ex[0] == null) {
                                jcrSession.save();
                                n++;
                                synchronized (fOut) {
                                    fOut.println("<script>pb.inform(" + n + ", '')</script>");
                                    fOut.flush();
                                }
                                if (n >= numDocs * (typeIdx + 1) / filetypes.size()) {
                                    break;
                                }
                            } else {
                                jcrSession.refresh(false);
                            }
                        }
                    }
                    offset += 10;
                }
            }
%>  </div>
  </body>
</html>
<% } else {
request.setAttribute("title", "Populate workspace " + wspName);
%><jsp:include page="header.jsp"/>
<p>
  This page allows you to populate the workspace with documents downloaded
  from the Internet.
</p>
    <form method="POST">
      <table>
      <tr><td>Seed word (optional):</td><td><input name="seed" type="text" size="30" value="<%= seedWord == null ? "" : Text.encodeIllegalXMLCharacters(seedWord) %>"/></td></tr>
      <tr><td>Number of documents:</td><td><input name="num" type="text" size="30" value="<%= numDocs == 0 ? 100 : numDocs %>"/></td></tr>
      <tr valign="top"><td>Document types:</td><td><input name="filetype" type="checkbox" value="pdf" <%= filetypes.contains("pdf") ? "checked" : "" %>/> Adobe Acrobat PDF<br/><input name="filetype" type="checkbox" value="rtf" <%= filetypes.contains("rtf") ? "checked" : "" %>/> Rich Text Format<br/><input name="filetype" type="checkbox" value="doc" <%= filetypes.contains("doc") ? "checked" : "" %>/> Microsoft Word<br/><input name="filetype" type="checkbox" value="ppt" <%= filetypes.contains("ppt") ? "checked" : "" %>/> Microsoft PowerPoint<br/><input name="filetype" type="checkbox" value="xls" <%= filetypes.contains("xls") ? "checked" : "" %>/> Microsoft Excel<br/></td></tr>
      <tr><td> </td><td><input type="submit" value="Populate!"/></td></tr>
      </table>
    </form>
<jsp:include page="footer.jsp"/>
<%    }
    } finally {
        if (jcrSession != null) {
            jcrSession.logout();
        }
    }
%><%!

    public static final List DEFAULT_TYPES = Arrays.asList(
            new String[]{"pdf", "rtf", "doc", "ppt", "xls"});

    public static class Search {

        private static final String CHARSET = "UTF-8";

        private final String filetype;

        private final String term;

        private final int start;

        public Search(String filetype, String term, int start) {
            this.filetype = filetype;
            this.term = term;
            this.start = start;
        }

        public URL[] getURLs() throws Exception {
            List<URL> urls = new ArrayList<URL>();
            String googleBaseUrl = "https://ajax.googleapis.com/ajax/services/search/web";
            String googleQueryString = "?v=1.0&start=" + start + "&rsz=8&q=";
            String query = term + " filetype:" + this.filetype;
            URL google = new URL(googleBaseUrl + googleQueryString + URLEncoder.encode(query, CHARSET));
            InputStreamReader reader = null;
            try {
                URLConnection conn = google.openConnection();
                conn.setRequestProperty("Referer", "https://jackrabbit.apache.org/");
                reader = new InputStreamReader(conn.getInputStream(), CHARSET);
                Object obj = JSONValue.parse(reader);
                JSONObject jsonObject = (JSONObject) obj;
                JSONObject responseData = (JSONObject) jsonObject.get("responseData");
                if (responseData != null) {
                    JSONArray results = (JSONArray) responseData.get("results");
                    if (results != null) {
                        for (int i = 0; i < results.size(); i++) {
                            JSONObject result = (JSONObject) results.get(i);
                            if (result != null) {
                                String urlString = (String) result.get("url");
                                URL url = new URL(new URL("http", "www.google.com", "dummy"), urlString);
                                if (!url.getHost().contains("google")) {
                                    urls.add(url);
                                }
                            }
                        }
                    }
                }
            } finally {
                reader.close();
            }
            return urls.toArray(new URL[urls.size()]);
        }
    }

    public static class ProgressInputStream extends FilterInputStream {

        private final int length;

        private final String fileName;

        private final String varName;

        private final JspWriter out;

        private long read;

        private long nextReport = (16 * 1024);

        public ProgressInputStream(InputStream in, int length, String fileName,
                                   String varName, JspWriter out) {
            super(in);
            this.length = length;
            this.fileName = fileName;
            this.varName = varName;
            this.out = out;
        }

        public int read() throws IOException {
            int r = super.read();
            reportProgress(r);
            return r;
        }

        public int read(byte b[]) throws IOException {
            int r = super.read(b);
            reportProgress(r);
            return r;
        }

        public int read(byte b[], int off, int len) throws IOException {
            int r = super.read(b, off, len);
            reportProgress(r);
            return r;
        }

        private void reportProgress(int r) throws IOException {
            if (r != -1) {
                read += r;
                if (read > nextReport || read == length) {
                    // report every 16k
                    synchronized (out) {
                        double s = 1000d * (double) read / (double) length;
                        out.println("<script>" + varName + ".inform(" +
                                Math.min((int) Math.ceil(s), 1000) +
                                ", '" + Text.encodeIllegalXMLCharacters(fileName) + "')</script>");
                        out.flush();
                    }
                    nextReport += (16 * 1024);
                }
            }
        }
    }
%>
  • Execute mvn clean install against your jackrabbit-webapp project.

    对您的jackrabbit-webapp项目执行mvn clean install
  • you already have a Maven installed into your machine as well as ready system variables.

    您已经在计算机中安装了Maven以及就绪的系统变量。
  • You should get success build for your later Maven command like below.

    您应该为以后的Maven命令获得成功的构建,如下所示。
  • Open your Eclipse.

    打开您的Eclipse。
  • Create new Apache Tomcat 7 server.

    创建新的Apache Tomcat 7服务器。
  • Configure created Apache Tomcat by setting Server locations like below:

    通过设置如下所示的服务器位置来配置创建的Apache Tomcat:
  • Deploy Jackrabbit Web Application from your jackrabbit-webapp project.

    jackrabbit-webapp项目部署Jackrabbit Web应用程序。
  • Download JCR 2.0 API JAR from here into your Apache Tomcat lib.

    此处将JCR 2.0 API JAR下载到您的Apache Tomcat库中。
  • Run your Tomcat Server from your Eclipse.

    从Eclipse运行Tomcat服务器。
  • Access https://localhost:8080/jackrabbit-webapp-2.8.0/ to open the home page of Apache Jackrabbit.

    访问https://localhost:8080/jackrabbit-webapp-2.8.0/打开Apache Jackrabbit的主页。
  • Create new repository by clicking on Create Content Repository. Your repository home directory will be jackrabbit just like you see above.

    通过单击创建内容存储库来创建新的存储库。 就像您在上面看到的那样,您的存储库主目录将是jackrabbit。
  • Now, you may find below my Repository configurations listed at the console of Eclipse as well as the Repository of mine is created on D:\JournalDev\eclipse\jackrabbit.

    现在,您可能会在下面的Eclipse控制台中找到我的存储库配置,以及我的存储库是在D:\JournalDev\eclipse\jackrabbit

Jackrabbit Configurations

Jackrabbit Configurations

2014-12-30 20:42:34.499 INFO  [http-bio-8080-exec-7] Installer.java:159 Creating new repository home 'jackrabbit'
2014-12-30 20:42:34.500 INFO  [http-bio-8080-exec-7] Installer.java:197 Creating new repository config: jackrabbit\repository.xml
2014-12-30 20:42:34.505 INFO  [http-bio-8080-exec-7] Installer.java:221 Creating new bootstrap properties: jackrabbit\bootstrap.properties
2014-12-30 20:42:34.527 INFO  [http-bio-8080-exec-7] RepositoryStartupServlet.java:253 RepositoryStartupServlet initializing...
2014-12-30 20:42:34.528 INFO  [http-bio-8080-exec-7] AbstractConfig.java:101 Configuration of BootstrapConfig
2014-12-30 20:42:34.528 INFO  [http-bio-8080-exec-7] AbstractConfig.java:102 ----------------------------------------------
2014-12-30 20:42:34.536 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   valid: true
2014-12-30 20:42:34.536 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   rmiConfig: org.apache.jackrabbit.j2ee.RMIConfig@36db4bcf
2014-12-30 20:42:34.536 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   repositoryConfig: jackrabbit\repository.xml
2014-12-30 20:42:34.537 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   class: class org.apache.jackrabbit.j2ee.BootstrapConfig
2014-12-30 20:42:34.537 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   repositoryHome: jackrabbit
2014-12-30 20:42:34.537 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   repositoryName: jackrabbit.repository
2014-12-30 20:42:34.537 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   jndiConfig: org.apache.jackrabbit.j2ee.JNDIConfig@774e1f2b
2014-12-30 20:42:34.537 INFO  [http-bio-8080-exec-7] AbstractConfig.java:108 ----------------------------------------------
2014-12-30 20:42:34.537 INFO  [http-bio-8080-exec-7] AbstractConfig.java:101 Configuration of JNDIConfig
2014-12-30 20:42:34.538 INFO  [http-bio-8080-exec-7] AbstractConfig.java:102 ----------------------------------------------
2014-12-30 20:42:34.538 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   valid: true
2014-12-30 20:42:34.538 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   jndiName: jackrabbit.repository
2014-12-30 20:42:34.538 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   jndiEnabled: true
2014-12-30 20:42:34.538 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   class: class org.apache.jackrabbit.j2ee.JNDIConfig
2014-12-30 20:42:34.538 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   jndiEnv: {java.naming.provider.url=https://www.apache.org/jackrabbit, java.naming.factory.initial=org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory}
2014-12-30 20:42:34.539 INFO  [http-bio-8080-exec-7] AbstractConfig.java:108 ----------------------------------------------
2014-12-30 20:42:34.539 INFO  [http-bio-8080-exec-7] AbstractConfig.java:101 Configuration of RMIConfig
2014-12-30 20:42:34.539 INFO  [http-bio-8080-exec-7] AbstractConfig.java:102 ----------------------------------------------
2014-12-30 20:42:34.539 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   valid: true
2014-12-30 20:42:34.539 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   rmiName: jackrabbit.repository
2014-12-30 20:42:34.539 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   class: class org.apache.jackrabbit.j2ee.RMIConfig
2014-12-30 20:42:34.540 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   rmiUri: //localhost:1099/jackrabbit.repository
2014-12-30 20:42:34.540 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   rmiPort: 1099
2014-12-30 20:42:34.540 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   rmiEnabled: true
2014-12-30 20:42:34.540 INFO  [http-bio-8080-exec-7] AbstractConfig.java:106   rmiHost: localhost
2014-12-30 20:42:34.540 INFO  [http-bio-8080-exec-7] AbstractConfig.java:108 ----------------------------------------------
2014-12-30 20:42:34.810 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:258 Starting repository...
2014-12-30 20:42:34.816 INFO  [http-bio-8080-exec-7] LocalFileSystem.java:166 LocalFileSystem initialized at path D:\JournalDev\eclipse\jackrabbit\repository
2014-12-30 20:42:35.011 INFO  [http-bio-8080-exec-7] NodeTypeRegistry.java:841 no custom node type definitions found
2014-12-30 20:42:35.094 INFO  [http-bio-8080-exec-7] LocalFileSystem.java:166 LocalFileSystem initialized at path D:\JournalDev\eclipse\jackrabbit\version
2014-12-30 20:42:44.290 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:2034 initializing workspace 'default'...
2014-12-30 20:42:44.291 INFO  [http-bio-8080-exec-7] LocalFileSystem.java:166 LocalFileSystem initialized at path D:\JournalDev\eclipse\jackrabbit\workspaces\default
2014-12-30 20:42:52.648 INFO  [http-bio-8080-exec-7] ClusterNode.java:432 not started: namespace operation ignored.
2014-12-30 20:42:52.657 INFO  [http-bio-8080-exec-7] ClusterNode.java:432 not started: namespace operation ignored.
2014-12-30 20:42:52.663 INFO  [http-bio-8080-exec-7] ClusterNode.java:432 not started: namespace operation ignored.
2014-12-30 20:42:53.948 INFO  [http-bio-8080-exec-7] MultiIndex.java:1221 indexing... /jcr:system/jcr:nodeTypes/rep:Token/jcr:propertyDefinition (100)
2014-12-30 20:42:54.451 INFO  [http-bio-8080-exec-7] SearchIndex.java:602 Index initialized: D:\JournalDev\eclipse\jackrabbit/repository/index Version: 3
2014-12-30 20:42:54.537 INFO  [http-bio-8080-exec-7] SearchIndex.java:602 Index initialized: D:\JournalDev\eclipse\jackrabbit\workspaces\default/index Version: 3
2014-12-30 20:42:54.537 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:2038 workspace 'default' initialized
2014-12-30 20:42:54.544 INFO  [http-bio-8080-exec-7] ClusterNode.java:1064 not started: namespace operation ignored.
2014-12-30 20:42:54.545 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:546 created system workspace: security
2014-12-30 20:42:54.552 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:454 SecurityManager = class org.apache.jackrabbit.core.DefaultSecurityManager
2014-12-30 20:42:54.553 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:2034 initializing workspace 'security'...
2014-12-30 20:42:54.553 INFO  [http-bio-8080-exec-7] LocalFileSystem.java:166 LocalFileSystem initialized at path D:\JournalDev\eclipse\jackrabbit\workspaces\security
2014-12-30 20:43:02.458 INFO  [http-bio-8080-exec-7] SearchIndex.java:602 Index initialized: D:\JournalDev\eclipse\jackrabbit\workspaces\security/index Version: 3
2014-12-30 20:43:02.459 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:2038 workspace 'security' initialized
2014-12-30 20:43:02.470 INFO  [http-bio-8080-exec-7] DefaultSecurityManager.java:173 init: use Repository Login-Configuration for Jackrabbit
2014-12-30 20:43:02.512 INFO  [http-bio-8080-exec-7] UserManagerImpl.java:446 Admin user does not exist.
2014-12-30 20:43:02.793 INFO  [http-bio-8080-exec-7] ClusterNode.java:631 not started: update create ignored.
2014-12-30 20:43:02.803 INFO  [http-bio-8080-exec-7] ClusterNode.java:652 not started: update prepare ignored.
2014-12-30 20:43:02.840 INFO  [http-bio-8080-exec-7] ClusterNode.java:695 not started: update commit ignored.
2014-12-30 20:43:02.857 INFO  [http-bio-8080-exec-7] UserManagerImpl.java:1010 ... created admin user with id 'admin' and default pw.
2014-12-30 20:43:02.886 INFO  [http-bio-8080-exec-7] ClusterNode.java:631 not started: update create ignored.
2014-12-30 20:43:02.887 INFO  [http-bio-8080-exec-7] ClusterNode.java:652 not started: update prepare ignored.
2014-12-30 20:43:02.915 INFO  [http-bio-8080-exec-7] ClusterNode.java:695 not started: update commit ignored.
2014-12-30 20:43:02.918 INFO  [http-bio-8080-exec-7] DefaultSecurityManager.java:627 ... created anonymous user with id 'anonymous' ...
2014-12-30 20:43:02.967 INFO  [http-bio-8080-exec-7] RepositoryImpl.java:366 Repository started (28157ms)
2014-12-30 20:43:03.230 INFO  [http-bio-8080-exec-7] RepositoryStartupServlet.java:597 Repository bound via RMI with name: //localhost:1099/jackrabbit.repository
2014-12-30 20:43:03.234 INFO  [http-bio-8080-exec-7] RepositoryStartupServlet.java:487 Repository bound to JNDI with name: jackrabbit.repository
2014-12-30 20:43:03.234 INFO  [http-bio-8080-exec-7] RepositoryStartupServlet.java:260 RepositoryStartupServlet initialized.
  • Populate random content from Google by clicking on Populate link that’s located underneath Default Workspace at the left pane, accept all options, press on Populate ! and waiting till the process of content gathering get finished.

    通过单击左侧窗格“ 默认工作区”下方“ Populate链接Populate Google的随机内容,接受所有选项,然后按“ 填充”! 并等到内容收集过程完成。

Don’t miss the step that’s fixing the populate.jsp mentioned later. Even you may use the latest version of Jackrabbit 2.8.0 but actually this is also contained a known bug in populate page that prevents you from populating contents.

不要错过修复稍后提到的populate.jsp的步骤。 即使您可能使用的是最新版本的Jackrabbit 2.8.0,但实际上,它也包含在填充页面中的一个已知错误,该错误阻止您填充内容。

  • To ensure that you’re really populating contents into your repository, just access the following link https://localhost:8080/jackrabbit-webapp-2.8.0/repository/default/. This link is also known as WebDAV client. You may be asked for username and password while any may be fair enough. WebDAV is one of the ways that can be used for accessing the content of Repository. Later on different ways might be taken in the consideration.

    为确保您确实将内容填充到存储库中,只需访问以下链接https://localhost:8080/jackrabbit-webapp-2.8.0/repository/default/ 。 此链接也称为WebDAV客户端。 可能会要求您提供用户名和密码,而其中的任何一个都足够公平。 WebDAV是可用于访问存储库内容的方式之一。 以后可以考虑采用不同的方式。
  • Follow above links to access your content into your repository just like you see in the image below. URL marked yellow has linked to PDF document.

    按照上面的链接访问您的内容到存储库中,就像您在下图中看到的那样。 标记为黄色的URL已链接到PDF文档。

JCR / JSR 170和283入门 (Getting Started Using of JCR/JSR 170 & 283)

It’s not fit to start discussing JCR/JSR 170 without mentioning the main concept of Content Repository. First of all let’s define Repository Model, a Content Repositories consists of one or more Workspaces, each of which contains a tree of items.

不提内容存储库的主要概念就不适合开始讨论JCR / JSR 170。 首先,让我们定义存储库模型,一个内容存储库由一个或多个工作区组成 ,每个工作区都包含一棵项目树。

Basically, every item in the tree is either a node or a property, each node may have zero or more child nodes and zero or more child properties. There is a single root node per workspace, which has no parent. All other nodes have one parent. Properties have one parent and cannot have children; they are actually leaves of the tree.

基本上,树中的每个项目都是节点或属性,每个节点可能具有零个或多个子节点以及零个或多个子属性。 每个工作区只有一个根节点,没有父节点。 所有其他节点都有一个父节点。 财产有一个父母,不能有孩子。 它们实际上是树的叶子。

Below figure depict you how the repository would look like:

下图描述了存储库的外观:

Alfresco - Content Repository Model

Here’s detailed explanation for the figure mentioned above:


以下是上述图形的详细说明:

  • For every Workspace, there’s only one root node.

    对于每个工作区,只有一个根节点。
  • Per every root node, there’s a lot of nodes as a children.

    每个根节点都有许多作为子节点的节点。
  • Per every node, there’s a nodes or properties.

    每个节点都有一个节点或属性。
  • Nodes may or may not have a child while properties shouldn’t ever have children.

    节点可能有也可能没有孩子,而属性则永远不会有孩子。

Now, let’s see the API basics for the JCR/JSR 170 and how can we leverage it connecting Jackrabbit content repository. Here’s below main highlights about JCR / JSR 170/283 API:

现在,让我们看看JCR / JSR 170的API基础知识,以及如何利用它来连接Jackrabbit内容存储库。 以下是有关JCR / JSR 170/283 API的主要要点:

  • The javax.jcr.Repository class represents the reference of the whole Repository that you may connect. Actually this is the entry point for the Repository.

    javax.jcr.Repository类表示您可以连接的整个存储库的引用。 实际上,这是存储库的入口点。
  • Calling of getRootNode() against your Repository instance will return back to you the Root node for default workspace.

    针对您的Repository实例调用getRootNode()将返回给您默认工作空间的Root节点。
  • You may get all properties for a node through using of node.getProperties().

    您可以通过使用node.getProperties()获得节点的所有属性。
  • You may get all node’s children by calling of node.getNodes().

    您可以通过调用node.getNodes()获得所有节点的子节点。
  • You may get specific property for a specific node just like get binary data for which the node is created.

    您可以获取特定节点的特定属性,就像获取为其创建节点的二进制数据一样。

Actually, there are a lot of things you may take care of when it comes to discuss Content Repository concept. Data management, Query facility, Transactions and much more might be subjects for next coming tutorials that absolutely will provide you something comprehensive rather focusing on the integration that happened here.

实际上,在讨论内容存储库概念时,您需要处理很多事情。 数据管理,查询工具,事务以及更多内容可能是下一本教程的主题,这些教程绝对可以为您提供全面的知识,而专注于此处发生的集成。

访问存储库–本地访问/ JNDI (Accessing Repository – Local Access / JNDI)

Even though Jackrabbit has defined its Repository through Dummy JNDI directory local to the jackrabbit-webapp-2.8.0 but actually this resource isn’t Global JNDI resource since you can’t define a ResourceLink inside your Web Application to get accessed this defined Repository instance.

即使Jackrabbit已通过jackrabbit-webapp-2.8.0本地的Dummy JNDI目录定义了其存储库,但实际上该资源不是Global JNDI资源,因为您无法在Web应用程序中定义ResourceLink来访问此已定义的Repository实例。

Actually you may refer to good article had written by Pankaj for getting JNDI resources defined and to know what the difference between local resources and global resources as the process of defining Jackrabbit Repository Global resource may require you knowing a lot of information relevant for this field.

实际上,您可能会参考Pankaj撰写的出色文章,以定义JNDI资源并了解本地资源和全局资源之间的区别,因为定义Jackrabbit Repository Global资源的过程可能需要您了解很多与该领域相关的信息。

Following below steps required for defining Jackrabbit Repository and get it accessed after then through a simple Servlet:

遵循以下定义Jackrabbit存储库所需的步骤,然后通过一个简单的Servlet对其进行访问:

  • Make sure you’re able of seeing the Repository contents through WebDAV as stated earlier. Through accessing https://localhost:8080/jackrabbit-webapp-2.8.0/repository/default/ URL will retrieve all contents by calling local defined JNDI and by that you will be make sure that you have installed your Repository correctly.

    确保您能够通过WebDAV看到仓库信息,如前所述。 通过访问https://localhost:8080/jackrabbit-webapp-2.8.0/repository/default/ URL将通过调用本地定义的JNDI来检索所有内容,并确保已正确安装了存储库。
  • Shut down your Server (Apache Tomcat 7) and make sure you’re removed deployed Jackrabbit-webapp-2.8.0 either that exploded folder or WAR copy to prevent this Jackrabbit Web application from locking the Repository.

    关闭服务器(Apache Tomcat 7),并确保已删除已展开的Jackrabbit-webapp-2.8.0文件夹或WAR副本,以防止该Jackrabbit Web应用程序锁定存储库。
  • Open your server.xml file that is located beneath of conf folder that exist under your Apache Server home.

    打开位于Apache Server主目录下conf文件夹下的server.xml文件。
  • Add your Repository Global Repository Resource into your GlobalNamingResources to be look like below:

    将您的存储库全局存储库资源添加到GlobalNamingResources ,如下所示:

server.xml

server.xml

<GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>

	<Resource configFilePath="D:\JournalDev\eclipse\jackrabbit\repository.xml"
			  factory="org.apache.jackrabbit.core.jndi.BindableRepositoryFactory"
			  name="jackrabbit.repository" repHomeDir="D:\JournalDev\eclipse\jackrabbit"
			  type="javax.jcr.Repository"
			  auth="Container" />
  </GlobalNamingResources>
  • Copy all JARs from Jackrabbit-webapp-2.8.0\WEB-INF\lib into Tomact’s library folder D:\Apache Api\apache-tomcat-7.0.35\lib. This exactly will make creation of Repository JNDI global resource possible.

    将所有JAR从Jackrabbit-webapp-2.8.0 \ WEB-INF \ lib复制到Tomact的库文件夹D:\Apache Api\apache-tomcat-7.0.35\lib 。 这恰好使创建存储库JNDI全局资源成为可能。
  • Create Maven web application.

    创建Maven Web应用程序
  • Create simple Servlet to acquire JCR Repository instance by using JNDI like below:

    使用如下所示的JNDI创建简单的Servlet来获取JCR Repository实例:

LocalAccess.java

LocalAccess.java

package com.journaldev.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Properties;

import javax.jcr.LoginException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.users.MemoryUserDatabase;

/**
 * Servlet implementation class LocalAccess
 */
public class LocalAccess extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor.
     */
    public LocalAccess() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {

			// Acquire initial context
			InitialContext context = new InitialContext();

			// Print out context reference
			System.out.println(context);

			// Access environment context
			Context envCtx = (Context)context.lookup("java:comp/env");

			// Lookup JNDI local resource
			MemoryUserDatabase memoryDB = (MemoryUserDatabase)
					  envCtx.lookup("jdbc/MyDB");

			// Print out the memoryUserDatabase reference
			System.out.println(memoryDB);

			// Lookup Global JNDI for JCR Repository
			Repository repository = (Repository) envCtx.lookup("jackrabbit.repository");

			// Print out reference variable
			System.out.println(repository);

			// Get Repository session by loggin into
			Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

			response.getWriter().print("You're logged in successfully ::");
			// Print out the root node
			System.out.println(session.getRootNode());

			response.getWriter().print("Repository Acquired :: Root Node Identifier Is :: "+session.getRootNode().getIdentifier()+" & Its Path Is :: "+session.getRootNode().getPath());

		} catch (NamingException e) {
			e.printStackTrace();
		} catch (LoginException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RepositoryException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
  • You may define as many resources as you wish inside your web.xml, but you may not be able of defining some of them due to resources creation limitation and requirements. For this purpose, Tomcat has defined the context.xml file that should be defined under webapp/META-INF/context.xml to take its effect. Following below the context file of LocalAccess application.

    您可以在web.xml中定义任意数量的资源,但是由于资源创建的限制和要求,您可能无法定义其中的一些资源。 为此,Tomcat定义了context.xml文件,该文件应该 webapp/META-INF/context.xml 定义才能生效。 以下是LocalAccess应用程序的上下文文件。

context.xml

context.xml

<Context path="/LocalAccess" docBase="${catalina.home}/webapps/LocalAccess" crossContext="true"
			privileged="true" antiResourceLocking="false" antiJARLocking="false">
	<GlobalNamingResources>
		<Resource name="jdbc/MyDB" auth="Container"
		            type="org.apache.catalina.UserDatabase"
		     			description="Memory Database"
		     			factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
	</GlobalNamingResources>
	<ResourceLink name="jdbc/MyDB"
            global="jdbc/MyDB"
            	type="org.apache.catalina.UserDatabase"
            		description="Memory Database"
		     			factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
	<ResourceLink name="jackrabbit.repository"
            global="jackrabbit.repository"
		        auth="Container"
		        	type="javax.jcr.Repository"/>
</Context>

For now, you made a lot of steps and most of them need to be clarified for you. Here’s detailed explanation for codes listed above:

目前,您已经采取了很多步骤,其中大多数步骤都需要为您澄清。 以下是上面列出的代码的详细说明:

  • By referring for Pankaj tutorial, you may able of knowing to which these resources mentioned are referred. We have one two global resources defined in server.xml and three resources defined locally (In context.xml which relevant for LocalAccess).

    通过参考Pankaj教程,您可能能够知道所提到的这些资源。 我们在server.xml定义了两个全局资源,在本地定义了三个资源(在context.xml中与LocalAccess相关)。
  • You may not be able of accessing the Repository global JNDI resource that had defined in server.xml if you’re not provided the resource link for it inside your localAccess’s context file.

    如果没有在localAccess的上下文文件中提供它的资源链接,则可能无法访问server.xml定义的存储库全局JNDI资源。
  • According for Apache Tomcat, it’s not recommended to use server.xml to define your contexts and/or global resources as this file isn’t got reflected but when the Tomcat server has restarted.

    对于Apache Tomcat,不建议使用server.xml来定义上下文和/或全局资源,因为该文件不会得到反映,而是在Tomcat服务器重新启动时得到反映。
  • It’s so elegant for you to use local context files for much cases faced.

    您可以在很多情况下使用本地上下文文件,这非常优雅。
  • As exceptional case, you may not be able of seeing your Repository initialized in case you defined it locally as such you see its global definition above within server.xml.

    在特殊情况下,如果您在本地定义存储库,则可能看不到初始化的存储库,因此您可以在server.xml看到其全局定义。
  • Apache Tomcat provides a JNDI InitialContext implementation instance for each Web Application/Context running under it. As such you may use InitialContext ctx = new InitialContext() safely.

    Apache Tomcat为在其下运行的每个Web应用程序/上下文提供了一个JNDI InitialContext实现实例。 这样,您可以安全地使用InitialContext ctx = new InitialContext()
  • You may notice that we’ve used the Jackrabbit-webapp.2.8.0 to initialize Jackrabbit Repository and after that we omitted it. If you’re defining your Global JNDI resource while still Jackrabbit-webapp.2.8.0 is still defined under Tomcat’s webapps your Jackrabbit-webapp.2.8.0 will be failed as the Global JNDI resource has already locked the Repository.

    您可能会注意到,我们已经使用Jackrabbit-webapp.2.8.0来初始化Jackrabbit存储库,然后我们省略了它。 如果在Tomcat的Jackrabbit-webapp.2.8.0程序下仍定义Jackrabbit-webapp.2.8.0同时定义Global JNDI资源,则由于Global JNDI资源已经锁定了存储库,因此Jackrabbit-webapp.2.8.0将会失败。

Now, look at the expected result right below here:

现在,在下面查看预期的结果:

Acquiring Repository JNDI And Logged Into Successfully
Find here  Acquiring Jackrabbit Repository By JNDI Example.

在此处找到通过JNDI示例获取Jackrabbit存储库

访问存储库–本地访问/ Servlet上下文 (Accessing Repository – Local Access / Servlet Context)

This type of accessing Jackrabbit Repository is so easy in compare of previous JNDI resource. Here, all what you need is just to configure your context to support cross context and hence you become able of accessing Jackrabbit Repository by acquiring it from Jackrabbit-webapp-2.8.0 context attributes.

与以前的JNDI资源相比,这种访问Jackrabbit存储库的类型非常容易。 在这里,您只需要配置上下文即可支持跨上下文,因此您可以通过从Jackrabbit-webapp-2.8.0上下文属性获取它来访问Jackrabbit存储库。

If you were print out all defined attributes inside Jackrabbit-webapp-2.8.0 you will see the following result:

如果已打印出Jackrabbit-webapp-2.8.0内部的所有已定义属性,则将看到以下结果:

LocalAccess-Context Attributes

LocalAccess-Context Attributes

javax.jcr.Repository
jackrabbit.webdav.jcr.resourcepath
org.apache.tomcat.InstanceManager
org.apache.catalina.jsp_classpath
repository.access.servlet
jackrabbit.webdav.simple.resourcepath
org.apache.tomcat.util.scan.MergedWebXml
javax.servlet.context.tempdir
org.apache.catalina.resources
org.apache.tomcat.JarScanner
org.apache.jasper.compiler.TldLocationsCache
repository.startup.servet

According for previous result, there’s an attribute named javax.jrc.Repository that bounded into real Jackrabbit Repository instance. To use this methodology you may follow below steps:

根据先前的结果,有一个名为javax.jrc.Repository的属性已绑定到实际的Jackrabbit Repository实例中。 要使用此方法,您可以按照以下步骤操作:

  • Create New Maven Web Application. We assumed that you create LocalAccess-Context.

    创建新的Maven Web应用程序。 我们假定您创建了LocalAccess-Context。
  • Create LocalAccess Servlet like below and use the ServletContext to access Repository instance that’s defined in Jackrabbit-webapp-2.8.0.

    如下所示创建LocalAccess Servlet并使用ServletContext访问Jackrabbit-webapp-2.8.0中定义的Repository实例。

LocalAccess.java

LocalAccess.java

package com.journaldev.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Properties;

import javax.jcr.LoginException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.users.MemoryUserDatabase;

/**
 * Servlet implementation class LocalAccess
 */
public class LocalAccess extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor.
     */
    public LocalAccess() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			// Acquire ServletContext
			ServletContext context = this.getServletContext();

			// Asking ServletContext get you Jackrabbit context
			ServletContext jackrabbitCtx = context.getContext("/jackrabbit-webapp-2.8.0");

			// Get all attributes
			Enumeration<String> enums = jackrabbitCtx.getAttributeNames();

			for(;enums.hasMoreElements();){
				System.out.println(enums.nextElement());
			}

			Repository repository = (Repository)jackrabbitCtx.getAttribute(Repository.class.getName());

			// Print out reference variable
			System.out.println(repository);

			// Get Repository session by loggin into
			Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

			response.getWriter().print("You're logged in successfully ::");
			// Print out the root node
			System.out.println(session.getRootNode());

			response.getWriter().print("Repository Acquired :: Root Node Identifier Is :: "+session.getRootNode().getIdentifier()+" & Its Path Is :: "+session.getRootNode().getPath());
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

}

Here’s below detailed explanation for the code listed above:

以下是上面列出的代码的详细说明:

  • We’ve assumed that you were provided context.xml file with attribute crossContext="true". If you weren’t provided it you’ll likely get an exception of cause NullPointerException since there’s no instance is returned from context.getContext("/jackrabbit-webapp-2.8.0").

    我们假定为您提供了属性为crossContext="true" context.xml文件。 如果未提供该消息,则很可能会导致原因NullPointerException异常,因为context.getContext("/jackrabbit-webapp-2.8.0")没有返回任何实例。
  • Jackrabbit-webapp-2.8.0 has defined Jackrabbit Repository reference as attribute.

    Jackrabbit-webapp-2.8.0已将Jackrabbit存储库引用定义为属性。
  • Make sure you have Jackrabbit-webapp-2.8.0 up & running.

    确保已启动并正在运行Jackrabbit-webapp-2.8.0。

Acquiring Repository Context Attribute And Logged Into Successfully
Find here  Acquiring Jackrabbit Repository By Context Attribute Example.

在此处找到通过上下文属性示例获取Jackrabbit存储库

访问存储库–本地访问/ JCR-Servlet (Accessing Repository – Local Access / JCR-Servlet)

This way of Repository access isn’t variant from this old one that uses the Jackrabbit-webapp-2.8.0 context. The difference here is that you’re now using a new Maven library provided by Jackrabbit to create a Repository from any HttpServlet that has javax.jcr.Repositoryinstance inside its context.

这种存储库访问方式与使用Jackrabbit-webapp-2.8.0上下文的旧版本无异。 此处的区别在于,您现在使用的是Jackrabbit提供的新Maven库,可以从其上下文中具有javax.jcr.Repository实例的任何HttpServlet创建存储库。

To use this methodology, following below steps for that:

要使用此方法,请执行以下步骤:

  • Create Maven Web Application.

    创建Maven Web应用程序。
  • Create a Servlet inside your Application and make it seems like below:

    在您的应用程序内部创建一个Servlet,使其看起来如下所示:

LocalAccess.java

LocalAccess.java

package com.journaldev.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Properties;

import javax.jcr.LoginException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.users.MemoryUserDatabase;
import org.apache.jackrabbit.servlet.ServletRepository;

/**
 * Servlet implementation class LocalAccess
 */
public class LocalAccess extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor.
     */
    public LocalAccess() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {

			// Acquire ServletContext
			ServletContext context = this.getServletContext();

			// Asking ServletContext get you Jackrabbit context
			ServletContext jackrabbitCtx = context.getContext("/jackrabbit-webapp-2.8.0");

			// Create Repository through using of ServletRepository
			Repository repository = new ServletRepository((HttpServlet)jackrabbitCtx.getAttribute("repository.access.servlet"));

			// Print out reference variable
			System.out.println(repository);

			// Get Repository session by loggin into
			Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

			response.getWriter().print("You're logged in successfully ::");
			// Print out the root node
			System.out.println(session.getRootNode());

			response.getWriter().print("Repository Acquired :: Root Node Identifier Is :: "+session.getRootNode().getIdentifier()+" & Its Path Is :: "+session.getRootNode().getPath());
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

}

Here’s below detailed explanation for the code listed above:

以下是上面列出的代码的详细说明:

  • We added jackrabbit-jcr-servlet Maven library into you project dependencies.

    我们向您的项目依赖项中添加了jackrabbit-jcr-servlet Maven库。
  • We’ve acquired Jackrabbit Servlet context just like we did in previously.

    就像之前一样,我们已经获得了Jackrabbit Servlet上下文。
  • We’ve get HttpServlet reference for repository.access.servlet that’s defined within Jackrabbit context.

    我们已经获得了在Jackrabbit上下文中定义的repository.access.servlet的HttpServlet参考。
  • Pass Jackrabbit acquired Servlet into ServletRepository and the later will be able of recognizing the Repository within passed Servlet and it will return for you an instance of Repository.

    将Jackrabbit获得的Servlet传递到ServletRepository中,稍后后者将能够识别所传递的Servlet中的Repository,它将为您返回一个Repository实例。
  • Make sure you have Jackrabbit-webapp-2.8.0 up & running.

    确保已启动并正在运行Jackrabbit-webapp-2.8.0。

Find here Acquiring Jackrabbit Repository By JCR Servlet Example.

在此处找到通过JCR Servlet示例获取Jackrabbit存储库

访问存储库–远程访问/ RMI (Accessing Repository – Remote Access / RMI)

All of previous methodologies were served being Jackrabbit Repository has deployed on the same machine just like your consumer applications. But what if you want to access your Repository from totally different Virtual Machine.

Jackrabbit Repository已像您的消费者应用程序一样部署在同一台计算机上,从而满足了所有以前的方法。 但是,如果要从完全不同的虚拟机访问存储库,该怎么办。

The solution is to use RMI registry either through using it directly or by referencing it through HTTP protocol. Following below steps required for doing that:

解决方案是通过直接使用RMI注册表或通过HTTP协议引用它来使用RMI注册表。 请按照以下步骤进行操作:

  • Create Maven Web Application.

    创建Maven Web应用程序。
  • Add jackrabbit-jcr-rmi dependency into your Pom file.

    jackrabbit-jcr-rmi依赖项添加到您的Pom文件中。
  • Create Simple Servlet the looks like below:

    创建简单的Servlet的外观如下所示:

RemoteAccess.java

RemoteAccess.java

package com.journaldev.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.users.MemoryUserDatabase;
import org.apache.jackrabbit.rmi.repository.RMIRemoteRepository;
import org.apache.jackrabbit.rmi.repository.URLRemoteRepository;

/**
 * Servlet implementation class LocalAccess
 */
public class RemoteAccess extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor.
     */
    public RemoteAccess() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			// Acquiring Repository using RMI Registry
			Repository repository =
				    new RMIRemoteRepository("//localhost/jackrabbit.repository");

			response.getWriter().print("Repository Is Acquired By Using RMI Registry :: "+repository +"\n");
			// Acquiring Repository using direct HTTP
			Repository repo =
				    new URLRemoteRepository("https://localhost:8080/jackrabbit-webapp-2.8.0/rmi");

			response.getWriter().print("Repository Is Acquired By Using HTTP RMI Registry :: "+repo +"\n");

			// Get Repository session by loggin into
			Session rmiSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

			response.getWriter().print("You're logged in successfully Using RMI :: \n");
			// Print out the root node
			System.out.println(rmiSession.getRootNode());

			response.getWriter().print("Repository Acquired :: Root Node Identifier Is :: "+rmiSession.getRootNode().getIdentifier()+" & Its Path Is :: "+rmiSession.getRootNode().getPath()+"\n");

			// Get Repository session by loggin into
			Session httpRmiSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

			response.getWriter().print("You're logged in successfully Using HTTP RMI :: \n");
			// Print out the root node
			System.out.println(httpRmiSession.getRootNode());

			response.getWriter().print("Repository Acquired :: Root Node Identifier Is :: "+httpRmiSession.getRootNode().getIdentifier()+" & Its Path Is :: "+httpRmiSession.getRootNode().getPath()+"\n");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
  • Access Jackrabbit Repository through using of RMI registry. This can be happened by direct access for RMI or by accessing it through HTTP protocol. Both cases will make sure that you’re getting the Jackrabbit repository stub.

    通过使用RMI注册表访问Jackrabbit存储库。 可以通过直接访问RMI或通过HTTP协议访问它来实现。 两种情况都将确保您获得了Jackrabbit存储库存根。
  • Make sure you have Jackrabbit-webapp-2.8.0 up & running.

    确保已启动并正在运行Jackrabbit-webapp-2.8.0。

Find here Repository Access Though Using of RMI Example.

通过RMI示例在此处找到存储库访问

Apache Pluto和Jackrabbit集成 (Apache Pluto & Jackrabbit Integration)

Regardless of the way in which you access the Jackrabbit repository and regardless of type operations that you need for which such that integration, here’s a simple Portlet that has ability to communicate with Apache Jackrabbit Content Repository through using of JCR / JSR 170/283 standard library.

不管您访问Jackrabbit存储库的方式如何,无论您需要进行哪种类型的操作以进行集成,这都是一个简单的Portlet,它能够通过使用JCR / JSR 170/283标准库与Apache Jackrabbit Content Repository通信。

Following below steps all what you need to get this achieved:

请按照以下步骤操作,以实现此目标所需的一切:

  • Make sure that you’re so familiar with Apache Pluto Portal, Create Portlet, Create Portal Page and deploy the Portlet into your Portal Page and etc. This can be found onto Apache Pluto Introduction Tutorial.

    确保您熟悉Apache Pluto门户,创建Portlet,创建门户页面并将Portlet部署到门户页面等,这些内容可以在Apache Pluto入门教程中找到
  • I’ll use RMI to get this Achieved as already Jackrabbit-webapp-2.8.0 has already deployed on Apache 7 while Apache Pluto Portal will be deployed on different Apache Tomcat instance.

    我将使用RMI来实现此目标,因为Jackrabbit-webapp-2.8.0已经部署在Apache 7上,而Apache Pluto Portal将部署在不同的Apache Tomcat实例上。
  • Import your Apache Pluto Into your Eclipse just like you did in the introduction tutorial. One major modification that you need to do now is modifying server Ports to be look like below:

    就像在入门教程中一样,将Apache Pluto导入到Eclipse中。 您现在需要做的一项主要修改是修改服务器端口,如下所示:
  • Modify tomcat-users.xml to make sure tomcat user has authenticated and authorized properly. Your file should look like what already configured in the introduction.

    修改tomcat-users.xml ,以确保tomcat用户已正确认证和授权。 您的文件应类似于简介中已配置的文件。
  • Run your Apache Pluto from your Eclipse and access the new Ports, it should work willingly.

    从Eclipse运行Apache Pluto,并访问新的Ports,它应该可以正常工作。
  • Create Maven Web Application called JCR-Integration and add all Apache Pluto accompanies files like portlet.xml and those important Pom.xml entries. This is already covered in the introduction as you may refer it from here.

    创建名为JCR-Integration的Maven Web应用程序,并添加所有Apache Pluto随附的文件,例如portlet.xml和那些重要的Pom.xml条目。 简介中已经对此进行了介绍,您可以从此处进行引用。
  • Add both of JCR standard API & RMI dependencies into your Pom.xml file. Look file below:

    将JCR标准API和RMI依赖项都添加到Pom.xml文件中。 在下面查看文件:

pom.xml

pom.xml

<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.journaldev</groupId>
	<artifactId>JCR-Integration</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>JCR-Integration</name>
	<url>https://maven.apache.org</url>
	<properties>
		<deployFolder>D:/ApachePluto/pluto-2.0.3/webapps</deployFolder>
	</properties>
	<dependencies>
		<!-- Java Portlet Specification V2.0 -->
		<dependency>
			<groupId>org.apache.portals</groupId>
			<artifactId>portlet-api_2.0_spec</artifactId>
			<version>1.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.4</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>commons-beanutils</groupId>
			<artifactId>commons-beanutils</artifactId>
			<version>1.7.0</version>
		</dependency>
		<dependency>
			<groupId>commons-collections</groupId>
			<artifactId>commons-collections</artifactId>
			<version>3.1</version>
		</dependency>
		<dependency>
			<groupId>commons-digester</groupId>
			<artifactId>commons-digester</artifactId>
			<version>1.7</version>
		</dependency>
		<dependency>
			<groupId>commons-digester</groupId>
			<artifactId>commons-digester</artifactId>
			<version>1.7</version>
		</dependency>
		<dependency>
			<groupId>org.apache.velocity</groupId>
			<artifactId>velocity</artifactId>
			<version>1.5</version>
		</dependency>
		<dependency>
			<groupId>org.apache.velocity</groupId>
			<artifactId>velocity-tools</artifactId>
			<version>2.0</version>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
		</dependency>
		<dependency>
			<groupId>org.apache.pluto</groupId>
			<artifactId>pluto-taglib</artifactId>
			<version>1.1.7</version>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.32</version>
		</dependency>
		<dependency>
			<groupId>org.apache.portals.bridges</groupId>
			<artifactId>portals-bridges-perl</artifactId>
			<version>1.0.4</version>
			<exclusions>
				<exclusion>
					<groupId>org.apache.portals.jetspeed-2:</groupId>
					<artifactId>jetspeed-rewriter</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.apache.portals.jetspeed-2</groupId>
			<artifactId>jetspeed-rewriter</artifactId>
			<version>2.1.4</version>
			<exclusions>
				<exclusion>
					<groupId>castor</groupId>
					<artifactId>castor</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>castor</groupId>
			<artifactId>castor</artifactId>
			<version>1.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.portals.bridges</groupId>
			<artifactId>portals-bridges-common</artifactId>
			<version>2.0</version>
		</dependency>
		<dependency>
			<groupId>javax.jcr</groupId>
			<artifactId>jcr</artifactId>
			<version>2.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.jackrabbit</groupId>
			<artifactId>jackrabbit-jcr-rmi</artifactId>
			<version>2.8.0</version>
		</dependency>
	</dependencies>
	<build>
		<finalName>${project.artifactId}</finalName>
		<plugins>
			<!-- bind 'pluto2:assemble' goal to 'process-resources' lifecycle -->
			<!-- This plugin will read your portlet.xml and web.xml and injects required
				lines -->
			<plugin>
				<groupId>org.apache.portals.pluto</groupId>
				<artifactId>maven-pluto-plugin</artifactId>
				<version>2.1.0-M3</version>
				<executions>
					<execution>
						<id>generate-sources</id>
						<phase>generate-sources</phase>
						<goals>
							<goal>assemble</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<!-- configure maven-war-plugin to use updated web.xml -->
			<!-- This plugin will make sure your WAR will contain the updated web.xml -->
			<plugin>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.1.1</version>
				<configuration>
					<webXml>${project.build.directory}/pluto-resources/web.xml</webXml>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-antrun-plugin</artifactId>
				<executions>
					<execution>
						<id>copy</id>
						<phase>integration-test</phase>
						<configuration>
							<tasks>
								<copy file="target/${project.artifactId}.war" tofile="${deployFolder}/${project.artifactId}.war" />
							</tasks>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>
					<execution>
						<id>delete</id>
						<phase>clean</phase>
						<configuration>
							<tasks>
								<delete file="${deployFolder}/${project.artifactId}.war" />
								<delete dir="${deployFolder}/${project.artifactId}" />
							</tasks>
							<detail>true</detail>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

Also, you may find below a ready-made Portlet that aimed to Traverse All Universe within your Repository and expose all binary documents inside supposed directory beneath C:/files.

另外,您可能会在下面找到一个现成的Portlet,该Portlet旨在遍历您的存储库中的所有宇宙并在C:/files下的假定目录下公开所有二进制C:/files

JCRIntegrator.java

JCRIntegrator.java

package com.journaldev.portlet;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Value;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.apache.jackrabbit.rmi.repository.URLRemoteRepository;

public class JCRIntegrator extends GenericPortlet{
	private Repository repository = null;
	private Session session = null;

	{
		try {
			// Acquiring Repository using RMI Registry
			this.repository =
				    new URLRemoteRepository("https://localhost:8080/jackrabbit-webapp-2.8.0/rmi");

			System.out.println("Repository Is Acquired By Using RMI Registry :: "+repository +"\n");

			// Get Repository session by log into
			this.session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

			System.out.println("You're logged in successfully Using RMI :: \n");
			// Print out the root node
			System.out.println(this.session.getRootNode());

			System.out.println("Repository Acquired :: Root Node Identifier Is :: "+this.session.getRootNode().getIdentifier()+
						" & Its Path Is :: "+this.session.getRootNode().getPath()+"\n");
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

	public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
		try {

			if(this.session.isLive()){
				// Get root node for the current workspace
				Node root = this.session.getRootNode();

				// Traverse node
				traverseNode(root);

				// Traverse has finished
				response.getWriter().println("Traverse whole repository has been finished :: Please review C:/files directory as it should contain all Binay documents ::");

				// Logout session
				this.session.logout();
			}
			else {
				// Login again
				this.session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
			}

		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

	// Recursive traverse node
	public void traverseNode(Node node){
		try {
				// Specify whether the node has child or not
				if(node.getNodes().getSize() != 0){
					// Get child iterator
					NodeIterator iterator =  node.getNodes();

					// Loop over child and traverse them one by one
					while(iterator.hasNext()){
						Node _node = (Node)iterator.next();
						traverseNode(_node);
					}
				}
				else {
					// Print out node information
					System.out.println("Node Name :: "+node.getName()+" :: Node Path :: "+node.getPath()+" :: Node Identifier :: "+node.getIdentifier());

					// Print out properties
					System.out.println("Node Properties :: ");

					PropertyIterator iterator =  node.getProperties();

					while(iterator.hasNext()){
						// Get property
						Property property = (Property)iterator.next();

						// Get specific property like jcr:data
						if(node.getProperty("jcr:data") != null){
							// Get binary stream
							InputStream content = node.getProperty("jcr:data").getBinary().getStream();

							// Create bytes array by number of available bytes
							byte [] bytes = new byte [content.available()];

							// Read contents
							content.read(bytes,0,content.available());

							// Create file, we've assumed that we will persist all binary data into C:/files
							File file = new File("c:/files/"+node.getIdentifier()+node.getPath().substring(node.getPath().indexOf("."),node.getPath().indexOf(".")+4));

							// Create file output stream
							FileOutputStream wf = new FileOutputStream(file);

							// Write binary
							wf.write(bytes);
							// Flush
							wf.flush();
							// Close
							wf.close();
						}
						// Specify whether the property has multiple values or not
						if(property.isMultiple()){
							// Print out the property information
							System.out.print("Property Name :: "+property.getName()+" :: Property Type :: "+property.getType() + " :: Property Value :: ");
							for(Value value : property.getValues()){
								System.out.print("Value :: "+value);
							}
							System.out.println("\n");
						}
						else {
							// Print out the property information
							System.out.println("Property Name :: "+property.getName()+" :: Property Type :: "+property.getType() + " :: Property Value :: "+property.getValue());
						}

					}
				}
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
	}

	public Repository getRepository() {
		return repository;
	}

	public void setRepository(Repository repository) {
		this.repository = repository;
	}

	public Session getSession() {
		return session;
	}

	public void setSession(Session session) {
		this.session = session;
	}

}

Here’s below detailed explanation for the code listed above:

以下是上面列出的代码的详细说明:

  • Before any use for our Repository, you should be able of opening a session.

    在用于我们的存储库之前,您应该可以打开一个会话。
  • This session may be closed by invoking a direct logout method.

    可以通过调用直接注销方法来关闭此会话。
  • To ensure that certain session is opened, just invoke isLive method.

    要确保打开某些会话,只需调用isLive方法。
  • You may not be able of opening the session once again, but you may have the ability to use Repository object to get new session opened.

    您可能无法再次打开该会话,但是您可以使用存储库对象来打开新的会话。
  • We’ve used Traverse recursive method that’s aimed to print out all information relevant for specific node in the Content Repository structure.

    我们已经使用了遍历递归方法,该方法旨在打印出与Content Repository结构中特定节点有关的所有信息。
  • The node has figured out its major attributes; name, path, identifier and many more can be invoked through direct method against node object.

    该节点已确定其主要属性。 名称,路径,标识符等可以通过针对节点对象的直接方法调用。
  • We’ve used RMI method for getting integrated with the JCR Repository system.

    我们已经使用RMI方法与JCR存储库系统集成。

By accessing the URL https://localhost:8181/pluto/portal/JournalDev you will be able of seeing the following results:

通过访问URL https://localhost:8181/pluto/portal/JournalDev您将能够看到以下结果:

Here’s below the success response for the Portlet as it inform you that the Traverse process has been finished successfully and you may see the all files located underneath mentioned directory.

这是Portlet成功响应的下方,因为它通知您Traverse流程已成功完成,并且您可能会看到位于上述目录下的所有文件。

Traverse Whole Repository Contents

Below, you may also find the console of the Eclipse as Traverse has printed out all information relevant of every traversed node.


在下面,您还可以找到Eclipse的控制台,因为Traverse已打印出与每个被遍历的节点相关的所有信息。

Traverse Whole Repository - Print out Node Information

Also, you may find below the  C:/filesdirectory that contains all binary data that are retained in the Jackrabbit Repository.


另外,您可能会在C:/files目录下找到该目录,其中包含保留在Jackrabbit存储库中的所有二进制数据。

Traverse Whole Repository - All Binaries

Also, find here  Apache Pluto JCR Integration Example.


另外,在这里找到Apache Pluto JCR集成示例

摘要 (Summary)

Content Repository API for Java is fundamental core library that integrated these days with most of systems being used. This tutorial is a full comprehensive reference that can help you integrating your Portal with any of Content Repository that you may use.

用于Java的Content Repository API是基本的核心库,如今已与大多数正在使用的系统集成在一起。 本教程是一本全面的参考资料,可以帮助您将Portal与您可以使用的任何内容存储库集成。

Jackrabbit content repository is used for such purpose and Apache Pluto is our Portal provider. Contribute us by commenting below and find above all sources that you may need for your practice.

Jackrabbit内容存储库用于此目的,Apache Pluto是我们的门户网站提供商。 通过在下面评论,为我们做出贡献,并首先找到您练习所需的所有资源。

翻译自: https://www.journaldev.com/5109/apache-pluto-jackrabbit-integration-example-tutorial

adalm pluto

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值