logger.error("Bad filesize in principal properties: " + fileUploadMaximumSize);
}
try
{
MultiPartRequestWrapper mpr = ActionContext.getMultiPartRequest();
if(mpr == null)
{
this.reasonKey = "tool.contenttool.fileUpload.fileUploadFailedOnSizeText";
//------------------------------------------------------------------
// If we fail because the file is bigger than the system maximum
// we might still want to print the local maximum file size because
// it makes more sense to the user.
//------------------------------------------------------------------
if (uploadMaxSize > myFileUploadSizeLimit && myFileUploadSizeLimit > -1)
{
this.uploadMaxSize = getLocalizedString(getLocale(), "tool.contenttool.myFileUploadLimit", formatter.formatFileSize(myFileUploadSizeLimit));
}
else if (digitalAssetKey == null)
{
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;