mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
99981: Merged 5.0.N (5.0.2) to HEAD-BUG-FIX (5.1/Cloud) (PARTIAL MERGE) 99482: Merged DEV to 5.0.N (5.0.1) 99198 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc typo in project alfresco-jlan 99413 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project alfresco-jlan 99205 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project core 99415 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project data-model 99227 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project file-transfer-receiver 99416 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project legacy-lucene 99417 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project qa-share 99418 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project remote-api 99427 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc in project Repository, letters S..Z 99433 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc in project Repository, letters A..R 99421 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project share-po 99247 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc typo in project slingshot 99248 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project slingshot 99424 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project solr 99426 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project solr4 99253 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project solr-client 99259 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project web-client 99260 : MNT-13545: JavaDoc : Inconsistencies between the Java doc and the actual code - Changed Javadoc parameters inconsistence in project web-framework-commons git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@100501 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
201 lines
5.6 KiB
Java
201 lines
5.6 KiB
Java
/*
|
|
* Copyright (C) 2005-2010 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.filesys.repo;
|
|
|
|
import java.io.IOException;
|
|
|
|
import org.alfresco.model.ContentModel;
|
|
import org.alfresco.service.cmr.repository.ContentService;
|
|
import org.alfresco.service.cmr.repository.MimetypeService;
|
|
import org.alfresco.service.cmr.repository.NodeRef;
|
|
import org.alfresco.service.cmr.repository.NodeService;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
/**
|
|
* OpenOffice Content Network File Class
|
|
*
|
|
* <p>Provides special handling for OpenOffice file saves that open the file, truncate, close, then open the file
|
|
* again to write the data, as this causes multiple versions to be generated when the file is versionable.
|
|
*
|
|
* @author gkspencer
|
|
*/
|
|
public class OpenOfficeContentNetworkFile extends ContentNetworkFile {
|
|
|
|
// Debug logging
|
|
|
|
private static final Log logger = LogFactory.getLog(OpenOfficeContentNetworkFile.class);
|
|
|
|
// Flag to indicate the last I/O operation was a truncate file to zero size
|
|
|
|
private boolean m_truncateToZero;
|
|
|
|
// Delayed file close count
|
|
|
|
private int m_delayedClose;
|
|
|
|
/**
|
|
* Class constructor
|
|
*
|
|
* @param nodeService NodeService
|
|
* @param contentService ContentService
|
|
* @param mimetypeService MimetypeService
|
|
* @param nodeRef NodeRef
|
|
* @param name String
|
|
*/
|
|
protected OpenOfficeContentNetworkFile(
|
|
NodeService nodeService,
|
|
ContentService contentService,
|
|
MimetypeService mimetypeService,
|
|
NodeRef nodeRef,
|
|
String name)
|
|
{
|
|
super(nodeService, contentService, mimetypeService, nodeRef, name);
|
|
|
|
// DEBUG
|
|
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("Using OpenOffice network file for " + name + ", versionLabel=" + nodeService.getProperty( nodeRef, ContentModel.PROP_VERSION_LABEL));
|
|
}
|
|
|
|
/**
|
|
* Return the delayed close count
|
|
*
|
|
* @return int
|
|
*/
|
|
public final int getDelayedCloseCount() {
|
|
return m_delayedClose;
|
|
}
|
|
|
|
/**
|
|
* Increment the delayed close count
|
|
*/
|
|
public final void incrementDelayedCloseCount() {
|
|
m_delayedClose++;
|
|
|
|
// Clear the truncate to zero status
|
|
|
|
m_truncateToZero = false;
|
|
|
|
// DEBUG
|
|
|
|
if ( logger.isDebugEnabled())
|
|
logger.debug("Increment delayed close count=" + getDelayedCloseCount() + ", path=" + getName());
|
|
}
|
|
|
|
/**
|
|
* Check if the last file operation was a truncate to zero length
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public final boolean truncatedToZeroLength() {
|
|
return m_truncateToZero;
|
|
}
|
|
|
|
/**
|
|
* Read from the file.
|
|
*
|
|
* @param buffer byte[]
|
|
* @param length int
|
|
* @param position int
|
|
* @param fileOffset long
|
|
* @return Length of data read.
|
|
* @exception IOException
|
|
*/
|
|
public int readFile(byte[] buffer, int length, int position, long fileOffset)
|
|
throws IOException
|
|
{
|
|
// Clear the truncate flag
|
|
|
|
m_truncateToZero = false;
|
|
|
|
// Chain to the standard read
|
|
|
|
return super.readFile( buffer, length, position, fileOffset);
|
|
}
|
|
|
|
/**
|
|
* Write a block of data to the file.
|
|
*
|
|
* @param buffer byte[]
|
|
* @param length int
|
|
* @param position int
|
|
* @param fileOffset long
|
|
* @exception IOException
|
|
*/
|
|
public void writeFile(byte[] buffer, int length, int position, long fileOffset)
|
|
throws IOException
|
|
{
|
|
// Clear the truncate flag
|
|
|
|
m_truncateToZero = false;
|
|
|
|
// Chain to the standard write
|
|
|
|
super.writeFile( buffer, length, position, fileOffset);
|
|
}
|
|
|
|
/**
|
|
* Truncate or extend the file to the specified length
|
|
*
|
|
* @param size long
|
|
* @exception IOException
|
|
*/
|
|
public void truncateFile(long size)
|
|
throws IOException
|
|
{
|
|
// Chain to the standard truncate
|
|
|
|
super.truncateFile( size);
|
|
|
|
// Check for a truncate to zero length
|
|
|
|
if ( size == 0L) {
|
|
m_truncateToZero = true;
|
|
|
|
// DEBUG
|
|
|
|
if ( logger.isDebugEnabled())
|
|
logger.debug("OpenOffice document truncated to zero length, path=" + getName());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Close the file
|
|
*
|
|
* @exception IOException
|
|
*/
|
|
public void closeFile()
|
|
throws IOException
|
|
{
|
|
// DEBUG
|
|
|
|
if ( logger.isDebugEnabled()) {
|
|
logger.debug("Close OpenOffice file, " + getName() + ", delayed close count=" + getDelayedCloseCount() + ", writes=" + getWriteCount() +
|
|
", modified=" + isModified());
|
|
logger.debug(" Open count=" + getOpenCount() + ", fstate open=" + getFileState().getOpenCount());
|
|
}
|
|
|
|
// Chain to the standard close
|
|
|
|
super.closeFile();
|
|
}
|
|
}
|