<modelVersion>4.0.0</modelVersion>
<groupId>net.pterodactylus</groupId>
<artifactId>sone</artifactId>
- <version>0.9.3</version>
+ <version>0.9.4</version>
<dependencies>
<dependency>
<groupId>net.pterodactylus</groupId>
<version>1.3</version>
</dependency>
<dependency>
+ <groupId>org.jsoup</groupId>
+ <artifactId>jsoup</artifactId>
+ <version>1.7.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.freenetproject</groupId>
<artifactId>fred</artifactId>
<version>0.7.5.1467.99.3</version>
/*
- * Sone - Core.java - Copyright © 2010–2013 David Roden
+ * Sone - Core.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - FreenetInterface.java - Copyright © 2010–2013 David Roden
+ * Sone - FreenetInterface.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageInserter.java - Copyright © 2011–2013 David Roden
+ * Sone - ImageInserter.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Options.java - Copyright © 2010–2013 David Roden
+ * Sone - Options.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Preferences.java - Copyright © 2013 David Roden
+ * Sone - Preferences.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneDownloader.java - Copyright © 2010–2013 David Roden
+ * Sone - SoneDownloaderImpl.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneException.java - Copyright © 2010–2013 David Roden
+ * Sone - SoneException.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneInsertException.java - Copyright © 2011–2013 David Roden
+ * Sone - SoneInsertException.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneInserter.java - Copyright © 2010–2013 David Roden
+ * Sone - SoneInserter.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
}
/* okay, apparently everything was parsed correctly. Now import. */
- /* atomic setter operation on the Sone. */
- synchronized (sone) {
- sone.setProfile(profile);
- sone.setPosts(posts);
- sone.setReplies(replies);
- sone.setLikePostIds(likedPostIds);
- sone.setLikeReplyIds(likedReplyIds);
- for (Album album : topLevelAlbums) {
- sone.getRootAlbum().addAlbum(album);
- }
+ sone.setProfile(profile);
+ sone.setPosts(posts);
+ sone.setReplies(replies);
+ sone.setLikePostIds(likedPostIds);
+ sone.setLikeReplyIds(likedReplyIds);
+ for (Album album : topLevelAlbums) {
+ sone.getRootAlbum().addAlbum(album);
}
return sone;
/*
- * Sone - SoneRescuer.java - Copyright © 2011–2013 David Roden
+ * Sone - SoneRescuer.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneUri.java - Copyright © 2013 David Roden
+ * Sone - SoneUri.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UpdateChecker.java - Copyright © 2011–2013 David Roden
+ * Sone - UpdateChecker.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - WebOfTrustUpdater.java - Copyright © 2013 David Roden
+ * Sone - WebOfTrustUpdaterImpl.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageEvent.java - Copyright © 2013 David Roden
+ * Sone - ImageEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageInsertAbortedEvent.java - Copyright © 2013 David Roden
+ * Sone - ImageInsertAbortedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageInsertFailedEvent.java - Copyright © 2013 David Roden
+ * Sone - ImageInsertFailedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageInsertFinishedEvent.java - Copyright © 2013 David Roden
+ * Sone - ImageInsertFinishedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageInsertStartedEvent.java - Copyright © 2013 David Roden
+ * Sone - ImageInsertStartedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - MarkPostKnownEvent.java - Copyright © 2013 David Roden
+ * Sone - MarkPostKnownEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - MarkPostReplyKnownEvent.java - Copyright © 2013 David Roden
+ * Sone - MarkPostReplyKnownEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - MarkSoneKnownEvent.java - Copyright © 2013 David Roden
+ * Sone - MarkSoneKnownEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - NewPostFoundEvent.java - Copyright © 2013 David Roden
+ * Sone - NewPostFoundEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - NewPostReplyFoundEvent.java - Copyright © 2013 David Roden
+ * Sone - NewPostReplyFoundEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - NewSoneFoundEvent.java - Copyright © 2013 David Roden
+ * Sone - NewSoneFoundEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostEvent.java - Copyright © 2013 David Roden
+ * Sone - PostEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostRemovedEvent.java - Copyright © 2013 David Roden
+ * Sone - PostRemovedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostReplyEvent.java - Copyright © 2013 David Roden
+ * Sone - PostReplyEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostReplyRemovedEvent.java - Copyright © 2013 David Roden
+ * Sone - PostReplyRemovedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneEvent.java - Copyright © 2013 David Roden
+ * Sone - SoneEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneInsertAbortedEvent.java - Copyright © 2013 David Roden
+ * Sone - SoneInsertAbortedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneInsertedEvent.java - Copyright © 2013 David Roden
+ * Sone - SoneInsertedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneInsertingEvent.java - Copyright © 2013 David Roden
+ * Sone - SoneInsertingEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneLockedEvent.java - Copyright © 2013 David Roden
+ * Sone - SoneLockedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneRemovedEvent.java - Copyright © 2013 David Roden
+ * Sone - SoneRemovedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneUnlockedEvent.java - Copyright © 2013 David Roden
+ * Sone - SoneUnlockedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UpdateFoundEvent.java - Copyright © 2013 David Roden
+ * Sone - UpdateFoundEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Album.java - Copyright © 2011–2013 David Roden
+ * Sone - Album.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Client.java - Copyright © 2010–2013 David Roden
+ * Sone - Client.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Fingerprintable.java - Copyright © 2011–2013 David Roden
+ * Sone - Fingerprintable.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Identified.java - Copyright © 2013 David Roden
+ * Sone - Identified.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Image.java - Copyright © 2011–2013 David Roden
+ * Sone - Image.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Post.java - Copyright © 2010–2013 David Roden
+ * Sone - Post.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostReply.java - Copyright © 2010–2013 David Roden
+ * Sone - PostReply.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Profile.java - Copyright © 2010–2013 David Roden
+ * Sone - Profile.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Reply.java - Copyright © 2010–2013 David Roden
+ * Sone - Reply.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Sone.java - Copyright © 2010–2013 David Roden
+ * Sone - Sone.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - TemporaryImage.java - Copyright © 2011–2013 David Roden
+ * Sone - TemporaryImage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AbstractAlbumBuilder.java - Copyright © 2013 David Roden
+ * Sone - AbstractAlbumBuilder.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AbstractImageBuilder.java - Copyright © 2013 David Roden
+ * Sone - AbstractImageBuilder.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AbstractPostBuilder.java - Copyright © 2013 David Roden
+ * Sone - AbstractPostBuilder.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AbstractPostReplyBuilder.java - Copyright © 2013 David Roden
+ * Sone - AbstractPostReplyBuilder.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ReplyBuilder.java - Copyright © 2013 David Roden
+ * Sone - AbstractReplyBuilder.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - MemoryAlbumBuilder.java - Copyright © 2013 David Roden
+ * Sone - AlbumBuilderImpl.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Album.java - Copyright © 2011–2013 David Roden
+ * Sone - AlbumImpl.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DefaultPostBuilderFactory.java - Copyright © 2013 David Roden
+ * Sone - DefaultPostBuilderFactory.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DefaultPostReplyBuilderFactory.java - Copyright © 2013 David Roden
+ * Sone - DefaultPostReplyBuilderFactory.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageBuilderImpl.java - Copyright © 2013 David Roden
+ * Sone - ImageBuilderImpl.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageImpl.java - Copyright © 2011–2013 David Roden
+ * Sone - ImageImpl.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostBuilderImpl.java - Copyright © 2013 David Roden
+ * Sone - PostBuilderImpl.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostImpl.java - Copyright © 2010–2013 David Roden
+ * Sone - PostImpl.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostReplyBuilderImpl.java - Copyright © 2013 David Roden
+ * Sone - PostReplyBuilderImpl.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostReplyImpl.java - Copyright © 2010–2013 David Roden
+ * Sone - PostReplyImpl.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ReplyImpl.java - Copyright © 2011–2013 David Roden
+ * Sone - ReplyImpl.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneImpl.java - Copyright © 2010–2013 David Roden
+ * Sone - SoneImpl.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AlbumBuilder.java - Copyright © 2013 David Roden
+ * Sone - AlbumBuilder.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AlbumBuilderFactory.java - Copyright © 2013 David Roden
+ * Sone - AlbumBuilderFactory.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AlbumDatabase.java - Copyright © 2013 David Roden
+ * Sone - AlbumDatabase.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AlbumProvider.java - Copyright © 2013 David Roden
+ * Sone - AlbumProvider.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AlbumStore.java - Copyright © 2013 David Roden
+ * Sone - AlbumStore.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Database.java - Copyright © 2013 David Roden
+ * Sone - Database.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DatabaseException.java - Copyright © 2013 David Roden
+ * Sone - DatabaseException.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageBuilder.java - Copyright © 2013 David Roden
+ * Sone - ImageBuilder.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageBuilderFactory.java - Copyright © 2013 David Roden
+ * Sone - ImageBuilderFactory.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageDatabase.java - Copyright © 2013 David Roden
+ * Sone - ImageDatabase.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageProvider.java - Copyright © 2013 David Roden
+ * Sone - ImageProvider.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageStore.java - Copyright © 2013 David Roden
+ * Sone - ImageStore.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostBuilder.java - Copyright © 2013 David Roden
+ * Sone - PostBuilder.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostBuilderFactory.java - Copyright © 2013 David Roden
+ * Sone - PostBuilderFactory.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostDatabase.java - Copyright © 2013 David Roden
+ * Sone - PostDatabase.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostProvider.java - Copyright © 2011–2013 David Roden
+ * Sone - PostProvider.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostReplyBuilder.java - Copyright © 2013 David Roden
+ * Sone - PostReplyBuilder.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostReplyBuilderFactory.java - Copyright © 2013 David Roden
+ * Sone - PostReplyBuilderFactory.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostReplyDatabase.java - Copyright © 2013 David Roden
+ * Sone - PostReplyDatabase.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostReplyProvider.java - Copyright © 2013 David Roden
+ * Sone - PostReplyProvider.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostReplyStore.java - Copyright © 2013 David Roden
+ * Sone - PostReplyStore.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostStore.java - Copyright © 2013 David Roden
+ * Sone - PostStore.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ReplyBuilder.java - Copyright © 2013 David Roden
+ * Sone - ReplyBuilder.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneProvider.java - Copyright © 2011–2013 David Roden
+ * Sone - SoneProvider.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - MemoryDatabase.java - Copyright © 2013 David Roden
+ * Sone - MemoryDatabase.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostImpl.java - Copyright © 2010–2013 David Roden
+ * Sone - MemoryPost.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - MemoryPostBuilder.java - Copyright © 2013 David Roden
+ * Sone - MemoryPostBuilder.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - MemoryPostReply.java - Copyright © 2013 David Roden
+ * Sone - MemoryPostReply.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - MemoryPostReplyBuilder.java - Copyright © 2013 David Roden
+ * Sone - MemoryPostReplyBuilder.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AbstractSoneCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - AbstractSoneCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - CreatePostCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - CreatePostCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - CreateReplyCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - CreateReplyCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DeletePostCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - DeletePostCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DeleteReplyCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - DeleteReplyCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - FcpInterface.java - Copyright © 2011–2013 David Roden
+ * Sone - FcpInterface.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetLocalSonesCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - GetLocalSonesCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetPostCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - GetPostCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetPostFeedCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - GetPostFeedCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetPostsCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - GetPostsCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetSoneCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - GetSoneCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetSonesCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - GetSonesCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LikePostCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - LikePostCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LikeReplyCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - LikeReplyCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LockSoneCommand.java - Copyright © 2013 David Roden
+ * Sone - LockSoneCommand.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LockSoneCommand.java - Copyright © 2013 David Roden
+ * Sone - UnlockSoneCommand.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - VersionCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - VersionCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - L10nFilter.java - Copyright © 2010–2013 David Roden
+ * Sone - L10nFilter.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PluginStoreConfigurationBackend.java - Copyright © 2010–2013 David Roden
+ * Sone - PluginStoreConfigurationBackend.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SimpleFieldSetBuilder.java - Copyright © 2011–2013 David Roden
+ * Sone - SimpleFieldSetBuilder.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AbstractCommand.java - Copyright © 2011–2013 David Roden
+ * Sone - AbstractCommand.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Command.java - Copyright © 2011–2013 David Roden
+ * Sone - Command.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - FcpException.java - Copyright © 2011–2013 David Roden
+ * Sone - FcpException.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PluginConnector.java - Copyright © 2010–2013 David Roden
+ * Sone - PluginConnector.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PluginException.java - Copyright © 2010–2013 David Roden
+ * Sone - PluginException.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ReceivedReplyEvent.java - Copyright © 2013 David Roden
+ * Sone - ReceivedReplyEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Context.java - Copyright © 2014 David Roden
+ * Sone - Context.java - Copyright © 2014–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DefaultIdentity.java - Copyright © 2010–2013 David Roden
+ * Sone - DefaultIdentity.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DefaultOwnIdentity.java - Copyright © 2010–2013 David Roden
+ * Sone - DefaultOwnIdentity.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Identity.java - Copyright © 2010–2013 David Roden
+ * Sone - Identity.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IdentityChangeDetector.java - Copyright © 2013 David Roden
+ * Sone - IdentityChangeDetector.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IdentityChangeEventSender.java - Copyright © 2013 David Roden
+ * Sone - IdentityChangeEventSender.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IdentityLoader.java - Copyright © 2013 David Roden
+ * Sone - IdentityLoader.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IdentityManager.java - Copyright © 2010–2013 David Roden
+ * Sone - IdentityManagerImpl.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - OwnIdentity.java - Copyright © 2010–2013 David Roden
+ * Sone - OwnIdentity.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Trust.java - Copyright © 2010–2013 David Roden
+ * Sone - Trust.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - WebOfTrustConnector.java - Copyright © 2010–2013 David Roden
+ * Sone - WebOfTrustConnector.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - WebOfTrustException.java - Copyright © 2010–2013 David Roden
+ * Sone - WebOfTrustException.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IdentityAddedEvent.java - Copyright © 2013 David Roden
+ * Sone - IdentityAddedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IdentityEvent.java - Copyright © 2013 David Roden
+ * Sone - IdentityEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IdentityRemovedEvent.java - Copyright © 2013 David Roden
+ * Sone - IdentityRemovedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IdentityUpdatedEvent.java - Copyright © 2013 David Roden
+ * Sone - IdentityUpdatedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - OwnIdentityAddedEvent.java - Copyright © 2013 David Roden
+ * Sone - OwnIdentityAddedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - OwnIdentityEvent.java - Copyright © 2013 David Roden
+ * Sone - OwnIdentityEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - OwnIdentityRemovedEvent.java - Copyright © 2013 David Roden
+ * Sone - OwnIdentityRemovedEvent.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
--- /dev/null
+package net.pterodactylus.sone.main;
+
+import java.io.File;
+
+import net.pterodactylus.sone.template.FilesystemTemplate;
+import net.pterodactylus.sone.web.ReloadingPage;
+import net.pterodactylus.util.template.FilesystemTemplateProvider;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateProvider;
+import net.pterodactylus.util.web.Page;
+import net.pterodactylus.util.web.Request;
+
+/**
+ * {@link Loaders} implementation that loads all resources from the filesystem.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class DebugLoaders implements Loaders {
+
+ private final String filesystemPath;
+
+ public DebugLoaders(String filesystemPath) {
+ this.filesystemPath = filesystemPath;
+ }
+
+ @Override
+ public Template loadTemplate(String path) {
+ return new FilesystemTemplate(new File(filesystemPath, path).getAbsolutePath());
+ }
+
+ @Override
+ public <REQ extends Request> Page<REQ> loadStaticPage(String basePath, String prefix, String mimeType) {
+ return new ReloadingPage<REQ>(basePath, new File(filesystemPath, prefix).getAbsolutePath(), mimeType);
+ }
+
+ @Override
+ public TemplateProvider getTemplateProvider() {
+ return new FilesystemTemplateProvider(new File(filesystemPath, "/templates/").getAbsolutePath());
+ }
+
+}
--- /dev/null
+package net.pterodactylus.sone.main;
+
+import static net.pterodactylus.util.template.TemplateParser.parse;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.util.io.Closer;
+import net.pterodactylus.util.template.ClassPathTemplateProvider;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateProvider;
+import net.pterodactylus.util.web.Page;
+import net.pterodactylus.util.web.Request;
+import net.pterodactylus.util.web.StaticPage;
+
+/**
+ * Default {@link Loaders} implementation that loads resources from the classpath.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class DefaultLoaders implements Loaders {
+
+ @Override
+ public Template loadTemplate(String path) {
+ InputStream templateInputStream = null;
+ Reader reader = null;
+ try {
+ templateInputStream = getClass().getResourceAsStream(path);
+ reader = new InputStreamReader(templateInputStream, "UTF-8");
+ return parse(reader);
+ } catch (UnsupportedEncodingException uee1) {
+ throw new RuntimeException("UTF-8 not supported.");
+ } finally {
+ Closer.close(reader);
+ Closer.close(templateInputStream);
+ }
+ }
+
+ @Override
+ public <REQ extends Request> Page<REQ> loadStaticPage(String pathPrefix, String basePath, String mimeType) {
+ return new StaticPage<REQ>(pathPrefix, basePath, mimeType) {
+ };
+ }
+
+ @Override
+ public TemplateProvider getTemplateProvider() {
+ return new ClassPathTemplateProvider(WebInterface.class, "/templates/");
+ }
+
+}
--- /dev/null
+package net.pterodactylus.sone.main;
+
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateProvider;
+import net.pterodactylus.util.web.Page;
+import net.pterodactylus.util.web.Request;
+
+import com.google.inject.ImplementedBy;
+
+/**
+ * Defines loaders for resources that can be loaded from various locations.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+@ImplementedBy(DefaultLoaders.class)
+public interface Loaders {
+
+ Template loadTemplate(String path);
+ <REQ extends Request> Page<REQ> loadStaticPage(String basePath, String prefix, String mimeType);
+ TemplateProvider getTemplateProvider();
+
+}
/*
- * Sone - SonePlugin.java - Copyright © 2010–2013 David Roden
+ * Sone - SonePlugin.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
}
/** The version. */
- public static final Version VERSION = new Version(0, 9, 3);
+ public static final Version VERSION = new Version(0, 9, 4);
/** The current year at time of release. */
private static final int YEAR = 2015;
private static final String SONE_HOMEPAGE = "USK@nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI,DuQSUZiI~agF8c-6tjsFFGuZ8eICrzWCILB60nT8KKo,AQACAAE/sone/";
- private static final int LATEST_EDITION = 70;
+ private static final int LATEST_EDITION = 71;
/** The logger. */
private static final Logger logger = getLogger(SonePlugin.class.getName());
bind(Context.class).toInstance(context);
bind(getOptionalContextTypeLiteral()).toInstance(of(context));
bind(SonePlugin.class).toInstance(SonePlugin.this);
+ if (startConfiguration.getBooleanValue("Developer.LoadFromFilesystem").getValue(false)) {
+ String path = startConfiguration.getStringValue("Developer.FilesystemPath").getValue(null);
+ if (path != null) {
+ bind(Loaders.class).toInstance(new DebugLoaders(path));
+ }
+ }
bindListener(Matchers.any(), new TypeListener() {
@Override
*/
@Override
public void terminate() {
- deregisterLoggerHandlers();
try {
/* stop the web interface. */
webInterface.stop();
webOfTrustConnector.stop();
} catch (Throwable t1) {
logger.log(Level.SEVERE, "Error while shutting down!", t1);
+ } finally {
+ deregisterLoggerHandlers();
}
}
/*
- * Sone - ListNotification.java - Copyright © 2010–2013 David Roden
+ * Sone - ListNotification.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ListNotificationFilters.java - Copyright © 2010–2013 David Roden
+ * Sone - ListNotificationFilters.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AlbumAccessor.java - Copyright © 2011–2013 David Roden
+ * Sone - AlbumAccessor.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - CollectionAccessor.java - Copyright © 2010–2013 David Roden
+ * Sone - CollectionAccessor.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - CssClassNameFilter.java - Copyright © 2010–2013 David Roden
+ * Sone - CssClassNameFilter.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
--- /dev/null
+package net.pterodactylus.sone.template;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+import net.pterodactylus.util.template.Part;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateException;
+import net.pterodactylus.util.template.TemplateParser;
+
+import freenet.support.io.Closer;
+
+import com.google.common.base.Charsets;
+
+/**
+ * {@link Template} implementation that can be reloaded from the filesystem.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class FilesystemTemplate extends Template {
+
+ private final String filename;
+ private final AtomicReference<LastLoadedTemplate> lastTemplate = new AtomicReference<LastLoadedTemplate>();
+ private final TemplateContext initialContext = new TemplateContext();
+ private final List<Part> parts = new ArrayList<Part>();
+
+ public FilesystemTemplate(String filename) {
+ this.filename = filename;
+ }
+
+ @Override
+ public TemplateContext getInitialContext() {
+ loadTemplate();
+ return initialContext;
+ }
+
+ private void loadTemplate() {
+ File templateFile = new File(filename);
+ if (!templateFile.exists()) {
+ throw new TemplateFileNotFoundException(filename);
+ }
+ if (templateWasLoaded() && !templateFileHasBeenModifiedAfterLoading(templateFile)) {
+ return;
+ }
+ InputStream templateInputStream = null;
+ Reader templateReader = null;
+ try {
+ templateInputStream = new FileInputStream(templateFile);
+ templateReader = new InputStreamReader(templateInputStream, Charsets.UTF_8);
+ Template template = TemplateParser.parse(templateReader);
+ lastTemplate.set(new LastLoadedTemplate(template));
+ template.getInitialContext().mergeContext(initialContext);
+ for (Part part : parts) {
+ template.add(part);
+ }
+ } catch (FileNotFoundException e) {
+ throw new TemplateFileNotFoundException(filename);
+ } finally {
+ Closer.close(templateReader);
+ Closer.close(templateInputStream);
+ }
+ }
+
+ private boolean templateWasLoaded() {
+ return lastTemplate.get() != null;
+ }
+
+ private boolean templateFileHasBeenModifiedAfterLoading(File templateFile) {
+ return templateFile.lastModified() > lastTemplate.get().getLoadTime();
+ }
+
+ @Override
+ public void add(Part part) {
+ loadTemplate();
+ parts.add(part);
+ lastTemplate.get().getTemplate().add(part);
+ }
+
+ @Override
+ public void render(TemplateContext templateContext, Writer writer) throws TemplateException {
+ loadTemplate();
+ lastTemplate.get().getTemplate().render(templateContext, writer);
+ }
+
+ @Override
+ public Iterator<Part> iterator() {
+ loadTemplate();
+ return lastTemplate.get().getTemplate().iterator();
+ }
+
+ @Override
+ public int getLine() {
+ loadTemplate();
+ return lastTemplate.get().getTemplate().getLine();
+ }
+
+ @Override
+ public int getColumn() {
+ loadTemplate();
+ return lastTemplate.get().getTemplate().getColumn();
+ }
+
+ private static class LastLoadedTemplate {
+
+ private final Template template;
+ private final long loadTime = System.currentTimeMillis();
+
+ private LastLoadedTemplate(Template template) {
+ this.template = template;
+ }
+
+ public Template getTemplate() {
+ return template;
+ }
+
+ public long getLoadTime() {
+ return loadTime;
+ }
+
+ }
+
+ /**
+ * Exception that signals that a template file could not be found.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+ public static class TemplateFileNotFoundException extends RuntimeException {
+
+ public TemplateFileNotFoundException(String filename) {
+ super(filename);
+ }
+
+ }
+
+}
/*
- * Sone - GetPagePlugin.java - Copyright © 2010–2013 David Roden
+ * Sone - GetPagePlugin.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - HttpRequestAccessor.java - Copyright © 2011–2013 David Roden
+ * Sone - HttpRequestAccessor.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IdentityAccessor.java - Copyright © 2010–2013 David Roden
+ * Sone - IdentityAccessor.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageAccessor.java - Copyright © 2011–2013 David Roden
+ * Sone - ImageAccessor.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageLinkFilter.java - Copyright © 2011–2013 David Roden
+ * Sone - ImageLinkFilter.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
import net.pterodactylus.util.template.TemplateContextFactory;
import net.pterodactylus.util.template.TemplateParser;
+import com.google.common.base.Function;
import com.google.common.base.Optional;
/**
if (image == null) {
return null;
}
- String imageClass = valueOf(parameters.get("class"));
+ String imageClass = Optional.fromNullable(parameters.get("class")).transform(getStringValue()).orNull();
int maxWidth = parseInt(valueOf(parameters.get("max-width")), MAX_VALUE);
int maxHeight = parseInt(valueOf(parameters.get("max-height")), MAX_VALUE);
String mode = valueOf(parameters.get("mode"));
- String title = valueOf(parameters.get("title"));
+ String title = Optional.fromNullable(parameters.get("title")).transform(getStringValue()).orNull();
TemplateContext linkTemplateContext = templateContextFactory.createTemplateContext();
linkTemplateContext.set("class", imageClass);
return stringWriter.toString();
}
+ private Function<Object, String> getStringValue() {
+ return new Function<Object, String>() {
+ @Override
+ public String apply(Object input) {
+ return (input != null) ? input.toString() : null;
+ }
+ };
+ }
+
}
/*
- * Sone - JavascriptFilter.java - Copyright © 2011–2013 David Roden
+ * Sone - JavascriptFilter.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ParserFilter.java - Copyright © 2011–2013 David Roden
+ * Sone - ParserFilter.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostAccessor.java - Copyright © 2010–2013 David Roden
+ * Sone - PostAccessor.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ProfileAccessor.java - Copyright © 2011–2013 David Roden
+ * Sone - ProfileAccessor.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ReplyAccessor.java - Copyright © 2010–2013 David Roden
+ * Sone - ReplyAccessor.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ReplyGroupFilter.java - Copyright © 2010–2013 David Roden
+ * Sone - ReplyGroupFilter.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - RequestChangeFilter.java - Copyright © 2010–2013 David Roden
+ * Sone - RequestChangeFilter.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneAccessor.java - Copyright © 2010–2013 David Roden
+ * Sone - SoneAccessor.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SubstringFilter.java - Copyright © 2010–2013 David Roden
+ * Sone - SubstringFilter.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - TrustAccessor.java - Copyright © 2010–2013 David Roden
+ * Sone - TrustAccessor.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UniqueElementFilter.java - Copyright © 2011–2013 David Roden
+ * Sone - UniqueElementFilter.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UnknownDateFilter.java - Copyright © 2011–2013 David Roden
+ * Sone - UnknownDateFilter.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - FreenetLinkPart.java - Copyright © 2011–2013 David Roden
+ * Sone - FreenetLinkPart.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LinkPart.java - Copyright © 2011–2013 David Roden
+ * Sone - LinkPart.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Parser.java - Copyright © 2010–2013 David Roden
+ * Sone - Parser.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ParserContext.java - Copyright © 2010–2013 David Roden
+ * Sone - ParserContext.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Part.java - Copyright © 2010–2013 David Roden
+ * Sone - Part.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PartContainer.java - Copyright © 2010–2013 David Roden
+ * Sone - PartContainer.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PlainTextPart.java - Copyright © 2011–2013 David Roden
+ * Sone - PlainTextPart.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PostPart.java - Copyright © 2011–2013 David Roden
+ * Sone - PostPart.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SonePart.java - Copyright © 2011–2013 David Roden
+ * Sone - SonePart.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneTextParser.java - Copyright © 2010–2013 David Roden
+ * Sone - SoneTextParser.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneTextParserContext.java - Copyright © 2011–2013 David Roden
+ * Sone - SoneTextParserContext.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - TextFilter.java - Copyright © 2011–2013 David Roden
+ * Sone - TextFilter.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IntegerRangePredicate.java - Copyright © 2013 David Roden
+ * Sone - IntegerRangePredicate.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - AboutPage.java - Copyright © 2010–2013 David Roden
+ * Sone - AboutPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - BookmarkPage.java - Copyright © 2011–2013 David Roden
+ * Sone - BookmarkPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - BookmarksPage.java - Copyright © 2011–2013 David Roden
+ * Sone - BookmarksPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - CreateAlbumPage.java - Copyright © 2011–2013 David Roden
+ * Sone - CreateAlbumPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - CreatePostPage.java - Copyright © 2010–2013 David Roden
+ * Sone - CreatePostPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - CreateReplyPage.java - Copyright © 2010–2013 David Roden
+ * Sone - CreateReplyPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - CreateSonePage.java - Copyright © 2010–2013 David Roden
+ * Sone - CreateSonePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DeleteAlbumPage.java - Copyright © 2011–2013 David Roden
+ * Sone - DeleteAlbumPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DeleteImagePage.java - Copyright © 2011–2013 David Roden
+ * Sone - DeleteImagePage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DeletePostPage.java - Copyright © 2010–2013 David Roden
+ * Sone - DeletePostPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DeleteProfileFieldPage.java - Copyright © 2011–2013 David Roden
+ * Sone - DeleteProfileFieldPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DeleteReplyPage.java - Copyright © 2010–2013 David Roden
+ * Sone - DeleteReplyPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DeleteSonePage.java - Copyright © 2010–2013 David Roden
+ * Sone - DeleteSonePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DismissNotificationPage.java - Copyright © 2010–2013 David Roden
+ * Sone - DismissNotificationPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DistrustPage.java - Copyright © 2011–2013 David Roden
+ * Sone - DistrustPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - EditAlbumPage.java - Copyright © 2011–2013 David Roden
+ * Sone - EditAlbumPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - EditImagePage.java - Copyright © 2010–2013 David Roden
+ * Sone - EditImagePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - EditProfileFieldPage.java - Copyright © 2011–2013 David Roden
+ * Sone - EditProfileFieldPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - EditProfilePage.java - Copyright © 2010–2013 David Roden
+ * Sone - EditProfilePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - FollowSonePage.java - Copyright © 2010–2013 David Roden
+ * Sone - FollowSonePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetImagePage.java - Copyright © 2011–2013 David Roden
+ * Sone - GetImagePage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ImageBrowserPage.java - Copyright © 2011–2013 David Roden
+ * Sone - ImageBrowserPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IndexPage.java - Copyright © 2010–2013 David Roden
+ * Sone - IndexPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - KnownSonesPage.java - Copyright © 2010–2013 David Roden
+ * Sone - KnownSonesPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LikePage.java - Copyright © 2010–2013 David Roden
+ * Sone - LikePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LockSonePage.java - Copyright © 2010–2013 David Roden
+ * Sone - LockSonePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LoginPage.java - Copyright © 2010–2013 David Roden
+ * Sone - LoginPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LogoutPage.java - Copyright © 2010–2013 David Roden
+ * Sone - LogoutPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - MarkAsKnownPage.java - Copyright © 2011–2013 David Roden
+ * Sone - MarkAsKnownPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - NewPage.java - Copyright © 2013 David Roden
+ * Sone - NewPage.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - OptionsPage.java - Copyright © 2010–2013 David Roden
+ * Sone - OptionsPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
--- /dev/null
+/*
+ * Sone - ReloadingPage.java - Copyright © 2010–2015 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import net.pterodactylus.util.io.Closer;
+import net.pterodactylus.util.io.StreamCopier;
+import net.pterodactylus.util.web.Page;
+import net.pterodactylus.util.web.Request;
+import net.pterodactylus.util.web.Response;
+
+/**
+ * {@link Page} implementation that delivers static files from the filesystem.
+ *
+ * @param <REQ>
+ * The type of the request
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ReloadingPage<REQ extends Request> implements Page<REQ> {
+
+ private final String pathPrefix;
+ private final String filesystemPath;
+ private final String mimeType;
+
+ public ReloadingPage(String pathPrefix, String filesystemPathPrefix, String mimeType) {
+ this.pathPrefix = pathPrefix;
+ this.filesystemPath = filesystemPathPrefix;
+ this.mimeType = mimeType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getPath() {
+ return pathPrefix;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isPrefixPage() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Response handleRequest(REQ request, Response response) throws IOException {
+ String path = request.getUri().getPath();
+ int lastSlash = path.lastIndexOf('/');
+ String filename = path.substring(lastSlash + 1);
+ InputStream fileInputStream = new FileInputStream(new File(filesystemPath, filename));
+ if (fileInputStream == null) {
+ return response.setStatusCode(404).setStatusText("Not found.");
+ }
+ OutputStream contentOutputStream = response.getContent();
+ try {
+ StreamCopier.copy(fileInputStream, contentOutputStream);
+ } finally {
+ Closer.close(fileInputStream);
+ Closer.close(contentOutputStream);
+ }
+ return response.setStatusCode(200).setStatusText("OK").setContentType(mimeType);
+ }
+}
/*
- * Sone - RescuePage.java - Copyright © 2011–2013 David Roden
+ * Sone - RescuePage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SearchPage.java - Copyright © 2010–2013 David Roden
+ * Sone - SearchPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - SoneTemplatePage.java - Copyright © 2010–2013 David Roden
+ * Sone - SoneTemplatePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - TrustPage.java - Copyright © 2011–2013 David Roden
+ * Sone - TrustPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UnbookmarkPage.java - Copyright © 2011–2013 David Roden
+ * Sone - UnbookmarkPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UnfollowSonePage.java - Copyright © 2010–2013 David Roden
+ * Sone - UnfollowSonePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UnlikePage.java - Copyright © 2010–2013 David Roden
+ * Sone - UnlikePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UnlockSonePage.java - Copyright © 2010–2013 David Roden
+ * Sone - UnlockSonePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UntrustPage.java - Copyright © 2011–2013 David Roden
+ * Sone - UntrustPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UploadImagePage.java - Copyright © 2011–2013 David Roden
+ * Sone - UploadImagePage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ViewPostPage.java - Copyright © 2010–2013 David Roden
+ * Sone - ViewPostPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - ViewSonePage.java - Copyright © 2010–2013 David Roden
+ * Sone - ViewSonePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - WebInterface.java - Copyright © 2010–2013 David Roden
+ * Sone - WebInterface.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
import static net.pterodactylus.util.template.TemplateParser.parse;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import net.pterodactylus.sone.freenet.L10nFilter;
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.freenet.wot.Trust;
+import net.pterodactylus.sone.main.Loaders;
import net.pterodactylus.sone.main.ReparseFilter;
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.sone.notify.ListNotification;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.sone.web.page.PageToadlet;
import net.pterodactylus.sone.web.page.PageToadletFactory;
-import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.notify.Notification;
import net.pterodactylus.util.notify.NotificationManager;
import net.pterodactylus.util.notify.TemplateNotification;
-import net.pterodactylus.util.template.ClassPathTemplateProvider;
import net.pterodactylus.util.template.CollectionSortFilter;
import net.pterodactylus.util.template.ContainsFilter;
import net.pterodactylus.util.template.DateFilter;
import net.pterodactylus.util.template.TemplateProvider;
import net.pterodactylus.util.template.XmlFilter;
import net.pterodactylus.util.web.RedirectPage;
-import net.pterodactylus.util.web.StaticPage;
import net.pterodactylus.util.web.TemplatePage;
import com.google.common.collect.Collections2;
/** The logger. */
private static final Logger logger = getLogger(WebInterface.class.getName());
+ /** The loaders for templates, pages, and classpath providers. */
+ private final Loaders loaders;
+
/** The notification manager. */
private final NotificationManager notificationManager = new NotificationManager();
* The Sone plugin
*/
@Inject
- public WebInterface(SonePlugin sonePlugin) {
+ public WebInterface(SonePlugin sonePlugin, Loaders loaders) {
this.sonePlugin = sonePlugin;
+ this.loaders = loaders;
formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
soneTextParser = new SoneTextParser(getCore(), getCore());
templateContextFactory.addFilter("mod", new ModFilter());
templateContextFactory.addFilter("paginate", new PaginationFilter());
templateContextFactory.addProvider(TemplateProvider.TEMPLATE_CONTEXT_PROVIDER);
- templateContextFactory.addProvider(new ClassPathTemplateProvider(WebInterface.class, "/templates/"));
+ templateContextFactory.addProvider(loaders.getTemplateProvider());
templateContextFactory.addTemplateObject("webInterface", this);
templateContextFactory.addTemplateObject("formPassword", formPassword);
/* create notifications. */
- Template newSoneNotificationTemplate = parseTemplate("/templates/notify/newSoneNotification.html");
+ Template newSoneNotificationTemplate = loaders.loadTemplate("/templates/notify/newSoneNotification.html");
newSoneNotification = new ListNotification<Sone>("new-sone-notification", "sones", newSoneNotificationTemplate, false);
- Template newPostNotificationTemplate = parseTemplate("/templates/notify/newPostNotification.html");
+ Template newPostNotificationTemplate = loaders.loadTemplate("/templates/notify/newPostNotification.html");
newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate, false);
- Template localPostNotificationTemplate = parseTemplate("/templates/notify/newPostNotification.html");
+ Template localPostNotificationTemplate = loaders.loadTemplate("/templates/notify/newPostNotification.html");
localPostNotification = new ListNotification<Post>("local-post-notification", "posts", localPostNotificationTemplate, false);
- Template newReplyNotificationTemplate = parseTemplate("/templates/notify/newReplyNotification.html");
+ Template newReplyNotificationTemplate = loaders.loadTemplate("/templates/notify/newReplyNotification.html");
newReplyNotification = new ListNotification<PostReply>("new-reply-notification", "replies", newReplyNotificationTemplate, false);
- Template localReplyNotificationTemplate = parseTemplate("/templates/notify/newReplyNotification.html");
+ Template localReplyNotificationTemplate = loaders.loadTemplate("/templates/notify/newReplyNotification.html");
localReplyNotification = new ListNotification<PostReply>("local-reply-notification", "replies", localReplyNotificationTemplate, false);
- Template mentionNotificationTemplate = parseTemplate("/templates/notify/mentionNotification.html");
+ Template mentionNotificationTemplate = loaders.loadTemplate("/templates/notify/mentionNotification.html");
mentionNotification = new ListNotification<Post>("mention-notification", "posts", mentionNotificationTemplate, false);
- Template lockedSonesTemplate = parseTemplate("/templates/notify/lockedSonesNotification.html");
+ Template lockedSonesTemplate = loaders.loadTemplate("/templates/notify/lockedSonesNotification.html");
lockedSonesNotification = new ListNotification<Sone>("sones-locked-notification", "sones", lockedSonesTemplate);
- Template newVersionTemplate = parseTemplate("/templates/notify/newVersionNotification.html");
+ Template newVersionTemplate = loaders.loadTemplate("/templates/notify/newVersionNotification.html");
newVersionNotification = new TemplateNotification("new-version-notification", newVersionTemplate);
- Template insertingImagesTemplate = parseTemplate("/templates/notify/inserting-images-notification.html");
+ Template insertingImagesTemplate = loaders.loadTemplate("/templates/notify/inserting-images-notification.html");
insertingImagesNotification = new ListNotification<Image>("inserting-images-notification", "images", insertingImagesTemplate);
- Template insertedImagesTemplate = parseTemplate("/templates/notify/inserted-images-notification.html");
+ Template insertedImagesTemplate = loaders.loadTemplate("/templates/notify/inserted-images-notification.html");
insertedImagesNotification = new ListNotification<Image>("inserted-images-notification", "images", insertedImagesTemplate);
- Template imageInsertFailedTemplate = parseTemplate("/templates/notify/image-insert-failed-notification.html");
+ Template imageInsertFailedTemplate = loaders.loadTemplate("/templates/notify/image-insert-failed-notification.html");
imageInsertFailedNotification = new ListNotification<Image>("image-insert-failed-notification", "images", imageInsertFailedTemplate);
}
- private Template parseTemplate(String resourceName) {
- InputStream templateInputStream = null;
- Reader reader = null;
- try {
- templateInputStream = getClass().getResourceAsStream(resourceName);
- reader = new InputStreamReader(templateInputStream, "UTF-8");
- return parse(reader);
- } catch (UnsupportedEncodingException uee1) {
- throw new RuntimeException("UTF-8 not supported.");
- } finally {
- Closer.close(reader);
- Closer.close(templateInputStream);
- }
- }
-
//
// ACCESSORS
//
*/
public void setFirstStart(boolean firstStart) {
if (firstStart) {
- Template firstStartNotificationTemplate = parseTemplate("/templates/notify/firstStartNotification.html");
+ Template firstStartNotificationTemplate = loaders.loadTemplate("/templates/notify/firstStartNotification.html");
Notification firstStartNotification = new TemplateNotification("first-start-notification", firstStartNotificationTemplate);
notificationManager.addNotification(firstStartNotification);
}
*/
public void setNewConfig(boolean newConfig) {
if (newConfig && !hasFirstStartNotification()) {
- Template configNotReadNotificationTemplate = parseTemplate("/templates/notify/configNotReadNotification.html");
+ Template configNotReadNotificationTemplate = loaders.loadTemplate("/templates/notify/configNotReadNotification.html");
Notification configNotReadNotification = new TemplateNotification("config-not-read-notification", configNotReadNotificationTemplate);
notificationManager.addNotification(configNotReadNotification);
}
registerToadlets();
/* notification templates. */
- Template startupNotificationTemplate = parseTemplate("/templates/notify/startupNotification.html");
+ Template startupNotificationTemplate = loaders.loadTemplate("/templates/notify/startupNotification.html");
final TemplateNotification startupNotification = new TemplateNotification("startup-notification", startupNotificationTemplate);
notificationManager.addNotification(startupNotification);
}
}, 2, TimeUnit.MINUTES);
- Template wotMissingNotificationTemplate = parseTemplate("/templates/notify/wotMissingNotification.html");
+ Template wotMissingNotificationTemplate = loaders.loadTemplate("/templates/notify/wotMissingNotification.html");
final TemplateNotification wotMissingNotification = new TemplateNotification("wot-missing-notification", wotMissingNotificationTemplate);
ticker.scheduleAtFixedRate(new Runnable() {
*/
private void registerToadlets() {
Template emptyTemplate = parse(new StringReader(""));
- Template loginTemplate = parseTemplate("/templates/login.html");
- Template indexTemplate = parseTemplate("/templates/index.html");
- Template newTemplate = parseTemplate("/templates/new.html");
- Template knownSonesTemplate = parseTemplate("/templates/knownSones.html");
- Template createSoneTemplate = parseTemplate("/templates/createSone.html");
- Template createPostTemplate = parseTemplate("/templates/createPost.html");
- Template createReplyTemplate = parseTemplate("/templates/createReply.html");
- Template bookmarksTemplate = parseTemplate("/templates/bookmarks.html");
- Template searchTemplate = parseTemplate("/templates/search.html");
- Template editProfileTemplate = parseTemplate("/templates/editProfile.html");
- Template editProfileFieldTemplate = parseTemplate("/templates/editProfileField.html");
- Template deleteProfileFieldTemplate = parseTemplate("/templates/deleteProfileField.html");
- Template viewSoneTemplate = parseTemplate("/templates/viewSone.html");
- Template viewPostTemplate = parseTemplate("/templates/viewPost.html");
- Template deletePostTemplate = parseTemplate("/templates/deletePost.html");
- Template deleteReplyTemplate = parseTemplate("/templates/deleteReply.html");
- Template deleteSoneTemplate = parseTemplate("/templates/deleteSone.html");
- Template imageBrowserTemplate = parseTemplate("/templates/imageBrowser.html");
- Template createAlbumTemplate = parseTemplate("/templates/createAlbum.html");
- Template deleteAlbumTemplate = parseTemplate("/templates/deleteAlbum.html");
- Template deleteImageTemplate = parseTemplate("/templates/deleteImage.html");
- Template noPermissionTemplate = parseTemplate("/templates/noPermission.html");
- Template emptyImageTitleTemplate = parseTemplate("/templates/emptyImageTitle.html");
- Template emptyAlbumTitleTemplate = parseTemplate("/templates/emptyAlbumTitle.html");
- Template optionsTemplate = parseTemplate("/templates/options.html");
- Template rescueTemplate = parseTemplate("/templates/rescue.html");
- Template aboutTemplate = parseTemplate("/templates/about.html");
- Template invalidTemplate = parseTemplate("/templates/invalid.html");
- Template postTemplate = parseTemplate("/templates/include/viewPost.html");
- Template replyTemplate = parseTemplate("/templates/include/viewReply.html");
- Template openSearchTemplate = parseTemplate("/templates/xml/OpenSearch.xml");
+ Template loginTemplate = loaders.loadTemplate("/templates/login.html");
+ Template indexTemplate = loaders.loadTemplate("/templates/index.html");
+ Template newTemplate = loaders.loadTemplate("/templates/new.html");
+ Template knownSonesTemplate = loaders.loadTemplate("/templates/knownSones.html");
+ Template createSoneTemplate = loaders.loadTemplate("/templates/createSone.html");
+ Template createPostTemplate = loaders.loadTemplate("/templates/createPost.html");
+ Template createReplyTemplate = loaders.loadTemplate("/templates/createReply.html");
+ Template bookmarksTemplate = loaders.loadTemplate("/templates/bookmarks.html");
+ Template searchTemplate = loaders.loadTemplate("/templates/search.html");
+ Template editProfileTemplate = loaders.loadTemplate("/templates/editProfile.html");
+ Template editProfileFieldTemplate = loaders.loadTemplate("/templates/editProfileField.html");
+ Template deleteProfileFieldTemplate = loaders.loadTemplate("/templates/deleteProfileField.html");
+ Template viewSoneTemplate = loaders.loadTemplate("/templates/viewSone.html");
+ Template viewPostTemplate = loaders.loadTemplate("/templates/viewPost.html");
+ Template deletePostTemplate = loaders.loadTemplate("/templates/deletePost.html");
+ Template deleteReplyTemplate = loaders.loadTemplate("/templates/deleteReply.html");
+ Template deleteSoneTemplate = loaders.loadTemplate("/templates/deleteSone.html");
+ Template imageBrowserTemplate = loaders.loadTemplate("/templates/imageBrowser.html");
+ Template createAlbumTemplate = loaders.loadTemplate("/templates/createAlbum.html");
+ Template deleteAlbumTemplate = loaders.loadTemplate("/templates/deleteAlbum.html");
+ Template deleteImageTemplate = loaders.loadTemplate("/templates/deleteImage.html");
+ Template noPermissionTemplate = loaders.loadTemplate("/templates/noPermission.html");
+ Template emptyImageTitleTemplate = loaders.loadTemplate("/templates/emptyImageTitle.html");
+ Template emptyAlbumTitleTemplate = loaders.loadTemplate("/templates/emptyAlbumTitle.html");
+ Template optionsTemplate = loaders.loadTemplate("/templates/options.html");
+ Template rescueTemplate = loaders.loadTemplate("/templates/rescue.html");
+ Template aboutTemplate = loaders.loadTemplate("/templates/about.html");
+ Template invalidTemplate = loaders.loadTemplate("/templates/invalid.html");
+ Template postTemplate = loaders.loadTemplate("/templates/include/viewPost.html");
+ Template replyTemplate = loaders.loadTemplate("/templates/include/viewReply.html");
+ Template openSearchTemplate = loaders.loadTemplate("/templates/xml/OpenSearch.xml");
PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
pageToadlets.add(pageToadletFactory.createPageToadlet(new RedirectPage<FreenetRequest>("", "index.html")));
pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyAlbumTitle.html", emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.Title", this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationPage(emptyTemplate, this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("invalid.html", invalidTemplate, "Page.Invalid.Title", this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage<FreenetRequest>("css/", "/static/css/", "text/css")));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage<FreenetRequest>("javascript/", "/static/javascript/", "text/javascript")));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage<FreenetRequest>("images/", "/static/images/", "image/png")));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(loaders.<FreenetRequest>loadStaticPage("css/", "/static/css/", "text/css")));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(loaders.<FreenetRequest>loadStaticPage("javascript/", "/static/javascript/", "text/javascript")));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(loaders.<FreenetRequest>loadStaticPage("images/", "/static/images/", "image/png")));
pageToadlets.add(pageToadletFactory.createPageToadlet(new TemplatePage<FreenetRequest>("OpenSearch.xml", "application/opensearchdescription+xml", templateContextFactory, openSearchTemplate)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new GetImagePage(this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
synchronized (soneInsertNotifications) {
TemplateNotification templateNotification = soneInsertNotifications.get(sone);
if (templateNotification == null) {
- templateNotification = new TemplateNotification(parseTemplate("/templates/notify/soneInsertNotification.html"));
+ templateNotification = new TemplateNotification(loaders.loadTemplate("/templates/notify/soneInsertNotification.html"));
templateNotification.set("insertSone", sone);
soneInsertNotifications.put(sone, templateNotification);
}
newSoneNotification.remove(markSoneKnownEvent.sone());
}
- /**
- * Notifies the web interface that a {@link Post} was marked as known.
- *
- * @param markPostKnownEvent
- * The event
- */
@Subscribe
public void markPostKnown(MarkPostKnownEvent markPostKnownEvent) {
- newPostNotification.remove(markPostKnownEvent.post());
- localPostNotification.remove(markPostKnownEvent.post());
- if (!localSoneMentionedInNewPostOrReply(markPostKnownEvent.post())) {
- mentionNotification.remove(markPostKnownEvent.post());
- }
+ removePost(markPostKnownEvent.post());
}
- /**
- * Notifies the web interface that a {@link PostReply} was marked as known.
- *
- * @param markPostReplyKnownEvent
- * The event
- */
@Subscribe
public void markReplyKnown(MarkPostReplyKnownEvent markPostReplyKnownEvent) {
- PostReply postReply = markPostReplyKnownEvent.postReply();
- newReplyNotification.remove(postReply);
- localReplyNotification.remove(postReply);
- if (postReply.getPost().isPresent() && !localSoneMentionedInNewPostOrReply(postReply.getPost().get())) {
- mentionNotification.remove(postReply.getPost().get());
- }
+ removeReply(markPostReplyKnownEvent.postReply());
}
- /**
- * Notifies the web interface that a {@link Sone} was removed.
- *
- * @param soneRemovedEvent
- * The event
- */
@Subscribe
public void soneRemoved(SoneRemovedEvent soneRemovedEvent) {
newSoneNotification.remove(soneRemovedEvent.sone());
+ for (Post post : soneRemovedEvent.sone().getPosts()) {
+ removePost(post);
+ }
+ for (PostReply postReply : soneRemovedEvent.sone().getReplies()) {
+ removeReply(postReply);
+ }
}
- /**
- * Notifies the web interface that a {@link Post} was removed.
- *
- * @param postRemovedEvent
- * The event
- */
@Subscribe
public void postRemoved(PostRemovedEvent postRemovedEvent) {
- newPostNotification.remove(postRemovedEvent.post());
- localPostNotification.remove(postRemovedEvent.post());
- if (!localSoneMentionedInNewPostOrReply(postRemovedEvent.post())) {
- mentionNotification.remove(postRemovedEvent.post());
+ removePost(postRemovedEvent.post());
+ }
+
+ private void removePost(Post post) {
+ newPostNotification.remove(post);
+ localPostNotification.remove(post);
+ if (!localSoneMentionedInNewPostOrReply(post)) {
+ mentionNotification.remove(post);
}
}
- /**
- * Notifies the web interface that a {@link PostReply} was removed.
- *
- * @param postReplyRemovedEvent
- * The event
- */
@Subscribe
public void replyRemoved(PostReplyRemovedEvent postReplyRemovedEvent) {
- PostReply reply = postReplyRemovedEvent.postReply();
+ removeReply(postReplyRemovedEvent.postReply());
+ }
+
+ private void removeReply(PostReply reply) {
newReplyNotification.remove(reply);
localReplyNotification.remove(reply);
if (reply.getPost().isPresent() && !localSoneMentionedInNewPostOrReply(reply.getPost().get())) {
/*
- * Sone - BookmarkAjaxPage.java - Copyright © 2011–2013 David Roden
+ * Sone - BookmarkAjaxPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - CreatePostAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - CreatePostAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - CreateReplyAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - CreateReplyAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DeletePostAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - DeletePostAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DeleteProfileFieldAjaxPage.java - Copyright © 2011–2013 David Roden
+ * Sone - DeleteProfileFieldAjaxPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DeleteReplyAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - DeleteReplyAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DismissNotificationAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - DismissNotificationAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DistrustAjaxPage.java - Copyright © 2011–2013 David Roden
+ * Sone - DistrustAjaxPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - EditAlbumAjaxPage.java - Copyright © 2011–2013 David Roden
+ * Sone - EditAlbumAjaxPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - EditImageAjaxPage.java - Copyright © 2011–2013 David Roden
+ * Sone - EditImageAjaxPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - EditProfileFieldAjaxPage.java - Copyright © 2011–2013 David Roden
+ * Sone - EditProfileFieldAjaxPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - FollowSoneAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - FollowSoneAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetLikesAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - GetLikesAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetNotificationsAjaxPage.java - Copyright © 2011–2013 David Roden
+ * Sone - GetNotificationsAjaxPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetPostAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - GetPostAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetReplyAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - GetReplyAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetStatusAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - GetStatusAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - GetTimesAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - GetTimesAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
/*
- * Sone - GetTranslationPage.java - Copyright © 2010–2013 David Roden
+ * Sone - GetTranslationPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - JsonPage.java - Copyright © 2010–2013 David Roden
+ * Sone - JsonPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LikeAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - LikeAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LockSoneAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - LockSoneAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - MarkAsKnownAjaxPage.java - Copyright © 2011–2013 David Roden
+ * Sone - MarkAsKnownAjaxPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - MoveProfileFieldAjaxPage.java - Copyright © 2011–2013 David Roden
+ * Sone - MoveProfileFieldAjaxPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - TrustAjaxPage.java - Copyright © 2011–2013 David Roden
+ * Sone - TrustAjaxPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UnbookmarkAjaxPage.java - Copyright © 2011–2013 David Roden
+ * Sone - UnbookmarkAjaxPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UnfollowSoneAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - UnfollowSoneAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UnlikeAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - UnlikeAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UnlockSoneAjaxPage.java - Copyright © 2010–2013 David Roden
+ * Sone - UnlockSoneAjaxPage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - UntrustAjaxPage.java - Copyright © 2011–2013 David Roden
+ * Sone - UntrustAjaxPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - FreenetPage.java - Copyright © 2011–2013 David Roden
+ * Sone - FreenetPage.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - FreenetRequest.java - Copyright © 2011–2013 David Roden
+ * Sone - FreenetRequest.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - FreenetTemplatePage.java - Copyright © 2010–2013 David Roden
+ * Sone - FreenetTemplatePage.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PageToadlet.java - Copyright © 2010–2013 David Roden
+ * Sone - PageToadlet.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - PageToadletFactory.java - Copyright © 2010–2013 David Roden
+ * Sone - PageToadletFactory.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Page.Options.Title=Opciones - Sone
Page.Options.Page.Title=Opciones
-Page.Options.Page.Description=Estas opciones influencian en la ejecución del plugin de Sone
+Page.Options.Page.Description=Estas opciones influencian en la ejecución del plugin "Sone"
Page.Options.Section.SoneSpecificOptions.Title=Opciones específicas de Sone
Page.Options.Section.SoneSpecificOptions.NotLoggedIn=Estas opciones solo están disponibles si has {link}iniciado sesión{/link}.
Page.Options.Section.SoneSpecificOptions.LoggedIn=Estas opciones solo están disponibles mientras hayas iniciado sesión y solo son válidas para el Sone con el que hayas hecho login.
Page.Index.Label.Text=Publicar texto:
Page.Index.Label.Sender=Mensajero:
Page.Index.Button.Post=Publicar!
-Page.Index.PostList.Title=Publicar Feed
+Page.Index.PostList.Title=Publicaciones
Page.Index.PostList.Text.NoPostYet=Nadie ha escrito ningún post todavía. Probablemente deberías empezar ahora!
Page.Index.PostList.Text.FollowSomeSones=O quizás no estás siguiendo ningún Sone? Echa un vistado a la lista de {link}Sones conocidos{/link} y sigue a quienes te parezcan interesantes
Page.Index.PostList.Text.AutoFollowOption=También tienes la opción de seguir automáticamente cualquier Sone que descubras. Echa un vistado a las {link}opciones{/link} para activar la opción "Seguir automáticamente"!
View.Sone.Button.LockSone.Tooltip=Impide que este Sone sea insertado ahora
View.Sone.Button.UnfollowSone=dejar de seguir
View.Sone.Button.FollowSone=seguir
-View.Sone.Status.Modified=Esto Sone fue modificado y espera para ser insertado.
+View.Sone.Status.Modified=Este Sone fue modificado y espera para ser insertado.
View.Sone.Status.Unknown=Este Sone aun no ha sido recivido.
View.Sone.Status.Idle=Este Sone está desocupado, i.e. no está siendo descargado ni insertado.
View.Sone.Status.Downloading=Este Sone está siendo descargado.
View.Time.XYearsAgo=hace ${year} años
WebInterface.DefaultText.StatusUpdate=Qué estás pensando?
-WebInterface.DefaultText.Message=Escrivir un mensaje…
-WebInterface.DefaultText.Reply=Escrivir una respuesta…
+WebInterface.DefaultText.Message=Escribir un mensaje…
+WebInterface.DefaultText.Reply=Escribir una respuesta…
WebInterface.DefaultText.FirstName=Primer nombre
WebInterface.DefaultText.MiddleName=Segundo nombre
WebInterface.DefaultText.LastName=Apellido
WebInterface.DefaultText.BirthYear=Año
WebInterface.DefaultText.FieldName=Nombre del campo
WebInterface.DefaultText.Option.InsertionDelay=Tiempo a esperar tras la modificación de un Sone antes de insertarlo (en segundos)
-WebInterface.DefaultText.Search=Qué estás buscando?
+WebInterface.DefaultText.Search=Qué quieres buscar?
WebInterface.DefaultText.CreateAlbum.Name=Título del álbum
WebInterface.DefaultText.CreateAlbum.Description=Descripción del álbum
WebInterface.DefaultText.EditAlbum.Title=Título del álbum
WebInterface.SelectBox.Choose=Elegir…
WebInterface.SelectBox.Yes=Si
WebInterface.SelectBox.No=No
-WebInterface.ClickToShow.Replies=Clica aquía para mostrar las respuestas ocultas.
+WebInterface.ClickToShow.Replies=Clica aquí para mostrar las respuestas ocultas.
WebInterface.VersionInformation.CurrentVersion=Versión actual:
WebInterface.VersionInformation.LatestVersion=Última versión:
WebInterface.VersionInformation.Homepage=Página de inicio
/*
- * Sone - Matchers.java - Copyright © 2013 David Roden
+ * Sone - Matchers.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - MemoryDatabaseTest.java - Copyright © 2013 David Roden
+ * Sone - MemoryDatabaseTest.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LockSoneCommandTest.java - Copyright © 2013 David Roden
+ * Sone - LockSoneCommandTest.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - LockSoneCommandTest.java - Copyright © 2013 David Roden
+ * Sone - UnlockSoneCommandTest.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DefaultIdentityTest.java - Copyright © 2013 David Roden
+ * Sone - DefaultIdentityTest.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - DefaultOwnIdentityTest.java - Copyright © 2013 David Roden
+ * Sone - DefaultOwnIdentityTest.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - Identities.java - Copyright © 2013 David Roden
+ * Sone - Identities.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IdentityChangeDetectorTest.java - Copyright © 2013 David Roden
+ * Sone - IdentityChangeDetectorTest.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IdentityChangeEventSenderTest.java - Copyright © 2013 David Roden
+ * Sone - IdentityChangeEventSenderTest.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/*
- * Sone - IdentityLoaderTest.java - Copyright © 2013 David Roden
+ * Sone - IdentityLoaderTest.java - Copyright © 2013–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
--- /dev/null
+package net.pterodactylus.sone.main;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.startsWith;
+import static org.mockito.Mockito.mock;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateProvider;
+import net.pterodactylus.util.web.Method;
+import net.pterodactylus.util.web.Page;
+import net.pterodactylus.util.web.Response;
+
+import freenet.clients.http.ToadletContext;
+import freenet.support.api.HTTPRequest;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ * Unit test for {@link DebugLoaders}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class DebugLoadersTest {
+
+ @Rule
+ public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ private final StringWriter stringWriter = new StringWriter();
+ private final TemplateContext templateContext = new TemplateContext();
+ private Loaders loaders;
+
+ @Before
+ public void setupLoader() throws IOException {
+ String templatePath = temporaryFolder.newFolder("temps").getPath();
+ loaders = new DebugLoaders(templatePath);
+ File templateFile = new File(templatePath, "template.txt");
+ Files.write("<%if foo>foo<%else>bar<%/if>", templateFile, Charsets.UTF_8);
+ new File(templatePath, "templates").mkdir();
+ File secondTemplateFile = new File(templatePath, "templates/template.txt");
+ Files.write("<%if foo>foo<%else>bar<%/if>", secondTemplateFile, Charsets.UTF_8);
+ }
+
+ @Test
+ public void debugLoaderCanLoadTemplatesFromFilesystem() throws IOException {
+ Template template = loaders.loadTemplate("/template.txt");
+ template.render(templateContext, stringWriter);
+ assertThat(stringWriter.toString(), is("bar"));
+ }
+
+ @Test
+ public void staticPageIsServedFromFilesystem() throws URISyntaxException, IOException {
+ Page<FreenetRequest> page = loaders.loadStaticPage("text/", "", "text/plain");
+ URI uri = new URI("http://some.host/text/template.txt");
+ Method method = Method.GET;
+ HTTPRequest httpRequest = mock(HTTPRequest.class);
+ ToadletContext toadletContext = mock(ToadletContext.class);
+ FreenetRequest request = new FreenetRequest(uri, method, httpRequest, toadletContext);
+ OutputStream outputStream = new ByteArrayOutputStream();
+ Response response = new Response(outputStream);
+ page.handleRequest(request, response);
+ assertThat(response.getContentType(), startsWith("text/plain"));
+ assertThat(response.getStatusCode(), is(200));
+ }
+
+ @Test
+ public void templateProviderLocatesTemplatesInFileSystem() {
+ TemplateProvider templateProvider = loaders.getTemplateProvider();
+ Template template = templateProvider.getTemplate(templateContext, "template.txt");
+ template.render(templateContext, stringWriter);
+ assertThat(stringWriter.toString(), is("bar"));
+ }
+
+}
--- /dev/null
+package net.pterodactylus.sone.main;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.startsWith;
+import static org.mockito.Mockito.mock;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateProvider;
+import net.pterodactylus.util.web.Method;
+import net.pterodactylus.util.web.Page;
+import net.pterodactylus.util.web.Response;
+
+import freenet.clients.http.ToadletContext;
+import freenet.support.api.HTTPRequest;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link DefaultLoaders}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class DefaultLoadersTest {
+
+ private final Loaders loaders = new DefaultLoaders();
+ private final StringWriter stringWriter = new StringWriter();
+ private final TemplateContext templateContext = new TemplateContext();
+
+ @Test
+ public void templateCanBeLoadedFromTheClasspath() {
+ Template template = loaders.loadTemplate("/net/pterodactylus/sone/main/template.txt");
+ template.render(templateContext, stringWriter);
+ assertThat(stringWriter.toString(), is("Template. bar\n"));
+ }
+
+ @Test
+ public void staticPageIsServedFromClasspath() throws IOException, URISyntaxException {
+ Page<FreenetRequest> staticPage = loaders.loadStaticPage("text/", "/net/pterodactylus/sone/main/", "text/plain");
+ URI uri = new URI("http://some.host/text/template.txt");
+ Method method = Method.GET;
+ HTTPRequest httpRequest = mock(HTTPRequest.class);
+ ToadletContext toadletContext = mock(ToadletContext.class);
+ FreenetRequest request = new FreenetRequest(uri, method, httpRequest, toadletContext);
+ OutputStream outputStream = new ByteArrayOutputStream();
+ Response response = new Response(outputStream);
+ staticPage.handleRequest(request, response);
+ assertThat(response.getContentType(), startsWith("text/plain"));
+ assertThat(response.getStatusCode(), is(200));
+ }
+
+ @Test
+ public void templateIsLocatedInClasspath() {
+ TemplateProvider templateProvider = loaders.getTemplateProvider();
+ Template template = templateProvider.getTemplate(templateContext, "about.html");
+ assertThat(template, notNullValue());
+ }
+
+}
--- /dev/null
+package net.pterodactylus.sone.template;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicReference;
+
+import net.pterodactylus.util.template.Part;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateException;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit test for {@link FilesystemTemplate}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class FilesystemTemplateTest {
+
+ private final File tempFile;
+ private final FilesystemTemplate filesystemTemplate;
+ private final AtomicReference<StringWriter> stringWriter = new AtomicReference<StringWriter>(new StringWriter());
+ private final TemplateContext templateContext = new TemplateContext();
+
+ public FilesystemTemplateTest() throws IOException {
+ tempFile = File.createTempFile("template-", ".dat");
+ writeTemplate("Text");
+ filesystemTemplate = new FilesystemTemplate(tempFile.getAbsolutePath());
+ }
+
+ private void writeTemplate(String text) throws IOException {
+ Files.write(text + ".<%foreach values value><% value><%/foreach>", tempFile, Charsets.UTF_8);
+ }
+
+ @Before
+ public void setupTemplateContext() {
+ templateContext.set("values", Arrays.asList("a", 1));
+ }
+
+ @Test(expected = FilesystemTemplate.TemplateFileNotFoundException.class)
+ public void loadingTemplateFromNonExistingFileThrowsException() throws IOException {
+ FilesystemTemplate filesystemTemplate = new FilesystemTemplate("/a/b/c.dat");
+ filesystemTemplate.getInitialContext();
+ }
+
+ @Test
+ public void templateCanBeLoadedFromTheFilesystem() {
+ filesystemTemplate.render(templateContext, stringWriter.get());
+ assertThat(getRenderedString(), is("Text.a1"));
+ }
+
+ @Test
+ public void templateCanBeReloaded() throws IOException, InterruptedException {
+ filesystemTemplate.render(templateContext, stringWriter.get());
+ assertThat(getRenderedString(), is("Text.a1"));
+ Thread.sleep(1000);
+ writeTemplate("New");
+ filesystemTemplate.render(templateContext, stringWriter.get());
+ assertThat(getRenderedString(), is("New.a1"));
+ }
+
+ @Test
+ public void templateIsNotReloadedIfNotChanged() {
+ filesystemTemplate.render(templateContext, stringWriter.get());
+ assertThat(getRenderedString(), is("Text.a1"));
+ filesystemTemplate.render(templateContext, stringWriter.get());
+ assertThat(getRenderedString(), is("Text.a1"));
+ }
+
+ private String getRenderedString() {
+ String renderedString = stringWriter.get().toString();
+ stringWriter.set(new StringWriter());
+ return renderedString;
+ }
+
+ @Test
+ public void initialContextIsCopiedToReloadedTemplates() throws IOException, InterruptedException {
+ filesystemTemplate.getInitialContext().set("values", "test");
+ Thread.sleep(1000);
+ writeTemplate("New");
+ assertThat(filesystemTemplate.getInitialContext().get("values"), is((Object) "test"));
+ }
+
+ @Test
+ public void partsAreCopiedToReloadedTemplates() throws InterruptedException, IOException {
+ filesystemTemplate.add(new Part() {
+ @Override
+ public void render(TemplateContext templateContext, Writer writer) throws TemplateException {
+ try {
+ writer.write(".Test");
+ } catch (IOException e) {
+ throw new TemplateException(e);
+ }
+ }
+ });
+ Thread.sleep(1000);
+ writeTemplate("New");
+ filesystemTemplate.render(templateContext, stringWriter.get());
+ assertThat(getRenderedString(), is("New.a1.Test"));
+ }
+
+}
--- /dev/null
+package net.pterodactylus.sone.template;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.util.template.HtmlFilter;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateContextFactory;
+
+import com.google.common.collect.ImmutableMap;
+import org.hamcrest.Matchers;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit test for {@link ImageLinkFilterTest}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ImageLinkFilterTest {
+
+ private final Core core = mock(Core.class);
+ private final TemplateContextFactory templateContextFactory = new TemplateContextFactory();
+ private final ImageLinkFilter imageLinkFilter = new ImageLinkFilter(core, templateContextFactory);
+ private final TemplateContext templateContext = null;
+ private final Image image = mock(Image.class);
+
+ @Before
+ public void setupTemplateContextFactory() {
+ templateContextFactory.addFilter("html", new HtmlFilter());
+ }
+
+ @Before
+ public void setupCore() {
+ when(core.getImage("image-id", false)).thenReturn(image);
+ }
+
+ @Before
+ public void setupImage() {
+ when(image.getId()).thenReturn("image-id");
+ when(image.getKey()).thenReturn("image-key");
+ when(image.isInserted()).thenReturn(true);
+ when(image.getWidth()).thenReturn(640);
+ when(image.getHeight()).thenReturn(270);
+ when(image.getTitle()).thenReturn("image title");
+ when(image.getDescription()).thenReturn("image description");
+ }
+
+ @Test
+ public void imageLinkIsGeneratedCorrectlyForNotInsertedImages() {
+ when(image.isInserted()).thenReturn(false);
+ String result = String.valueOf(imageLinkFilter.format(templateContext, image, ImmutableMap.<String, Object>of()));
+ Element imageElement = getSingleElement(result);
+ assertThat(imageElement.attr("class"), is(""));
+ assertThat(imageElement.attr("src"), is("getImage.html?image=image-id"));
+ assertThat(imageElement.attr("title"), is("image title"));
+ assertThat(imageElement.attr("alt"), is("image description"));
+ assertThat(imageElement.attr("width"), is("640"));
+ assertThat(imageElement.attr("height"), is("270"));
+ }
+
+ @Test
+ public void imageLinkIsGeneratedCorrectlyForInsertedImages() {
+ String result = String.valueOf(imageLinkFilter.format(templateContext, image, ImmutableMap.<String, Object>of()));
+ Element imageElement = getSingleElement(result);
+ assertThat(imageElement.attr("class"), is(""));
+ assertThat(imageElement.attr("src"), is("/image-key?forcedownload=true"));
+ assertThat(imageElement.attr("title"), is("image title"));
+ assertThat(imageElement.attr("alt"), is("image description"));
+ assertThat(imageElement.attr("width"), is("640"));
+ assertThat(imageElement.attr("height"), is("270"));
+ }
+
+ @Test
+ public void imageTitleAndDescriptionAreOverriddenCorrectly() {
+ String result = String.valueOf(imageLinkFilter.format(templateContext, image, ImmutableMap.<String, Object>of("title", "Test Title")));
+ Element imageElement = getSingleElement(result);
+ assertThat(imageElement.attr("title"), is("Test Title"));
+ assertThat(imageElement.attr("alt"), is("Test Title"));
+ }
+
+ @Test
+ public void imageIsScaledByWidthCorrectly() {
+ String result = String.valueOf(imageLinkFilter.format(templateContext, image, ImmutableMap.<String, Object>of("max-width", "320")));
+ Element imageElement = getSingleElement(result);
+ assertThat(imageElement.attr("width"), is("320"));
+ assertThat(imageElement.attr("height"), is("135"));
+ }
+
+ @Test
+ public void imageIsScaledByHeightCorrectly() {
+ String result = String.valueOf(imageLinkFilter.format(templateContext, image, ImmutableMap.<String, Object>of("max-height", "135")));
+ Element imageElement = getSingleElement(result);
+ assertThat(imageElement.attr("width"), is("320"));
+ assertThat(imageElement.attr("height"), is("135"));
+ }
+
+ @Test
+ public void wideImageIsEnlargedCorrectly() {
+ String result = String.valueOf(imageLinkFilter.format(templateContext, image,
+ ImmutableMap.<String, Object>of("mode", "enlarge", "max-width", "100", "max-height", "100")));
+ Element imageElement = getSingleElement(result);
+ assertThat(imageElement.attr("width"), is("237"));
+ assertThat(imageElement.attr("height"), is("100"));
+ assertThat(imageElement.attr("style"), containsString("left: -68px"));
+ assertThat(imageElement.attr("style"), containsString("top: 0px"));
+ }
+
+ @Test
+ public void highImageIsEnlargedCorrectly() {
+ when(image.getWidth()).thenReturn(270);
+ when(image.getHeight()).thenReturn(640);
+ String result = String.valueOf(imageLinkFilter.format(templateContext, image,
+ ImmutableMap.<String, Object>of("mode", "enlarge", "max-width", "100", "max-height", "100")));
+ Element imageElement = getSingleElement(result);
+ assertThat(imageElement.attr("width"), is("100"));
+ assertThat(imageElement.attr("height"), is("237"));
+ assertThat(imageElement.attr("style"), containsString("left: 0px"));
+ assertThat(imageElement.attr("style"), containsString("top: -68px"));
+ }
+
+ @Test
+ public void nullImageIsReturnedAsNull() {
+ assertThat(imageLinkFilter.format(templateContext, null, null), nullValue());
+ }
+
+ @Test
+ public void stringIsUsedToLoadImageFromCore() {
+ String result = String.valueOf(imageLinkFilter.format(templateContext, "image-id", ImmutableMap.<String, Object>of()));
+ Element imageElement = getSingleElement(result);
+ assertThat(imageElement.attr("class"), is(""));
+ assertThat(imageElement.attr("src"), is("/image-key?forcedownload=true"));
+ assertThat(imageElement.attr("title"), is("image title"));
+ assertThat(imageElement.attr("alt"), is("image description"));
+ assertThat(imageElement.attr("width"), is("640"));
+ assertThat(imageElement.attr("height"), is("270"));
+ }
+
+ private Element getSingleElement(String result) {
+ Document document = Jsoup.parseBodyFragment(result);
+ assertThatBodyHasASingleElement(document);
+ return getSingleElement(document);
+ }
+
+ private void assertThatBodyHasASingleElement(Document document) {
+ assertThat(document.body().select("> *"), Matchers.hasSize(1));
+ }
+
+ private Element getSingleElement(Document document) {
+ return document.body().select("> *").get(0);
+ }
+
+}
/*
- * Sone - SoneTextParserTest.java - Copyright © 2011–2013 David Roden
+ * Sone - SoneTextParserTest.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
--- /dev/null
+Template. <%if foo>foo<%else>bar<%/if>
--- /dev/null
+<%if foo>foo<%else>bar<%/if>
\ No newline at end of file