r183 - in trunk/src/main/java/org/nuiton/scmwebeditor: . actions
Author: kcardineaud Date: 2011-07-22 11:04:24 +0200 (Fri, 22 Jul 2011) New Revision: 183 Url: http://nuiton.org/repositories/revision/scmwebeditor/183 Log: Add some file's types in compatibility list Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java Modified: trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-07-21 08:19:04 UTC (rev 182) +++ trunk/src/main/java/org/nuiton/scmwebeditor/ScmWebEditorBaseAction.java 2011-07-22 09:04:24 UTC (rev 183) @@ -235,7 +235,7 @@ } - protected String getMineType(File file) throws IOException, SAXException, TikaException { + protected String getMimeType(File file) throws IOException, SAXException, TikaException { InputStream is = new FileInputStream(file); try { BodyContentHandler contenthandler = new BodyContentHandler(); @@ -254,7 +254,7 @@ } } - protected String getMineType(String content, String filename) throws IOException, SAXException, TikaException { + protected String getMimeType(String content, String filename) throws IOException, SAXException, TikaException { InputStream is = new ByteArrayInputStream(content.getBytes()); try { BodyContentHandler contenthandler = new BodyContentHandler(); @@ -274,4 +274,26 @@ } } + protected String[] getMimeTypes(String content, String filename) throws IOException, SAXException, TikaException { + InputStream is = new ByteArrayInputStream(content.getBytes()); + try { + BodyContentHandler contenthandler = new BodyContentHandler(); + Metadata metadata = new Metadata(); + metadata.set(Metadata.RESOURCE_NAME_KEY, filename); + AutoDetectParser parser = new AutoDetectParser(); + parser.parse(is, contenthandler, metadata); + String[] result = metadata.getValues(Metadata.CONTENT_TYPE); + + if(log.isDebugEnabled()) { + log.debug("Mine type of " + filename + " is : " + result); + } + + return result; + } + finally { + is.close(); + } + } + + } Modified: trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java =================================================================== --- trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-07-21 08:19:04 UTC (rev 182) +++ trunk/src/main/java/org/nuiton/scmwebeditor/actions/ScmWebEditorMainAction.java 2011-07-22 09:04:24 UTC (rev 183) @@ -2,6 +2,7 @@ import java.io.ByteArrayOutputStream; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; @@ -21,6 +22,7 @@ import org.tmatesoft.svn.core.io.SVNRepositoryFactory; import org.tmatesoft.svn.core.wc.SVNWCUtil; + import com.opensymphony.xwork2.Action; public class ScmWebEditorMainAction extends ScmWebEditorBaseAction implements ServletRequestAware { @@ -123,9 +125,6 @@ HttpSession httpSession = request.getSession(true); - if(log.isInfoEnabled()) { - log.info("IP client : "+request.getRemoteAddr() + " , get file : "+address); - } //SvnSession object creation if doesn't already exist SvnSession svnSess = getSvnSession(httpSession); @@ -204,6 +203,9 @@ request.setAttribute("projectUrl", projectUrl); //Suppression du repertoire temporaire delTempDirectory(svnSess); + if(log.isErrorEnabled()) { + log.error("Error with svn path or file "); + } return "errorPath"; } @@ -232,6 +234,9 @@ request.setAttribute("projectUrl", projectUrl); //Suppression du repertoire temporaire delTempDirectory(svnSess); + if(log.isErrorEnabled()) { + log.error("SVN error ",e); + } return "errorPath"; } @@ -239,26 +244,44 @@ - String mineType =null; + String mimeType =null; try { - mineType = getMineType(originalText, svnSess.getFileName()); + mimeType = getMimeType(originalText, svnSess.getFileName()); } catch (Exception e) { if(log.isErrorEnabled()) { log.error("Can't get MimeType",e); } } + /* + String[] mimeTypes =null; + try { + mimeTypes = getMimeTypes(originalText, svnSess.getFileName()); + + log.info("size : "+mimeTypes.length); + + for (String element : mimeTypes){ + log.info("Type : "+element); + } + } catch (Exception e) { + log.error("tika error",e); + } + */ // Si le fichier n'est pas de type texte, on ne peut pas l'éditer - if(mineType==null || !mineType.matches(".*text.*|.*xml.*|.*javascript.*") ) { + if(mimeType==null || !mimeType.matches(".*text.*|.*xml.*|.*javascript.*|.*sh.*|.*x-tex.*") ) { request.setAttribute("projectUrl", projectUrl); //On supprime le repertoire temporaire delTempDirectory(svnSess); + + if(log.isErrorEnabled()) { + log.error("Can't edit this file, mimetype : "+mimeType); + } return "errorPath"; } else { - request.setAttribute("minetype", mineType); + request.setAttribute("minetype", mimeType); } @@ -277,6 +300,10 @@ request.setAttribute(ATTRIBUTE_SCM_EDITOR_URI, request.getRequestURI()); request.setAttribute(ATTRIBUTE_PREVIEW_SERVLET_URL, request.getContextPath() + "/previewservlet"); + if(log.isInfoEnabled()) { + log.info("IP client : "+request.getRemoteAddr() + " , get file : "+address+ ". File's mimetype : "+mimeType); + } + return "editPage";
participants (1)
-
kcardineaud@users.nuiton.org