Merged CMIS063 to HEAD

17100: Chemistry: AtomPub TCK updates, Alfresco CMIS URL bindings, Delete Content Stream

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@17258 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2009-10-30 14:23:42 +00:00
parent ae1cbc22ab
commit be4912981e
80 changed files with 944 additions and 564 deletions

View File

@@ -0,0 +1,138 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.web.scripts.content;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.cmis.CMISObjectReference;
import org.alfresco.cmis.reference.ReferenceFactory;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.scripts.AbstractWebScript;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.web.scripts.WebScriptResponse;
/**
* Content Delete Service
*
* Delete content stream from the Repository.
*
* @author davidc
*/
public class ContentDelete extends AbstractWebScript
{
// Component dependencies
private ReferenceFactory referenceFactory;
private NamespaceService namespaceService;
private NodeService nodeService;
/**
* @param reference factory
*/
public void setReferenceFactory(ReferenceFactory referenceFactory)
{
this.referenceFactory = referenceFactory;
}
/**
* @param namespaceService
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @param nodeService
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @see org.alfresco.web.scripts.WebScript#execute(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
*/
public void execute(WebScriptRequest req, WebScriptResponse res)
throws IOException
{
// create map of args
String[] names = req.getParameterNames();
Map<String, String> args = new HashMap<String, String>(names.length, 1.0f);
for (String name : names)
{
args.put(name, req.getParameter(name));
}
// create map of template vars
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
// create object reference from url
CMISObjectReference reference = referenceFactory.createObjectReferenceFromUrl(args, templateVars);
NodeRef nodeRef = reference.getNodeRef();
if (nodeRef == null)
{
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + reference.toString());
}
// determine content property
QName propertyQName = ContentModel.PROP_CONTENT;
String contentPart = templateVars.get("property");
if (contentPart.length() > 0 && contentPart.charAt(0) == ';')
{
if (contentPart.length() < 2)
{
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Content property malformed");
}
String propertyName = contentPart.substring(1);
if (propertyName.length() > 0)
{
propertyQName = QName.createQName(propertyName, namespaceService);
}
}
// retrieve content property
ContentData contentData = (ContentData)nodeService.getProperty(nodeRef, propertyQName);
if (contentData != null)
{
contentData = new ContentData(null, null, 0, null);
nodeService.setProperty(nodeRef, propertyQName, contentData);
}
// no content returned
res.setStatus(204);
}
}

View File

@@ -25,13 +25,14 @@
package org.alfresco.repo.web.scripts.content;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.cmis.CMISObjectReference;
import org.alfresco.cmis.reference.ReferenceFactory;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.model.Repository;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
@@ -56,15 +57,15 @@ public class ContentGet extends StreamContent
private static final Log logger = LogFactory.getLog(ContentGet.class);
// Component dependencies
private Repository repository;
private ReferenceFactory referenceFactory;
private NamespaceService namespaceService;
/**
* @param repository
* @param reference factory
*/
public void setRepository(Repository repository)
public void setReferenceFactory(ReferenceFactory referenceFactory)
{
this.repository = repository;
this.referenceFactory = referenceFactory;
}
/**
@@ -80,20 +81,24 @@ public class ContentGet extends StreamContent
*/
public void execute(WebScriptRequest req, WebScriptResponse res)
throws IOException
{
// convert web script URL to node reference in Repository
String match = req.getServiceMatch().getPath();
String[] matchParts = match.split("/");
{
// create map of args
String[] names = req.getParameterNames();
Map<String, String> args = new HashMap<String, String>(names.length, 1.0f);
for (String name : names)
{
args.put(name, req.getParameter(name));
}
// create map of template vars
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String[] id = templateVars.get("id").split("/");
String[] path = new String[id.length + 2];
path[0] = templateVars.get("store_type");
path[1] = templateVars.get("store_id");
System.arraycopy(id, 0, path, 2, id.length);
NodeRef nodeRef = repository.findNodeRef(matchParts[2], path);
// create object reference from url
CMISObjectReference reference = referenceFactory.createObjectReferenceFromUrl(args, templateVars);
NodeRef nodeRef = reference.getNodeRef();
if (nodeRef == null)
{
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + matchParts[2] + " reference " + Arrays.toString(path));
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + reference.toString());
}
// determine content property

View File

@@ -28,14 +28,16 @@ import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.cmis.CMISObjectReference;
import org.alfresco.cmis.reference.ObjectPathReference;
import org.alfresco.cmis.reference.ReferenceFactory;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.encoding.ContentCharsetFinder;
import org.alfresco.repo.model.Repository;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
@@ -68,18 +70,18 @@ public class ContentSet extends AbstractWebScript
private static final Log logger = LogFactory.getLog(ContentSet.class);
// Component dependencies
private Repository repository;
private ReferenceFactory referenceFactory;
private DictionaryService dictionaryService;
private NamespaceService namespaceService;
private ContentService contentService;
private MimetypeService mimetypeService;
/**
* @param repository
* @param reference factory
*/
public void setRepository(Repository repository)
public void setReferenceFactory(ReferenceFactory referenceFactory)
{
this.repository = repository;
this.referenceFactory = referenceFactory;
}
/**
@@ -119,20 +121,24 @@ public class ContentSet extends AbstractWebScript
*/
public void execute(WebScriptRequest req, WebScriptResponse res)
throws IOException
{
// convert web script URL to node reference in Repository
String match = req.getServiceMatch().getPath();
String[] matchParts = match.split("/");
{
// create map of args
String[] names = req.getParameterNames();
Map<String, String> args = new HashMap<String, String>(names.length, 1.0f);
for (String name : names)
{
args.put(name, req.getParameter(name));
}
// create map of template vars
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String[] id = templateVars.get("id").split("/");
String[] path = new String[id.length + 2];
path[0] = templateVars.get("store_type");
path[1] = templateVars.get("store_id");
System.arraycopy(id, 0, path, 2, id.length);
NodeRef nodeRef = repository.findNodeRef(matchParts[2], path);
// create object reference from url
CMISObjectReference reference = referenceFactory.createObjectReferenceFromUrl(args, templateVars);
NodeRef nodeRef = reference.getNodeRef();
if (nodeRef == null)
{
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + matchParts[2] + " reference " + Arrays.toString(path));
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + reference.toString());
}
// determine content property
@@ -153,7 +159,7 @@ public class ContentSet extends AbstractWebScript
PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
if (propertyDef == null)
{
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find " + matchParts[2] + " reference " + Arrays.toString(path) + " content property " + propertyQName);
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find content property " + propertyQName + " of " + reference.toString());
}
if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
{
@@ -180,9 +186,9 @@ public class ContentSet extends AbstractWebScript
String mimetype = req.getContentType();
if (mimetype == null)
{
if (matchParts[2].equals("path") || matchParts[2].equals("avmpath"))
if (reference instanceof ObjectPathReference)
{
mimetype = mimetypeService.guessMimetype(templateVars.get("id"));
mimetype = mimetypeService.guessMimetype(((ObjectPathReference)reference).getPath());
}
}
if (mimetype != null)