mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Publishing: added authorisation framework for channel types. Migrated YouTube channel type onto it, and added Twitter and SlideShare channel types. Facebook is also added, but there is an issue with the way it authorises apps, so it isn't wired in yet.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28910 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.publishing.slideshare;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.publishing.AbstractChannelType;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.publishing.channels.Channel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
public class SlideShareChannelType extends AbstractChannelType
|
||||
{
|
||||
public final static String ID = "slideshare";
|
||||
private final static Set<String> DEFAULT_MIME_TYPES = new TreeSet<String>();
|
||||
|
||||
private NodeService nodeService;
|
||||
private ActionService actionService;
|
||||
private Set<String> permittedMimeTypes = Collections.unmodifiableSet(DEFAULT_MIME_TYPES);
|
||||
|
||||
static
|
||||
{
|
||||
DEFAULT_MIME_TYPES.add(MimetypeMap.MIMETYPE_PPT);
|
||||
DEFAULT_MIME_TYPES.add(MimetypeMap.MIMETYPE_PDF);
|
||||
DEFAULT_MIME_TYPES.add(MimetypeMap.MIMETYPE_OPENDOCUMENT_PRESENTATION);
|
||||
DEFAULT_MIME_TYPES.add(MimetypeMap.MIMETYPE_OPENXML_PRESENTATION);
|
||||
DEFAULT_MIME_TYPES.add(MimetypeMap.MIMETYPE_IWORK_KEYNOTE);
|
||||
DEFAULT_MIME_TYPES.add(MimetypeMap.MIMETYPE_IWORK_PAGES);
|
||||
DEFAULT_MIME_TYPES.add(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
DEFAULT_MIME_TYPES.add(MimetypeMap.MIMETYPE_OPENDOCUMENT_TEXT);
|
||||
DEFAULT_MIME_TYPES.add(MimetypeMap.MIMETYPE_TEXT_CSV);
|
||||
DEFAULT_MIME_TYPES.add(MimetypeMap.MIMETYPE_EXCEL);
|
||||
DEFAULT_MIME_TYPES.add(MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING);
|
||||
DEFAULT_MIME_TYPES.add(MimetypeMap.MIMETYPE_OPENDOCUMENT_SPREADSHEET);
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setActionService(ActionService actionService)
|
||||
{
|
||||
this.actionService = actionService;
|
||||
}
|
||||
|
||||
public void setPermittedMimeTypes(Set<String> permittedMimeTypes)
|
||||
{
|
||||
if (permittedMimeTypes == null)
|
||||
{
|
||||
permittedMimeTypes = Collections.emptySet();
|
||||
}
|
||||
this.permittedMimeTypes = Collections.unmodifiableSet(permittedMimeTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublish()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPublishStatusUpdates()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUnpublish()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QName getChannelNodeType()
|
||||
{
|
||||
return SlideSharePublishingModel.TYPE_DELIVERY_CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<QName> getSupportedContentTypes()
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedMimetypes()
|
||||
{
|
||||
return permittedMimeTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(NodeRef nodeToPublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
Action publishAction = actionService.createAction(SlideSharePublishAction.NAME);
|
||||
actionService.executeAction(publishAction, nodeToPublish);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unpublish(NodeRef nodeToUnpublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatus(Channel channel, String status, Map<QName, Serializable> properties)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNodeUrl(NodeRef node)
|
||||
{
|
||||
String url = null;
|
||||
if (node != null && nodeService.exists(node) && nodeService.hasAspect(node, SlideSharePublishingModel.ASPECT_ASSET))
|
||||
{
|
||||
url = (String)nodeService.getProperty(node, SlideSharePublishingModel.PROP_PLAYER_URL);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.publishing.slideshare;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
|
||||
import org.alfresco.repo.content.filestore.FileContentReader;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ParameterDefinition;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.benfante.jslideshare.SlideShareAPI;
|
||||
|
||||
public class SlideSharePublishAction extends ActionExecuterAbstractBase
|
||||
{
|
||||
private final static Log log = LogFactory.getLog(SlideSharePublishAction.class);
|
||||
|
||||
public static final String NAME = "publish_slideshare";
|
||||
|
||||
private NodeService nodeService;
|
||||
private ContentService contentService;
|
||||
private TaggingService taggingService;
|
||||
private SlideSharePublishingHelper slideShareHelper;
|
||||
|
||||
public void setSlideShareHelper(SlideSharePublishingHelper slideShareHelper)
|
||||
{
|
||||
this.slideShareHelper = slideShareHelper;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
public void setTaggingService(TaggingService taggingService)
|
||||
{
|
||||
this.taggingService = taggingService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeImpl(Action action, NodeRef nodeRef)
|
||||
{
|
||||
SlideShareAPI api = slideShareHelper.getSlideShareApi();
|
||||
Pair<String,String> usernamePassword = slideShareHelper.getSlideShareCredentialsForNode(nodeRef);
|
||||
if (api == null || usernamePassword == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("publish.failed.unable_to_connect_to_service_provider");
|
||||
}
|
||||
|
||||
ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
|
||||
if (reader.exists())
|
||||
{
|
||||
File contentFile;
|
||||
boolean deleteContentFileOnCompletion = false;
|
||||
if (FileContentReader.class.isAssignableFrom(reader.getClass()))
|
||||
{
|
||||
//Grab the content straight from the content store if we can...
|
||||
contentFile = ((FileContentReader)reader).getFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
//...otherwise copy it to a temp file and use the copy...
|
||||
File tempDir = TempFileProvider.getLongLifeTempDir("slideshare");
|
||||
contentFile = TempFileProvider.createTempFile("slideshare", "", tempDir);
|
||||
reader.getContent(contentFile);
|
||||
deleteContentFileOnCompletion = true;
|
||||
}
|
||||
|
||||
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
|
||||
String title = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
|
||||
if (title == null || title.length() == 0)
|
||||
{
|
||||
title = name;
|
||||
}
|
||||
String description = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION);
|
||||
if (description == null || description.length() == 0)
|
||||
{
|
||||
description = title;
|
||||
}
|
||||
|
||||
List<String> tagList = taggingService.getTags(nodeRef);
|
||||
StringBuilder tags = new StringBuilder();
|
||||
for (String tag : tagList)
|
||||
{
|
||||
tags.append(tag);
|
||||
tags.append(' ');
|
||||
}
|
||||
|
||||
String assetId = api.uploadSlideshow(usernamePassword.getFirst(), usernamePassword.getSecond(), title,
|
||||
contentFile, description, tags.toString(), false, false, false, false, false);
|
||||
nodeService.setProperty(nodeRef, SlideSharePublishingModel.PROP_ASSET_ID, assetId);
|
||||
|
||||
if (deleteContentFileOnCompletion)
|
||||
{
|
||||
contentFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.publishing.slideshare;
|
||||
|
||||
import org.alfresco.repo.publishing.PublishingModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
import com.benfante.jslideshare.SlideShareAPI;
|
||||
import com.benfante.jslideshare.SlideShareAPIFactory;
|
||||
|
||||
public class SlideSharePublishingHelper
|
||||
{
|
||||
private NodeService nodeService;
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
|
||||
public SlideShareAPI getSlideShareApi()
|
||||
{
|
||||
return SlideShareAPIFactory.getSlideShareAPI("hhjh", "oijkl");
|
||||
}
|
||||
|
||||
|
||||
public Pair<String, String> getSlideShareCredentialsForNode(NodeRef publishNode)
|
||||
{
|
||||
Pair<String, String> result = null;
|
||||
if (nodeService.exists(publishNode))
|
||||
{
|
||||
NodeRef parent = nodeService.getPrimaryParent(publishNode).getParentRef();
|
||||
if (nodeService.hasAspect(parent, SlideSharePublishingModel.ASPECT_DELIVERY_CHANNEL))
|
||||
{
|
||||
String username = (String) nodeService.getProperty(parent, PublishingModel.PROP_CHANNEL_USERNAME);
|
||||
String password = (String) nodeService.getProperty(parent, PublishingModel.PROP_CHANNEL_PASSWORD);
|
||||
if (username != null && password != null)
|
||||
{
|
||||
result = new Pair<String, String>(username, password);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.publishing.slideshare;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Brian
|
||||
*
|
||||
*/
|
||||
public interface SlideSharePublishingModel
|
||||
{
|
||||
public static final String NAMESPACE = "http://www.alfresco.org/model/publishing/youtube/1.0";
|
||||
public static final String PREFIX = "youtube";
|
||||
|
||||
public static final QName TYPE_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannel");
|
||||
|
||||
public static final QName ASPECT_DELIVERY_CHANNEL = QName.createQName(NAMESPACE, "DeliveryChannelAspect");
|
||||
|
||||
public static final QName ASPECT_ASSET = QName.createQName(NAMESPACE, "AssetAspect");
|
||||
public static final QName PROP_ASSET_ID = QName.createQName(NAMESPACE, "assetId");
|
||||
public static final QName PROP_PLAYER_URL = QName.createQName(NAMESPACE, "assetUrl");
|
||||
}
|
Reference in New Issue
Block a user