- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用路径从露天下载文档,但我的内容长度为空,并且可以在浏览器中下载图像,但没有显示任何内容。谁能指出我做错了什么。
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Folder;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
public class TestServlet extends HttpServlet {
private static final String ALFRSCO_ATOMPUB_URL = "http://localhost:8484/alfresco/cmisatom";
private static final String REPOSITORY_ID = "cf9aacff-a023-477f-a7e1-a8a901cf0b27";
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet TestServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
Map<String, String> parameter = new HashMap<String, String>();
// Set the user credentials
parameter.put(SessionParameter.USER, "admin");
parameter.put(SessionParameter.PASSWORD, "admin");
// Specify the connection settings
parameter.put(SessionParameter.ATOMPUB_URL, ALFRSCO_ATOMPUB_URL);
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
//Add repository Id
parameter.put(SessionParameter.REPOSITORY_ID, REPOSITORY_ID);
// Create a session
SessionFactory factory = SessionFactoryImpl.newInstance();
Session session = factory.getRepositories(parameter).get(0).createSession();
System.out.println("Connected to repository:" + session.getRepositoryInfo().getName());
Folder root = session.getRootFolder();
System.out.println("Repository Name: "+root.getName()+"id: "+session.getRepositoryInfo().getId());
// (minimal set: name and object type id)
String path1 = "/Hello/img.jpg";
Document doc = (Document) session.getObjectByPath(path1);
System.out.println(doc.getId()+" docname: "+doc.getName());// docId=workspace://SpacesStore/669bd07f-7a3d-471c-b6f3-bff6764f827e
// String fullPath= "/Hello" + "/imgss.png";
Document doc1 = (Document)session.getObject(doc.getId());
// CmisObject obj=doc1;
Document newDocument = (Document) session.getObjectByPath(path1);
System.out.println(newDocument.getId());
//File file = new File(home+"/Downloads/" + fileName + ".txt");
response.setContentType("application/force-download");
//response.setContentLength(-1);
response.setContentType("application/octet-stream");
response.setHeader("Content-Transfer-Encoding", "binary");
response.setHeader("Content-Disposition","attachment; filename=img.jpg");//fileName);
try {
ContentStream cs = doc1.getContentStream(null);
System.out.println("buffered content: "+cs);
BufferedInputStream in =new BufferedInputStream(cs.getStream());
// FileOutputStream fos = new FileOutputStream(home);
// OutputStream bufferedOutputStream = new BufferedOutputStream(fos);
System.out.println("buffered outputstream: "+in);
DataInputStream din = new DataInputStream(in);
while(din.available() > 0){
out.print(din.readLine());
out.print("\n");
}
din.close();
in.close();
}
catch (IOException e)
{
throw new RuntimeException(e.getLocalizedMessage());
}
}
}
}
我在控制台中得到的输出:
Connected to repository:Main Repository
Repository Name: Company Homeid: 4cdc8cd1-ddf1-4e30-95f8-4a2219073580
workspace://SpacesStore/2284cd59-8480-40fa-baed-05d54ddfc561;1.0 docname: imgss.png
workspace://SpacesStore/2284cd59-8480-40fa-baed-05d54ddfc561;1.0
buffered content: ContentStream [filename=imgss.png, length=null, MIME type=image/png, has stream=true][extensions=null]
buffered outputstream: java.io.BufferedInputStream@173b5e2
露天图片:
我下载的图片是:
最佳答案
在露天,您可以使用以下方式下载文档
在我的解决方案中,您将使用
serverUrl : "http://127.0.0.1:8080/alfresco/api/-default-/public/cmis/versions/1.0/atom";
username : admin
password : admin
第一种方法:使用文档 ID
文档的ID是我们在Alfresco上传时Alfresco为该文档固定的ID
public static void downloadDocumentByID(String serverUrl, String username, String password ,String documentID,String fileName,String destinationFolder){
String fullPath= destinationFolder + fileName;
Document newDocument = (Document) getSession(serverUrl, username, password).getObject(documentID);
System.out.println(newDocument.getId());
try {
ContentStream cs = newDocument.getContentStream(null);
BufferedInputStream in =new BufferedInputStream(cs.getStream());
FileOutputStream fos = new FileOutputStream(fullPath);
OutputStream bufferedOutputStream = new BufferedOutputStream(fos);
byte[] buf = new byte[1024];
int n=0;
while ((n=in.read(buf))>0)
{
bufferedOutputStream.write(buf,0,n);
}
bufferedOutputStream.close();
fos.close();
in.close();
}
catch (IOException e)
{
throw new RuntimeException(e.getLocalizedMessage());
}
}
第二种方式:使用文档路径
在这个解决方案中,您必须获取文档的路径,有时很难获取它,这是我总是使用第一个的方式
public static void downloadDocumentByPath(String serverUrl, String username, String password ,String path,String destinationFolder){
String fileExtention = path.substring(path.lastIndexOf(".")+1,path.length());
String folderPath=path.substring(0,path.lastIndexOf("/"));
String fileName=path.substring(path.lastIndexOf("/")+1,path.length());
Folder parentFolder = getFolderByPath(serverUrl, username, password,folderPath);
Document newDocument = getChild(serverUrl, username, password , parentFolder ,fileName);
String fullPath = destinationFolder+fileName;
try {
ContentStream cs = newDocument.getContentStream(null);
BufferedInputStream in =new BufferedInputStream(cs.getStream());
FileOutputStream fos = new FileOutputStream(destinationFolder);
System.out.println("****-**"+destinationFolder+":::");
OutputStream bufferedOutputStream = new BufferedOutputStream(fos);
byte[] buf = new byte[1024];
int n=0;
while ((n=in.read(buf))>0)
{
bufferedOutputStream.write(buf,0,n);
}
bufferedOutputStream.close();
fos.close();
in.close();
}
catch (IOException e)
{
throw new RuntimeException(e.getLocalizedMessage());
}
}
您可以在此处了解更多信息Download user selected file/upload a file to a user selected directory both with primefaces
此外,您可以使用 contentStram ,它看起来像这样
public InputStream downloadDocument(String serverURL, String nomUtilisateur, String passwordUtilisateur, String path, String nomFile) {
Document newDocument = (Document) getSession(serverURL, nomUtilisateur, passwordUtilisateur).getObject(path);
ContentStream cs = newDocument.getContentStream(null);
return cs.getStream();
}
然后简单地调用这个方法
public void downloaddoc(Document doc) throws FileNotFoundException, TransformerConfigurationException, TransformerException {
InputStream input = downloaddoc(serverUrl, username, password, doc.getPath(), doc.getNameFile);
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
setDownload(new DefaultStreamedContent(input, externalContext.getMimeType(doc.getNomRepertoire()), doc.getNomRepertoire()));
}
希望对您有帮助。
关于java - 使用 opencmis 从 alfresco 下载文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41418224/
我必须使用以下路径在露天创建文件夹: COMPANY_HOME/测试/年/月/日/文档 目前我可以创建一个像这样的文件夹: Map newFolderProps = new HashMap<>();
我正在使用 Apache Chemistry API 创建客户端 session 。 SessionFactory 允许创建 session 但不提供关闭 session 的方法。关闭创建的 sess
已结束。此问题正在寻求书籍、工具、软件库等的推荐。不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便用
在 Alfresco 中,我有以下结构/Company Home/A 和/Company Home/B 一些用户主文件夹设置为 A,其他设置为 B。 问题:我发现为了通过 OpenCMIS 从我的应用
我正在尝试创建一个脚本,使用 opencmis 库(python)将文档上传到 Alfresco 存储库中。上传实际文档没问题,但我正在绞尽脑汁思考如何向文档添加标签。 我的想法是: props =
我刚刚在 Apache OpenCMIS 上注意到了这个项目: https://svn.apache.org/repos/asf/chemistry/opencmis/trunk/chemistry-
我正在尝试通过 OpenCMIS 更新 alfresco 文件的内容类型。 CMIS 工作台在类型窗口中显示类型,只有禁用开关“策略可控”。它的本地名称是document,queryname是pref
我正在尝试使用 Apache Chemistry OpenCMIS 将文件上传到我的 Alfresco 存储库。文件已创建且属性正确但没有内容,文件为 0 字节。我已经仔细检查过,源文件没有任何问题。
我想获取所有具有 aspect A 或 aspect B 的文件。 这是我的查询: SELECT * FROM SELECT * FROM ` 我知道 opencmis 中不存在 UNION,那么有
我正在尝试按照 Apache 中的说明设置 OpenCMIS InMemory 存储库但在运行maven命令mvn clean install -Dmaven.test.skip=true时不断收到以
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我正在使用 chemistry opencmis 0.13.0 版连接到 alfresco 存储库。下面是代码片段 Map parameter = new HashMap(); //
我正在使用 Apache Chemistry OpenCMIS java 库。给定一个 QueryResult (例如,我通过搜索元数据属性找到了一个文档或一堆文档),这是检索 Document 对象
我正在尝试添加 OpenCmis客户端到 Web 应用程序,该应用程序已经有其他客户端使用 CXF。它将部署在Weblogic上。我有基于 http://chemistry.apache.org/ja
我想使用路径从露天下载文档,但我的内容长度为空,并且可以在浏览器中下载图像,但没有显示任何内容。谁能指出我做错了什么。 import java.io.BufferedInputStream;
我正在写 OpenCMIS基于应用程序,它从 Alfresco 3.3 中提取一些数据。 它适用于标准 CMIS 属性,例如 cmis:name或 cmis:contentStreamMimeType
我想知道如何使用 OpenCmis 在 Alfresco 中手动更改文档版本?截至目前,当我更新文档时,每次 alfresco 都会更改版本本身,但我想根据用户输入更改版本,如 1.0、2.0、2.1
本文整理了Java中org.apache.chemistry.opencmis.commons.impl.XMLUtils类的一些代码示例,展示了XMLUtils类的具体用法。这些代码示例主要来源于G
我使用 alfresco-community-4.0.e、OpenCMIS 和 primefaces 作为用户界面构建网络应用程序。 我需要以编程方式在 alfresco 中创建用户。我尝试使用以下代
我做了非常简单的查询 SELECT cmis:objectId, cmis:name, cmis:parentId FROM cmis:folder ORDER BY cmis:name 使用 apa
我是一名优秀的程序员,十分优秀!