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

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


    Form uploadForm(final Form form) {
        return new Form("uploadForm") {
            @Override
            protected void onSubmit() {
                FileUpload upload = fileUploadField.getFileUpload();
                if (upload == null) {
                    warn("No file selected.");
                    return;
                }
                ByteArrayOutputStream bout = new ByteArrayOutputStream();

                try {
                    IOUtils.copy(upload.getInputStream(), bout);
                    setRawSLD(new InputStreamReader(new ByteArrayInputStream(bout.toByteArray()), "UTF-8"));
                    editor.setModelObject(rawSLD);
                } catch (IOException e) {
                    throw new WicketRuntimeException(e);
                }

                // update the style object
                StyleInfo s = (StyleInfo) form.getModelObject();
                if (s.getName() == null || "".equals(s.getName().trim())) {
                    // set it
                    nameTextField.setModelValue(ResponseUtils.stripExtension(upload
                            .getClientFileName()));
                    nameTextField.modelChanged();
                }
            }
        };
View Full Code Here


        return new Form<Void>(identifier) {

            @Override
            protected void onSubmit() {

                FileUpload fileUpload = fileUploadField.getFileUpload();

                boolean abort = false;
                if (fileUpload == null) {
                    abort = true;
                    warn("You did not choose a file!");
                }
                if (sourceFormat.getModelObject() == null) {
                    abort = true;
                    warn("You did not choose a source format!");
                }
                if (targetFormat.getModelObject() == null) {
                    abort = true;
                    warn("You did not choose a target format!");
                }
                if (abort) {
                    return;
                }

                File transactionFolder = new File(DemoApplication.get().getUploadFolder(), DemoApplication.get().nextFolderName());
                if (!transactionFolder.mkdirs()) {
                    LOGGER.warn("Could not create directory", transactionFolder);
                }
                File newFile = new File(transactionFolder, FileRow.SOURCE_FILE_NAME);

                try {
                    if (!newFile.createNewFile()) {
                        throw new IOException(String.format("Could not create file %s", newFile));
                    }
                    fileUpload.writeTo(newFile);
                    File target = new File(transactionFolder, FileRow.TARGET_FILE_NAME);

                    Properties properties = new Properties();
                    properties.setProperty(FileRow.INPUT_NAME_PROPERTY_KEY, fileUpload.getClientFileName());
                    properties.setProperty(FileRow.SOURCE_FORMAT, sourceFormat.getModelObject().toString());
                    properties.setProperty(FileRow.TARGET_FORMAT, targetFormat.getModelObject().toString());

                    FeedbackMessageConductor conductor = new FeedbackMessageConductor(fileUpload.getClientFileName());
                    long conversionDuration;
                    try {
                        conversionDuration = System.currentTimeMillis();
                        DemoApplication.get().getConverter()
                                .convert(newFile).as(sourceFormat.getModelObject())
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

     */
    protected void onSubmit() {
      super.onSubmit();

      if (!this.hasError()) {
        final FileUpload upload = fileUploadField.getFileUpload();
        if (upload != null) {
          try {
            StringWriter xmlSourceWriter = new StringWriter();
            IOUtils.copy(upload.getInputStream(), xmlSourceWriter);
            processSubmittedDoap(xmlSourceWriter.toString());
          } catch (IOException e) {
            setResponsePage(new ErrorReportPage(new UserReportableException(
                "Unable to add doap using RDF supplied", DoapFormPage.class, e)));
          }
View Full Code Here

     */
    protected void onSubmit() {
      super.onSubmit();

      if (!this.hasError()) {
        final FileUpload upload = fileUploadField.getFileUpload();
        if (upload != null) {
          File newFile = new File(getUploadFolder(), upload.getClientFileName());

          if (newFile.exists() && !Files.remove(newFile)) {
            throw new IllegalStateException("Unable to overwrite "
                + newFile.getAbsolutePath());
          }

          try {
            boolean success = newFile.createNewFile();
            if (!success) {
              logger.warn("Trying ot create a file that already exists: "
                  + newFile);
            }
            upload.writeTo(newFile);
            logger.info("Uploaded PIMS export saved to "
                + upload.getClientFileName());
          } catch (IOException e) {
            throw new IllegalStateException("Unable to write file");
          }

          try {
View Full Code Here

    Form uploadForm(final Form form) {
        return new Form("uploadForm") {
            @Override
            protected void onSubmit() {
                FileUpload upload = fileUploadField.getFileUpload();
                if (upload == null) {
                    warn("No file selected.");
                    return;
                }
                ByteArrayOutputStream bout = new ByteArrayOutputStream();

                try {
                    IOUtils.copy(upload.getInputStream(), bout);
                    setRawStyle(new InputStreamReader(new ByteArrayInputStream(bout.toByteArray()), "UTF-8"));
                    editor.setModelObject(rawStyle);
                } catch (IOException e) {
                    throw new WicketRuntimeException(e);
                }

                // update the style object
                StyleInfo s = (StyleInfo) form.getModelObject();
                if (s.getName() == null || "".equals(s.getName().trim())) {
                    // set it
                    nameTextField.setModelValue(ResponseUtils.stripExtension(upload
                            .getClientFileName()));
                    nameTextField.modelChanged();
                }
            }
        };
View Full Code Here

                     * @see org.apache.wicket.markup.html.form.Button#onSubmit()
                     */
                    @Override
                    public void onSubmit()
                    {
                        final FileUpload upload = fileUpload;
                        final String userName = getPortletRequest()
                                .getUserPrincipal().getName();
                        String usrFolder;
                        String fileType;
                        String fileName;
                        String pathSeparator = System
                                .getProperty("file.separator");
                        boolean success = false;
                        if (upload != null)
                        {
                            try
                            {
                                PageManager pageManager = getServiceLocator()
                                        .getPageManager();
                                InputStream docStream = upload.getInputStream();
                                fileName = upload.getClientFileName();
                                fileType = fileExt(upload.getClientFileName());
                                cleanUserFolder(userName);
                                usrFolder = getTempFolder(userName);
                                String destPath = node.getNodePath();
                                upload.writeTo(new File(usrFolder
                                        + pathSeparator
                                        + upload.getClientFileName()));
                                // File writed in temp folder
                                if (fileType != null && !fileType.equals("")
                                        && fileName != null
                                        && !fileName.equals("")
                                        && destPath != null
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.