001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.gwt.client.ui.input.upload;
029
030import java.util.Comparator;
031
032import com.google.gwt.core.client.JavaScriptObject;
033import com.google.gwt.dom.client.InputElement;
034
035/**
036 * A file object.<p>
037 *
038 * @since 8.0.0
039 */
040public class CmsFileInfo extends JavaScriptObject {
041
042    /** The file info comparator. */
043    public static final Comparator<CmsFileInfo> INFO_COMPARATOR = new Comparator<CmsFileInfo>() {
044
045        /**
046         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
047         */
048        public int compare(CmsFileInfo o1, CmsFileInfo o2) {
049
050            return o1.getFileName().compareTo(o2.getFileName());
051        }
052    };
053
054    /**
055     * Creates a simple JS file object.<p>
056     */
057    protected CmsFileInfo() {
058
059        // noop
060    }
061
062    /**
063     * Returns the file name.<p>
064     *
065     * @return the file name
066     */
067    public final native String getFileName() /*-{
068
069                                             return this.name ? this.name : this.fileName;
070
071                                             }-*/;
072
073    /**
074     * Returns the file size.<p>
075     *
076     * @return the file size
077     */
078    public final native int getFileSize() /*-{
079
080                                          return this.size ? this.size : this.fileSize;
081
082                                          }-*/;
083
084    /**
085     * Returns the suffix of the file name with the dot at the beginning e.g. <code>".zip"</code>.<p>
086     *
087     * @return the suffix of the file name
088     */
089    public final native String getFileSuffix() /*-{
090
091                                               var filename = this.name ? this.name : this.fileName;
092                                               var dot = filename.lastIndexOf(".");
093                                               if (dot >= 0) {
094                                               return filename.substr(dot, filename.length);
095                                               }
096                                               return "";
097
098                                               }-*/;
099
100    /**
101     * Returns the associated input element if available.<p>
102     *
103     * @return the input element
104     */
105    public final native InputElement getInputElement() /*-{
106                                                       return this.input ? this.input : null;
107                                                       }-*/;
108
109    /**
110     * Returns the file name to override the original one if set, or the original file name.<p>
111     *
112     * @return the override file name
113     */
114    public final native String getOverrideFileName() /*-{
115                                                     return this.overrideFileName ? this.overrideFileName
116                                                     : this.name ? this.name : this.fileName;
117                                                     }-*/;
118
119    /**
120     * Sets the file name to override the original one.<p>
121     *
122     * @param overrideFileName the override file name
123     */
124    public final native void setOverrideFileName(String overrideFileName) /*-{
125                                                                          this.overrideFileName = overrideFileName;
126                                                                          }-*/;
127}