Example usage for org.apache.wicket.util.resource StringResourceStream setCharset

List of usage examples for org.apache.wicket.util.resource StringResourceStream setCharset

Introduction

In this page you can find the example usage for org.apache.wicket.util.resource StringResourceStream setCharset.

Prototype

@Override
public void setCharset(final Charset charset) 

Source Link

Document

Sets the character set used for reading this resource.

Usage

From source file:nl.knaw.dans.dccd.web.download.DownloadPanel.java

License:Apache License

private WebResource getXMLWebResource() //final Project project)
{
    WebResource export = new WebResource() {
        private static final long serialVersionUID = -5599977621589734872L;

        @Override// ww  w .  java  2s  .co m
        public IResourceStream getResourceStream() {

            CharSequence xml = null;
            java.io.StringWriter sw = new StringWriter();

            // get complete project from repository,
            // just overwrite any thing allready downloaded
            // convert that to TRiDaS
            //
            // Note: make it a service to get xml from a project
            try {
                // NOTE for refactoring; we only need an StroreId, not a whole project
                project = DccdDataService.getService().getProject(storeId);

                //
                JAXBContext jaxbContext = null;
                // System.out.println("\n TRiDaS XML, non valid, but with the structure");
                jaxbContext = JAXBContext.newInstance("org.tridas.schema");
                // now marshall the pruned clone
                Marshaller marshaller = jaxbContext.createMarshaller();
                marshaller.setProperty(Marshaller.JAXB_ENCODING, TRIDAS_XML_CHARSET);
                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);// testing
                marshaller.marshal(project.getTridas(), sw);
                // System.out.print(sw.toString());

            } catch (DataServiceException e) {
                e.printStackTrace();
                error(e.getMessage());
            } catch (JAXBException e) {
                e.printStackTrace();
                error(e.getMessage());
            }

            xml = sw.toString();
            StringResourceStream rs = new StringResourceStream(xml, "text/xml");
            rs.setCharset(Charset.forName(TRIDAS_XML_CHARSET)); // must be according to tridas
            return rs;
        }

        @Override
        protected void setHeaders(WebResponse response) {
            super.setHeaders(response);

            // construct filename
            final String XML_EXTENSION = "xml";
            String filename = project.getTitle();
            if (filename.length() == 0)
                filename = "tridas"; // at least have decent filename
            filename = filename + "-" + project.getSid(); // add the repository unique id?
            filename = filename + "." + XML_EXTENSION;

            response.setAttachmentHeader(filename);
        }
    };
    export.setCacheable(false);

    return export;
}

From source file:nl.knaw.dans.dccd.web.search.SearchResultDownloadPage.java

License:Apache License

private IResourceStream getResourceStreamForXML() {
    CharSequence txt = theData;//getAllResultsAsXML();

    StringResourceStream rs = new StringResourceStream(txt, MIMETYPE_XML);
    rs.setCharset(Charset.forName("UTF-8"));
    return rs;//from  ww w.jav  a  2s .c  o  m
}

From source file:nl.knaw.dans.dccd.web.search.SearchResultDownloadPage.java

License:Apache License

private IResourceStream getResourceStreamForCSV() {
    // prepend BOM, some programs like it others don't 
    CharSequence txt = UTF8_BOM + getDataAsTabDelimitedText();

    StringResourceStream rs = new StringResourceStream(txt, MIMETYPE_CSV);
    rs.setCharset(Charset.forName("UTF-8"));
    return rs;//w  ww.  j a  v  a2  s.  c  o m
}

From source file:org.apache.openmeetings.web.room.StartSharingEventBehavior.java

License:Apache License

@Override
protected void respond(AjaxRequestTarget target) {
    //TODO deny download in case other screen sharing is in progress
    String app = "";
    try (InputStream jnlp = getClass().getClassLoader().getResourceAsStream("APPLICATION.jnlp")) {
        ConfigurationDao cfgDao = getBean(ConfigurationDao.class);
        app = IOUtils.toString(jnlp, StandardCharsets.UTF_8);
        String baseUrl = cfgDao.getBaseUrl();
        Room room = getBean(RoomDao.class).get(roomId);
        String publicSid = getParam(getComponent(), PARAM_PUBLIC_SID).toString();
        SessionManager sessionManager = getBean(SessionManager.class);
        Client rc = getClient(publicSid);
        if (rc == null) {
            throw new RuntimeException(String.format("Unable to find client by publicSID '%s'", publicSid));
        }//from w ww .  j  a  v a2s.  c  o  m
        String _url = rc.getTcUrl();
        URI url = new URI(_url);
        String path = url.getPath();
        path = path.substring(path.lastIndexOf('/') + 1);
        if (Strings.isEmpty(path) || rc.getRoomId() == null || !path.equals(rc.getRoomId().toString())
                || !rc.getRoomId().equals(roomId)) {
            throw new RuntimeException(String.format("Invalid room id passed %s, expected, %s", path, roomId));
        }
        Protocol protocol = Protocol.valueOf(url.getScheme());
        app = addKeystore(rc, app, protocol).replace("$codebase", baseUrl + "screenshare")
                .replace("$applicationName", cfgDao.getAppName()).replace("$url", _url)
                .replace("$publicSid", publicSid)
                .replace("$labels",
                        CDATA_BEGIN + getLabels(730, 731, 732, 733, 734, 735, 737, 738, 739, 740, 741, 742, 844,
                                869, 870, 871, 872, 878, 1089, 1090, 1091, 1092, 1093, 1465, 1466, 1467, 1468,
                                1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476, 1477, 1589, 1598, 1078)
                                + CDATA_END)
                .replace("$defaultQuality", cfgDao.getConfValue(CONFIG_SCREENSHARING_QUALITY, String.class, ""))
                .replace("$defaultFps", cfgDao.getConfValue(CONFIG_SCREENSHARING_FPS, String.class, ""))
                .replace("$showFps", cfgDao.getConfValue(CONFIG_SCREENSHARING_FPS_SHOW, String.class, "true"))
                .replace("$allowRemote",
                        cfgDao.getConfValue(CONFIG_SCREENSHARING_ALLOW_REMOTE, String.class, "true"))
                .replace("$allowRecording",
                        "" + (rc.getUserId() > 0 && room.isAllowRecording() && rc.isAllowRecording()
                                && (0 == sessionManager.getRecordingCount(roomId))))
                .replace("$allowPublishing", "" + (0 == sessionManager.getPublishingCount(roomId)));
    } catch (Exception e) {
        log.error("Unexpected error while creating jnlp file", e);
    }
    StringResourceStream srs = new StringResourceStream(app, "application/x-java-jnlp-file");
    srs.setCharset(StandardCharsets.UTF_8);
    download.setResourceStream(srs);
    download.initiate(target);
}

From source file:org.opensingular.lib.wicket.util.bootstrap.layout.TemplatePanel.java

License:Apache License

@Override
protected IMarkupSourcingStrategy newMarkupSourcingStrategy() {
    return new PanelMarkupSourcingStrategy(false) {
        @Override//from w  w w  .  j  ava  2 s.c o  m
        public IMarkupFragment getMarkup(MarkupContainer parent, Component child) {
            // corrige o problema de encoding
            StringResourceStream stringResourceStream = new StringResourceStream(
                    "<wicket:panel>" + getTemplateFunction().apply(TemplatePanel.this) + "</wicket:panel>",
                    "text/html");
            stringResourceStream.setCharset(Charset.forName(
                    Optional.ofNullable(Application.get().getMarkupSettings().getDefaultMarkupEncoding())
                            .orElse(StandardCharsets.UTF_8.name())));

            MarkupParser markupParser = new MarkupParser(new MarkupResourceStream(stringResourceStream));
            markupParser.setWicketNamespace(MarkupParser.WICKET);
            Markup markup;
            try {
                markup = markupParser.parse();
            } catch (Exception e) {
                throw SingularUtil.propagate(e);
            }

            // If child == null, than return the markup fragment starting
            // with <wicket:panel>
            if (child == null) {
                return markup;
            }

            // Copiado da superclasse. buscando markup do child
            IMarkupFragment associatedMarkup = markup.find(child.getId());
            if (associatedMarkup != null) {
                return associatedMarkup;
            }
            associatedMarkup = searchMarkupInTransparentResolvers(parent, parent.getMarkup(), child);
            if (associatedMarkup != null) {
                return associatedMarkup;
            }
            return findMarkupInAssociatedFileHeader(parent, child);
        }

        @Override
        public void onComponentTagBody(Component component, MarkupStream markupStream, ComponentTag openTag) {
            TemplatePanel.this.onBeforeComponentTagBody(markupStream, openTag);
            super.onComponentTagBody(component, markupStream, openTag);
            TemplatePanel.this.onAfterComponentTagBody(markupStream, openTag);
        }
    };
}