001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.markup.html.form.upload;
018
019import java.io.Serializable;
020import java.util.Date;
021import java.util.Objects;
022import com.github.openjson.JSONObject;
023
024/**
025 * Description of file properties as in browser client side.
026 */
027public class FileDescription implements Serializable {
028
029    private static final long serialVersionUID = 1L;
030
031    private final String fileName;
032    private final long fileSize;
033    private final Date lastModified;
034    private final String mimeType;
035
036   public FileDescription(JSONObject jsonObject) {
037        this(jsonObject.getString("fileName"), jsonObject.getLong("fileSize"),
038                jsonObject.getLong("lastModified"), jsonObject.getString("mimeType"));
039    }
040
041    public FileDescription(String fileName, long fileSize, long lastModified, String mimeType) {
042        this.fileName = fileName;
043        this.fileSize = fileSize;
044        this.lastModified = new Date(lastModified);
045        this.mimeType = mimeType;
046    }
047
048    public String getFileName() {
049        return fileName;
050    }
051
052    public long getFileSize() {
053        return fileSize;
054    }
055
056    public Date getLastModified() {
057        return lastModified;
058    }
059
060    public String getMimeType() {
061        return mimeType;
062    }
063
064    @Override
065    public boolean equals(Object o) {
066        if (this == o) return true;
067        if (o == null || getClass() != o.getClass()) return false;
068        FileDescription that = (FileDescription) o;
069        return fileName.equals(that.fileName);
070    }
071
072    @Override
073    public int hashCode() {
074        return Objects.hash(fileName);
075    }
076}