From 5a77e6009c75923efcdc78dc1943d2f5067d7988 Mon Sep 17 00:00:00 2001 From: shentar Date: Sun, 10 Jul 2016 11:27:27 +0800 Subject: [PATCH] format code. --- photoweb/src/com/backend/BaseSqliteStore.java | 36 +++--- photoweb/src/com/backend/DateRecords.java | 3 +- photoweb/src/com/backend/DateTableDao.java | 15 ++- photoweb/src/com/backend/ExifCreator.java | 15 ++- photoweb/src/com/backend/FileInfo.java | 3 +- .../src/com/backend/FileSHA256Caculater.java | 9 +- photoweb/src/com/backend/FileTools.java | 33 ++++-- .../com/backend/PerformanceStatistics.java | 9 +- photoweb/src/com/backend/ReadEXIF.java | 33 ++++-- .../src/com/backend/SqliteConnManger.java | 3 +- .../src/com/backend/ThumbnailGenerator.java | 34 ++++-- .../src/com/backend/ThumbnailManager.java | 9 +- photoweb/src/com/backend/ToolMain.java | 33 ++++-- photoweb/src/com/backend/UniqPhotosStore.java | 30 +++-- .../backend/dirwathch/DirWatchService.java | 27 +++-- photoweb/src/com/service/DayService.java | 16 ++- photoweb/src/com/service/ErrorResource.java | 3 +- photoweb/src/com/service/MonthService.java | 16 ++- photoweb/src/com/service/ObjectService.java | 16 ++- .../src/com/service/RestRootWebService.java | 51 ++++++--- photoweb/src/com/service/YearService.java | 13 ++- .../src/com/service/filter/WebFilter.java | 19 ++-- .../com/service/listener/SpecialListener.java | 35 +++--- photoweb/src/com/utils/conf/AppConfig.java | 3 +- photoweb/src/com/utils/web/GenerateHTML.java | 105 ++++++++++++------ 25 files changed, 372 insertions(+), 197 deletions(-) diff --git a/photoweb/src/com/backend/BaseSqliteStore.java b/photoweb/src/com/backend/BaseSqliteStore.java index 5699e18..4afffa3 100644 --- a/photoweb/src/com/backend/BaseSqliteStore.java +++ b/photoweb/src/com/backend/BaseSqliteStore.java @@ -21,7 +21,8 @@ public class BaseSqliteStore { - private static final Logger logger = LoggerFactory.getLogger(BaseSqliteStore.class); + private static final Logger logger = LoggerFactory + .getLogger(BaseSqliteStore.class); private Connection conn = SqliteConnManger.getInstance().getConn(); @@ -30,7 +31,8 @@ public class BaseSqliteStore private static BaseSqliteStore instance = new BaseSqliteStore(); // 对于树莓派等系统,最多只能2个线程同时计算缩略图。 - public static final ExecutorService threadPool = Executors.newFixedThreadPool(2); + public static final ExecutorService threadPool = Executors + .newFixedThreadPool(2); private BaseSqliteStore() { @@ -79,7 +81,7 @@ public FileInfo getOneFileByHashID(String id) { lock.readLock().unlock(); } - + return null; } @@ -112,7 +114,8 @@ private void insertOneRecord(File f, String sha256) } fi.setHash256(sha256); lock.writeLock().lock(); - prep = conn.prepareStatement("insert into files values(?,?,?,?,?,?,?);"); + prep = conn.prepareStatement( + "insert into files values(?,?,?,?,?,?,?);"); prep.setString(1, fi.getPath()); prep.setString(2, fi.getHash256()); prep.setLong(3, fi.getSize()); @@ -167,14 +170,16 @@ public boolean checkIfAlreadyExist(File f) { FileInfo oldfi = getFileInfoFromTable(res); if (oldfi.getSize() == f.length() && oldfi.getcTime() != null - && oldfi.getcTime().getTime() == FileTools.getFileCreateTime(f)) + && oldfi.getcTime().getTime() == FileTools + .getFileCreateTime(f)) { checkPhotoTime(oldfi); return true; } else { - logger.warn("the file was changed, rebuild the record: " + oldfi); + logger.warn("the file was changed, rebuild the record: " + + oldfi); deleteOneRecord(oldfi); return false; } @@ -239,7 +244,8 @@ private void checkPhotoTime(FileInfo oldfi) throws IOException { boolean bneedupdate = false; if (oldfi.getPhotoTime() == null || oldfi.getcTime() == null - || oldfi.getPhotoTime().getTime() > System.currentTimeMillis()) + || oldfi.getPhotoTime().getTime() > System + .currentTimeMillis()) { oldfi = ReadEXIF.genAllInfos(oldfi.getPath(), true); bneedupdate = true; @@ -260,8 +266,8 @@ private void updatePhotoInfo(FileInfo fi) try { lock.writeLock().lock(); - PreparedStatement prep = conn - .prepareStatement("update files set phototime=?,width=?,height=? where path=?;"); + PreparedStatement prep = conn.prepareStatement( + "update files set phototime=?,width=?,height=? where path=?;"); prep.setDate(1, fi.getPhotoTime()); prep.setLong(2, fi.getWidth()); prep.setLong(3, fi.getHeight()); @@ -302,7 +308,8 @@ public void scanAllRecords(List excludeDirs) } else { - if (ThumbnailManager.checkTheThumbnailExist(fi.getHash256())) + if (ThumbnailManager + .checkTheThumbnailExist(fi.getHash256())) { PerformanceStatistics.getInstance().addOneFile(false); continue; @@ -314,7 +321,8 @@ public void scanAllRecords(List excludeDirs) } } prep.close(); - PerformanceStatistics.getInstance().printPerformanceLog(System.currentTimeMillis()); + PerformanceStatistics.getInstance() + .printPerformanceLog(System.currentTimeMillis()); logger.warn("end checking all records in the files table."); } catch (Exception e) @@ -330,7 +338,8 @@ private void submitAnThumbnailTask(final FileInfo fi) isdone = GloableLockBaseOnString.getInstance().tryToDo(fi.getHash256()); if (!isdone) { - logger.info("the task of pic id [{}] is already being done.", fi.getHash256()); + logger.info("the task of pic id [{}] is already being done.", + fi.getHash256()); return; } @@ -390,7 +399,8 @@ public void deleteRecordsInDirs(String dir) try { lock.writeLock().lock(); - prep = conn.prepareStatement("delete from files where path like ?;"); + prep = conn + .prepareStatement("delete from files where path like ?;"); prep.setString(1, dir + "%"); prep.execute(); diff --git a/photoweb/src/com/backend/DateRecords.java b/photoweb/src/com/backend/DateRecords.java index 3a29d3f..fc583f5 100644 --- a/photoweb/src/com/backend/DateRecords.java +++ b/photoweb/src/com/backend/DateRecords.java @@ -53,7 +53,8 @@ public int hashCode() final int prime = 31; int result = 1; result = prime * result + ((datestr == null) ? 0 : datestr.hashCode()); - result = prime * result + ((datetype == null) ? 0 : datetype.hashCode()); + result = prime * result + + ((datetype == null) ? 0 : datetype.hashCode()); return result; } diff --git a/photoweb/src/com/backend/DateTableDao.java b/photoweb/src/com/backend/DateTableDao.java index ee6c65c..038e07e 100644 --- a/photoweb/src/com/backend/DateTableDao.java +++ b/photoweb/src/com/backend/DateTableDao.java @@ -16,7 +16,8 @@ public class DateTableDao { - private static final Logger logger = LoggerFactory.getLogger(DateTableDao.class); + private static final Logger logger = LoggerFactory + .getLogger(DateTableDao.class); private Connection conn = SqliteConnManger.getInstance().getConn(); @@ -58,7 +59,8 @@ public TreeMap>> getAllDate String month = date.substring(4, 6); String year = date.substring(0, 4); - TreeMap> myear = allrecords.get(year); + TreeMap> myear = allrecords + .get(year); if (myear == null) { myear = new TreeMap>(); @@ -106,7 +108,8 @@ public DateRecords getOneRecordsByDay(String day) ResultSet res = null; try { - prep = conn.prepareStatement("select * from daterecords where datestr=?;"); + prep = conn.prepareStatement( + "select * from daterecords where datestr=?;"); prep.setString(1, day); res = prep.executeQuery(); @@ -138,7 +141,8 @@ public void refreshDate() { logger.warn("refresh all date record."); - Map dst = UniqPhotosStore.getInstance().genAllDateRecords(); + Map dst = UniqPhotosStore.getInstance() + .genAllDateRecords(); if (dst == null || dst.isEmpty()) { logger.warn("there is no pic."); @@ -153,7 +157,8 @@ public void refreshDate() prep.execute(); prep.close(); - prep = conn.prepareStatement("insert into daterecords values(?,?,?);"); + prep = conn + .prepareStatement("insert into daterecords values(?,?,?);"); for (Entry dr : dst.entrySet()) { prep.setString(1, dr.getKey()); diff --git a/photoweb/src/com/backend/ExifCreator.java b/photoweb/src/com/backend/ExifCreator.java index 99ebe14..1e29e0e 100644 --- a/photoweb/src/com/backend/ExifCreator.java +++ b/photoweb/src/com/backend/ExifCreator.java @@ -29,7 +29,8 @@ public class ExifCreator { - private static final Logger logger = LoggerFactory.getLogger(ExifCreator.class); + private static final Logger logger = LoggerFactory + .getLogger(ExifCreator.class); public static void addExifDate(String[] args) throws Exception { @@ -88,7 +89,8 @@ public static void addExifDate(String[] args) throws Exception if (!(imageInfo instanceof Exif)) { logger.info("Adding a Dummy Exif Header"); - llj.addAppx(LLJTran.dummyExifHeader, 0, LLJTran.dummyExifHeader.length, true); + llj.addAppx(LLJTran.dummyExifHeader, 0, + LLJTran.dummyExifHeader.length, true); imageInfo = llj.getImageInfo(); // This would have changed Exif exif = (Exif) imageInfo; @@ -118,7 +120,8 @@ public static void addExifDate(String[] args) throws Exception } // 4. Set the new Thumbnail - if (llj.setThumbnail(newThumbnail, 0, newThumbnail.length, ImageResources.EXT_JPG)) + if (llj.setThumbnail(newThumbnail, 0, newThumbnail.length, + ImageResources.EXT_JPG)) logger.info("Successfully Set New Thumbnail"); else logger.info("Error Setting New Thumbnail"); @@ -126,7 +129,8 @@ public static void addExifDate(String[] args) throws Exception // 5. Transfer the image from inputFile to outputFile replacing the new // Exif with the Thumbnail so that outputFile has a Thumbnail. fip = new BufferedInputStream(new FileInputStream(args[0])); - OutputStream out = new BufferedOutputStream(new FileOutputStream(args[1])); + OutputStream out = new BufferedOutputStream( + new FileOutputStream(args[1])); // Replace the new Exif Header in llj while copying the image from fip // to out llj.xferInfo(fip, out, LLJTran.REPLACE, LLJTran.RETAIN); @@ -168,7 +172,8 @@ private static byte[] getThumbnailImage(InputStream ip) throws IOException factor = factor1; AffineTransform tx = new AffineTransform(); tx.scale(factor, factor); - AffineTransformOp affineOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); + AffineTransformOp affineOp = new AffineTransformOp(tx, + AffineTransformOp.TYPE_NEAREST_NEIGHBOR); image = affineOp.filter(image, null); // Write Out the Scaled Image to a ByteArrayOutputStream and return the diff --git a/photoweb/src/com/backend/FileInfo.java b/photoweb/src/com/backend/FileInfo.java index e68f56b..0302223 100644 --- a/photoweb/src/com/backend/FileInfo.java +++ b/photoweb/src/com/backend/FileInfo.java @@ -50,7 +50,8 @@ public void setPhotoTime(Date photoTime) public String toString() { - return "[path: " + path + "; hahstr: " + hash256 + "; phototime: " + photoTime + "]"; + return "[path: " + path + "; hahstr: " + hash256 + "; phototime: " + + photoTime + "]"; } public long getHeight() diff --git a/photoweb/src/com/backend/FileSHA256Caculater.java b/photoweb/src/com/backend/FileSHA256Caculater.java index d4cf6ad..8092a71 100644 --- a/photoweb/src/com/backend/FileSHA256Caculater.java +++ b/photoweb/src/com/backend/FileSHA256Caculater.java @@ -14,14 +14,16 @@ public class FileSHA256Caculater { public static final int BUFFERED_SIZE = 1024 * 128; - public static String calFileSha256(File f) throws NoSuchAlgorithmException, IOException + public static String calFileSha256(File f) + throws NoSuchAlgorithmException, IOException { if (f == null || !f.exists() || f.isDirectory()) { return null; } - MessageDigest md = MessageDigest.getInstance(AppConfig.getInstance().getHashAlog()); + MessageDigest md = MessageDigest + .getInstance(AppConfig.getInstance().getHashAlog()); InputStream in = null; try { @@ -34,7 +36,8 @@ public static String calFileSha256(File f) throws NoSuchAlgorithmException, IOEx boolean bcomplete = false; while (offset < BUFFERED_SIZE) { - int readlen = in.read(buffer, offset, BUFFERED_SIZE - offset); + int readlen = in.read(buffer, offset, + BUFFERED_SIZE - offset); if (readlen < 0) { bcomplete = true; diff --git a/photoweb/src/com/backend/FileTools.java b/photoweb/src/com/backend/FileTools.java index e7198e1..c229ede 100644 --- a/photoweb/src/com/backend/FileTools.java +++ b/photoweb/src/com/backend/FileTools.java @@ -30,13 +30,16 @@ public class FileTools { - private static final Logger logger = LoggerFactory.getLogger(FileTools.class); - public static boolean usesqlite = "true".equals(System.getProperty("usesqlite", "true")) ? true : false; + private static final Logger logger = LoggerFactory + .getLogger(FileTools.class); + public static boolean usesqlite = "true" + .equals(System.getProperty("usesqlite", "true")) ? true : false; public static long lastScanTime = 0; public static final ExecutorService threadPool = Executors .newFixedThreadPool(AppConfig.getInstance().getThreadCount()); - public static void readShortFileContent(byte[] buffer, File f) throws FileNotFoundException, IOException + public static void readShortFileContent(byte[] buffer, File f) + throws FileNotFoundException, IOException { int maxLen = buffer.length; FileInputStream fin = null; @@ -70,14 +73,17 @@ public static void readShortFileContent(byte[] buffer, File f) throws FileNotFou } } - public static boolean checkFileDeleted(final FileInfo fi, List excludeDirs) throws IOException + public static boolean checkFileDeleted(final FileInfo fi, + List excludeDirs) throws IOException { if (fi != null) { File f = new File(fi.getPath()); - if (f.isFile() && f.length() > AppConfig.getInstance().getMinFileSize()) + if (f.isFile() + && f.length() > AppConfig.getInstance().getMinFileSize()) { - if (fi.getcTime().getTime() == FileTools.getFileCreateTime(new File(fi.getPath()))) + if (fi.getcTime().getTime() == FileTools + .getFileCreateTime(new File(fi.getPath()))) { if (excludeDirs != null) { @@ -116,7 +122,8 @@ private static void rotateOneFile(FileInfo fi, int angel) { String tmpFilePath = fi.getPath() + "_tmpfile"; new File(fi.getPath()).renameTo(new File(tmpFilePath)); - ExifCreator.addExifDate(new String[] { tmpFilePath, fi.getPath(), sf.format(fi.getPhotoTime()) }); + ExifCreator.addExifDate(new String[] { tmpFilePath, fi.getPath(), + sf.format(fi.getPhotoTime()) }); } catch (Exception e) @@ -132,8 +139,10 @@ public static long getFileCreateTime(File f) throws IOException return -1; } - Path path = FileSystems.getDefault().getPath(f.getParent(), f.getName()); - BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); + Path path = FileSystems.getDefault().getPath(f.getParent(), + f.getName()); + BasicFileAttributes attrs = Files.readAttributes(path, + BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); return attrs.creationTime().toMillis(); } @@ -163,10 +172,12 @@ public static void rotatePhonePhoto(String fullPath, int angel) Rectangle rect_des = new Rectangle(new Dimension(swidth, sheight)); - BufferedImage res = new BufferedImage(rect_des.width, rect_des.height, BufferedImage.TYPE_INT_RGB); + BufferedImage res = new BufferedImage(rect_des.width, + rect_des.height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = res.createGraphics(); - g2.translate((rect_des.width - src_width) / 2, (rect_des.height - src_height) / 2); + g2.translate((rect_des.width - src_width) / 2, + (rect_des.height - src_height) / 2); g2.rotate(Math.toRadians(angel), src_width / 2, src_height / 2); g2.drawImage(src, null, null); diff --git a/photoweb/src/com/backend/PerformanceStatistics.java b/photoweb/src/com/backend/PerformanceStatistics.java index 8db9f66..337e13b 100644 --- a/photoweb/src/com/backend/PerformanceStatistics.java +++ b/photoweb/src/com/backend/PerformanceStatistics.java @@ -7,10 +7,12 @@ public class PerformanceStatistics { - private static final Logger logger = LoggerFactory.getLogger(PerformanceStatistics.class); + private static final Logger logger = LoggerFactory + .getLogger(PerformanceStatistics.class); private volatile AtomicLong totalFileCount = new AtomicLong(0); private volatile AtomicLong careFileCount = new AtomicLong(0); - private volatile AtomicLong timenow = new AtomicLong(System.currentTimeMillis()); + private volatile AtomicLong timenow = new AtomicLong( + System.currentTimeMillis()); private static PerformanceStatistics instance = new PerformanceStatistics(); @@ -55,6 +57,7 @@ public void addOneFile(boolean isCare) public void printPerformanceLog(long now) { timenow.set(now); - logger.warn("total file count: " + totalFileCount.get() + " checked file count: " + careFileCount.get()); + logger.warn("total file count: " + totalFileCount.get() + + " checked file count: " + careFileCount.get()); } } diff --git a/photoweb/src/com/backend/ReadEXIF.java b/photoweb/src/com/backend/ReadEXIF.java index cde2b86..0ac4730 100644 --- a/photoweb/src/com/backend/ReadEXIF.java +++ b/photoweb/src/com/backend/ReadEXIF.java @@ -22,7 +22,8 @@ public class ReadEXIF { - private static final Logger logger = LoggerFactory.getLogger(ReadEXIF.class); + private static final Logger logger = LoggerFactory + .getLogger(ReadEXIF.class); public static FileInfo genAllInfos(String filePath, boolean needExif) { @@ -44,7 +45,8 @@ public static FileInfo genAllInfos(String filePath, boolean needExif) fi = new FileInfo(); fi.setPath(f.getCanonicalPath()); fi.setSize(f.length()); - fi.setcTime(new java.sql.Date(FileTools.getFileCreateTime(new File(fi.getPath())))); + fi.setcTime(new java.sql.Date( + FileTools.getFileCreateTime(new File(fi.getPath())))); if (needExif) { try @@ -69,7 +71,8 @@ public static FileInfo genAllInfos(String filePath, boolean needExif) return fi; } - private static void getInfo(Metadata metadata, FileInfo fi) throws MetadataException, IOException + private static void getInfo(Metadata metadata, FileInfo fi) + throws MetadataException, IOException { Iterable dirs = metadata.getDirectories(); boolean getheightandweight = false; @@ -94,13 +97,15 @@ else if (dir instanceof ExifSubIFDDirectory) { if (dir.containsTag(ExifDirectoryBase.TAG_IMAGE_HEIGHT)) { - fi.setHeight(dir.getInt(ExifDirectoryBase.TAG_IMAGE_HEIGHT)); + fi.setHeight(dir.getInt( + ExifDirectoryBase.TAG_IMAGE_HEIGHT)); getheightandweight = true; } if (dir.containsTag(ExifDirectoryBase.TAG_IMAGE_WIDTH)) { - fi.setWidth(dir.getInt(ExifDirectoryBase.TAG_IMAGE_WIDTH)); + fi.setWidth(dir + .getInt(ExifDirectoryBase.TAG_IMAGE_WIDTH)); getheightandweight = true; } } @@ -112,13 +117,15 @@ else if (dir instanceof ExifSubIFDDirectory) { if (dir.containsTag(JpegDirectory.TAG_IMAGE_HEIGHT)) { - fi.setHeight(dir.getInt(JpegDirectory.TAG_IMAGE_HEIGHT)); + fi.setHeight( + dir.getInt(JpegDirectory.TAG_IMAGE_HEIGHT)); getheightandweight = true; } if (dir.containsTag(JpegDirectory.TAG_IMAGE_WIDTH)) { - fi.setWidth(dir.getInt(JpegDirectory.TAG_IMAGE_WIDTH)); + fi.setWidth( + dir.getInt(JpegDirectory.TAG_IMAGE_WIDTH)); getheightandweight = true; } } @@ -127,13 +134,15 @@ else if (dir instanceof ExifSubIFDDirectory) { if (dir.containsTag(PngDirectory.TAG_IMAGE_HEIGHT)) { - fi.setHeight(dir.getInt(PngDirectory.TAG_IMAGE_HEIGHT)); + fi.setHeight( + dir.getInt(PngDirectory.TAG_IMAGE_HEIGHT)); getheightandweight = true; } if (dir.containsTag(PngDirectory.TAG_IMAGE_WIDTH)) { - fi.setWidth(dir.getInt(PngDirectory.TAG_IMAGE_WIDTH)); + fi.setWidth( + dir.getInt(PngDirectory.TAG_IMAGE_WIDTH)); getheightandweight = true; } } @@ -195,11 +204,13 @@ public static int needRotateAngel(String path) { try { - Metadata metadata = ImageMetadataReader.readMetadata(new File(path)); + Metadata metadata = ImageMetadataReader + .readMetadata(new File(path)); Iterable dirs = metadata.getDirectories(); for (Directory dir : dirs) { - if (dir instanceof ExifDirectoryBase && dir.containsTag(ExifDirectoryBase.TAG_ORIENTATION)) + if (dir instanceof ExifDirectoryBase + && dir.containsTag(ExifDirectoryBase.TAG_ORIENTATION)) { int angel = dir.getInt(ExifDirectoryBase.TAG_ORIENTATION); if (angel == 3) diff --git a/photoweb/src/com/backend/SqliteConnManger.java b/photoweb/src/com/backend/SqliteConnManger.java index b9410e1..3b0bcc5 100644 --- a/photoweb/src/com/backend/SqliteConnManger.java +++ b/photoweb/src/com/backend/SqliteConnManger.java @@ -9,7 +9,8 @@ public class SqliteConnManger { - private static final Logger logger = LoggerFactory.getLogger(SqliteConnManger.class); + private static final Logger logger = LoggerFactory + .getLogger(SqliteConnManger.class); private Connection conn; diff --git a/photoweb/src/com/backend/ThumbnailGenerator.java b/photoweb/src/com/backend/ThumbnailGenerator.java index a715b57..13df9cc 100644 --- a/photoweb/src/com/backend/ThumbnailGenerator.java +++ b/photoweb/src/com/backend/ThumbnailGenerator.java @@ -18,9 +18,11 @@ public class ThumbnailGenerator { - private static final Logger logger = LoggerFactory.getLogger(ThumbnailGenerator.class); + private static final Logger logger = LoggerFactory + .getLogger(ThumbnailGenerator.class); - public static BufferedImage generateThumbnail(String fpath, int w, int h, boolean force) throws IOException + public static BufferedImage generateThumbnail(String fpath, int w, int h, + boolean force) throws IOException { File imgFile = new File(fpath); checkPicType(imgFile); @@ -45,13 +47,17 @@ public static BufferedImage generateThumbnail(String fpath, int w, int h, boolea if ((width * 1.0) / w > (height * 1.0) / h) { - h = Integer.parseInt(new java.text.DecimalFormat("0").format(height * w / (width * 1.0))); - logger.debug("change image's height, width:{}, height:{}.", w, h); + h = Integer.parseInt(new java.text.DecimalFormat("0") + .format(height * w / (width * 1.0))); + logger.debug("change image's height, width:{}, height:{}.", w, + h); } else { - w = Integer.parseInt(new java.text.DecimalFormat("0").format(width * h / (height * 1.0))); - logger.debug("change image's width, width:{}, height:{}.", w, h); + w = Integer.parseInt(new java.text.DecimalFormat("0") + .format(width * h / (height * 1.0))); + logger.debug("change image's width, width:{}, height:{}.", w, + h); } } @@ -73,19 +79,24 @@ private static String checkPicType(File imgFile) throws IOException // 获取图片后缀 if (imgFile.getName().indexOf(".") > -1) { - suffix = imgFile.getName().substring(imgFile.getName().lastIndexOf(".") + 1); + suffix = imgFile.getName() + .substring(imgFile.getName().lastIndexOf(".") + 1); } - if (suffix == null || types.toLowerCase().indexOf(suffix.toLowerCase()) < 0) + if (suffix == null + || types.toLowerCase().indexOf(suffix.toLowerCase()) < 0) { - logger.error("Sorry, the image suffix is illegal. the standard image suffix is {}." + types); + logger.error( + "Sorry, the image suffix is illegal. the standard image suffix is {}." + + types); throw new IOException("the file type is not supported!"); } return suffix; } - public static InputStream generateThumbnailInputStream(String fpath, int w, int h, boolean force) + public static InputStream generateThumbnailInputStream(String fpath, int w, + int h, boolean force) { try { @@ -106,7 +117,8 @@ public static InputStream generateThumbnailInputStream(String fpath, int w, int return null; } - public static boolean createThumbnail(String fpath, String thumbnailPath, int w, int h, boolean force) + public static boolean createThumbnail(String fpath, String thumbnailPath, + int w, int h, boolean force) { try { diff --git a/photoweb/src/com/backend/ThumbnailManager.java b/photoweb/src/com/backend/ThumbnailManager.java index dbd4fcc..1f43dce 100644 --- a/photoweb/src/com/backend/ThumbnailManager.java +++ b/photoweb/src/com/backend/ThumbnailManager.java @@ -15,7 +15,8 @@ public class ThumbnailManager { - private static final Logger logger = LoggerFactory.getLogger(ThumbnailManager.class); + private static final Logger logger = LoggerFactory + .getLogger(ThumbnailManager.class); private static boolean isBaseDriValid = false; @@ -54,7 +55,8 @@ private static String getPicThumbnailPath(String id) { String dir2 = id.substring(id.length() - 2, id.length()); String dir1 = id.substring(id.length() - 4, id.length() - 2); - return baseDir + File.separator + dir1 + File.separator + dir2 + File.separator + id; + return baseDir + File.separator + dir1 + File.separator + dir2 + + File.separator + id; } public static boolean checkTheThumbnailExist(String id) @@ -97,7 +99,8 @@ public static void checkAndGenThumbnail(FileInfo fi) String tmpFile = "." + File.separator + fi.getHash256(); File tmpF = new File(tmpFile); - if (!ThumbnailGenerator.createThumbnail(fi.getPath(), tmpFile, 400, 400, false)) + if (!ThumbnailGenerator.createThumbnail(fi.getPath(), tmpFile, 400, 400, + false)) { if (!FileTools.copyFile(fi.getPath(), tmpFile)) { diff --git a/photoweb/src/com/backend/ToolMain.java b/photoweb/src/com/backend/ToolMain.java index fb1e809..8a62f1d 100644 --- a/photoweb/src/com/backend/ToolMain.java +++ b/photoweb/src/com/backend/ToolMain.java @@ -9,13 +9,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.backend.dirwathch.DirWatchService; import com.utils.conf.AppConfig; public class ToolMain { - private static final Logger logger = LoggerFactory.getLogger(ToolMain.class); + private static final Logger logger = LoggerFactory + .getLogger(ToolMain.class); - private static BaseSqliteStore metaDataStore = BaseSqliteStore.getInstance(); + private static BaseSqliteStore metaDataStore = BaseSqliteStore + .getInstance(); private static UniqPhotosStore photostore = UniqPhotosStore.getInstance(); @@ -32,16 +35,20 @@ public static void scanfiles() if (firstRun) { firstRun = false; - logger.warn("start one roundle."); + logger.warn( + "start to scan the base table one time after the program start."); filecount.set(0); PerformanceStatistics.getInstance().reset(); - List excludeDirs = AppConfig.getInstance().getExcludedir(); + List excludeDirs = AppConfig.getInstance() + .getExcludedir(); logger.warn("the exclude dirs are: " + excludeDirs); metaDataStore.scanAllRecords(excludeDirs); + logger.warn("end to scan the base table."); PerformanceStatistics.getInstance().reset(); - logger.warn("start to scan the filesystem which specified by the config file: " - + AppConfig.getInstance().getInputDir()); + logger.warn( + "start to scan the filesystem which specified by the config file: " + + AppConfig.getInstance().getInputDir()); for (String dir : AppConfig.getInstance().getInputDir()) { mapAllfiles(new File(dir), excludeDirs); @@ -51,7 +58,8 @@ public static void scanfiles() { Thread.sleep(100); } - PerformanceStatistics.getInstance().printPerformanceLog(System.currentTimeMillis()); + PerformanceStatistics.getInstance() + .printPerformanceLog(System.currentTimeMillis()); logger.warn("end to scan the filesystem."); } } @@ -71,6 +79,8 @@ public static void renewTheData() datestore.refreshDate(); logger.warn("completed one roundle."); } + logger.warn("the count of dir which is monitered is " + + DirWatchService.getInstance().getTheWatchDirCount() + "."); } public static void mapAllfiles(final File f, List excludeDirs) @@ -100,7 +110,8 @@ public void run() { if (f.getCanonicalPath().startsWith(s)) { - logger.info("this folder is execluded: " + f.getCanonicalPath()); + logger.info("this folder is execluded: " + + f.getCanonicalPath()); return; } } @@ -127,7 +138,8 @@ public static void checkOneFile(File f) boolean isCare = false; for (String s : AppConfig.getInstance().getFileSuffix()) { - if (f.getName().toLowerCase().endsWith(s) && f.length() > AppConfig.getInstance().getMinFileSize()) + if (f.getName().toLowerCase().endsWith(s) && f + .length() > AppConfig.getInstance().getMinFileSize()) { if (metaDataStore.checkIfAlreadyExist(f)) { @@ -136,7 +148,8 @@ public static void checkOneFile(File f) else { isCare = true; - metaDataStore.dealWithOneHash(f, FileSHA256Caculater.calFileSha256(f)); + metaDataStore.dealWithOneHash(f, + FileSHA256Caculater.calFileSha256(f)); } break; } diff --git a/photoweb/src/com/backend/UniqPhotosStore.java b/photoweb/src/com/backend/UniqPhotosStore.java index 4ce697c..92007ea 100644 --- a/photoweb/src/com/backend/UniqPhotosStore.java +++ b/photoweb/src/com/backend/UniqPhotosStore.java @@ -19,7 +19,8 @@ public class UniqPhotosStore { - private static final Logger logger = LoggerFactory.getLogger(UniqPhotosStore.class); + private static final Logger logger = LoggerFactory + .getLogger(UniqPhotosStore.class); private Connection conn = SqliteConnManger.getInstance().getConn(); @@ -46,7 +47,8 @@ public FileInfo getOneFileByHashStr(String id) ResultSet res = null; try { - prep = conn.prepareStatement("select * from uniqphotos1 where hashstr=?;"); + prep = conn.prepareStatement( + "select * from uniqphotos1 where hashstr=?;"); prep.setString(1, id); res = prep.executeQuery(); @@ -138,12 +140,15 @@ public List getNextNineFileByHashStr(String id, int count) if (fi != null) { - prep = conn.prepareStatement("select * from uniqphotos1 where phototime getPrevNineFileByHashStr(String id, int count) if (fi != null) { prep = conn.prepareStatement( - "select * from uniqphotos1 where phototime>? order by phototime asc limit " + count + ";"); + "select * from uniqphotos1 where phototime>? order by phototime asc limit " + + count + ";"); prep.setDate(1, fi.getPhotoTime()); } else { - prep = conn - .prepareStatement("select * from uniqphotos1 order by phototime asc limit " + count + ";"); + prep = conn.prepareStatement( + "select * from uniqphotos1 order by phototime asc limit " + + count + ";"); } res = prep.executeQuery(); @@ -243,7 +250,8 @@ public void getDupFiles() logger.warn("delete all records form uniqphotos2."); prep = conn.prepareStatement( - "insert into uniqphotos2(path,hashstr,size,phototime,width,height) " + "select path,sha256,size," + "insert into uniqphotos2(path,hashstr,size,phototime,width,height) " + + "select path,sha256,size," + "phototime,width,height from files where sha256 in(select sha256 from files group by sha256) " + "group by sha256 ORDER BY phototime DESC"); prep.execute(); @@ -258,7 +266,8 @@ public void getDupFiles() prep.close(); logger.warn("delete all records form uniqphotos1."); - prep = conn.prepareStatement("insert into uniqphotos1 select * from uniqphotos2;"); + prep = conn.prepareStatement( + "insert into uniqphotos1 select * from uniqphotos2;"); prep.execute(); prep.close(); logger.warn("insert new records to uniqphotos1."); @@ -321,7 +330,8 @@ public List getAllPhotosBy(String day) Date dend = new Date(d.getTime() + 24 * 3600 * 1000); try { - prep = conn.prepareStatement("select * from uniqphotos1 where phototime>=? and phototime=? and phototime keyMap = new ConcurrentHashMap(); private WatchService ws = null; private static DirWatchService instance = new DirWatchService(); @@ -39,7 +40,8 @@ public static DirWatchService getInstance() return instance; } - public void init(final List inputDirs, final List excludeDirs) + public void init(final List inputDirs, + final List excludeDirs) { try { @@ -122,7 +124,9 @@ public void addListener(String path) { try { - WatchKey k = p.register(ws, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE, + WatchKey k = p.register(ws, + StandardWatchEventKinds.ENTRY_MODIFY, + StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE); if (StringUtils.isNotBlank(path)) { @@ -171,11 +175,13 @@ public void run() { try { - ToolMain.mapAllfiles(cf, AppConfig.getInstance().getExcludedir()); + ToolMain.mapAllfiles(cf, AppConfig + .getInstance().getExcludedir()); } catch (Exception e) { - logger.warn("map all files of: " + fullPath + " failed, ", e); + logger.warn("map all files of: " + fullPath + + " failed, ", e); } } }); @@ -188,7 +194,8 @@ else if (kd.equals(StandardWatchEventKinds.ENTRY_DELETE)) @Override public void run() { - BaseSqliteStore.getInstance().deleteRecordsInDirs(fullPath); + BaseSqliteStore.getInstance() + .deleteRecordsInDirs(fullPath); } }); } @@ -202,7 +209,8 @@ else if (kd.equals(StandardWatchEventKinds.ENTRY_MODIFY)) @Override public void run() { - BaseSqliteStore.getInstance().checkIfAlreadyExist(cf); + BaseSqliteStore.getInstance() + .checkIfAlreadyExist(cf); } }); } @@ -228,4 +236,9 @@ public void run() } } + + public long getTheWatchDirCount() + { + return keyMap.size(); + } } diff --git a/photoweb/src/com/service/DayService.java b/photoweb/src/com/service/DayService.java index c2564ae..74e3ed2 100644 --- a/photoweb/src/com/service/DayService.java +++ b/photoweb/src/com/service/DayService.java @@ -22,7 +22,8 @@ public class DayService { - private static final Logger logger = LoggerFactory.getLogger(MonthService.class); + private static final Logger logger = LoggerFactory + .getLogger(MonthService.class); private String day; @@ -32,11 +33,12 @@ public DayService(String day) } @GET - public Response getDayIndex(@Context HttpServletRequest req, @Context HttpServletResponse response) + public Response getDayIndex(@Context HttpServletRequest req, + @Context HttpServletResponse response) { ResponseBuilder builder = Response.status(200); - TreeMap>> map = DateTableDao.getInstance() - .getAllDateRecord(); + TreeMap>> map = DateTableDao + .getInstance().getAllDateRecord(); String year = day.substring(0, 4); String month = day.substring(4, 6); String sday = day.substring(6, 8); @@ -76,8 +78,10 @@ public Response getDayIndex(@Context HttpServletRequest req, @Context HttpServle } else { - List flst = UniqPhotosStore.getInstance().getAllPhotosBy(day); - builder.entity(GenerateHTML.generateDayPage(day, prevDay, nextDay, flst)); + List flst = UniqPhotosStore.getInstance() + .getAllPhotosBy(day); + builder.entity( + GenerateHTML.generateDayPage(day, prevDay, nextDay, flst)); return builder.build(); } } diff --git a/photoweb/src/com/service/ErrorResource.java b/photoweb/src/com/service/ErrorResource.java index db32013..cedbb7e 100644 --- a/photoweb/src/com/service/ErrorResource.java +++ b/photoweb/src/com/service/ErrorResource.java @@ -11,7 +11,8 @@ public class ErrorResource { @GET - public Response get(@Context HttpServletRequest req, @Context HttpServletResponse response, InputStream body) + public Response get(@Context HttpServletRequest req, + @Context HttpServletResponse response, InputStream body) { return Response.status(500).entity("500 internel error!").build(); } diff --git a/photoweb/src/com/service/MonthService.java b/photoweb/src/com/service/MonthService.java index 0e8110e..0d21778 100644 --- a/photoweb/src/com/service/MonthService.java +++ b/photoweb/src/com/service/MonthService.java @@ -19,7 +19,8 @@ public class MonthService { - private static final Logger logger = LoggerFactory.getLogger(MonthService.class); + private static final Logger logger = LoggerFactory + .getLogger(MonthService.class); private String month; @@ -29,14 +30,16 @@ public MonthService(String month) } @GET - public Response getMonthIndex(@Context HttpServletRequest req, @Context HttpServletResponse response) + public Response getMonthIndex(@Context HttpServletRequest req, + @Context HttpServletResponse response) { ResponseBuilder builder = Response.status(200); - TreeMap>> allrecords = DateTableDao.getInstance() - .getAllDateRecord(); + TreeMap>> allrecords = DateTableDao + .getInstance().getAllDateRecord(); String year = month.substring(0, 4); String smonth = month.substring(4, 6); - TreeMap> currentyear = allrecords.get(year); + TreeMap> currentyear = allrecords + .get(year); if (currentyear == null || currentyear.isEmpty()) { logger.info("there is no photos in this year: " + year); @@ -66,7 +69,8 @@ public Response getMonthIndex(@Context HttpServletRequest req, @Context HttpServ nextMonth = null; } - builder.entity(GenerateHTML.generateMonthPage(month, nextMonth, prevMonth, currentyear.get(smonth))); + builder.entity(GenerateHTML.generateMonthPage(month, nextMonth, + prevMonth, currentyear.get(smonth))); return builder.build(); } } diff --git a/photoweb/src/com/service/ObjectService.java b/photoweb/src/com/service/ObjectService.java index f8984c8..d8884a7 100644 --- a/photoweb/src/com/service/ObjectService.java +++ b/photoweb/src/com/service/ObjectService.java @@ -28,7 +28,8 @@ public class ObjectService { - private static final Logger logger = LoggerFactory.getLogger(ObjectService.class); + private static final Logger logger = LoggerFactory + .getLogger(ObjectService.class); private String id; @@ -38,8 +39,8 @@ public ObjectService(String id) } @GET - public Response getPhotoData(@Context HttpServletRequest req, @Context HttpServletResponse response) - throws IOException + public Response getPhotoData(@Context HttpServletRequest req, + @Context HttpServletResponse response) throws IOException { ResponseBuilder builder = Response.status(200); BaseSqliteStore meta = BaseSqliteStore.getInstance(); @@ -57,7 +58,8 @@ public Response getPhotoData(@Context HttpServletRequest req, @Context HttpServl if (fi == null) { - fi = new BufferedInputStream(new FileInputStream(new File(f.getPath()))); + fi = new BufferedInputStream( + new FileInputStream(new File(f.getPath()))); } if (fi != null) @@ -69,8 +71,10 @@ public Response getPhotoData(@Context HttpServletRequest req, @Context HttpServl long expirtime = System.currentTimeMillis() + expirAge; builder.header("Expires", new Date(expirtime)); builder.header("Cache-Control", "max-age=" + expirAge); - builder.header("Content-Disposition", "filename=" + new File(f.getPath()).getName()); - builder.header("PicFileFullPath", URLEncoder.encode(f.getPath(), "UTF-8")); + builder.header("Content-Disposition", + "filename=" + new File(f.getPath()).getName()); + builder.header("PicFileFullPath", + URLEncoder.encode(f.getPath(), "UTF-8")); logger.info("the file is: {}, Mime: {}", f, contenttype); } } diff --git a/photoweb/src/com/service/RestRootWebService.java b/photoweb/src/com/service/RestRootWebService.java index ade5878..8246763 100644 --- a/photoweb/src/com/service/RestRootWebService.java +++ b/photoweb/src/com/service/RestRootWebService.java @@ -27,16 +27,19 @@ import com.utils.conf.AppConfig; import com.utils.web.GenerateHTML; -@Produces(value = { "text/xml", "application/json", "application/xml", "text/html" }) +@Produces(value = { "text/xml", "application/json", "application/xml", + "text/html" }) public class RestRootWebService extends HttpServlet { - private static final Logger logger = LoggerFactory.getLogger(RestRootWebService.class); + private static final Logger logger = LoggerFactory + .getLogger(RestRootWebService.class); private static final long serialVersionUID = -7748065720779404006L; @GET @Path("/favicon.ico") - public Response getFavicon(@Context HttpServletRequest req, @Context HttpServletResponse response) + public Response getFavicon(@Context HttpServletRequest req, + @Context HttpServletResponse response) { logger.debug("getFavicon in!"); ResponseBuilder builder = null; @@ -58,7 +61,8 @@ public Response getFavicon(@Context HttpServletRequest req, @Context HttpServlet @GET @Path("/") - public Response getMsg(@Context HttpServletRequest req, @Context HttpServletResponse response) throws IOException + public Response getMsg(@Context HttpServletRequest req, + @Context HttpServletResponse response) throws IOException { ResponseBuilder builder = Response.status(200); String body = GenerateHTML.genneateIndex(getFileList(req)); @@ -91,10 +95,12 @@ public List getFileList(HttpServletRequest req) if (StringUtils.isNotBlank(next)) { - lst = UniqPhotosStore.getInstance().getNextNineFileByHashStr(next, count); + lst = UniqPhotosStore.getInstance().getNextNineFileByHashStr(next, + count); if (lst == null || lst.isEmpty()) { - lst = UniqPhotosStore.getInstance().getNextNineFileByHashStr(null, count); + lst = UniqPhotosStore.getInstance() + .getNextNineFileByHashStr(null, count); } return lst; @@ -103,21 +109,26 @@ public List getFileList(HttpServletRequest req) String prev = req.getParameter("prev"); if (StringUtils.isNotBlank(prev)) { - lst = UniqPhotosStore.getInstance().getPrevNineFileByHashStr(prev, count); + lst = UniqPhotosStore.getInstance().getPrevNineFileByHashStr(prev, + count); if (lst == null || lst.isEmpty()) { - lst = UniqPhotosStore.getInstance().getPrevNineFileByHashStr(null, count); + lst = UniqPhotosStore.getInstance() + .getPrevNineFileByHashStr(null, count); } return lst; } - return UniqPhotosStore.getInstance().getNextNineFileByHashStr(null, count); + return UniqPhotosStore.getInstance().getNextNineFileByHashStr(null, + count); } @Path("/photos/{id}") - public Object getPhoto(@PathParam("id") String id, @Context HttpServletRequest req, - @Context HttpServletResponse response, @Context HttpHeaders headers, InputStream body) + public Object getPhoto(@PathParam("id") String id, + @Context HttpServletRequest req, + @Context HttpServletResponse response, @Context HttpHeaders headers, + InputStream body) { if (StringUtils.isNotBlank(id)) { @@ -130,8 +141,10 @@ public Object getPhoto(@PathParam("id") String id, @Context HttpServletRequest r } @Path("/year/{year}") - public Object getYearView(@PathParam("year") String year, @Context HttpServletRequest req, - @Context HttpServletResponse response, @Context HttpHeaders headers, InputStream body) + public Object getYearView(@PathParam("year") String year, + @Context HttpServletRequest req, + @Context HttpServletResponse response, @Context HttpHeaders headers, + InputStream body) { if (StringUtils.isNotBlank(year)) { @@ -144,8 +157,10 @@ public Object getYearView(@PathParam("year") String year, @Context HttpServletRe } @Path("/month/{month}") - public Object getMonthView(@PathParam("month") String month, @Context HttpServletRequest req, - @Context HttpServletResponse response, @Context HttpHeaders headers, InputStream body) + public Object getMonthView(@PathParam("month") String month, + @Context HttpServletRequest req, + @Context HttpServletResponse response, @Context HttpHeaders headers, + InputStream body) { if (StringUtils.isNotBlank(month) && month.length() == 6) { @@ -158,8 +173,10 @@ public Object getMonthView(@PathParam("month") String month, @Context HttpServle } @Path("/day/{day}") - public Object getDayView(@PathParam("day") String day, @Context HttpServletRequest req, - @Context HttpServletResponse response, @Context HttpHeaders headers, InputStream body) + public Object getDayView(@PathParam("day") String day, + @Context HttpServletRequest req, + @Context HttpServletResponse response, @Context HttpHeaders headers, + InputStream body) { if (StringUtils.isNotBlank(day) && day.length() == 8) { diff --git a/photoweb/src/com/service/YearService.java b/photoweb/src/com/service/YearService.java index 9ea5326..1348f73 100644 --- a/photoweb/src/com/service/YearService.java +++ b/photoweb/src/com/service/YearService.java @@ -18,7 +18,8 @@ public class YearService { - private static final Logger logger = LoggerFactory.getLogger(YearService.class); + private static final Logger logger = LoggerFactory + .getLogger(YearService.class); private String year; @@ -28,12 +29,14 @@ public YearService(String year) } @GET - public Response getYearIndex(@Context HttpServletRequest req, @Context HttpServletResponse response) + public Response getYearIndex(@Context HttpServletRequest req, + @Context HttpServletResponse response) { ResponseBuilder builder = Response.status(200); - TreeMap>> allrecords = DateTableDao.getInstance() - .getAllDateRecord(); - TreeMap> currentyear = allrecords.get(year); + TreeMap>> allrecords = DateTableDao + .getInstance().getAllDateRecord(); + TreeMap> currentyear = allrecords + .get(year); if (currentyear == null || currentyear.isEmpty() || year.length() != 4) { logger.info("there is no photos in this year: " + year); diff --git a/photoweb/src/com/service/filter/WebFilter.java b/photoweb/src/com/service/filter/WebFilter.java index dced705..341e35b 100644 --- a/photoweb/src/com/service/filter/WebFilter.java +++ b/photoweb/src/com/service/filter/WebFilter.java @@ -20,7 +20,8 @@ public class WebFilter implements Filter { - private static final Logger logger = LoggerFactory.getLogger(WebFilter.class); + private static final Logger logger = LoggerFactory + .getLogger(WebFilter.class); private static final String REQEUSTIDKEY = "requestid"; @@ -31,26 +32,30 @@ public void destroy() } @Override - public void doFilter(ServletRequest req, ServletResponse res, FilterChain chains) - throws IOException, ServletException + public void doFilter(ServletRequest req, ServletResponse res, + FilterChain chains) throws IOException, ServletException { try { MDC.put(REQEUSTIDKEY, UUIDGenerator.getUUID()); - logger.warn("get a request: " + System.nanoTime() + " the remote port is: " + req.getRemotePort()); + logger.warn("get a request: " + System.nanoTime() + + " the remote port is: " + req.getRemotePort()); - if (!(req instanceof HttpServletRequest) || !(res instanceof HttpServletResponse)) + if (!(req instanceof HttpServletRequest) + || !(res instanceof HttpServletResponse)) { logger.error("got an not request not http."); return; } - ((HttpServletResponse) res).setHeader("Request-ID", (String) MDC.get(REQEUSTIDKEY)); + ((HttpServletResponse) res).setHeader("Request-ID", + (String) MDC.get(REQEUSTIDKEY)); chains.doFilter(req, res); - logger.warn("done a request: " + System.nanoTime() + " the remote port is: " + req.getRemotePort()); + logger.warn("done a request: " + System.nanoTime() + + " the remote port is: " + req.getRemotePort()); } finally { diff --git a/photoweb/src/com/service/listener/SpecialListener.java b/photoweb/src/com/service/listener/SpecialListener.java index 12a93da..2f2e92f 100644 --- a/photoweb/src/com/service/listener/SpecialListener.java +++ b/photoweb/src/com/service/listener/SpecialListener.java @@ -18,7 +18,8 @@ public class SpecialListener implements ServletContextListener { - private static Logger logger = LoggerFactory.getLogger(SpecialListener.class); + private static Logger logger = LoggerFactory + .getLogger(SpecialListener.class); private static Future f = null; @@ -43,9 +44,10 @@ public void contextInitialized(ServletContextEvent arg0) private void startBackGroundTask() { - DirWatchService.getInstance().init(AppConfig.getInstance().getInputDir(), + DirWatchService.getInstance().init( + AppConfig.getInstance().getInputDir(), AppConfig.getInstance().getExcludedir()); - + // 全盘扫描,每次启动时执行一次。 new Thread() { @@ -63,19 +65,20 @@ public void run() }.start(); // 300秒定期刷新新数据表。 - f = new ScheduledThreadPoolExecutor(1).scheduleWithFixedDelay(new Runnable() - { - public void run() - { - try + f = new ScheduledThreadPoolExecutor(1) + .scheduleWithFixedDelay(new Runnable() { - ToolMain.renewTheData(); - } - catch (Throwable e) - { - logger.error("caught: ", e); - } - } - }, 10, 300, TimeUnit.SECONDS); + public void run() + { + try + { + ToolMain.renewTheData(); + } + catch (Throwable e) + { + logger.error("caught: ", e); + } + } + }, 10, 300, TimeUnit.SECONDS); } } diff --git a/photoweb/src/com/utils/conf/AppConfig.java b/photoweb/src/com/utils/conf/AppConfig.java index cf61c03..6766d11 100644 --- a/photoweb/src/com/utils/conf/AppConfig.java +++ b/photoweb/src/com/utils/conf/AppConfig.java @@ -12,7 +12,8 @@ public class AppConfig { - private static final Logger logger = LoggerFactory.getLogger(AppConfig.class); + private static final Logger logger = LoggerFactory + .getLogger(AppConfig.class); public static final String configFilePath = "jalbum.xml"; diff --git a/photoweb/src/com/utils/web/GenerateHTML.java b/photoweb/src/com/utils/web/GenerateHTML.java index 3ee48b5..802d143 100644 --- a/photoweb/src/com/utils/web/GenerateHTML.java +++ b/photoweb/src/com/utils/web/GenerateHTML.java @@ -37,12 +37,18 @@ public static String genneateIndex(List flst) sb.append(getHtmlHead()); sb.append( ""); - sb.append(""); - sb.append(""); + sb.append(""); - sb.append("
上一页" + firstP.getPhotoTime() + " ~ " + endP.getPhotoTime() + sb.append( + "
上一页" + + firstP.getPhotoTime() + " ~ " + endP.getPhotoTime() + "下一页
"); + sb.append("下一页"); sb.append("

"); sb.append( ""); @@ -57,9 +63,12 @@ public static String genneateIndex(List flst) sb.append(""); } - sb.append(""); if ((i + 1) % 5 == 0) @@ -90,8 +99,8 @@ public static String getHtmlHead() + " " + "相册"; - TreeMap>> allrecords = DateTableDao.getInstance() - .getAllDateRecord(); + TreeMap>> allrecords = DateTableDao + .getInstance().getAllDateRecord(); if (allrecords != null && !allrecords.isEmpty()) { StringBuffer ylst = new StringBuffer( @@ -113,7 +122,8 @@ public static String getHtmlHead() if (i == 0) { - ylst.append(""); i++; } @@ -182,19 +192,26 @@ public static String generateSinglePhoto(FileInfo f) sb.append("

"); - sb.append(""); - sb.append("
"); + sb.append("
"); + sb.append("" + "
"); + ylst.append( + ""); ylst.append("首页
"); - sb.append(""); - sb.append(""); - sb.append("
上一张" + f.getPhotoTime() + "下一张
"); + sb.append( + "上一张"); + sb.append("" + + f.getPhotoTime() + ""); + sb.append( + "下一张"); sb.append("

"); sb.append(""); sb.append(""); - sb.append("

"); - sb.append(""); - sb.append("
"); + sb.append("
"); + sb.append("" + "
"); sb.append(getHtmlFoot()); @@ -202,7 +219,8 @@ public static String generateSinglePhoto(FileInfo f) } } - public static String generateYearPage(String year, TreeMap> currentyear) + public static String generateYearPage(String year, + TreeMap> currentyear) { if (currentyear == null || currentyear.isEmpty()) { @@ -243,10 +261,13 @@ public static String generateYearPage(String year, TreeMap"); + sb.append( + ""); sb.append(""); - sb.append("" + "
" + year + "-" + mo + "月份 (" + filecount + sb.append("" + + "
" + year + "-" + mo + "月份 (" + filecount + "张)"); } if ((i + 1) % 4 == 0) @@ -269,7 +290,8 @@ public static String generateYearPage(String year, TreeMap flst) + public static String generateDayPage(String day, String prevDay, + String nextDay, List flst) { if (flst == null || flst.isEmpty()) { @@ -281,15 +303,16 @@ public static String generateDayPage(String day, String prevDay, String nextDay, sb.append(""); sb.append(""); - sb.append(""); } - sb.append(""); if ((i + 1) % 5 == 0) @@ -331,8 +357,8 @@ public static String generateDayPage(String day, String prevDay, String nextDay, return sb.toString(); } - public static Object generateMonthPage(String monthstr, String nextMonth, String prevMonth, - TreeMap map) + public static Object generateMonthPage(String monthstr, String nextMonth, + String prevMonth, TreeMap map) { if (map == null || map.isEmpty()) { @@ -344,14 +370,16 @@ public static Object generateMonthPage(String monthstr, String nextMonth, String sb.append("
"); - sb.append("返回" + day.substring(0, 4) + "年" + day.substring(4, 6) - + "月"); + sb.append("返回" + + day.substring(0, 4) + "年" + day.substring(4, 6) + "月"); sb.append(""); if (StringUtils.isNotBlank(prevDay)) { sb.append("" + "上一天"); } sb.append("" + day + ""); + sb.append("" + day + + ""); if (StringUtils.isNotBlank(nextDay)) { sb.append("" + "下一天"); @@ -306,9 +329,12 @@ public static String generateDayPage(String day, String prevDay, String nextDay, sb.append("
"); - sb.append(""); - sb.append(""); + sb.append(""); + sb.append("" + "
"); sb.append("" + "" + ""); - sb.append(""); } if ((i + 1) % 4 == 0)
"); - sb.append("返回" + monthstr.substring(0, 4) + "年"); + sb.append("返回" + + monthstr.substring(0, 4) + "年"); sb.append(""); if (StringUtils.isNotBlank(prevMonth)) { sb.append("" + "上一月"); } sb.append("" + monthstr + "月" + ""); + sb.append("" + monthstr + + "月" + ""); if (StringUtils.isNotBlank(nextMonth)) { sb.append("" + "下一月"); @@ -378,10 +406,13 @@ public static Object generateMonthPage(String monthstr, String nextMonth, String FileInfo f = UniqPhotosStore.getInstance().getOneFileByHashStr(pic); if (f != null) { - sb.append(""); + sb.append( + ""); sb.append(""); - sb.append("" + "
" + monthstr + "-" + day + " (" + sb.append("" + + "
" + monthstr + "-" + day + " (" + mr.getPiccount() + "张)