/* (non-Javadoc) * @see org.alfresco.service.cmr.view.Exporter#content(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.io.InputStream) */ public void content( NodeRef nodeRef, QName property, InputStream content, ContentData contentData, int index) { try { byte[] data = new byte[1048576]; // 1MB int read = content.read(data); ArrayList<Byte> total = new ArrayList<Byte>(); while (read > -1) { for (int i = 0; i < read; i++) { total.add(data[i]); } read = content.read(data); } byte[] toEncode = new byte[total.size()]; for (int i = 0; i < toEncode.length; i++) { toEncode[i] = total.get(i).byteValue(); } String temp = Base64.encodeBytes(toEncode); String ptemp = contentData.getMimetype() + "|" + contentData.getSize() + "|" + contentData.getEncoding() + "|"; contentHandler.characters(ptemp.toCharArray(), 0, ptemp.length()); contentHandler.characters(temp.toCharArray(), 0, temp.length()); } catch (Exception e) { throw new ExporterException("Failed to process export of base64 content: " + e.getMessage()); } }
/** * @see * org.alfresco.repo.version.operations.VersionOperationsService#checkin(org.alfresco.repo.ref.NodeRef, * Map<String,Serializable>, java.lang.String, boolean) */ public NodeRef checkin( NodeRef workingCopyNodeRef, Map<String, Serializable> versionProperties, String contentUrl, boolean keepCheckedOut) { NodeRef nodeRef = null; // Check that we have been handed a working copy if (this.nodeService.hasAspect(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY) == false) { // Error since we have not been passed a working copy throw new AspectMissingException(ContentModel.ASPECT_WORKING_COPY, workingCopyNodeRef); } // Check that the working node still has the copy aspect applied if (this.nodeService.hasAspect(workingCopyNodeRef, ContentModel.ASPECT_COPIEDFROM) == true) { // Invoke policy invokeBeforeCheckIn(workingCopyNodeRef, versionProperties, contentUrl, keepCheckedOut); Map<QName, Serializable> workingCopyProperties = nodeService.getProperties(workingCopyNodeRef); // Try and get the original node reference nodeRef = (NodeRef) workingCopyProperties.get(ContentModel.PROP_COPY_REFERENCE); if (nodeRef == null) { // Error since the original node can not be found throw new CheckOutCheckInServiceException(MSG_ERR_BAD_COPY); } try { // Release the lock this.lockService.unlock(nodeRef); } catch (UnableToReleaseLockException exception) { throw new CheckOutCheckInServiceException(MSG_ERR_NOT_OWNER, exception); } if (contentUrl != null) { ContentData contentData = (ContentData) workingCopyProperties.get(ContentModel.PROP_CONTENT); if (contentData == null) { throw new AlfrescoRuntimeException( MSG_ERR_WORKINGCOPY_HAS_NO_MIMETYPE, new Object[] {workingCopyNodeRef}); } else { contentData = new ContentData( contentUrl, contentData.getMimetype(), contentData.getSize(), contentData.getEncoding()); } // Set the content url value onto the working copy this.nodeService.setProperty(workingCopyNodeRef, ContentModel.PROP_CONTENT, contentData); } // Copy the contents of the working copy onto the original this.copyService.copy(workingCopyNodeRef, nodeRef); // Handle name change on working copy (only for folders/files) if (fileFolderService.getFileInfo(workingCopyNodeRef) != null) { String origName = (String) this.nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); String name = (String) this.nodeService.getProperty(workingCopyNodeRef, ContentModel.PROP_NAME); if (hasWorkingCopyNameChanged(name, origName)) { // ensure working copy has working copy label in its name to avoid name clash if (!name.contains(" " + getWorkingCopyLabel())) { try { fileFolderService.rename(workingCopyNodeRef, createWorkingCopyName(name)); } catch (FileExistsException e) { throw new CheckOutCheckInServiceException( e, MSG_ERR_CANNOT_RENAME, name, createWorkingCopyName(name)); } catch (FileNotFoundException e) { throw new CheckOutCheckInServiceException( e, MSG_ERR_CANNOT_RENAME, name, createWorkingCopyName(name)); } } try { // rename original to changed working name fileFolderService.rename(nodeRef, getNameFromWorkingCopyName(name)); } catch (FileExistsException e) { throw new CheckOutCheckInServiceException( e, MSG_ERR_CANNOT_RENAME, origName, getNameFromWorkingCopyName(name)); } catch (FileNotFoundException e) { throw new CheckOutCheckInServiceException( e, MSG_ERR_CANNOT_RENAME, name, getNameFromWorkingCopyName(name)); } } } if (versionProperties != null && this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true) { // Create the new version this.versionService.createVersion(nodeRef, versionProperties); } if (keepCheckedOut == false) { // Delete the working copy this.nodeService.deleteNode(workingCopyNodeRef); } else { // Re-lock the original node this.lockService.lock(nodeRef, LockType.READ_ONLY_LOCK); } // Invoke policy invokeOnCheckIn(nodeRef); } else { // Error since the copy aspect is missing throw new AspectMissingException(ContentModel.ASPECT_COPIEDFROM, workingCopyNodeRef); } return nodeRef; }