Examples of UploadedFile


Examples of com.sun.webui.jsf.model.UploadedFile

            @HandlerInput(name="file", type=UploadedFile.class)},
  output={
            @HandlerOutput(name="origPath", type=String.class),
            @HandlerOutput(name="uploadedTempFile", type=String.class)})
    public static void uploadFileToTempDir(HandlerContext handlerCtx) {
  UploadedFile uploadedFile = (UploadedFile)handlerCtx.getInputValue("file");
  File tmpFile = null;
        String uploadTmpFile = "";
  if(uploadedFile != null) {
            String name = uploadedFile.getOriginalName();
            //see bug# 6498910, for IE, getOriginalName() returns the full path, including the drive.
            //for any other browser, it just returns the file name.
            int lastIndex = name.lastIndexOf("\\");
            if (lastIndex != -1){
                name = name.substring(lastIndex+1, name.length());
            }
      int index = name.indexOf(".");
      if(index <= 0) {
        String mesg = GuiUtil.getMessage("msg.deploy.nullArchiveError");
                GuiUtil.handleError(handlerCtx, mesg);
        return;
      }
            String suffix = name.substring(index);
            String prefix = name.substring(0, index);
            handlerCtx.setOutputValue("origPath", prefix);
            try {
                //createTempFile requires min. of 3 char for prefix.
                if (prefix.length() <=2)
                    prefix= prefix + new Random().nextInt(100000);
                tmpFile = File.createTempFile(prefix, suffix);
    tmpFile.deleteOnExit();
    uploadedFile.write(tmpFile);
    uploadTmpFile = tmpFile.getCanonicalPath();
            } catch (IOException ioex) {
                try {
                    uploadTmpFile = tmpFile.getAbsolutePath();
    } catch (Exception ex) {
View Full Code Here

Examples of fitnesse.http.UploadedFile

    FileUtil.deleteFileSystemDirectory(context.getRootPagePath());
  }

  @Test
  public void testMakeResponse() throws Exception {
    request.addInput("file", new UploadedFile("sourceFilename.txt", "plain/text", testFile));
    request.setResource("files/");

    Response response = responder.makeResponse(context, request);

    File file = new File(context.getRootPagePath() + "/files/sourceFilename.txt");
View Full Code Here

Examples of it.eng.spagobi.commons.utilities.UploadedFile

  // get exported file and eventually the associations file
//  UploadedFile archive = null;
//  UploadedFile associationsFile = null;
  FileItem archive = null;
  FileItem associationsFileItem = null;
  UploadedFile associationsFile = null;
  AssociationFile assFile = null;
  try {
    String assKindFromReq = (String) request.getAttribute("importAssociationKind");
    boolean isNoAssociationModality = assKindFromReq != null && assKindFromReq.equalsIgnoreCase("noassociations");
    List uplFiles = request.getAttributeAsList("UPLOADED_FILE");
    Iterator uplFilesIter = uplFiles.iterator();
    while (uplFilesIter.hasNext()) {
        //UploadedFile uplFile = (UploadedFile) uplFilesIter.next();
      FileItem uplFile = (FileItem) uplFilesIter.next();
        //String nameInForm = uplFile.getFieldNameInForm();
      String nameInForm = uplFile.getFieldName();
        if (nameInForm.equals("exportedArchive")) {
          archive = uplFile;
        } else if (nameInForm.equals("associationsFile")) {
          associationsFileItem = uplFile;
        }
    }
    // check that the name of the uploaded archive is not empty
    //String archiveName = archive.getFileName();
    String archiveName = GeneralUtilities.getRelativeFileNames(archive.getName());
    if (archiveName.trim().equals("")) {
        logger.error("Missing exported file");
      response.setAttribute(ImportExportConstants.PUBLISHER_NAME, "ImportExportLoopbackStopImport");
        throw new EMFValidationError(EMFErrorSeverity.ERROR, "exportedArchive", "8007", "component_impexp_messages");
    }
   
    int maxSize = ImportUtilities.getImportFileMaxSize();
    if (archive.getSize() > maxSize) {
        logger.error("File is too large!!!");
      response.setAttribute(ImportExportConstants.PUBLISHER_NAME, "ImportExportLoopbackStopImport");
        throw new EMFValidationError(EMFErrorSeverity.ERROR, "exportedArchive", "202");
    }
   
    // checks if the association file is bigger than 1 MB, that is more than enough!!
    if (associationsFileItem != null) {
      if (associationsFileItem.getSize() > 1048576) {
        throw new EMFValidationError(EMFErrorSeverity.ERROR, "associationsFile", "202");
      }
      // loads association file
      associationsFile = new UploadedFile();
      associationsFile.setFileContent(associationsFileItem.get());
      associationsFile.setFieldNameInForm(associationsFileItem.getFieldName());
      associationsFile.setSizeInBytes(associationsFileItem.getSize());
      associationsFile.setFileName(GeneralUtilities.getRelativeFileNames(associationsFileItem.getName()));
    }
   
    // if the user choose to have no associations, checks the form, otherwise set the variable associationsFile = null
    if (!isNoAssociationModality) {
      // check if the name of associations file is empty (in this case set
      // null to the variable)
      if (associationsFile != null) {
        String associationsFileName = associationsFile.getFileName();
        if (associationsFileName.trim().equals("")) {
            associationsFile = null;
        }
      }
      // if the association file is empty then check if there is an
      // association id
      // rebuild the uploaded file and assign it to associationsFile variable
      if (associationsFile == null) {
          String assId = (String) request.getAttribute("hidAssId");
          if ((assId != null) && !assId.trim().equals("")) {
        IAssociationFileDAO assfiledao = new AssociationFileDAO();
        assFile = assfiledao.loadFromID(assId);
        byte[] content = assfiledao.getContent(assFile);
        UploadedFile uplFile = new UploadedFile();
        uplFile.setSizeInBytes(content.length);
        uplFile.setFileContent(content);
        uplFile.setFileName("association.xml");
        uplFile.setFieldNameInForm("");
        associationsFile = uplFile;
          }
      }
    } else {
      associationsFile = null;
View Full Code Here

Examples of org.apache.myfaces.custom.fileupload.UploadedFile

        return true;
  }
 
  public void validateFile(FacesContext context, UIComponent toValidate, Object value) {
    System.err.println("ValidateFile()");
    UploadedFile file = (UploadedFile) value;
    long size = file.getSize();
    Map properties = toValidate.getAttributes();
    long maxSize = Long.parseLong( (String) properties.get("maxSize") );
       
    if (size <= 0 || size > maxSize) {
      ((UIInput) toValidate).setValid(false);
View Full Code Here

Examples of org.apache.myfaces.custom.fileupload.UploadedFile

            folder.setName("UnamedDocument");
            folder.setParentCollection((Collection) CollectionDao.createInstance().getRootCollection().getCollections().get(0));
            folder.setDatestamp(new GregorianCalendar());
            folderDao.save(folder);
            for (Iterator it = this.files.values().iterator(); it.hasNext();) {
                UploadedFile currentFile = (UploadedFile) it.next();
                List storedFiles = new ArrayList();
                StoredFile newFile = new StoredFileImpl();
                newFile.setName("content" + Math.random() + ".doc");
                newFile.setParent(folder);
                try {
                    newFile.setData(currentFile.getInputStream());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                newFile.setMimeType("application/msword");
View Full Code Here

Examples of org.apache.myfaces.trinidad.model.UploadedFile

   * @param name the name under which the file is stored.  In HTML forms,
   *   this will be derived from the "name" set on the &lt;input&gt; tag.
   */
  public UploadedFile getUploadedFile(String name)
  {
    UploadedFile file = _map.get(name);
    if (file == null)
      return null;

    return new FixFilename(file, _characterEncoding);
  }
View Full Code Here

Examples of org.apache.myfaces.trinidad.model.UploadedFile

  public void dispose()
  {
    Iterator<UploadedFile> iterator = _map.values().iterator();
    while (iterator.hasNext())
    {
      UploadedFile file = iterator.next();
      file.dispose();
    }

    _map.clear();

    _totalMemory    = 0;
View Full Code Here

Examples of org.apache.myfaces.trinidad.model.UploadedFile

      final RequestContext   context,
      final ExternalContext  externalContext,
      final UploadedFiles     files,
      final MultipartFormItem item) throws IOException
  {
    final UploadedFile temp = new TempUploadedFile(item);

    final UploadedFile file =
      context.getUploadedFileProcessor().processFile(externalContext.getRequest(), temp);

    if (file != null)
    {
      // Store the file.
      files.__put(item.getName(), file);

      if (_LOG.isFine())
      {
        _LOG.fine("Uploaded file " + file.getFilename() + "(" +
            file.getLength() + " bytes) for ID " + item.getName());
      }
    }
  }
View Full Code Here

Examples of org.apache.myfaces.trinidad.model.UploadedFile

    // Since we override getSubmittedValue() entirely,
    // detect auto submit manually
    detectAutoSubmit(context, component, clientId);

    Object result = null;
    UploadedFile file = null;

    UploadedFiles files = UploadedFiles.getUploadedFiles(context);
    if (files != null)
    {
      file = files.getUploadedFile(clientId);
    }

    // If we couldn't find a file (or the file is empty), return "FALSE" to indicate that
    // the file upload *was* available, but didn't upload a file
    // this time.
    if (file == null || file.getLength() == 0)
      result = Boolean.FALSE;
    else
      result = file;

    return result;
View Full Code Here

Examples of org.apache.myfaces.trinidad.model.UploadedFile

  {
    // Convert FALSE back into null
    if (submittedValue == Boolean.FALSE)
      return null;

    UploadedFile file = (UploadedFile) submittedValue;
    if(file.getLength() == -1)
    {
      FacesMessage fm = MessageFactory.getMessage(context, "org.apache.myfaces.trinidad.UPLOAD");
      throw new ConverterException(fm);
    }

    FacesBean bean = getFacesBean(component);
    Converter converter = getConverter(bean);
    // support converter for the <inputFile> component
    if(converter != null)
    {
      // create a unique key (component class name + filename) and use this
      // key to add the actual uploaded file to the requestMap
      String fileNameKey = component.getClass().getName() + "." + file.getFilename();
      context.getExternalContext().getRequestMap().put(fileNameKey, file);
     
      // applying the above convention. The String here is just the
      // unique key which the converter has to use to look for the
      // actual uploaded file.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.