-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
24dcf00
commit c663c92
Showing
6 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
orienteer-core/src/main/java/org/orienteer/components/properties/BinaryEditPanel.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<wicket:panel> | ||
<input wicket:id="data" type="file"> | ||
</wicket:panel> |
27 changes: 27 additions & 0 deletions
27
orienteer-core/src/main/java/org/orienteer/components/properties/BinaryEditPanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.orienteer.components.properties; | ||
|
||
import org.apache.wicket.markup.html.form.FormComponentPanel; | ||
import org.apache.wicket.markup.html.form.upload.FileUpload; | ||
import org.apache.wicket.markup.html.form.upload.FileUploadField; | ||
import org.apache.wicket.model.IModel; | ||
|
||
public class BinaryEditPanel extends FormComponentPanel<byte[]> { | ||
|
||
private FileUploadField fileUploadField; | ||
|
||
public BinaryEditPanel(String id, IModel<byte[]> model) { | ||
super(id, model); | ||
fileUploadField = new FileUploadField("data"); | ||
add(fileUploadField); | ||
} | ||
|
||
@Override | ||
protected void convertInput() { | ||
FileUpload fileUpload = fileUploadField.getFileUpload(); | ||
if(fileUpload!=null) | ||
{ | ||
setConvertedInput(fileUpload.getBytes()); | ||
} | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
orienteer-core/src/main/java/org/orienteer/components/properties/BinaryViewPanel.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<wicket:panel> | ||
<a href="#" wicket:id="data"><wicket:message key="download.link">Data</wicket:message></a> | ||
</wicket:panel> |
55 changes: 55 additions & 0 deletions
55
orienteer-core/src/main/java/org/orienteer/components/properties/BinaryViewPanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.orienteer.components.properties; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
import org.apache.wicket.markup.html.link.ResourceLink; | ||
import org.apache.wicket.markup.html.panel.GenericPanel; | ||
import org.apache.wicket.model.IModel; | ||
import org.apache.wicket.request.resource.AbstractResource; | ||
import org.apache.wicket.request.resource.AbstractResource.ResourceResponse; | ||
import org.apache.wicket.request.resource.IResource.Attributes; | ||
import org.orienteer.services.IOClassIntrospector; | ||
|
||
import com.google.inject.Inject; | ||
import com.orientechnologies.orient.core.metadata.schema.OProperty; | ||
import com.orientechnologies.orient.core.record.impl.ODocument; | ||
|
||
public class BinaryViewPanel<V> extends GenericPanel<V> { | ||
|
||
private IModel<ODocument> documentModel; | ||
private IModel<OProperty> propertyModel; | ||
private IModel<V> valueModel; | ||
|
||
@Inject | ||
private IOClassIntrospector oClassIntrospector; | ||
|
||
@SuppressWarnings("unchecked") | ||
public BinaryViewPanel(String id, IModel<ODocument> docModel, IModel<OProperty> propModel, IModel<V> valueModel) { | ||
super(id, valueModel); | ||
this.documentModel = docModel; | ||
this.propertyModel = propModel; | ||
add(new ResourceLink<byte[]>("data", new AbstractResource() { | ||
|
||
@Override | ||
protected ResourceResponse newResourceResponse(Attributes attributes) { | ||
ResourceResponse resourceResponse = new ResourceResponse(); | ||
resourceResponse.setContentType("application/octet-stream"); | ||
String filename = oClassIntrospector.getDocumentName(documentModel.getObject()); | ||
filename += "."+propertyModel.getObject().getName()+".bin"; | ||
resourceResponse.setFileName(filename); | ||
resourceResponse.setWriteCallback(new WriteCallback() | ||
{ | ||
@Override | ||
public void writeData(Attributes attributes) throws IOException | ||
{ | ||
OutputStream outputStream = attributes.getResponse().getOutputStream(); | ||
outputStream.write((byte[])BinaryViewPanel.this.getModelObject()); | ||
} | ||
}); | ||
return resourceResponse; | ||
} | ||
})); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters