Package org.apache.wicket.markup.html.form.upload

Examples of org.apache.wicket.markup.html.form.upload.FileUpload


    fileUploadField.add(new AjaxFormSubmitBehavior(langForm, "onchange") {
      private static final long serialVersionUID = 2160216679027859231L;

      @Override
      protected void onSubmit(AjaxRequestTarget target) {
        FileUpload download = fileUploadField.getFileUpload();
        try {
          if (download == null || download.getInputStream() == null) {
            importFeedback.error("File is empty");
            return;
          }
          getBean(LanguageImport.class)
            .addLanguageByDocument(language.getLanguage_id(), download.getInputStream(), getUserId());
        } catch (Exception e) {
          log.error("Exception on panel language editor import ", e);
          importFeedback.error(e);
        }

        // repaint the feedback panel so that it is hidden
        target.add(importFeedback);
      }
    });

    // Add a component to download a file without page refresh
    final AjaxDownload download = new AjaxDownload();
    langForm.add(download);

    langForm.add(new AjaxButton("export"){
      private static final long serialVersionUID = 1L;

      protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

        final List<Fieldlanguagesvalues> flvList = getBean(FieldLanguagesValuesDao.class).getMixedFieldValuesList(language.getLanguage_id());

        FieldLanguage fl = getBean(FieldLanguageDao.class).getFieldLanguageById(language.getLanguage_id());
        if (fl != null && flvList != null) {
          download.setFileName(fl.getName() + ".xml");
          download.setResourceStream(new AbstractResourceStream() {
            private static final long serialVersionUID = 1L;
            private StringWriter sw;
            private InputStream is;
           
            public InputStream getInputStream() throws ResourceStreamNotFoundException {
              try {
                Document doc = createDocument(flvList, getBean(FieldLanguagesValuesDao.class).getUntranslatedFieldValuesList(language.getLanguage_id()));
                sw = new StringWriter();
                LangExport.serializetoXML(sw, "UTF-8", doc);
                is = new ByteArrayInputStream(sw.toString().getBytes());
                return is;
              } catch (Exception e) {
                throw new ResourceStreamNotFoundException(e);
              }
            }
           
            public void close() throws IOException {
              if (is != null) {
                is.close();
                is = null;
              }
              sw = null;
            }
          });//new FileResourceStream(new File(requestedFile)));
          download.initiate(target);
        }
       
        // repaint the feedback panel so that it is hidden
        target.add(importFeedback);
      }
View Full Code Here


      add(fileUploadField.add(new AjaxFormSubmitBehavior(this, "onchange") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
          FileUpload upload = fileUploadField.getFileUpload();
          try {
            if (upload == null || upload.getInputStream() == null) {
              uploadFeedback.error("File is empty");
              target.add(uploadFeedback);
              return;
            }
            getBean(BackupImport.class).performImport(upload.getInputStream());
          } catch (Exception e) {
            log.error("Exception on panel backup upload ", e);
            uploadFeedback.error(e);
          }
          // repaint the feedback panel so that it is hidden
View Full Code Here

    fileUploadField.add(new AjaxFormSubmitBehavior(langForm, "onchange") {
      private static final long serialVersionUID = 2160216679027859231L;

      @Override
      protected void onSubmit(AjaxRequestTarget target) {
        FileUpload download = fileUploadField.getFileUpload();
        try {
          if (download == null || download.getInputStream() == null) {
            importFeedback.error("File is empty");
            return;
          }
          getBean(LanguageImport.class)
            .addLanguageByDocument(language.getLanguage_id(), download.getInputStream(), getUserId());
        } catch (Exception e) {
          log.error("Exception on panel language editor import ", e);
          importFeedback.error(e);
        }

        // repaint the feedback panel so that it is hidden
        target.add(importFeedback);
      }
    });

    // Add a component to download a file without page refresh
    final AjaxDownload download = new AjaxDownload();
    langForm.add(download);

    langForm.add(new AjaxButton("export"){
      private static final long serialVersionUID = 1L;

      protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

        final List<Fieldlanguagesvalues> flvList = getBean(FieldLanguagesValuesDao.class).getMixedFieldValuesList(language.getLanguage_id());

        FieldLanguage fl = getBean(FieldLanguageDao.class).getFieldLanguageById(language.getLanguage_id());
        if (fl != null && flvList != null) {
          download.setFileName(fl.getName() + ".xml");
          download.setResourceStream(new AbstractResourceStream() {
            private static final long serialVersionUID = 1L;
            private StringWriter sw;
            private InputStream is;
           
            public InputStream getInputStream() throws ResourceStreamNotFoundException {
              try {
                Document doc = createDocument(flvList, getBean(FieldLanguagesValuesDao.class).getUntranslatedFieldValuesList(language.getLanguage_id()));
                sw = new StringWriter();
                LangExport.serializetoXML(sw, "UTF-8", doc);
                is = new ByteArrayInputStream(sw.toString().getBytes());
                return is;
              } catch (Exception e) {
                throw new ResourceStreamNotFoundException(e);
              }
            }
           
            public void close() throws IOException {
              if (is != null) {
                is.close();
                is = null;
              }
              sw = null;
            }
          });//new FileResourceStream(new File(requestedFile)));
          download.initiate(target);
        }
       
        // repaint the feedback panel so that it is hidden
        target.add(importFeedback);
      }
View Full Code Here

    assertNotNull(domainObject);
    assertNotNull(domainObject.getText());
    assertEquals("Mock value", domainObject.getText());

    FileUpload fileUpload = page.getFileUpload();
    assertNotNull(fileUpload);

    assertTrue("setFile failed, no upload content detected.", fileUpload.getBytes().length > 0);
    assertEquals("pom.xml", fileUpload.getClientFileName());
    assertEquals("text/xml", fileUpload.getContentType());
  }
View Full Code Here

    assertNotNull(domainObject);
    assertNotNull(domainObject.getText());
    assertEquals("Mock value", domainObject.getText());

    FileUpload fileUpload = page.getFileUpload();
    assertNotNull(fileUpload);

    assertTrue("uploaded content does not have the right size, expected 428, got " +
        fileUpload.getBytes().length, fileUpload.getBytes().length == 428);
    assertEquals("bg.jpg", fileUpload.getClientFileName());
    assertEquals("image/jpeg", fileUpload.getContentType());
  }
View Full Code Here

    assertNotNull(domainObject);
    assertNotNull(domainObject.getText());
    assertEquals("Mock value", domainObject.getText());

    FileUpload fileUpload = page.getFileUpload();
    assertNotNull(fileUpload);

    assertTrue("setFile failed, no upload content detected.", fileUpload.getBytes().length > 0);
    assertEquals("pom.xml", fileUpload.getClientFileName());
    assertEquals("text/xml", fileUpload.getContentType());
  }
View Full Code Here

    assertNotNull(domainObject);
    assertNotNull(domainObject.getText());
    assertEquals("Mock value", domainObject.getText());

    FileUpload fileUpload = page.getFileUpload();
    assertNotNull(fileUpload);

    assertTrue("uploaded content does not have the right size, expected 428, got " +
      fileUpload.getBytes().length, fileUpload.getBytes().length == 428);
    assertEquals("bg.jpg", fileUpload.getClientFileName());
    assertEquals("image/jpeg", fileUpload.getContentType());
  }
View Full Code Here

      @Override
      protected void onSubmit()
      {
        // display uploaded info
        info("Text: " + text.getModelObject());
        FileUpload upload = file.getFileUpload();
        if (upload == null)
        {
          info("No file uploaded");
        }
        else
        {
          info("File-Name: " + upload.getClientFileName() + " File-Size: " +
            Bytes.bytes(upload.getSize()).toString());
        }
      }
    };
    form.setMaxSize(Bytes.megabytes(1));
    add(form);
View Full Code Here

    protected void onSubmit()
    {
      Iterator<FileUpload> it = uploads.iterator();
      while (it.hasNext())
      {
        final FileUpload upload = it.next();
        // Create a new file
        File newFile = new File(getUploadFolder(), upload.getClientFileName());

        // Check new file, delete if it allready existed
        checkFileExists(newFile);
        try
        {
          // Save to new file
          newFile.createNewFile();
          upload.writeTo(newFile);

          MultiUploadPage.this.info("saved file: " + upload.getClientFileName());
        }
        catch (Exception e)
        {
          throw new IllegalStateException("Unable to write file");
        }
View Full Code Here

     * @see org.apache.wicket.markup.html.form.Form#onSubmit()
     */
    @Override
    protected void onSubmit()
    {
      final FileUpload upload = fileUploadField.getFileUpload();
      if (upload != null)
      {
        // Create a new file
        File newFile = new File(getUploadFolder(), upload.getClientFileName());

        // Check new file, delete if it allready existed
        checkFileExists(newFile);
        try
        {
          // Save to new file
          newFile.createNewFile();
          upload.writeTo(newFile);

          UploadPage.this.info("saved file: " + upload.getClientFileName());
        }
        catch (Exception e)
        {
          throw new IllegalStateException("Unable to write file");
        }
View Full Code Here

TOP

Related Classes of org.apache.wicket.markup.html.form.upload.FileUpload

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.