Changeset 8792
- Timestamp:
- 03/10/10 20:51:09 (6 months ago)
- Location:
- branches/private/meddle/linkable/modules
- Files:
-
- 8 modified
-
org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/interfaces/ResourceFrame.java (modified) (2 diffs)
-
org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/resource/ResourceDataPersistType.java (modified) (2 diffs)
-
org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/resource/ResourceFilesUtil.java (modified) (9 diffs)
-
org.sophie2.base.model.book/src/test/java/org/sophie2/base/model/book/resource/r4/ResourceFilesUtilTest.java (modified) (2 diffs)
-
org.sophie2.base.model.resources.r4/src/main/java/org/sophie2/base/model/resources/r4/file/FileAccessUtil.java (modified) (1 diff)
-
org.sophie2.base.persistence/src/main/java/org/sophie2/base/persistence/commons/PersistenceUtil.java (modified) (1 diff)
-
org.sophie2.extra.func.annotations/src/main/java/org/sophie2/extra/func/annotations/logic/AnnotationsLogic.java (modified) (1 diff)
-
org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/imports/ResourceImportInfo.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/private/meddle/linkable/modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/interfaces/ResourceFrame.java
r8355 r8792 1 1 package org.sophie2.base.model.book.interfaces; 2 2 3 import java.io.File; 3 4 import java.io.IOException; 4 5 6 import org.sophie2.base.model.book.resource.ResourceDataPersistType; 7 import org.sophie2.base.model.book.resource.ResourceFilesUtil; 8 import org.sophie2.base.model.resources.r4.LocationPrefix; 5 9 import org.sophie2.base.model.resources.r4.ResourceRefR4; 6 10 import org.sophie2.base.model.resources.r4.keys.DeeplyCopied; 7 11 import org.sophie2.base.model.resources.r4.keys.TemplatedResourceRefKey; 8 12 import org.sophie2.base.persistence.commons.PersistenceOptions; 13 import org.sophie2.base.persistence.commons.PersistenceUtil; 9 14 import org.sophie2.base.persistence.ref.ValueRef; 10 15 import org.sophie2.base.persistence.storage.Storage; … … 33 38 res = destination.getChild("content"); 34 39 } 40 41 String parentLocation = options.get(PersistenceUtil.LOCATION); 42 43 if (options.isSaveMode()) { 44 ResourceRefR4 original = ref.get(); 45 46 ResourceDataPersistType type = 47 ResourceDataPersistType.getPersistType(original, parentLocation); 48 if (type == ResourceDataPersistType.LINKED_RELATIVE) { 49 ref.set(ResourceFilesUtil.getSaveableRef(parentLocation, ref.get())); 50 ResourceFilesUtil.saveLoadableResource(parentLocation, 51 ref.get().getLocation(), 52 new File(original.getLocation().substring(LocationPrefix.FILE.length()))); 53 } 54 55 } 56 35 57 super.persistR3(ref, res, options, format); 58 59 if (options.isLoadMode()) { 60 ResourceDataPersistType type = 61 ResourceDataPersistType.getPersistType(ref.get(), parentLocation); 62 if (type == ResourceDataPersistType.LINKED_RELATIVE) { 63 ref.set(ResourceFilesUtil.getLoadableRef(parentLocation, ref.get())); 64 } 65 } 36 66 } 37 67 }; -
branches/private/meddle/linkable/modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/resource/ResourceDataPersistType.java
r8787 r8792 87 87 88 88 if (ref.isRelative()) { 89 if (ref.getLocation().contains(ResourceFilesUtil.SAVEABLE_TEMPLATE)) { 90 return LINKED_RELATIVE; 91 } 92 89 93 return EMBEDDED; 90 94 } … … 92 96 if (ref.isAbsolute()) { 93 97 if (parentLocation != null) { 94 if (ResourceFilesUtil.isRelativeToParent(ref, parentLocation)) { 98 if (ResourceFilesUtil.isRelativeToParent(ref, parentLocation) 99 || ref.getLocation().contains(ResourceFilesUtil.FILES_DIRECTORY)) { 95 100 return LINKED_RELATIVE; 96 101 } -
branches/private/meddle/linkable/modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/resource/ResourceFilesUtil.java
r8787 r8792 31 31 public static final String FILES_DIRECTORY = "_files"; 32 32 33 p rivatestatic final String SAVEABLE_TEMPLATE = "${files_dir}";33 public static final String SAVEABLE_TEMPLATE = "${files_dir}"; 34 34 35 35 /** … … 113 113 } 114 114 115 /** 116 * Checks if the passed {@link ResourceRefR4} points to a resource in the directory, 117 * relative to the passed <var>parentLocation</var> 118 * 119 * @param ref 120 * The ref to check. 121 * @param parentLocation 122 * The parent location to check. 123 * @return 124 * True if the ref is relative. 125 */ 115 126 public static boolean isRelativeToParent(ResourceRefR4 ref, String parentLocation) { 116 127 File parentDir = ResourceFilesUtil.getDir(parentLocation); … … 214 225 return relative.getLocation().replace(dirName, SAVEABLE_TEMPLATE); 215 226 } 227 228 public static ResourceRefR4 getSaveableRef(String parentPath, ResourceRefR4 ref) { 229 if (parentPath == null) { 230 return ref; 231 } 232 233 int lastSeparator = parentPath.lastIndexOf(ResourceRefR4.SEPARATOR); 234 String dirName = getDirName(parentPath, lastSeparator); 235 236 ResourceRefR4 targetRef = ref; 237 if (!targetRef.getLocation().contains(dirName)) { 238 targetRef = ResourceRefR4.make(new File(getDir(parentPath), ref.getName())); 239 } 240 241 ResourceRefR4 relative = ResourceRefR4.getRelativeRef( 242 ResourceRefR4.make(parentPath), targetRef); 243 244 245 return ResourceRefR4.make( 246 relative.getLocation().replace(dirName, SAVEABLE_TEMPLATE)); 247 } 216 248 217 249 /** … … 240 272 } 241 273 274 public static ResourceRefR4 getLoadableRef(String parentPath, ResourceRefR4 loadedRef) { 275 if (parentPath == null || !loadedRef.getLocation().contains(SAVEABLE_TEMPLATE)) { 276 return loadedRef; 277 } 278 279 ResourceRefR4 absolute = ResourceRefR4.make( 280 parentPath).append(loadedRef); 281 282 int lastSeparator = parentPath.lastIndexOf(ResourceRefR4.SEPARATOR); 283 284 return ResourceRefR4.make(absolute.getLocation().replace( 285 SAVEABLE_TEMPLATE, getDirName(parentPath, lastSeparator))); 286 } 287 242 288 /** 243 289 * Saves a resource file in such a way it can be loaded in the even … … 268 314 } 269 315 270 copy(original, target );316 copy(original, target, false); 271 317 } 272 318 } … … 290 336 assert original != null && target != null; 291 337 292 copy(original, target); 293 } 294 295 296 private static void copy(File original, File target) { 338 String tmpDir = System.getProperty("java.io.tmpdir"); 339 boolean delOnExit = target.getAbsolutePath().startsWith(tmpDir); 340 copy(original, target, delOnExit); 341 } 342 343 344 private static void copy(File original, File target, boolean deleteOnExit) { 297 345 if (!original.exists()) { 298 346 return; … … 305 353 306 354 for (File file : original.listFiles()) { 307 copy(file, new File(target, file.getName()) );355 copy(file, new File(target, file.getName()), deleteOnExit); 308 356 } 309 357 } else { … … 317 365 try { 318 366 BinData.transport(new FileInputStream(original), new FileOutputStream(target)); 367 if (deleteOnExit) { 368 target.deleteOnExit(); 369 } 319 370 } catch (FileNotFoundException e) { 320 371 throw new RuntimeException(e); … … 412 463 } 413 464 414 public static void persistRefData(final ValueRef<ResourceRefR4> ref, Storage storage, 415 final PersistenceOptions options, String format) throws IOException { 416 if (options.isSaveMode() && ref.get() == null) { 417 return; 418 } 419 420 String parentLocation = options.get(PersistenceUtil.LOCATION); 421 422 ValueRef<ResourceDataPersistType> enumRef = new ValueRef<ResourceDataPersistType>(); 423 if (options.isSaveMode()) { 424 enumRef.set(ResourceDataPersistType.getPersistType(ref.get(), parentLocation)); 425 } 426 427 if (options.isLoadMode() && storage.getChild("dataType") == null) { 428 storage.child("dataType").setTextContent( 429 ResourceDataPersistType.getPersistType(ref.get(), parentLocation).name()); 430 } 431 432 MasterPersister.persist(enumRef, storage.child("dataType"), 433 options, PersistenceUtil.getStorageR3Schema(ResourceDataPersistType.class)); 434 465 public static boolean isInSaveableFormat(String location) { 466 return location.startsWith(SAVEABLE_TEMPLATE); 435 467 } 436 468 -
branches/private/meddle/linkable/modules/org.sophie2.base.model.book/src/test/java/org/sophie2/base/model/book/resource/r4/ResourceFilesUtilTest.java
r8787 r8792 79 79 * @throws Exception 80 80 */ 81 @Test 81 82 public void testIsRelativeToParent() throws Exception { 82 83 String parentLocation = "file:///home/meddle/stuff.book.s2"; … … 90 91 } 91 92 93 /** 94 * Tests the {@link ResourceFilesUtil#getSaveableRef(String, ResourceRefR4)} 95 * method. 96 * 97 * @throws Exception 98 */ 99 @Test 100 public void testGetSaveableRef() throws Exception { 101 String parentLocation = "file:///home/meddle/stuff.book.s2"; 102 ResourceRefR4 ref = ResourceRefR4.make(new File("/home/meddle/stuff_book_s2_files/stuff.dat")); 103 104 ResourceRefR4 target = 105 ResourceFilesUtil.getSaveableRef(parentLocation, ref); 106 107 assertEquals(ResourceRefR4.make( 108 ResourceRefR4.PARENT + 109 ResourceRefR4.SEPARATOR + 110 ResourceFilesUtil.SAVEABLE_TEMPLATE + 111 ResourceRefR4.SEPARATOR + 112 "stuff.dat"), target); 113 } 114 115 /** 116 * Tests the {@link ResourceFilesUtil#getLoadableRef(String, ResourceRefR4)} 117 * method. 118 * 119 * @throws Exception 120 */ 121 @Test 122 public void testGetLoadableRef() throws Exception { 123 String parentLocation = "file:///home/meddle/stuff.book.s2"; 124 ResourceRefR4 ref = ResourceRefR4.make(ResourceRefR4.PARENT + 125 ResourceRefR4.SEPARATOR + 126 ResourceFilesUtil.SAVEABLE_TEMPLATE + 127 ResourceRefR4.SEPARATOR + "stuff.dat"); 128 129 ResourceRefR4 target = 130 ResourceFilesUtil.getLoadableRef(parentLocation, ref); 131 132 assertEquals(ResourceRefR4.make( 133 new File("/home/meddle/stuff_book_s2_files/stuff.dat")), target); 134 } 135 92 136 } -
branches/private/meddle/linkable/modules/org.sophie2.base.model.resources.r4/src/main/java/org/sophie2/base/model/resources/r4/file/FileAccessUtil.java
r8777 r8792 3 3 import java.io.ByteArrayInputStream; 4 4 import java.io.File; 5 import java.io.FileNotFoundException;6 5 import java.io.FileOutputStream; 7 6 import java.io.IOException; -
branches/private/meddle/linkable/modules/org.sophie2.base.persistence/src/main/java/org/sophie2/base/persistence/commons/PersistenceUtil.java
r8078 r8792 41 41 String.class, null); 42 42 43 /** 44 * Key that provides the previous location of the persistence. 45 */ 46 public static final PersistKey<String> OLD_LOCATION = new PersistKey<String>("old-location", 47 String.class, null); 48 43 49 /** 44 50 * Gets the string identifier of the kind for persistence of the given -
branches/private/meddle/linkable/modules/org.sophie2.extra.func.annotations/src/main/java/org/sophie2/extra/func/annotations/logic/AnnotationsLogic.java
r8144 r8792 151 151 } catch (IOException e) { 152 152 DialogUtils.showExceptionDialog(source.swingComponent().get(), 153 e, "Couldn `t Export Anotation Set");153 e, "Couldn't Export Anotation Set"); 154 154 fileAccess.close(); 155 155 return false; -
branches/private/meddle/linkable/modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/imports/ResourceImportInfo.java
r8780 r8792 87 87 } 88 88 89 /** 90 * Getter of the model {@link ResourceImportType}. 91 * 92 * @return 93 * The <var>modelImportType</var>. 94 */ 89 95 public ResourceImportType getModelImportType() { 90 96 return this.modelImportType; 91 97 } 92 98 99 /** 100 * Returns true if the model is {@link ResourceImportType#LINK}ed 101 * or {@link ResourceImportType#COPY_AND_LINK}ed. 102 * 103 * @see ResourceImportInfo#getModelImportType() 104 * 105 * @return 106 * True if the model is linked. 107 */ 93 108 public boolean isModelLinked() { 94 109 return this.modelImportType == ResourceImportType.LINK
