- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 11 Aug 2009 16:05:38 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/input In directory hutz:/tmp/cvs-serv2609/src/org/w3c/unicorn/input Added Files: Tag: dev2 FileItemInputModule.java UploadInputModule.java DirectInputModule.java FakeUploadInputModule.java InputModule.java InputFactory.java URIInputModule.java Log Message: all initialization actions in Init.java + compatibility windows/linux --- NEW FILE: FakeUploadInputModule.java --- // $Id: FakeUploadInputModule.java,v 1.1.2.1 2009/08/11 16:05:36 tgambet Exp $ // Author: Damien LEROY. // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.input; import java.io.IOException; import java.io.InputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; import javax.activation.MimeType; import org.w3c.unicorn.contract.EnumInputMethod; /** * Class used for the fake upload input method check It means make the observer * believe it was a direct input whereas it wasn't * * @author Damien LEROY */ public class FakeUploadInputModule implements UploadInputModule { /** * Set the Input method to UPLOAD */ private final EnumInputMethod aEnumInputMethod = EnumInputMethod.UPLOAD; /** * Content of the input */ private String sContent = null; /** * Name of the file to input */ private String sFileName = null; /** * Mime type of the input */ private MimeType aMimeType = null; /** * Build the input Module by setting the properties * * @param aInputModule * @throws IOException */ protected FakeUploadInputModule(final InputModule aInputModule) throws IOException { InputModule.logger.trace("Constructor"); if (InputModule.logger.isDebugEnabled()) { InputModule.logger.debug("Input module : " + aInputModule + "."); } this.aMimeType = aInputModule.getMimeType(); this.sContent = aInputModule.getStringContent(); } /** * Get the filename of the input */ public String getFileName() { InputModule.logger.trace("getFileName"); return this.sFileName; } /** * Get the stream of the input using the content */ public InputStream getInputStream() throws IOException { InputModule.logger.trace("getInputStream"); final PipedOutputStream aPipedOutputStream = new PipedOutputStream(); aPipedOutputStream.write(this.sContent.getBytes()); aPipedOutputStream.close(); final PipedInputStream aPipedInputStream = new PipedInputStream(); aPipedOutputStream.connect(aPipedInputStream); return aPipedInputStream; } public EnumInputMethod getEnumInputMethod() { InputModule.logger.trace("getEnumInputMethod"); return this.aEnumInputMethod; } public MimeType getMimeType() { InputModule.logger.trace("getMimeType"); return this.aMimeType; } public Object getParameterValue() { InputModule.logger.trace("getParameterValue"); return this.sContent; } public String getStringContent() throws IOException { InputModule.logger.trace("getStringContent"); return this.sContent; } /** * Dispose the object */ public void dispose() { InputModule.logger.trace("dispose"); } /** * prints the object */ @Override public String toString() { final int iStringBufferSize = 500; final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize); aStringBuffer.append("FakeUploadInputModule{mimetype: ").append( this.aMimeType); aStringBuffer.append(", filename: ").append(this.sFileName).append("}"); return aStringBuffer.toString(); } } --- NEW FILE: DirectInputModule.java --- // $Id: DirectInputModule.java,v 1.1.2.1 2009/08/11 16:05:36 tgambet Exp $ // Author: Damien LEROY. // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.input; import java.io.IOException; import javax.activation.MimeType; import org.w3c.unicorn.contract.EnumInputMethod; /** * Class used for the direct input method check * * @author Damien LEROY */ public class DirectInputModule implements InputModule { /** * Sets the input method to DIRECT */ private final EnumInputMethod aEnumInputMethod = EnumInputMethod.DIRECT; /** * Parameter used for the direct call */ private String sInput = null; /** * Mime-type used for the call */ private MimeType aMimeType = null; /** * Build the DirectInput Module by filling the properties * * @param aMimeType * mime-type of the module * @param oInputParameterValue * input parameter for the module */ protected DirectInputModule(final MimeType aMimeType, final Object oInputParameterValue) { InputModule.logger.trace("Constructor"); if (InputModule.logger.isDebugEnabled()) { InputModule.logger.debug("Mime type : " + aMimeType + "."); InputModule.logger.debug("Input parameter value : " + oInputParameterValue + "."); } if (!(oInputParameterValue instanceof String)) { throw new IllegalArgumentException("Object oInputParameterValue : " + oInputParameterValue.toString() + "."); } this.aMimeType = aMimeType; this.sInput = (String) oInputParameterValue; } /** * Constructor for the Direct Input Module * * @param aInputModule * InputModule to nest into a direct input module * @throws IOException * for unknown error */ protected DirectInputModule(final InputModule aInputModule) throws IOException { InputModule.logger.trace("Constructor"); if (InputModule.logger.isDebugEnabled()) { InputModule.logger.debug("Input module : " + aInputModule + "."); } this.sInput = aInputModule.getStringContent(); this.aMimeType = aInputModule.getMimeType(); } public EnumInputMethod getEnumInputMethod() { InputModule.logger.trace("getEnumInputMethod"); return this.aEnumInputMethod; } public MimeType getMimeType() { InputModule.logger.trace("getMimeType"); return this.aMimeType; } public Object getParameterValue() { InputModule.logger.trace("getParameterValue"); return this.sInput; } public String getStringContent() { InputModule.logger.trace("getStringContent"); return this.sInput; } /** * Dispose the object */ public void dispose() { InputModule.logger.trace("dispose"); } /** * Prints the object */ @Override public String toString() { final int iStringBufferSize = 500; final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize); aStringBuffer.append("DirectInputModule{mimetype: ").append( this.aMimeType).append("}"); return aStringBuffer.toString(); } } --- NEW FILE: URIInputModule.java --- // $Id: URIInputModule.java,v 1.1.2.1 2009/08/11 16:05:36 tgambet Exp $ // Author: Damien LEROY. // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.input; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.net.URL; import java.util.Date; import javax.activation.MimeType; import org.w3c.unicorn.Framework; import org.w3c.unicorn.contract.EnumInputMethod; import org.w3c.unicorn.output.EscapeXMLEntities; import org.w3c.unicorn.util.Property; /** * Class used to deal with the URI method for inputs * * @author Damien LEROY */ public class URIInputModule implements InputModule { /** * Sets the method of input to URI */ private final EnumInputMethod aEnumInputMethod = EnumInputMethod.URI; /** * Mime-type of the input */ private MimeType aMimeType = null; /** * URI of the input */ private String sURI = null; /** * File found at the URI */ private File aFile = null; /** * Constructor of the URI input module * * @param aMimeType * mime-type of the input * @param oInputParameterValue * parameter of the input */ protected URIInputModule(final MimeType aMimeType, final Object oInputParameterValue) { InputModule.logger.trace("Constructor."); if (InputModule.logger.isDebugEnabled()) { InputModule.logger.debug("oInputParameterValue : " + oInputParameterValue + "."); } if (!(oInputParameterValue instanceof String)) { throw new IllegalArgumentException("Object oInputParameterValue : " + oInputParameterValue.toString() + "."); } this.aMimeType = aMimeType; this.sURI = (String) oInputParameterValue; this.sURI = EscapeXMLEntities.escapeText(this.sURI); } /** * Copy an input module into a URI method module * * @param aInputModule * input to copy * @throws IOException * odd error occurs */ protected URIInputModule(final InputModule aInputModule) throws IOException { InputModule.logger.trace("Constructor."); if (InputModule.logger.isDebugEnabled()) { InputModule.logger.debug("InputModule : " + aInputModule + "."); } this.aMimeType = aInputModule.getMimeType(); final Date aDate = new Date(); final String sFileName; sFileName = "tmp_" + aDate.getTime() + "_." + Framework.aPropertiesExtension.getProperty(this.aMimeType .toString()); this.aFile = new File(Property.get("PATH_TO_TEMPORARY_FILES") + sFileName); this.aFile.createNewFile(); final PrintWriter aPrintWriter = new PrintWriter(aFile); aPrintWriter.print(aInputModule.getStringContent()); aPrintWriter.close(); this.sURI = Property.get("URL_TO_TEMPORARY_FILES") + sFileName; } public EnumInputMethod getEnumInputMethod() { InputModule.logger.trace("getEnumInputMethod"); return this.aEnumInputMethod; } public MimeType getMimeType() { InputModule.logger.trace("getMimeType"); return this.aMimeType; } public Object getParameterValue() { InputModule.logger.trace("getParameterValue"); return this.sURI; } public String getStringContent() throws IOException { InputModule.logger.trace("getString."); final URL aURL = new URL(this.sURI); final String sResult = (String) aURL.openConnection().getContent(); if (InputModule.logger.isDebugEnabled()) { InputModule.logger.debug("sResult : " + sResult + "."); } return sResult; } public String getURI() { InputModule.logger.trace("getURI"); return this.sURI; } /** * Dispose the object */ public void dispose() { InputModule.logger.trace("dispose"); if (null != this.aFile && this.aFile.delete()) { InputModule.logger.info("File deleted."); this.aFile = null; } } /** * Prints the object */ @Override public String toString() { final int iStringBufferSize = 500; final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize); aStringBuffer.append("URIInputModule{"); aStringBuffer.append("mimetype: ").append(this.aMimeType); aStringBuffer.append(", uri: ").append(this.sURI); aStringBuffer.append("}").append(this.sURI); return aStringBuffer.toString(); } } --- NEW FILE: InputFactory.java --- // $Id: InputFactory.java,v 1.1.2.1 2009/08/11 16:05:36 tgambet Exp $ // Author: Damien LEROY. // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.input; import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; import javax.activation.MimeType; import org.apache.commons.logging.Log; import org.w3c.unicorn.contract.EnumInputMethod; /** * Class which deals with the creation of input method * * @author Damien LEROY */ public class InputFactory { /** * Object used for complex logging purpose */ private static final Log logger = InputModule.logger; /** * Used to create an inputModule * * @param aMimeType * the mime-type of the input * @param aEnumInputMethod * the method used for the input * @param oInputParameterValue * the parameter for the input * @return an input Module ready to use */ public static InputModule createInputModule(final MimeType aMimeType, final EnumInputMethod aEnumInputMethod, final Object oInputParameterValue) { InputFactory.logger.trace("createInputModule"); if (InputFactory.logger.isDebugEnabled()) { InputFactory.logger.debug("Mime type : " + aMimeType + "."); InputFactory.logger.debug("Input method : " + aEnumInputMethod + "."); InputFactory.logger.debug("Input parameter value : " + oInputParameterValue + "."); } switch (aEnumInputMethod) { case DIRECT: return new DirectInputModule(aMimeType, oInputParameterValue); case UPLOAD: return new FileItemInputModule(aMimeType, oInputParameterValue); case URI: return new URIInputModule(aMimeType, oInputParameterValue); } return null; } /** * Data structure for all the input modules */ private Map<EnumInputMethod, InputModule> mapOfInputModule = null; /** * Default input module */ private InputModule aInputModuleDefault = null; /** * Constructor of the input factory * * @param aMimeType * mime-type of the input * @param aEnumInputMethod * method used for the input * @param oInputParameterValue * parameter of the input */ public InputFactory(final MimeType aMimeType, final EnumInputMethod aEnumInputMethod, final Object oInputParameterValue) { InputFactory.logger.trace("Constructor"); if (InputFactory.logger.isDebugEnabled()) { InputFactory.logger.debug("Mime type : " + aMimeType + "."); InputFactory.logger.debug("Input method : " + aEnumInputMethod + "."); InputFactory.logger.debug("Input parameter value : " + oInputParameterValue + "."); } this.mapOfInputModule = new LinkedHashMap<EnumInputMethod, InputModule>(); this.aInputModuleDefault = InputFactory.createInputModule(aMimeType, aEnumInputMethod, oInputParameterValue); this.mapOfInputModule.put(aEnumInputMethod, this.aInputModuleDefault); } /** * Get an input module depending on its method * * @param aEnumInputMethod * method used for the input * @return the input module found or created * @throws IOException * odd error occured */ public InputModule getInputModule(final EnumInputMethod aEnumInputMethod) throws IOException { InputFactory.logger.trace("getInputModule"); if (InputFactory.logger.isDebugEnabled()) { InputFactory.logger.debug("Input method : " + aEnumInputMethod + "."); } final InputModule aInputModule = this.mapOfInputModule .get(aEnumInputMethod); if (null != aInputModule) { return aInputModule; } return this.createInputModule(aEnumInputMethod); } /** * Creation of an input module * * @param aEnumInputMethod * method of the input module * @return a new input module * @throws IOException * odd error occured */ public InputModule createInputModule(final EnumInputMethod aEnumInputMethod) throws IOException { InputFactory.logger.trace("createInputModule"); if (InputFactory.logger.isDebugEnabled()) { InputFactory.logger.debug("Input method : " + aEnumInputMethod + "."); } switch (aEnumInputMethod) { case DIRECT: return new DirectInputModule(this.aInputModuleDefault); case UPLOAD: return new FakeUploadInputModule(this.aInputModuleDefault); case URI: return new URIInputModule(this.aInputModuleDefault); } return null; } public MimeType getMimeType() { InputFactory.logger.trace("getMimetype"); return this.aInputModuleDefault.getMimeType(); } public InputModule getDefaultInputModule() { InputFactory.logger.trace("getDefaultInputModule"); return this.aInputModuleDefault; } /** * Dispose the object * */ public void dispose() { InputFactory.logger.trace("dispose"); for (final InputModule aInputModule : this.mapOfInputModule.values()) { aInputModule.dispose(); } } /** * Prints the object */ @Override public String toString() { final int iStringBufferSize = 500; final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize); aStringBuffer.append("InputFactory{default: ").append( this.aInputModuleDefault.getEnumInputMethod()).append(", "); for (final InputModule aInputModule : this.mapOfInputModule.values()) { aStringBuffer.append(aInputModule).append(", "); } aStringBuffer.append("}"); return aStringBuffer.toString(); } } --- NEW FILE: FileItemInputModule.java --- // $Id: FileItemInputModule.java,v 1.1.2.1 2009/08/11 16:05:36 tgambet Exp $ // Author: Damien LEROY. // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.input; import java.io.IOException; import java.io.InputStream; import javax.activation.MimeType; import org.apache.commons.fileupload.FileItem; import org.w3c.unicorn.contract.EnumInputMethod; /** * Class to deal with the file input method * * @author Damien LEROY * */ public class FileItemInputModule implements UploadInputModule { /** * Sets the input method to UPLOAD */ private final EnumInputMethod aEnumInputMethod = EnumInputMethod.UPLOAD; /** * The file item */ private FileItem aFileItem = null; /** * The mime-type of the file */ private MimeType aMimeType = null; /** * Build the Input module * * @param aMimeType * mime-type of the file for the input * @param oInputParameterValue * parameter of the input */ protected FileItemInputModule(final MimeType aMimeType, final Object oInputParameterValue) { InputModule.logger.trace("Constructor"); if (InputModule.logger.isDebugEnabled()) { InputModule.logger.debug("Mime type : " + aMimeType + "."); InputModule.logger.debug("Input parameter value : " + oInputParameterValue + "."); } if (!(oInputParameterValue instanceof FileItem)) { throw new IllegalArgumentException("Object oInputParameterValue : " + oInputParameterValue.toString() + "."); } this.aMimeType = aMimeType; this.aFileItem = (FileItem) oInputParameterValue; } public EnumInputMethod getEnumInputMethod() { InputModule.logger.trace("getEnumInputMethod"); return this.aEnumInputMethod; } public String getFileName() { InputModule.logger.trace("getFileName"); return this.aFileItem.getName(); } public InputStream getInputStream() throws IOException { InputModule.logger.trace("getInputStream"); return this.aFileItem.getInputStream(); } public MimeType getMimeType() { InputModule.logger.trace("getMimeType"); return this.aMimeType; } public Object getParameterValue() { InputModule.logger.trace("getParameterValue"); return this.aFileItem; } public String getStringContent() { InputModule.logger.trace("getStringContent"); return this.aFileItem.getString(); } /** * Dispose the object */ public void dispose() { InputModule.logger.trace("dispose"); if (null != this.aFileItem) { this.aFileItem.delete(); this.aFileItem = null; } } /** * Prints the object */ @Override public String toString() { final int iStringBufferSize = 500; final StringBuffer aStringBuffer = new StringBuffer(iStringBufferSize); aStringBuffer.append("FileItemInputModule{mimetype: ").append( this.aMimeType); aStringBuffer.append(", filename: ").append(this.aFileItem.getName()) .append("}"); return aStringBuffer.toString(); } } --- NEW FILE: InputModule.java --- // $Id: InputModule.java,v 1.1.2.1 2009/08/11 16:05:36 tgambet Exp $ // Author: Damien LEROY. // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.input; import java.io.IOException; import javax.activation.MimeType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.unicorn.contract.EnumInputMethod; /** * Interface for an input module * * @author Damien LEROY */ public interface InputModule { public static final Log logger = LogFactory.getLog("org.w3c.unicorn.input"); public EnumInputMethod getEnumInputMethod(); public MimeType getMimeType(); public Object getParameterValue(); public String getStringContent() throws IOException; /** * Make all action necessary to remove input module. */ public void dispose(); } --- NEW FILE: UploadInputModule.java --- // $Id: UploadInputModule.java,v 1.1.2.1 2009/08/11 16:05:36 tgambet Exp $ // Author: Damien LEROY. // (c) COPYRIGHT MIT, ERCIM ant Keio, 2006. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.unicorn.input; import java.io.IOException; import java.io.InputStream; import org.w3c.unicorn.contract.EnumInputMethod; /** * Interface for the UploadInputModule * * @author Damien LEROY */ public interface UploadInputModule extends InputModule { public final EnumInputMethod aEnumInputMethod = EnumInputMethod.UPLOAD; public String getFileName(); public InputStream getInputStream() throws IOException; }
Received on Tuesday, 11 August 2009 16:09:02 UTC