X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=09b0cbf93e21d4eed5f7990aaae34a3800f2a6d8;hb=cb235b4dd68dccd0fceb451573aebb4137942385;hp=6a90c7afe2148864d9a5a4d0b38ebcce323501e2;hpb=4448c88ba0401366f4566eb42a850ded674f8ceb;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 6a90c7a..09b0cbf 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -39,6 +39,7 @@ import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.data.TemporaryImage; import net.pterodactylus.sone.freenet.wot.Identity; import net.pterodactylus.sone.freenet.wot.IdentityListener; import net.pterodactylus.sone.freenet.wot.IdentityManager; @@ -173,6 +174,9 @@ public class Core implements IdentityListener, UpdateListener { /** All known images. */ private Map images = new HashMap(); + /** All temporary images. */ + private Map temporaryImages = new HashMap(); + /** * Creates a new core. * @@ -799,6 +803,20 @@ public class Core implements IdentityListener, UpdateListener { } } + /** + * Returns the temporary image with the given ID. + * + * @param imageId + * The ID of the temporary image + * @return The temporary image, or {@code null} if there is no temporary + * image with the given ID + */ + public TemporaryImage getTemporaryImage(String imageId) { + synchronized (temporaryImages) { + return temporaryImages.get(imageId); + } + } + // // ACTIONS // @@ -1320,7 +1338,6 @@ public class Core implements IdentityListener, UpdateListener { } /* load albums. */ - Map albums = new HashMap(); List topLevelAlbums = new ArrayList(); while (true) { String albumPrefix = sonePrefix + "/Albums/" + albums.size(); @@ -1328,17 +1345,16 @@ public class Core implements IdentityListener, UpdateListener { if (albumId == null) { break; } - String albumName = configuration.getStringValue(albumPrefix + "/Name").getValue(null); + String albumTitle = configuration.getStringValue(albumPrefix + "/Title").getValue(null); String albumDescription = configuration.getStringValue(albumPrefix + "/Description").getValue(null); String albumParentId = configuration.getStringValue(albumPrefix + "/Parent").getValue(null); - if ((albumName == null) || (albumDescription == null)) { + if ((albumTitle == null) || (albumDescription == null)) { logger.log(Level.WARNING, "Invalid album found, aborting load!"); return; } - Album album = new Album(albumId).setSone(sone).setName(albumName).setDescription(albumDescription); - albums.put(albumId, album); + Album album = getAlbum(albumId).setSone(sone).setTitle(albumTitle).setDescription(albumDescription); if (albumParentId != null) { - Album parentAlbum = albums.get(albumParentId); + Album parentAlbum = getAlbum(albumParentId, false); if (parentAlbum == null) { logger.log(Level.WARNING, "Invalid parent album ID: " + albumParentId); return; @@ -1485,7 +1501,7 @@ public class Core implements IdentityListener, UpdateListener { for (Album album : albums) { String albumPrefix = sonePrefix + "/Albums/" + albumCounter++; configuration.getStringValue(albumPrefix + "/ID").setValue(album.getId()); - configuration.getStringValue(albumPrefix + "/Name").setValue(album.getName()); + configuration.getStringValue(albumPrefix + "/Title").setValue(album.getTitle()); configuration.getStringValue(albumPrefix + "/Description").setValue(album.getDescription()); configuration.getStringValue(albumPrefix + "/Parent").setValue(album.getParent() == null ? null : album.getParent().getId()); } @@ -1777,6 +1793,48 @@ public class Core implements IdentityListener, UpdateListener { } /** + * Creates a new temporary image. + * + * @param mimeType + * The MIME type of the temporary image + * @param imageData + * The encoded data of the image + * @return The temporary image + */ + public TemporaryImage createTemporaryImage(String mimeType, byte[] imageData) { + TemporaryImage temporaryImage = new TemporaryImage(); + temporaryImage.setMimeType(mimeType).setImageData(imageData); + synchronized (temporaryImages) { + temporaryImages.put(temporaryImage.getId(), temporaryImage); + } + return temporaryImage; + } + + /** + * Deletes the given temporary image. + * + * @param temporaryImage + * The temporary image to delete + */ + public void deteleTemporaryImage(TemporaryImage temporaryImage) { + Validation.begin().isNotNull("Temporary Image", temporaryImage).check(); + deleteTemporaryImage(temporaryImage.getId()); + } + + /** + * Deletes the temporary image with the given ID. + * + * @param imageId + * The ID of the temporary image to delete + */ + public void deleteTemporaryImage(String imageId) { + Validation.begin().isNotNull("Temporary Image ID", imageId).check(); + synchronized (temporaryImages) { + temporaryImages.remove(imageId); + } + } + + /** * Starts the core. */ public void start() {