Skip to content

Commit

Permalink
Fixes #651 - Use Component#urlFor() to create a url to SummernoteStor…
Browse files Browse the repository at this point in the history
…edImageResourceReference

This requires adding an abstract method to SummernoteEditor to get the storageId
  • Loading branch information
martin-g committed Dec 18, 2016
1 parent 37918a7 commit 67473ba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @author Tobias Soloschenko
*
*/
public class SummernoteEditor extends FormComponent<String> {
public abstract class SummernoteEditor extends FormComponent<String> {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -194,7 +194,9 @@ private Map<String,FileItem> storeFile(AjaxRequestTarget target, MultipartServle
SummernoteStorage storage = SummernoteConfig.getStorage(config.getStorageId());
storage.writeContent(imageName, fileItem.getInputStream());
WebResponse response = (WebResponse) target.getHeaderResponse().getResponse();
response.setHeader("imageUrl", SummernoteStoredImageResourceReference.SUMMERNOTE_MOUNT_PATH
final String storageId = getStorageId();
final CharSequence imageReferenceUrl = urlFor(new SummernoteStoredImageResourceReference(storageId), null);
response.setHeader("imageUrl", imageReferenceUrl
+ "?image=" + Base64.encodeBase64String(imageName.getBytes()));
fileItemsMap.put(imageName, fileItem);
} catch (IOException e) {
Expand All @@ -212,4 +214,8 @@ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
}
}

/**
* @return The id of the storage used for Summernote image uploads
*/
protected abstract String getStorageId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public SummernoteStoredImageResource(String storageId, String imageName) {
*/
@Override
protected byte[] getImageData(Attributes attributes) {
return SummernoteConfig.getStorage(storageId).getContent(imageName);
return SummernoteConfig.getStorage(storageId).getContent(imageName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.resource.IResource;
import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.string.StringValue;

/**
* Provides the image data by the given storage id
*
* @author Tobias Soloschenko
*
*/
public class SummernoteStoredImageResourceReference extends ResourceReference {

private static final long serialVersionUID = 1L;

public static final String SUMMERNOTE_MOUNT_PATH = "/summernoteimages";
public static final String SUMMERNOTE_MOUNT_PATH = "/wicket/bootstrap/summernote/images";

private String storageId;

Expand All @@ -28,8 +28,8 @@ public class SummernoteStoredImageResourceReference extends ResourceReference {
* the id of the file storage
*/
public SummernoteStoredImageResourceReference(String storageId) {
super("summernoteimages");
this.storageId = storageId;
super("summernote/images/"+storageId);
this.storageId = Args.notEmpty(storageId, "storageId");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ private void addForm(String idSuffix, final boolean isAirMode) {

final IModel<String> summernoteModel = Model.of("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam \r\nnvoluptua.");

final SummernoteEditor summernoteEditor = new SummernoteEditor("summernote" + idSuffix, summernoteModel, summernoteConfig);
final SummernoteEditor summernoteEditor = new SummernoteEditor("summernote" + idSuffix, summernoteModel, summernoteConfig) {
@Override
protected String getStorageId() {
return WicketApplication.STORAGE_ID;
}
};
form.add(summernoteEditor);
form.add(new SummernoteAjaxButton("submit" + idSuffix, summernoteEditor) {
private static final long serialVersionUID = 1L;
Expand Down

0 comments on commit 67473ba

Please sign in to comment.