bugfix: added missing setCaption() in fileasset.java
git-svn-id: https://svn.libreccm.org/ccm/trunk@3375 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
7a866b11e2
commit
ed33bc8f77
|
|
@ -25,6 +25,7 @@ import com.arsdigita.persistence.DataObject;
|
||||||
import com.arsdigita.persistence.Filter;
|
import com.arsdigita.persistence.Filter;
|
||||||
import com.arsdigita.persistence.OID;
|
import com.arsdigita.persistence.OID;
|
||||||
import com.arsdigita.persistence.SessionManager;
|
import com.arsdigita.persistence.SessionManager;
|
||||||
|
import com.arsdigita.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
|
@ -33,19 +34,17 @@ import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link com.arsdigita.cms.Asset asset} describing a concrete
|
* An {@link com.arsdigita.cms.Asset asset} describing a concrete file, such as
|
||||||
* file, such as an image.
|
* an image.
|
||||||
*
|
*
|
||||||
* @author Scott Seago (scott@arsdigita.com)
|
* @author Scott Seago (scott@arsdigita.com)
|
||||||
* @version $Id: FileAsset.java 2155 2011-01-21 01:17:02Z pboy $
|
* @version $Id: FileAsset.java 2155 2011-01-21 01:17:02Z pboy $
|
||||||
*/
|
*/
|
||||||
public class FileAsset extends BinaryAsset {
|
public class FileAsset extends BinaryAsset {
|
||||||
|
|
||||||
public static final String BASE_DATA_OBJECT_TYPE =
|
public static final String BASE_DATA_OBJECT_TYPE
|
||||||
"com.arsdigita.cms.FileAsset";
|
= "com.arsdigita.cms.FileAsset";
|
||||||
|
|
||||||
|
|
||||||
public static final String CONTENT = "content";
|
public static final String CONTENT = "content";
|
||||||
public static final String HEIGHT = "height";
|
public static final String HEIGHT = "height";
|
||||||
|
|
@ -54,35 +53,35 @@ public class FileAsset extends BinaryAsset {
|
||||||
|
|
||||||
//public static final String MIME_JPEG = "image/jpeg";
|
//public static final String MIME_JPEG = "image/jpeg";
|
||||||
//public static final String MIME_GIF = "image/gif";
|
//public static final String MIME_GIF = "image/gif";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor. This creates a new text asset.
|
* Default constructor. This creates a new text asset.
|
||||||
**/
|
*
|
||||||
|
*/
|
||||||
public FileAsset() {
|
public FileAsset() {
|
||||||
super(BASE_DATA_OBJECT_TYPE);
|
super(BASE_DATA_OBJECT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. The contained <code>DataObject</code> is retrieved
|
* Constructor. The contained <code>DataObject</code> is retrieved from the
|
||||||
* from the persistent storage mechanism with an <code>OID</code>
|
* persistent storage mechanism with an <code>OID</code> specified by
|
||||||
* specified by <i>oid</i>.
|
* <i>oid</i>.
|
||||||
*
|
*
|
||||||
* @param oid The <code>OID</code> for the retrieved
|
* @param oid The <code>OID</code> for the retrieved
|
||||||
* <code>DataObject</code>.
|
* <code>DataObject</code>.
|
||||||
**/
|
*
|
||||||
|
*/
|
||||||
public FileAsset(OID oid) throws DataObjectNotFoundException {
|
public FileAsset(OID oid) throws DataObjectNotFoundException {
|
||||||
super(oid);
|
super(oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. The contained <code>DataObject</code> is retrieved
|
* Constructor. The contained <code>DataObject</code> is retrieved from the
|
||||||
* from the persistent storage mechanism with an <code>OID</code>
|
* persistent storage mechanism with an <code>OID</code> specified by
|
||||||
* specified by <i>id</i> and
|
* <i>id</i> and <code>FileAsset.BASE_DATA_OBJECT_TYPE</code>.
|
||||||
* <code>FileAsset.BASE_DATA_OBJECT_TYPE</code>.
|
|
||||||
*
|
*
|
||||||
* @param id The <code>id</code> for the retrieved
|
* @param id The <code>id</code> for the retrieved <code>DataObject</code>.
|
||||||
* <code>DataObject</code>.
|
*
|
||||||
**/
|
*/
|
||||||
public FileAsset(BigDecimal id) throws DataObjectNotFoundException {
|
public FileAsset(BigDecimal id) throws DataObjectNotFoundException {
|
||||||
this(new OID(BASE_DATA_OBJECT_TYPE, id));
|
this(new OID(BASE_DATA_OBJECT_TYPE, id));
|
||||||
}
|
}
|
||||||
|
|
@ -152,8 +151,8 @@ public class FileAsset extends BinaryAsset {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the file asset from the specified file. Automatically guesses
|
* Load the file asset from the specified file. Automatically guesses the
|
||||||
* the mime type of the file.
|
* mime type of the file.
|
||||||
*
|
*
|
||||||
* @param fileName The original name of the file
|
* @param fileName The original name of the file
|
||||||
* @param file The actual file on the server
|
* @param file The actual file on the server
|
||||||
|
|
@ -165,7 +164,7 @@ public class FileAsset extends BinaryAsset {
|
||||||
// Guess mime type
|
// Guess mime type
|
||||||
MimeType mime = MimeType.guessMimeTypeFromFile(fileName);
|
MimeType mime = MimeType.guessMimeTypeFromFile(fileName);
|
||||||
|
|
||||||
if(mime == null && defaultMimeType != null) {
|
if (mime == null && defaultMimeType != null) {
|
||||||
// Set default mime type
|
// Set default mime type
|
||||||
mime = MimeType.loadMimeType(defaultMimeType);
|
mime = MimeType.loadMimeType(defaultMimeType);
|
||||||
}
|
}
|
||||||
|
|
@ -174,12 +173,12 @@ public class FileAsset extends BinaryAsset {
|
||||||
|
|
||||||
// Extract the filename
|
// Extract the filename
|
||||||
int i = fileName.lastIndexOf("/");
|
int i = fileName.lastIndexOf("/");
|
||||||
if(i > 0) {
|
if (i > 0) {
|
||||||
fileName = fileName.substring(i+1);
|
fileName = fileName.substring(i + 1);
|
||||||
}
|
}
|
||||||
i = fileName.lastIndexOf("\\"); // DOS-style
|
i = fileName.lastIndexOf("\\"); // DOS-style
|
||||||
if(i > 0) {
|
if (i > 0) {
|
||||||
fileName = fileName.substring(i+1);
|
fileName = fileName.substring(i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
setName(fileName);
|
setName(fileName);
|
||||||
|
|
@ -188,6 +187,20 @@ public class FileAsset extends BinaryAsset {
|
||||||
readBytes(in);
|
readBytes(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a caption
|
||||||
|
*
|
||||||
|
* @author konerman
|
||||||
|
*/
|
||||||
|
public void setCaption() throws IOException {
|
||||||
|
MimeType mime;
|
||||||
|
mime = MimeType.loadMimeType("text/plain");
|
||||||
|
setMimeType(mime);
|
||||||
|
mime.setLabel("caption");
|
||||||
|
setName(StringUtils.urlize("caption"));
|
||||||
|
setContent("caption".getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the file asset content to a file.
|
* Write the file asset content to a file.
|
||||||
*
|
*
|
||||||
|
|
@ -206,15 +219,13 @@ public class FileAsset extends BinaryAsset {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all files in the database. Extremely expensive !
|
* Retrieve all files in the database. Extremely expensive !
|
||||||
*
|
*
|
||||||
* @return a collection of FileAssets
|
* @return a collection of FileAssets
|
||||||
*/
|
*/
|
||||||
public static FileAssetCollection getAllFiles() {
|
public static FileAssetCollection getAllFiles() {
|
||||||
DataCollection da = SessionManager.getSession().retrieve
|
DataCollection da = SessionManager.getSession().retrieve(BASE_DATA_OBJECT_TYPE);
|
||||||
(BASE_DATA_OBJECT_TYPE);
|
|
||||||
return new FileAssetCollection(da);
|
return new FileAssetCollection(da);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -249,11 +260,10 @@ public class FileAsset extends BinaryAsset {
|
||||||
return getFilesByKeyword(keyword, ContentItem.DRAFT);
|
return getFilesByKeyword(keyword, ContentItem.DRAFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void beforeSave() {
|
protected void beforeSave() {
|
||||||
if( null == getLanguage() ) {
|
if (null == getLanguage()) {
|
||||||
setLanguage( Locale.getDefault().getLanguage() );
|
setLanguage(Locale.getDefault().getLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
super.beforeSave();
|
super.beforeSave();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue