Try:
public class P1 extends WebPage {
private ResourceReference resourceRef;
static {
WebApplication app = (WebApplication) Application.get();
mount(app, Locale.ENGLISH);
mount(app, Locale.CHINESE);
}
private static void mount(WebApplication app, Locale locale) {
ResourceReference resourceRef = makeResourceReference();
resourceRef.setLocale(locale);
app.mountSharedResource("/download/cvs_" + locale + ".pdf",
resourceRef
.getSharedResourceKey());
}
@Override
protected void onBeforeRender() {
super.onBeforeRender();
resourceRef.setLocale(getLocale());
}
public P1() {
resourceRef = makeResourceReference();
ResourceLink link = new ResourceLink("link", resourceRef);
add(link);
Link changeLocale = new Link("changeLocale") {
private int n = 0;
@Override
public void onClick() {
n++;
Locale newLocale = (n % 2 == 0) ? Locale.ENGLISH
: Locale.CHINESE;
getSession().setLocale(newLocale);
}
};
add(changeLocale);
}
private static ResourceReference makeResourceReference() {
return new ResourceReference("cvs.pdf") {
@Override
protected Resource newResource() {
return new PDFResource(getLocale());
}
};
}
}
public class PDFResource extends DynamicWebResource {
public PDFResource(Locale locale) {
super(locale);
}
@Override
protected ResourceState getResourceState() {
ResourceState state = new ResourceState() {
@Override
public byte[] getData() {
return readPDF();
}
@Override
public String getContentType() {
return "application/pdf";
}
};
return state;
}
protected byte[] readPDF() {
try {
File f = new File("c:/tmp/cvs_"+getLocale()+".pdf");
FileInputStream s = new FileInputStream(f);
byte[] content = new byte[(int) f.length()];
s.read(content);
s.close();
return content;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
-----
--
Kent Tong
Wicket tutorials freely available at http://www.agileskills2.org/EWDW
Axis2 tutorials freely available at http://www.agileskills2.org/DWSAA
--
View this message in context:
http://www.nabble.com/Re%3A-Small-shared-resource-question...-tp15663443p15737491.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]