Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/category_dao.php on line 14

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/page_dao.php on line 8

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/category_dao.php on line 14

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/category_dao.php on line 14

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/category_dao.php on line 14

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/category_dao.php on line 14

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/category_dao.php on line 14

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/category_dao.php on line 14

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/category_dao.php on line 14

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/category_dao.php on line 14

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/category_dao.php on line 14

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/category_dao.php on line 14

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/category_dao.php on line 14

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/page_dao.php on line 8

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/page_dao.php on line 8

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/page_dao.php on line 8

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/page_dao.php on line 8

Warning: Wrong parameter count for get_parent_class() in /data/home/ug44s1/htdocs/q/domain/page_dao.php on line 8
第3页 - 海波无痕

Get the Mime Type from a File[zz]

2008年02月26日

Using javax.activation.MimetypesFileTypeMap
activation.jar is required, it can be downloaded from http://java.sun.com/products/javabeans/glasgow/jaf.html.
The MimetypesFileMap class is used to map a File to a Mime Type. Mime types supported are defined in a ressource file inside the activation.jar.

import javax.activation.MimetypesFileTypeMap; import java.io.File;  class GetMimeType {   public static void main(String args[]) {     File f = new File("gumby.gif");     System.out.println("Mime Type of " + f.getName() + " is " +                          new MimetypesFileTypeMap().getContentType(f));     // expected output :     // "Mime Type of gumby.gif is image/gif"   } }
The built-in mime-type list is very limited but a mechanism is available to add very easily more Mime Types/extensions.
The MimetypesFileTypeMap looks in various places in the user's system for MIME types file entries. When requests are made to search for MIME types in the MimetypesFileTypeMap, it searches MIME types files in the following order:

Programmatically added entries to the MimetypesFileTypeMap instance.
The file .mime.types in the user's home directory.
The file <java.home>/lib/mime.types.
The file or resources named META-INF/mime.types.
The file or resource named META-INF/mimetypes.default (usually found only in the activation.jar file).
This method is interesting when you need to deal with incoming files with the filenames normalized. The result is very fast because only the extension is used to guess the nature of a given file.
Using java.net.URL
Warning : this method is very slow!.
Like the above method a match is done with the extension. The mapping between the extension and the mime-type is defined in the file [jre_home]\lib\content-types.properties

import java.net.*;  public class FileUtils{   public static String getMimeType(String fileUrl)     throws java.io.IOException, MalformedURLException    {     String type = null;     URL u = new URL(fileUrl);     URLConnection uc = null;     uc = u.openConnection();     type = uc.getContentType();     return type;   }    public static void main(String args[]) throws Exception {     System.out.println(FileUtils.getMimeType("file://c:/temp/test.TXT"));     // output :  text/plain   } }
Using JMimeMagic
Checking the file extension is not a very strong way to determine the file type. A more robust solution is possible with the JMimeMagic library. JMimeMagic is a Java library (LGLP licence) that retrieves file and stream mime types by checking magic headers.
// snippet for JMimeMagic lib //     http://sourceforge.net/projects/jmimemagic/  Magic parser = new Magic() ; // getMagicMatch accepts Files or byte[],  // which is nice if you want to test streams MagicMatch match = parser.getMagicMatch(new File("gumby.gif")); System.out.println(match.getMimeType()) ;
Thanks to Jean-Marc Autexier and sygsix for the tip!
Using mime-util
Another tool is mime-util. This tool can detect using the file extension or the magic header technique.
// snippet for mime-util lib //     http://sourceforge.net/projects/mime-util  public static final String UNKNOWN_MIME_TYPE="application/x-unknown-mime-type"; ... String mimeType = MimeUtil.getMagicMimeType(file); if(mimeType == null) mimeType = UNKNOWN_MIME_TYPE;
The nice thing about mime-util is that there is no dependency (with others Apache packages) so it is very lightweight.
Using Droid
DROID (Digital Record Object Identification) is a software tool to perform automated batch identification of file formats.
DROID uses internal and external signatures to identify and report the specific file format versions of digital files. These signatures are stored in an XML signature file, generated from information recorded in the PRONOM technical registry. New and updated signatures are regularly added to PRONOM, and DROID can be configured to automatically download updated signature files from the PRONOM website via web services.

It can be invoked from two interfaces, a Java Swing GUI or a command line interface.

http://droid.sourceforge.net/wiki/index.php/Introduction

Aperture framework
Aperture is an open source library and framework for crawling and indexing information sources such as file systems, websites and mail boxes.
The Aperture code consists of a number of related but independently usable parts:

Crawling of information sources: file systems, websites, mail boxes
MIME type identification
Full-text and metadata extraction of various file formats
Opening of crawled resources
For each of these parts, a set of APIs has been developed and a number of implementations is provided.
http://aperture.wiki.sourceforge.net/Overview

 

http://www.rgagnon.com/javadetails/java-0487.html

Missing classpath resource '/dojo-0.4.3/dojo2.js'

2008年02月20日

Missing classpath resource '/dojo-0.4.3/dojo2.js'

Tapestry4.1.5 bug

http://article.gmane.org/gmane.comp.jakarta.tapestry.devel/24877
https://issues.apache.org/jira/browse/TAPESTRY-2171

修改
tapestry-framework-4.1.5.jar
org.apache.tapestry.dojo.html包下ScriptIncludes.jwc文件
按照org.apache.tapestry.html.Shell.jwc的写法 使用 jsManager 控制路径

屏蔽掉
<asset name="defaultDojoSource" path="classpath:/dojo-0.4.3/dojo.js" />
<asset name="defaultDojoFormSource" path="classpath:/dojo-0.4.3/dojo2.js" />
<asset name="defaultDojoWidgetSource" path="classpath:/dojo-0.4.3/dojo3.js" />
<asset name="defaultDojoPath" path="classpath:/dojo-0.4.3/" />
<asset name="defaultTapestrySource" path="classpath:/tapestry/core.js" />
<asset name="defaultTapestryPath" path="classpath:/tapestry/" />
增加
<inject property="valueConverter" object="service:tapestry.coerce.ValueConverter" />
<inject property="pageService" object="engine-service:page" />
<inject property="applicationSpecification" object="infrastructure:applicationSpecification" />
<inject property="baseTagWriter" object="service:tapestry.url.BaseTagWriter" />
<inject property="jsManager" object="service:tapestry.js.JavascriptManager" />
修改

<parameter name="tapestrySource" default-value="asset:defaultTapestrySource">
        <description>
            If specified, allows for the default tapestry source included to be overriden.
        </description>
    </parameter>
   
    <parameter name="tapestryPath" default-value="asset:defaultTapestryPath">
        <description>
            Sets the tapestry path, needed for dojo to properly detect and find tapestry js modules
            when overriding the default dojo bundled with tapestry.
        </description>
    </parameter>
   
    <parameter name="dojoSource" default-value="asset:defaultDojoSource">
        <description>
            If specified, allows for the default dojo source included to be overriden.
        </description>
    </parameter>

    <parameter name="dojoFormSource" default-value="asset:defaultDojoFormSource">
        <description>
            If specified, allows for the default dojo source included to be overriden.
        </description>
    </parameter>

    <parameter name="dojoWidgetSource" default-value="asset:defaultDojoWidgetSource">
        <description>
            If specified, allows for the default dojo source included to be overriden.
        </description>
    </parameter>

    <parameter name="dojoPath" default-value="asset:defaultDojoPath">
        <description>
            Specifies the default path to the root dojo folder, not the dojo.js file itself. This is
            used by the djConfig.baseRelativePath javascript configuration variable in dojo.
        </description>
    </parameter>
变为
 <parameter name="tapestrySource" default-value="ognl:jsManager.tapestryAsset">
        <description>
            If specified, allows for the default tapestry source included to be overriden.
        </description>
    </parameter>
   
    <parameter name="tapestryPath" default-value="ognl:jsManager.tapestryPath">
        <description>
            Sets the tapestry path, needed for dojo to properly detect and find tapestry js modules
            when overriding the default dojo bundled with tapestry.
        </description>
    </parameter>
   
    <parameter name="dojoSource" default-value="ognl:jsManager.firstAsset">
        <description>
            If specified, allows for the default dojo source included to be overriden.
        </description>
    </parameter>

    <parameter name="dojoFormSource" default-value="ognl:jsManager.firstFormAsset">
        <description>
            If specified, allows for the default dojo source included to be overriden.
        </description>
    </parameter>

    <parameter name="dojoWidgetSource" default-value="ognl:jsManager.firstWidgetAsset">
        <description>
            If specified, allows for the default dojo source included to be overriden.
        </description>
    </parameter>

    <parameter name="dojoPath" default-value="ognl:jsManager.path">
        <description>
            Specifies the default path to the root dojo folder, not the dojo.js file itself. This is
            used by the djConfig.baseRelativePath javascript configuration variable in dojo.
        </description>
    </parameter>   

修改Tapestry3在{yourServlet}.application配置加载存在于classpath中的组件规范

2008年01月18日

修改Tapestry3在{yourServlet}.application配置加载存在于classpath中的组件规范
在Tapestry3中的{yourServlet}.application文件中不能加载配置在classpath中的jwc组件规范

<application name="yourApp" engine-class="org.apache.tapestry.engine.BaseEngine">
 <component-type type="MyComponent" specification-path="/com/yourApp/components/MyComponent.jwc"/>
</application>

这种写法按照常规的应该从classpath拿到组件的规范文件,但Tapestry3中出错拿不到规范文件
tapestry3分别有两个 org.apache.tapestry.IResourceLocation 的实现
org.apache.tapestry.resource.ClasspathResourceLocation
org.apache.tapestry.resource.ContextResourceLocation
分别加载classpath下的资源和webContext下的资源

解决办法
修改org.apache.tapestry.engine.Namespace类

    private IComponentSpecification locateComponentSpecification(String type)
    {
        String path = _specification.getComponentSpecificationPath(type);

        if (path == null)
            throw new ApplicationRuntimeException(
                Tapestry.format("Namespace.no-such-alias", type, getNamespaceId()));

        IResourceLocation location = getSpecificationLocation().getRelativeLocation(path);
        //hack
        if (location.getResourceURL() == null && path.startsWith("/"))
            location = new ClasspathResourceLocation(_specification.getResourceResolver(), path);
        //hack

        return _specificationSource.getComponentSpecification(location);
    }

增加该方法的hack的地方强制从classpath中查找资源

Caused by: java.lang.ClassNotFoundException: Class bytes found but defineClass()failed for:

2008年01月17日

Caused by: java.lang.ClassNotFoundException: Class bytes found but defineClass()failed for:

高版本JDK编译的class在低版本JDK下无法运行

Jboss seam2.0.0.GA and myfaces1.2 java.lang.IllegalStateException: No Factories configured for this Application.

2007年12月14日

2007-12-14 14:23:05 org.apache.catalina.core.ApplicationContext log
严重: StandardWrapper.Throwable
java.lang.IllegalStateException: No Factories configured for this Application.
This happens if the faces-initialization does not work at all - make sure that you properly
include all configuration settings necessary for a basic faces application and that all the
necessary libs are included. Also check the logging output of your web application and your
container for any exceptions!
If you did that and find nothing, the mistake might be due to the fact that you use some special
web-containers which do not support registering context-listeners via TLD files and a context
listener is not setup in your web.xml.
A typical config looks like this;
<listener>
  <listener-class>org.apache.myfaces.webapp.

StartupServletContextListener</listener-class>
</listener>
    at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:90)
    at javax.faces.webapp.FacesServlet.init(FacesServlet.java:88)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2007-12-14 14:23:05 org.apache.catalina.core.StandardContext loadOnStartup


问题出在jsp-2.1.jar上,根据搜索我得出的结论是myfaces1.2跟seam2.0.0.GA不兼容,myfaces1.2不支持统一的EL导致


参考
http://www.mail-archive.com/users@myfaces.apache.org/msg42935.html
http://java.sun.com/javaee/javaserverfaces/docs/ReleaseNotes.html
http://forum.java.sun.com/thread.jspa?threadID=694101&messageID=9678276
http://www.jboss.org/?module=bb&op=viewtopic&t=101545
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4101012#4101012
http://blog.livedoor.jp/matusoft/archives/cat_50009447.html
http://wiki.apache.org/myfaces/SEAM_Integration
seam/2.0.0.GA/reference/