package de.t_systems.dks.eba.pages.docedit.iframe;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.wicket.markup.html.DynamicWebResource;
import org.apache.wicket.markup.html.form.upload.FileUpload;
public class MyPdfResource extends DynamicWebResource
{
private static final long serialVersionUID = 1L;
static int BUFFER_SIZE = 10 * 1024;
private byte[] file;
// private FileUpload upload;
// private String contentType;
private String contentType = "application/pdf"; //only for Test
// private String fileName;
private String fileName = "test.pdf"; //only for Test
/**
*
*/
public MyPdfResource()
{
}
public MyPdfResource(String contenttype, String filename)
{
contentType = contenttype;
fileName = filename;
}
/*
public MyPdfResource(FileUpload fileUpload)
{
upload = fileUpload;
}
*/
public MyPdfResource(byte[] file, String contenttype, String filename)
{
if (file != null)
this.file = file;
if (contenttype != null && !"".equalsIgnoreCase(contenttype))
contentType = contenttype;
if (filename != null && !"".equalsIgnoreCase(filename))
fileName = filename;
}
/* (non-Javadoc)
* @see
org.apache.wicket.markup.html.DynamicWebResource#getResourceState()
*/
@Override
protected ResourceState getResourceState()
{
return new ResourceState()
{
@Override
public String getContentType()
{
return contentType;
}
@Override
public byte[] getData()
{
try
{
//return
bytes(MyPdfResource.class.getResourceAsStream("test.pdf"));
if (file != null)
return file;
else
return
bytes(MyPdfResource.class.getResourceAsStream(fileName));
// if (upload == null) {
// return
bytes(MyPdfResource.class.getResourceAsStream("test.pdf"));
// } else {
// return
bytes(upload.getInputStream());
// }
//return file;
}
catch (Exception e)
{
return null;
}
}
};
}
public static byte[] bytes(InputStream is) throws IOException
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
copy(is, out);
return out.toByteArray();
}
public static void copy(InputStream is, OutputStream os) throws
IOException
{
byte[] buf = new byte[BUFFER_SIZE];
while (true)
{
int tam = is.read(buf);
if (tam == -1)
{
return;
}
os.write(buf, 0, tam);
}
}
}
-----Ursprüngliche Nachricht-----
Von: Ernesto Reinaldo Barreiro [mailto:[email protected]]
Gesendet: Dienstag, 16. November 2010 20:28
An: [email protected]
Betreff: Re: panel can not be refreshed
Can you show the complete code of your MyPdfResource class?
Ernesto
On Tue, Nov 16, 2010 at 5:24 PM, <[email protected]> wrote:
> Hello Ernesto,
>
> I use the classes from your link
> https://cwiki.apache.org/WICKET/displaying-content-eg-pdf-excel-word-i
> n-an-iframe.html
>
> The PDF-File is displayed only when I use the constructor of panel with a
> parameter, even when both constructors do the same.
> What am I doing wrong?
>
> public class MyPdfPanel extends Panel
> {
> public FileDisplayPage()
> {
> add(renderFileContent("mypdf"));
> }
>
> private MyPdfPanel renderFileContent(String id)
> {
>
> return new MyPdfPanel(id); // it works
> //return new MyPdfPanel(id, getRenderFileContentModel(),
> getFileNameModel(), getContentTypeModel()); //it does not work
> }
> ..
> }
>
>
> public class MyPdfPanel extends Panel
> {
>
> public MyPdfPanel(String id)
> {
> super(id);
> setRenderBodyOnly(true);
> add(new DocumentInlineFrame("mypdf", new MyPdfResource()));
> }
>
> public MyPdfPanel(String id, IModel fileContentModel, IModel
> fileNameModel, IModel contentTypeModel)
> {
> super(id);
>
> file = (byte[]) fileContentModel.getObject();
> String fileName = (String) fileNameModel.getObject();
> String contentType = (String) contentTypeModel.getObject();
> setRenderBodyOnly(true);
> add(new DocumentInlineFrame("mypdf", new MyPdfResource()));
>
> //I will do later following call. I commented out for testing
> //add(new DocumentInlineFrame("mypdf", new MyPdfResource(file,
> contentType, fileName)));
> }
>
> }
>
> Regards
> Mehmet
>
>
> -----Ursprüngliche Nachricht-----
> Von: Ernesto Reinaldo Barreiro [mailto:[email protected]]
> Gesendet: Donnerstag, 11. November 2010 09:29
> An: [email protected]
> Betreff: Re: panel can not be refreshed
>
> The approach described in [1] used to work for me some time ago.
>
> Regards,
>
> Ernesto
>
> 1-https://cwiki.apache.org/WICKET/displaying-content-eg-pdf-excel-word
> -in-an-iframe.html
>
> On Thu, Nov 11, 2010 at 9:19 AM, <[email protected]> wrote:
>> Can someone help me?
>> When the constructor DocEditPage is called, the variables file, file name
>> and content type are null. These variables set to be later. But the panel is
>> not refreshed.
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Kaplankiran, Mehmet
>> Gesendet: Mittwoch, 10. November 2010 13:09
>> An: [email protected]
>> Betreff: panel can not be refreshed
>>
>> Hello,
>>
>> I have implemented iframe and can view documents. Unfortunately, only in the
>> class MyPdfResource hard-coded filename (example: private string filename =
>> "test.pdf";) can be displayed.
>> The files can not be refreshed. I hope someone can help me.
>>
>> greetings, Mehmet
>>
>> HTML:
>> <div wicket:id="mypdf" border="1" width="900px" height="400px"></div>
>>
>> ++++++++++++++++++++++++++++++ class DocEditPage
>> ++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++
>> ++++++++++++++++++++++++++++++ ++++++++++++
>> public class DocEditPage extends MainTemplate {
>>
>> private byte[] file;
>> private String fileName;
>> private String contentType;
>>
>> ...
>> public DocEditPage(PageParameters params)
>> {
>> ...
>> add(renderFileContent("mypdf"));
>> }
>> ...
>>
>> private MyPdfPanel renderFileContent(String id)
>> {
>> return new MyPdfPanel(id, getRenderFileContentModel(),
>> getContentTypeModel(), getFileNameModel);
>> }
>> ...
>> private IModel getRenderFileContentModel()
>> {
>>
>> return new AbstractReadOnlyModel()
>> {
>> �...@override
>> public Object getObject()
>> {
>> return file;
>> }
>> };
>> }
>>
>> private IModel getContentTypeModel()
>> {
>> return new AbstractReadOnlyModel()
>> {
>> �...@override
>> public Object getObject()
>> {
>> return contentType;
>> }
>> };
>> }
>>
>> private IModel getFileNameModel()
>> {
>> return new AbstractReadOnlyModel()
>> {
>> �...@override
>> public Object getObject()
>> {
>> return fileName;
>> }
>> };
>> }
>>
>> ...
>>
>> private DISTree disTree(String id)
>> {
>> return new DISTree(id)
>> {
>> �...@override
>> public void selectNode(AjaxRequestTarget
>> target, DISTreeNode node)
>> {
>> //set file and contentType;
>> ...
>> DocEditPage.this.contentType =
>> content.getContentType();
>> DocEditPage.this.file =
>> content.getOrbLk();
>> }
>> }
>> }
>>
>> }
>>
>> ++++++++++++++++++++++++++++++ class MyPdfPanel
>> ++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++
>> ++++++++++++++++++++++++++++++ ++++++++++++
>> public class MyPdfPanel extends Panel {
>>
>> public MyPdfPanel(String id, IModel fileContentModel, IModel
>> fileNameModel, IModel contentTypeModel)
>> {
>> //super(id, fileContentModel);
>> super(id);
>>
>> file = (byte[]) fileContentModel.getObject();
>> String fileName = (String) fileNameModel.getObject();
>> String contentType = (String)
>> contentTypeModel.getObject();
>> setRenderBodyOnly(true);
>> add(new DocumentInlineFrame("mypdf", new
>> MyPdfResource(file, contentType, fileName)));
>> }
>>
>> }
>>
>> ++++++++++++++++++++++++++++++ class MyPdfResource
>> ++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++
>> ++++++++++++++++++++++++++++++ ++++++++++++
>> public class MyPdfResource extends DynamicWebResource {
>> private static final long serialVersionUID = 1L; ...
>> private byte[] file;
>> private String contentType = "application/pdf";
>> private String fileName = "test.pdf"; ...
>> public MyPdfResource(byte[] file, String contenttype, String
>> filename)
>> {
>> if (file != null)
>> this.file = file;
>> if (contenttype != null &&
>> !"".equalsIgnoreCase(contenttype))
>> contentType = contenttype;
>> if (filename != null &&
>> !"".equalsIgnoreCase(filename))
>> fileName = filename;
>> }
>> ...
>> }
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]