Author: mfortun Date: 2011-04-26 14:34:23 +0200 (Tue, 26 Apr 2011) New Revision: 834 Url: http://nuiton.org/repositories/revision/wikitty/834 Log: * add documentation Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java =================================================================== --- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-26 10:25:41 UTC (rev 833) +++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-26 12:34:23 UTC (rev 834) @@ -27,7 +27,6 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.net.URI; @@ -1331,14 +1330,21 @@ } /** + * Check on local file if there new file that have to be converted into + * wikitty, check wikitty if they have been modified, and check if some + * wikitty were deleted and update property * * @param starts + * the starting directory * @param label - * @throws Exception + * the current label, normaly equals to the starting directory + * @throws IOException + * if error while read file, read property */ protected void harvestNewCheckModificationsAndDeleted(File starts, - String label) throws Exception { + String label) throws IOException { + // write property directory if not exist File propertyFile = new File(starts + File.separator + PROPERTY_DIRECTORY); @@ -1347,14 +1353,17 @@ } + // create/load property file PropertiesExtended ids = getWikittyPublicationProperties(starts, WIKITTY_ID_PROPERTIES_FILE); PropertiesExtended meta = getWikittyPublicationProperties(starts, WIKITTY_FILE_META_PROPERTIES_FILE); + // set label meta.put(META_CURRENT_LABEL, label); meta.store(); + // for the child directory check on them List<String> listChildFileNonDir = new ArrayList<String>(); for (File child : starts.listFiles()) { @@ -1363,7 +1372,7 @@ harvestNewCheckModificationsAndDeleted(child, label + WIKITTYLABEL_SEPARATOR + child.getName()); } else if (!child.isDirectory()) { - + // list all of the file non dir listChildFileNonDir.add(child.getName()); // check if file is a wikitty by check if they is a id/file name // in the correct properties file @@ -1374,11 +1383,12 @@ if (!filesWikitty.contains(child.getName())) { writeWikittyFileProperties(child, null, null); } else { + // if the file is a wikitty check if there was modification checkModifications(child); } } } - // after the add of new file check for delete file + // after adding all new file, check for deleted wikitty ids = getWikittyPublicationProperties(starts, WIKITTY_ID_PROPERTIES_FILE); @@ -1386,7 +1396,8 @@ filesWikitty.addAll(CollectionUtil.toGenericCollection(ids.values(), String.class)); - // remove property of deleted wikitties + // if number of wikitty registered != number of current file (not dir) + // check for the deleted if (filesWikitty.size() != listChildFileNonDir.size()) { meta = getWikittyPublicationProperties(starts, @@ -1395,6 +1406,8 @@ filesWikitty.removeAll(listChildFileNonDir); for (String fileRemoved : filesWikitty) { + + // remove properties ids.remove(meta.get(META_PREFIX_KEY_ID + fileRemoved)); meta.remove(META_PREFIX_KEY_CHECKSUM + fileRemoved); @@ -1409,7 +1422,15 @@ } - protected void checkModifications(File child) throws IOException { + /** + * Check with the corresponding checksum if the file have been modified + * since the last check. If so, it increment the minor version of the + * wikitty and store the new checksum and version + * + * @param child the file need to check if modified + * @throws IOException + */ + protected void checkModifications(File child) throws IOException { // will check if there was modification with checksum BufferedInputStream input = new BufferedInputStream( @@ -1448,10 +1469,10 @@ * wiitty id, null if wikitty does not exist yet * @param wikittyVersion * wikitty version, null if wikitty not exist yet - * @throws Exception + * @throws IOException */ protected void writeWikittyFileProperties(File towrite, String wikittyID, - String wikittyVersion) throws Exception { + String wikittyVersion) throws IOException { if (towrite.exists() && !towrite.isDirectory()) { Wikitty wikitty = new WikittyImpl(wikittyID); @@ -1488,8 +1509,8 @@ id.store(); meta.store(); } else { - // TODO mfortun-2011-04-19 set proper type of exception - throw new Exception(); + throw new IOException(towrite.toString() + + " not exist or isn't a directory"); } } @@ -1506,7 +1527,7 @@ protected boolean createFilesFromLabelPath(String label) throws Exception { label = labelToPath(label); - + String[] pathElements = StringUtil.split(label, File.separator); boolean result = false; @@ -1528,7 +1549,9 @@ /** * Construct correctly the path from a label - * @param label the label + * + * @param label + * the label * @return the correct path */ public String labelToPath(String label) {