Changed file extensions
This commit is contained in:
parent
06861e1658
commit
4b992cad31
7 changed files with 26 additions and 13 deletions
|
|
@ -7,7 +7,7 @@
|
|||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/Test/lib/commons-cli-1.2.jar"/>
|
||||
<classpathentry kind="lib" path="/Test/lib/slf4j-api-1.6.4.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Ziver/Documents/Programmering/Java/libs/xuggler/xuggle-xuggler-5.4.jar"/>
|
||||
<classpathentry kind="lib" path="C:/Users/Ziver/Documents/Programmering/Java/libs/xuggler/xuggle-xuggler-5.4.jar" sourcepath="C:/Users/Ziver/Documents/Programmering/Java/libs/xuggler/xuggle-xuggler-5.4.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0"/>
|
||||
<classpathentry kind="output" path="build/classes"/>
|
||||
</classpath>
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@
|
|||
<%if( media instanceof Video ){ %>
|
||||
<jsp:include page="media_video.jsp" flush="false" />
|
||||
<%} else{ %>
|
||||
<A href="content?id=<%=media.getId()%>&size=full" rel="zoom">
|
||||
<A href="content?id=<%=media.getId()%>&size=large" rel="zoom">
|
||||
<IMG src="content?id=<%=media.getId()%>&size=medium" alt="<%=media.getTitle()%>" width="500" > <!-- height="375" -->
|
||||
</A>
|
||||
<%} %>
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ public class ZalleryContent extends HttpServlet{
|
|||
file = media.getFile( Media.Size.SMALL );
|
||||
else if( size.equalsIgnoreCase( "medium" ) )
|
||||
file = media.getFile( Media.Size.MEDIUM );
|
||||
else if( size.equalsIgnoreCase( "large" ) )
|
||||
file = media.getFile( Media.Size.LARGE );
|
||||
else
|
||||
file = media.getFile( Media.Size.ORIGINAL );
|
||||
|
||||
|
|
|
|||
|
|
@ -149,25 +149,26 @@ public class Folder extends DBBean{
|
|||
// Zallery not initialized.
|
||||
while( Zallery.DATA_PATH.isEmpty() ){
|
||||
logger.warning("Zallery not initialized or DATA_PATH not set!");
|
||||
try{Thread.sleep(100);}catch(Exception e){}
|
||||
return null;
|
||||
}
|
||||
|
||||
if( user == null || filename == null )
|
||||
return null;
|
||||
StringBuilder tmp = new StringBuilder();
|
||||
|
||||
// Get the Root path of the given size
|
||||
tmp.append( Zallery.DATA_PATH );
|
||||
if( tmp.charAt(tmp.length()-1) != File.separatorChar )
|
||||
tmp.append( File.separatorChar );
|
||||
|
||||
tmp.append( File.separatorChar );
|
||||
tmp.append( size.toString() );
|
||||
//tmp.append( File.separatorChar );
|
||||
//tmp.append( user.getId() );
|
||||
if( path.charAt(0) != '/' )
|
||||
tmp.append( File.separatorChar );
|
||||
|
||||
// Add UserID and this folders path
|
||||
String tmp_path = path.replaceAll("\\{NAME\\}", ""+user.getId());
|
||||
tmp_path = tmp_path.replaceAll("/", Matcher.quoteReplacement(File.separator));
|
||||
tmp.append( tmp_path );
|
||||
|
||||
// check if folder exists or else create it
|
||||
File folder = new File(tmp.toString());
|
||||
if( !folder.exists() )
|
||||
|
|
@ -175,10 +176,12 @@ public class Folder extends DBBean{
|
|||
logger.warning("Unable to create new folders: '"+folder+"'");
|
||||
throw new RuntimeException("Unable to create new folders: '"+folder+"'");
|
||||
}
|
||||
|
||||
// Add the filename
|
||||
if( tmp.charAt(tmp.length()-1) != File.separatorChar )
|
||||
tmp.append( File.separatorChar );
|
||||
tmp.append(filename);
|
||||
|
||||
logger.finest( "File path: "+tmp.toString() );
|
||||
return new File(tmp.toString());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@ import zutil.db.bean.DBBean;
|
|||
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||
import zutil.db.bean.DBBean.*;
|
||||
import zutil.image.ImageUtil;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
@DBTable(value="Image", superBean=true)
|
||||
public class Image extends Media{
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
public static final String type = "image";
|
||||
public static final String IMAGE_FORMAT = "jpg";
|
||||
|
||||
@DBLinkTable(table="Comments", beanClass=Comment.class, idColumn="image")
|
||||
private LinkedList<Comment> comments;
|
||||
|
|
@ -60,7 +62,7 @@ public class Image extends Media{
|
|||
throw new Exception("Folder not set for image!");
|
||||
// Generate unique filename
|
||||
filename = genFileName( item.getName() );
|
||||
filename += ".png";
|
||||
filename += "."+FileUtil.getFileExtension( item.getName() );
|
||||
File file = folder.getFile( filename, Size.ORIGINAL );
|
||||
|
||||
// Move uploaded file
|
||||
|
|
@ -78,7 +80,7 @@ public class Image extends Media{
|
|||
case ORIGINAL:
|
||||
return folder.getFile( filename, Size.ORIGINAL );
|
||||
default:
|
||||
File file = folder.getFile( filename, size );
|
||||
File file = folder.getFile( FileUtil.changeExtension(filename, IMAGE_FORMAT), size );
|
||||
File orgFile = folder.getFile( filename, Size.ORIGINAL );
|
||||
if( !file.exists() ){
|
||||
if(orgFile.exists() && orgFile.canRead() ){
|
||||
|
|
@ -92,8 +94,13 @@ public class Image extends Media{
|
|||
case MEDIUM:
|
||||
image = ImageUtil.scale(original, 500, 375, true);
|
||||
break;
|
||||
case LARGE:
|
||||
image = ImageUtil.scale(original, 1200, 800, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ImageIO.write(image, "png", file);
|
||||
ImageIO.write(image, IMAGE_FORMAT, file);
|
||||
}
|
||||
else if( !orgFile.exists() )
|
||||
logger.severe("Original image file missing: \""+file.getAbsolutePath()+"\"");
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public abstract class Media extends DBBean implements Comparable<Media>{
|
|||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
public static enum Size{
|
||||
ORIGINAL, MEDIUM, SMALL
|
||||
ORIGINAL, LARGE, MEDIUM, SMALL
|
||||
}
|
||||
|
||||
protected Folder folder;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import zutil.io.file.FileUtil;
|
|||
@DBTable(value="Video", superBean = true)
|
||||
public class Video extends Media{
|
||||
public static final String type = "video";
|
||||
public static final String VIDEO_FORMAT = "mp4";
|
||||
|
||||
/** The progress of a transcoding in %, 0 if there is no transcoding running **/
|
||||
protected transient int transcodingProgress;
|
||||
|
|
@ -99,9 +100,9 @@ public class Video extends Media{
|
|||
public File getFile(Size size) throws IOException{
|
||||
if( filename != null ){
|
||||
if( size == Size.SMALL )
|
||||
return folder.getFile( FileUtil.changeExtension(filename,"png"), size );
|
||||
return folder.getFile( FileUtil.changeExtension(filename, Image.IMAGE_FORMAT), size );
|
||||
else if( size == Size.MEDIUM )
|
||||
return folder.getFile( FileUtil.changeExtension(filename,"mp4"), size );
|
||||
return folder.getFile( FileUtil.changeExtension(filename, VIDEO_FORMAT), size );
|
||||
else
|
||||
return folder.getFile( filename, size );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue