List of usage examples for org.apache.wicket.util.lang Bytes Bytes
private Bytes(final long bytes)
From source file:com.locke.tricks.u.U.java
License:Apache License
@SuppressWarnings("unchecked") public U() {//from ww w . j a v a 2 s .c om final IColumn<Utility>[] columns = new IColumn[2]; columns[0] = new PropertyColumn<Utility>(new Model<String>("Code"), "code", "code"); columns[1] = new PropertyColumn<Utility>(new Model<String>("Output"), "output", "output"); final DataTable<Utility> dataTable = new DataTable<Utility>("utilities", columns, this.utilitiesDataProvider, Integer.MAX_VALUE); dataTable.addTopToolbar(new HeadersToolbar(dataTable, new ISortStateLocator() { private ISortState sortState = new SingleSortState(); public ISortState getSortState() { return this.sortState; } public void setSortState(final ISortState state) { this.sortState = state; } })); add(dataTable); this.utilities.add(new Utility("Time.now().toString()") { @Override public String getOutput() { return Time.now().toString(); } }); this.utilities.add(new Utility("Duration.ONE_WEEK.toString()") { @Override public String getOutput() { return Duration.ONE_WEEK.toString(); } }); this.utilities.add(new Utility("Duration.ONE_WEEK.add(Duration.ONE_DAY).toString()") { @Override public String getOutput() { return Duration.ONE_WEEK.add(Duration.ONE_DAY).toString(); } }); this.utilities.add(new Utility("Time.now().add(Duration.ONE_WEEK).toString()") { @Override public String getOutput() { return Time.now().add(Duration.ONE_WEEK).toString(); } }); this.utilities.add(new Utility("Bytes.valueOf(\"512K\") + Bytes.megabytes(1.3)") { @Override public String getOutput() { return Bytes.bytes(Bytes.valueOf("512K").bytes() + Bytes.megabytes(1.3).bytes()).toString(); } }); this.utilities.add(new Utility("Parsing \'13 + 13\' using MetaPattern") { @Override public String getOutput() { final IntegerGroup a = new IntegerGroup(MetaPattern.DIGITS); final IntegerGroup b = new IntegerGroup(MetaPattern.DIGITS); final MetaPattern sum = new MetaPattern(new MetaPattern[] { a, MetaPattern.OPTIONAL_WHITESPACE, MetaPattern.PLUS, MetaPattern.OPTIONAL_WHITESPACE, b }); final Matcher matcher = sum.matcher("13 + 13"); if (matcher.matches()) { return Integer.toString(a.getInt(matcher) + b.getInt(matcher)); } return "Failed to match."; } }); }
From source file:com.swordlord.gozer.frame.wicket.BinaryStreamWriter.java
License:Open Source License
@Override public Bytes length() { return Bytes.bytes(_stream.size()); }
From source file:cz.zcu.kiv.eegdatabase.wui.components.form.input.FileDownloadStreamWriter.java
License:Apache License
public FileDownloadStreamWriter(File file, String contentType) { this.file = file; this.contentType = contentType; this.length = Bytes.bytes(file.length()); }
From source file:eu.uqasar.web.pages.qmodel.QModelImportPage.java
License:Apache License
public QModelImportPage(PageParameters parameters) { super(parameters); logger.info("QModelImportPage::QModelImportPage start"); final Form<?> form = new Form<Void>("form") { /**// w w w .j a v a 2 s . c om * */ private static final long serialVersionUID = 4949407424211758709L; @Override protected void onSubmit() { logger.info("QModelImportPage::onSubmit starts"); errorMessage = ""; try { FileUpload upload = file.getFileUpload(); if (upload == null) { errorMessage = "qmodel.empty.file.error"; logger.info("QModelImportPage::onSubmit no file uploaded"); } else { logger.info("QModelImportPage::onSubmit some file uploaded"); if (upload.getSize() > Bytes.kilobytes(MAX_SIZE).bytes()) { errorMessage = "qmodel.max.file.error"; logger.info("QModelImportPage::onSubmit MAX_SIZE size" + upload.getSize()); } else { logger.info("QModelImportPage::onSubmit file name " + upload.getClientFileName() + " File-Size: " + Bytes.bytes(upload.getSize()).toString() + "content-type " + upload.getContentType()); user = UQasar.getSession().getLoggedInUser(); if (user.getCompany() != null) { company = companyService.getById(user.getCompany().getId()); } if (upload.getContentType() != null && upload.getContentType().equals(XML_CONTENT)) { //parsing qm = parse(upload, true); } else if (upload.getContentType() != null && (upload.getContentType().equals(JSON_CONTENT) || upload.getContentType().equals(OCT_CONTENT))) { //json candidate qm = parse(upload, false); } else { //file not valid errorMessage = "qmodel.type.file.error"; } } } if (qm != null) { qm.setUpdateDate(DateTime.now().toDate()); if (qm.getCompanyId() != 0) { qm.setCompany(companyService.getById(qm.getCompanyId())); } else { if (company != null) { qm.setCompany(company); qm.setCompanyId(company.getId()); } } qm = (QModel) qmodelService.create(qm); } } catch (uQasarException ex) { if (ex.getMessage().contains("nodeKey")) { errorMessage = "qmodel.key.unique"; } } catch (JsonProcessingException ex) { logger.info("JsonProcessingException----------------------------------------"); if (ex.getMessage().contains("expecting comma to separate ARRAY entries")) { errorMessage = "qmodel.json.parse.error"; } else if (ex.getMessage().contains("Unexpected character")) { errorMessage = "qmodel.json.char.error"; } else if (ex.getMessage().contains("Can not construct instance")) { errorMessage = "qmodel.json.enum.error"; } else { logger.info("JsonProcessingException----------------------------"); errorMessage = "qmodel.xml.parse.error"; } } catch (JAXBException ex) { logger.info("JAXBException----------------------------"); errorMessage = "qmodel.xml.parse.error"; } catch (Exception ex) { logger.info("IOException----------------------------"); errorMessage = "qmodel.import.importError"; } finally { PageParameters parameters = new PageParameters(); if (null != errorMessage && !errorMessage.equals("")) { logger.info("Attaching error message"); parameters.add(QModelImportPage.LEVEL_PARAM, FeedbackMessage.ERROR); parameters.add(QModelImportPage.MESSAGE_PARAM, getLocalizer().getString(errorMessage, this)); setResponsePage(QModelImportPage.class, parameters); } else { logger.info("qmodel successfully created: redirection"); //qmodel successfully created: redirection parameters.add(BasePage.LEVEL_PARAM, FeedbackMessage.SUCCESS); parameters.add(BasePage.MESSAGE_PARAM, getLocalizer().getString("treenode.imported.message", this)); parameters.add("qmodel-key", qm.getNodeKey()); parameters.add("name", qm.getName()); setResponsePage(QModelViewPage.class, parameters); } } } }; // create the file upload field file = new FileUploadField("file"); form.addOrReplace(file); form.add(new Label("max", new AbstractReadOnlyModel<String>() { /** * */ private static final long serialVersionUID = 3532428309651830468L; @Override public String getObject() { return (Bytes.kilobytes(MAX_SIZE)).toString(); } })); // add progress bar form.add(new UploadProgressBar("progress", form, file)); ServletContext context = ((WebApplication) getApplication()).getServletContext(); // Download xml example File filexml = new File(context.getRealPath("/assets/files/qmodel.xml")); DownloadLink xmlLink = new DownloadLink("xmlLink", filexml); form.add(xmlLink); // Download json example File filejson = new File(context.getRealPath("/assets/files/qmodel.json")); DownloadLink jsonLink = new DownloadLink("jsonLink", filejson); form.add(jsonLink); add(form); logger.info("QModelImportPage::QModelImportPage ends"); }
From source file:fiftyfive.wicket.util.LoggingUtils.java
License:Apache License
/** * Returns a Map with information associated with the following keys: * <ul>/* w ww . j a v a 2s .co m*/ * <li>{@code ID}</li> * <li>{@code Info} (if session implements {@link ISessionLogInfo})</li> * <li>{@code Size}</li> * <li>{@code Duration} (if {@link IRequestLogger} is enabled)</li> * </ul> */ public static Map<String, Object> getSessionInfo() { Session sess = Session.get(); Object detail = "--ISessionLogInfo not implemented--"; if (sess instanceof ISessionLogInfo) { detail = ((ISessionLogInfo) sess).getSessionInfo(); } Map<String, Object> info = new LinkedHashMap<String, Object>(); if (sess != null) { info.put("ID", sess.getId()); info.put("Info", detail); info.put("Size", Bytes.bytes(sess.getSizeInBytes())); Duration dur = getSessionDuration(); if (dur != null) { info.put("Duration", getSessionDuration()); } } return info; }
From source file:gr.interamerican.wicket.bo2.protocol.http.RequestCycleStats.java
License:Open Source License
/** * Writes to the log file useful things for debug purposes. * /*w w w.j ava 2s . co m*/ * @param workerNames * names of worker classes opened by this cycle. * @param timer * Timer. */ @SuppressWarnings("nls") void doLogForDebugging(String workerNames, Timer timer) { logger.debug("Cycles so far: " + cycles); logger.debug("Http session size estimation: " + Bytes.bytes(sessionSize).kilobytes() + " KB"); SystemState state = new SystemState(); logger.debug("Used memory = " + Double.toString(state.getUsedMemory())); long cycleDuration = timer.get(); if (cycleDuration > TOO_SLOW) { String userid = Utils.notNull(Bo2Session.getUserId(), NULL); String msg = StringUtils.concat("Slow cycle: ", " duration: ", StringUtils.toString(cycleDuration), " user: ", userid, " workers: ", workerNames); logger.debug(msg); } logExceptionStats(); }
From source file:gr.interamerican.wicket.markup.html.panel.FilePanel.java
License:Open Source License
/** * Refreshes the link label./*from w w w .java 2s. c o m*/ * * @param target */ @SuppressWarnings("nls") private void updateLinkLabel(AjaxRequestTarget target) { if (target != null) { target.add(downloadFileLink); } byte[] content = model.getObject() != null ? model.getObject() : new byte[0]; Bytes bytes = Bytes.bytes(content.length); linkLabel.setDefaultModelObject("[" + bytes.toString() + "]"); }
From source file:guru.mmp.application.web.template.resources.ErrorImageResourceStream.java
License:Apache License
/** * Returns the length of the resource stream. * * @return the length of the resource stream *//*from ww w .j a v a 2 s . c o m*/ @Override public Bytes length() { return Bytes.bytes(getErrorImageData().length); }
From source file:org.apache.openmeetings.web.common.UploadableImagePanel.java
License:Apache License
@Override protected void onInitialize() { super.onInitialize(); form.setMultiPart(true);//from w ww .j a v a2 s . c o m form.setMaxSize(Bytes.bytes(getMaxUploadSize())); // Model is necessary here to avoid writing image to the User object form.add(fileUploadField); form.add(new UploadProgressBar("progress", form, fileUploadField)); form.addOrReplace(getImage()); if (delayed) { add(new WebMarkupContainer("remove").add(AttributeModifier.append("onclick", "$(this).parent().find('.fileinput').fileinput('clear');"))); } else { add(new ConfirmableAjaxBorder("remove", getString("80"), getString("833")) { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { try { deleteImage(); } catch (Exception e) { log.error("Error", e); } update(Optional.of(target)); } }); fileUploadField.add(new AjaxFormSubmitBehavior(form, "change") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { process(Optional.of(target)); } }); } add(form.setOutputMarkupId(true)); add(BootstrapFileUploadBehavior.INSTANCE); }
From source file:org.apache.openmeetings.web.common.UploadableProfileImagePanel.java
License:Apache License
public UploadableProfileImagePanel(String id, final long userId) { super(id, userId); final Form<Void> form = new Form<Void>("form"); form.setMultiPart(true);//from w w w . j ava 2s . c o m form.setMaxSize(Bytes.bytes(getBean(ConfigurationDao.class).getMaxUploadSize())); // Model is necessary here to avoid writing image to the User object form.add(fileUploadField = new FileUploadField("image", new IModel<List<FileUpload>>() { private static final long serialVersionUID = 1L; //FIXME this need to be eliminated @Override public void detach() { } @Override public void setObject(List<FileUpload> object) { } @Override public List<FileUpload> getObject() { return null; } })); form.add(new UploadProgressBar("progress", form, fileUploadField)); fileUploadField.add(new AjaxFormSubmitBehavior(form, "change") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { FileUpload fu = fileUploadField.getFileUpload(); if (fu != null) { StoredFile sf = new StoredFile(fu.getClientFileName()); if (sf.isImage()) { boolean asIs = sf.isAsIs(); try { //FIXME need to work with InputStream !!! getBean(GenerateImage.class).convertImageUserProfile(fu.writeToTempFile(), userId, asIs); } catch (Exception e) { // TODO display error log.error("Error", e); } } else { //TODO display error } } update(); target.add(profile, form); } }); add(form.setOutputMarkupId(true)); add(BootstrapFileUploadBehavior.INSTANCE); }