X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=legacy%2Fruntime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fweb%2Fajaxplorer%2Ffile%2FAjxpFile.java;fp=legacy%2Fruntime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fweb%2Fajaxplorer%2Ffile%2FAjxpFile.java;h=2a589a4bda5d90e20ed8fc9e49ed205a54542698;hb=651d33e13bfa9a7b46464be412023ee747e612e8;hp=0000000000000000000000000000000000000000;hpb=868102c0f0220e12eca836b6ec9b3a2b9a3441e4;p=gpl%2Fargeo-slc.git diff --git a/legacy/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/ajaxplorer/file/AjxpFile.java b/legacy/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/ajaxplorer/file/AjxpFile.java new file mode 100644 index 000000000..2a589a4bd --- /dev/null +++ b/legacy/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/ajaxplorer/file/AjxpFile.java @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.slc.web.ajaxplorer.file; + +import java.io.File; +import java.net.URLEncoder; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.web.ajaxplorer.AjxpDriverException; + +public class AjxpFile { + private final static Log log = LogFactory.getLog(AjxpFile.class); + + // FIXME: more generic modif time format? + private final static SimpleDateFormat sdf = new SimpleDateFormat( + "dd/MM/yyyy hh:mm"); + + private final File file; + private final String parentPath; + private final String filePath; + + private final String ext; + private final FileType type; + + public AjxpFile(File file, String parentPath) { + this.file = file; + this.parentPath = parentPath; + if (parentPath.equals("/")) { + this.filePath = "/" + file.getName(); + } else { + this.filePath = parentPath + "/" + file.getName(); + } + this.ext = file.isDirectory() ? null : file.getName().substring( + file.getName().indexOf('.') + 1); + this.type = FileType.findType(ext); + } + + public String toXml(final LsMode mode, final String encoding) { + try { + StringBuffer buf = new StringBuffer(); + buf.append(""); + + if (log.isTraceEnabled()) + log.trace(buf.toString()); + + return buf.toString(); + } catch (Exception e) { + throw new AjxpDriverException("Could not serialize file " + file, e); + } + } + + private String formatModifTime() { + return sdf.format(new Date(file.lastModified())); + } + + private String formatFileSize() { + return (file.length() / 1024) + " Kb"; + } + + protected void addAttr(String attrName, String attrValue, StringBuffer buf) { + buf.append(" ").append(attrName).append("=\"").append(attrValue) + .append("\""); + } + + /** To be overridden, do nothing by default. */ + protected void addAdditionalAttrs(final StringBuffer buf, + final LsMode mode, final String encoding) { + + } +}