this.uploadMaxSize = getLocalizedString(getLocale(), "tool.contenttool.systemWideFileUploadLimit", formatter.formatFileSize(uploadMaxSize));
}
else if(this.contentTypeDefinitionId != null && digitalAssetKey != null)
{
this.contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(this.contentTypeDefinitionId);
AssetKeyDefinition assetKeyDefinition = ContentTypeDefinitionController.getController().getDefinedAssetKey(contentTypeDefinitionVO, true, digitalAssetKey);
if(assetKeyDefinition != null)
{
this.uploadMaxSize = getLocalizedString(getLocale(), "tool.contenttool.myFileUploadLimit", formatter.formatFileSize(assetKeyDefinition.getMaximumSize()));
}
}
return "uploadFailed";
}
if(this.contentVersionId != null)
{
this.contentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(this.contentVersionId);
this.contentTypeDefinitionVO = ContentController.getContentController().getContentTypeDefinition(contentVersionVO.getContentId());
}
else
{
if(this.entity.equalsIgnoreCase(UserProperties.class.getName()))
{
UserPropertiesVO userPropertiesVO = UserPropertiesController.getController().getUserPropertiesVOWithId(this.entityId);
this.contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(userPropertiesVO.getContentTypeDefinitionId());
}
else if(this.entity.equalsIgnoreCase(RoleProperties.class.getName()))
{
RolePropertiesVO rolePropertiesVO = RolePropertiesController.getController().getRolePropertiesVOWithId(this.entityId);
this.contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(rolePropertiesVO.getContentTypeDefinitionId());
}
else if(this.entity.equalsIgnoreCase(GroupProperties.class.getName()))
{
GroupPropertiesVO groupPropertiesVO = GroupPropertiesController.getController().getGroupPropertiesVOWithId(this.entityId);
this.contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(groupPropertiesVO.getContentTypeDefinitionId());
}
}
InputStream is = null;
//File renamedFile = null;
File file = null;
try
{
if(mpr != null)
{
Enumeration names = mpr.getFileNames();
while (names.hasMoreElements())
{
String name = (String)names.nextElement();
String contentType = mpr.getContentType(name);
String fileSystemName = mpr.getFilesystemName(name);
String fromEncoding = CmsPropertyHandler.getUploadFromEncoding();
if(fromEncoding == null)
fromEncoding = "iso-8859-1";
String toEncoding = CmsPropertyHandler.getUploadToEncoding();
if(toEncoding == null)
toEncoding = "utf-8";
digitalAssetKey = new String(digitalAssetKey.getBytes(fromEncoding), toEncoding);
fileSystemName = new String(fileSystemName.getBytes(fromEncoding), toEncoding);
logger.info("digitalAssetKey:" + digitalAssetKey);
logger.info("name:" + name);
logger.info("contentType:" + contentType);
logger.info("fileSystemName:" + fileSystemName);
if(digitalAssetKey == null || digitalAssetKey.equals(""))
{
if(fileSystemName.lastIndexOf(".") > -1)
digitalAssetKey = fileSystemName.substring(0, fileSystemName.lastIndexOf("."));
digitalAssetKey = formatter.replaceNiceURINonAsciiWithSpecifiedChars(digitalAssetKey, CmsPropertyHandler.getNiceURIDefaultReplacementCharacter());
//digitalAssetKey = formatter.replaceNonAscii(digitalAssetKey, '_');
}
logger.info("digitalAssetKey:" + digitalAssetKey);
if(useFileNameAsContentTypeBase)
{
if(fileSystemName.lastIndexOf(".") > -1)
{
String extension = fileSystemName.substring(fileSystemName.lastIndexOf(".") + 1);
logger.info("extension:" + extension);
if(extension.equalsIgnoreCase("gif"))
contentType = "image/gif";
else if(extension.equalsIgnoreCase("jpg"))
contentType = "image/jpg";
else if(extension.equalsIgnoreCase("png"))
contentType = "image/png";
else if(extension.equalsIgnoreCase("pdf"))
contentType = "application/pdf";
else if(extension.equalsIgnoreCase("doc"))
contentType = "application/msword";
else if(extension.equalsIgnoreCase("xls"))
contentType = "application/vnd.ms-excel";
else if(extension.equalsIgnoreCase("ppt"))
contentType = "application/vnd.ms-powerpoint";
else if(extension.equalsIgnoreCase("zip"))
contentType = "application/zip";
else if(extension.equalsIgnoreCase("xml"))
contentType = "text/xml";
}
}
logger.info("contentType:" + contentType);
file = mpr.getFile(name);
logger.info("file:" + file.getPath());
logger.info("file.exists:" + file.exists());
logger.info("file.length:" + file.length());
String fileName = fileSystemName;
logger.info("fileName:" + fileName);
fileName = formatter.replaceNiceURINonAsciiWithSpecifiedChars(fileName, CmsPropertyHandler.getNiceURIDefaultReplacementCharacter());
logger.info("fileName after conversion:" + fileName);
String tempFileName = "tmp_" + System.currentTimeMillis() + "_" + fileName;
//String filePath = file.getParentFile().getPath();
String filePath = CmsPropertyHandler.getDigitalAssetPath();
fileSystemName = filePath + File.separator + tempFileName;
logger.info("fileSystemName:" + fileSystemName);
DigitalAssetVO newAsset = new DigitalAssetVO();
newAsset.setAssetContentType(contentType);
newAsset.setAssetKey(digitalAssetKey);
newAsset.setAssetFileName(fileName);
newAsset.setAssetFilePath(filePath);
newAsset.setAssetFileSize(new Integer(new Long(file.length()).intValue()));
//is = new FileInputStream(renamedFile);
logger.info("CmsPropertyHandler.getEnableDiskAssets():" + CmsPropertyHandler.getEnableDiskAssets());
if(CmsPropertyHandler.getEnableDiskAssets().equals("false"))
{
logger.info("Trying to debug:" + file.getPath() + ":" + file.length());
if(file.length() < 1000 && logger.isInfoEnabled())
{
try
{
InputStream in = new FileInputStream(file);
byte[] b = new byte[(int)file.length()];
int len = b.length;
int total = 0;
while (total < len) {
int result = in.read(b, total, len - total);
if (result == -1) {
break;
}
total += result;
}
in.close();
logger.info(new String(b, "UTF-8"));
}
catch (Exception e)
{
e.printStackTrace();
}
}
is = new FileInputStream(file);
}
List existingAssetVOList = DigitalAssetController.getDigitalAssetVOList(contentVersionId);
Iterator existingAssetVOListIterator = existingAssetVOList.iterator();
while(existingAssetVOListIterator.hasNext())
{
DigitalAssetVO existingDigitalAssetVO = (DigitalAssetVO)existingAssetVOListIterator.next();
if(existingDigitalAssetVO.getAssetKey().equalsIgnoreCase(digitalAssetKey))
{
file.delete();
this.reasonKey = "tool.contenttool.fileUpload.fileUploadFailedOnAssetKeyExistingText";
this.uploadMaxSize = "\"" + digitalAssetKey + "\"";
this.getResponse().setContentType("text/html; charset=UTF-8");
//this.getResponse().setStatus(responseCode);
logger.info("this.getResponse():" + this.getResponse());
this.getResponse().setHeader("sendIGError", "true");
return "uploadFailed";
}
}
logger.info("fileUploadMaximumSize in create:" + fileUploadMaximumSize);
if(!fileUploadMaximumSize.equalsIgnoreCase("-1") && new Integer(fileUploadMaximumSize).intValue() < new Long(file.length()).intValue())
{
file.delete();
this.reasonKey = "tool.contenttool.fileUpload.fileUploadFailedOnSizeText";
this.uploadMaxSize = getLocalizedString(getLocale(), "tool.contenttool.myFileUploadLimit", formatter.formatFileSize(myFileUploadSizeLimit));
return "uploadFailed";
}
if(this.contentTypeDefinitionId != null && digitalAssetKey != null)
{
this.contentTypeDefinitionVO = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithId(this.contentTypeDefinitionId);
AssetKeyDefinition assetKeyDefinition = ContentTypeDefinitionController.getController().getDefinedAssetKey(contentTypeDefinitionVO, true, digitalAssetKey);
if(assetKeyDefinition != null)
{
if(assetKeyDefinition.getMaximumSize().intValue() < new Long(file.length()).intValue())
{
file.delete();
this.reasonKey = "tool.contenttool.fileUpload.fileUploadFailedOnSizeText";
this.uploadMaxSize = getLocalizedString(getLocale(), "tool.contenttool.myFileUploadLimit", formatter.formatFileSize(assetKeyDefinition.getMaximumSize()));
return "uploadFailed";
}
if(assetKeyDefinition.getAllowedContentTypes().startsWith("image"))
{
if(!contentType.startsWith("image"))
{
file.delete();
this.reasonKey = "tool.contenttool.fileUpload.fileUploadFailedOnTypeNotImageText";
return "uploadFailed";
}
Image image = javax.imageio.ImageIO.read(file);
int width = image.getWidth(null);
int height = image.getHeight(null);
String allowedWidth = assetKeyDefinition.getImageWidth();
String allowedHeight = assetKeyDefinition.getImageHeight();
if(!allowedWidth.equals("*"))
{
Integer allowedWidthNumber = new Integer(allowedWidth.substring(1));
if(allowedWidth.startsWith("<") && width >= allowedWidthNumber.intValue())
{
file.delete();
this.reasonKey = "tool.contenttool.fileUpload.fileUploadFailedOnImageToWideText";
return "uploadFailed";
}
if(allowedWidth.startsWith(">") && width <= allowedWidthNumber.intValue())
{
file.delete();
this.reasonKey = "tool.contenttool.fileUpload.fileUploadFailedOnImageNotWideEnoughText";
return "uploadFailed";
}
if(!allowedWidth.startsWith(">") && !allowedWidth.startsWith("<") && width != new Integer(allowedWidth).intValue())
{
file.delete();
this.reasonKey = "tool.contenttool.fileUpload.fileUploadFailedOnImageWrongWidthText";
return "uploadFailed";
}
}
if(!allowedHeight.equals("*"))
{
Integer allowedHeightNumber = new Integer(allowedHeight.substring(1));
if(allowedHeight.startsWith("<") && height >= allowedHeightNumber.intValue())
{
file.delete();
this.reasonKey = "tool.contenttool.fileUpload.fileUploadFailedOnImageToHighText";
return "uploadFailed";
}
if(allowedHeight.startsWith(">") && height <= allowedHeightNumber.intValue())
{
file.delete();
this.reasonKey = "tool.contenttool.fileUpload.fileUploadFailedOnImageNotHighEnoughText";
return "uploadFailed";
}
if(!allowedHeight.startsWith(">") && !allowedHeight.startsWith("<") && height != new Integer(allowedHeight).intValue())
{
file.delete();
this.reasonKey = "tool.contenttool.fileUpload.fileUploadFailedOnImageWrongHeightText";
return "uploadFailed";
}
}
}
}
}
boolean keepOriginal = true;
logger.info("this.contentVersionId:" + this.contentVersionId);
if(this.contentVersionId != null)
{
AssetKeyDefinition assetKeyDefinition = ContentTypeDefinitionController.getController().getDefinedAssetKey(contentTypeDefinitionVO, true, digitalAssetKey);
logger.info("assetKeyDefinition:" + assetKeyDefinition);
keepOriginal = handleTransformations(newAsset, file, contentType, assetKeyDefinition, contentTypeDefinitionVO);
logger.info("keepOriginal:" + keepOriginal);
if(keepOriginal)