cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jinhua Wang <ivywj...@gmail.com>
Subject Re: COMMAND_MAP in AttachmentUtil
Date Fri, 02 Nov 2012 09:57:59 GMT
Hello

Thanks for detailed consideration.
I think there is a workaround way to avoid copying default CommandMap.
When creating content handler, search corresponding handler in CXF's static
CommandMap firstly. If there is no corresponding handler, search content
handler in default CommandMap.


Sample code are as following:

AttachmentUtil:
private static final MailcapCommandMap COMMAND_MAP = new
EnhancedMailcapCommandMap();

EnhancedMailcapCommandMap :
import javax.activation.CommandMap;
import javax.activation.DataContentHandler;
import javax.activation.DataSource;
import javax.activation.MailcapCommandMap;

public class EnhancedMailcapCommandMap extends MailcapCommandMap {

@Override
public synchronized DataContentHandler createDataContentHandler(
String mimeType) {
DataContentHandler dch = super.createDataContentHandler(mimeType);
if (dch == null) {
dch = CommandMap.getDefaultCommandMap().createDataContentHandler(mimeType);
}
return dch;
}

@Override
public DataContentHandler createDataContentHandler(String mimeType,
DataSource ds) {
DataContentHandler dch = super.createDataContentHandler(mimeType);
if (dch == null) {
dch = CommandMap.getDefaultCommandMap().createDataContentHandler(mimeType,
ds);
}
return dch;
}

}


On Thu, Nov 1, 2012 at 10:09 PM, Daniel Kulp <dkulp@apache.org> wrote:

>
> >
> >
> > I wonder whether we could copy content handler from default CommandMap to
> > CommandMap in *AttachmentUtil* after adding ImageDataContentHandler ?
> >
>
> I'm not against it, but we would need to make sure that the current
> behavior for all the attachment types that we currently support remains the
> default.  Thus, it MAY require then creating additional content handlers to
> keep the streaming for the XML and Text and other types and make sure they
> are also added prior to the additional handles copied from the default map.
>
>
> Dan
>
>
>
> On Nov 1, 2012, at 8:24 AM, Jinhua Wang <ivywjhua@gmail.com> wrote:
>
> > Hello
> >
> > I have a question about content-handler.
> >
> > 1. In AttachmentImpl constructor, dataHandler is set the CommandMap
> > from AttachmentUtil.
> > *org.apache.cxf.attachment.AttachmentImpl.AttachmentImpl(String,
> > DataHandler)*
> >
> > this.dataHandler.setCommandMap(AttachmentUtil.getCommandMap());
> >
> >
> > 2. In AttachmentUtil, a static MailcapCommandMap was constructed with
> image
> > content handler.
> > *org.apache.cxf.attachment.AttachmentUtil*
> > private static final MailcapCommandMap COMMAND_MAP = *new
> > MailcapCommandMap()*;
> > static {
> > *COMMAND_MAP.addMailcap("image/*;;x-java-content-handler=" *
> > *   + ImageDataContentHandler.class.getName());*
> > }
> > public static CommandMap getCommandMap() {
> > return COMMAND_MAP;
> > }
> >
> > 3. In CommandMap, there is also a static default CommandMap.
> > javax.activation.CommandMap
> > *private static CommandMap defaultCommandMap = null;*
> > public static CommandMap getDefaultCommandMap()
> > {
> > if (defaultCommandMap == null) {
> >  defaultCommandMap = new MailcapCommandMap();
> > }
> > return defaultCommandMap;
> > }
> >
> >
> > 4. In RI implementation, xxx.saaj.soap.AttachmentPartImpl,
> > Some static statement would add specific content handler to default
> > CommandMap.
> >
> > CommandMap localCommandMap = CommandMap.getDefaultCommandMap();
> > *localMailcapCommandMap.addMailcap("text/xml" + str +
> > "xxx.saaj.soap.XmlDataContentHandler");*
> >
> >
> > In this scenario, AttachmentUtil.getCommandMap() in CXF would get
> > CommandMap constructed by itsself, because CXF does not use the default
> > CommandMap.
> > If other party add some specific content handler(such as #4),  the
> > CommandMap together with dataHandler in CXF does not contain these
> specific
> > content handlers.
> >
> > I wonder whether we could copy content handler from default CommandMap to
> > CommandMap in *AttachmentUtil* after adding ImageDataContentHandler ?
> >
> >
> >
> > Best Regards
>
> --
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
>


-- 
Best Regards
Shanghai China

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message