Return-Path: Delivered-To: apmail-avalon-cvs-archive@avalon.apache.org Received: (qmail 61362 invoked by uid 500); 31 Mar 2003 14:21:46 -0000 Mailing-List: contact cvs-help@avalon.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list cvs@avalon.apache.org Received: (qmail 61264 invoked by uid 500); 31 Mar 2003 14:21:44 -0000 Received: (qmail 61254 invoked from network); 31 Mar 2003 14:21:44 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 31 Mar 2003 14:21:44 -0000 Received: (qmail 68978 invoked by uid 1152); 31 Mar 2003 14:21:43 -0000 Date: 31 Mar 2003 14:21:43 -0000 Message-ID: <20030331142143.68974.qmail@icarus.apache.org> From: bloritsch@apache.org To: avalon-excalibur-cvs@apache.org Subject: cvs commit: avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl FileSource.java URLSource.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N bloritsch 2003/03/31 06:21:42 Modified: sourceresolve/src/java/org/apache/excalibur/source/impl FileSource.java URLSource.java Log: revert the m_file variable change, add an accessor, and deprecate the name of the file variable so that users will move to the accessor Revision Changes Path 1.4 +28 -28 avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/FileSource.java Index: FileSource.java =================================================================== RCS file: /home/cvs/avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/FileSource.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- FileSource.java 29 Mar 2003 18:53:26 -0000 1.3 +++ FileSource.java 31 Mar 2003 14:21:42 -0000 1.4 @@ -85,7 +85,7 @@ throws IOException { super.init( url, parameters ); - if ( null == this.m_file ) { + if ( null == getFile() ) { throw new IllegalArgumentException("Malformed url for a file source : " + url); } } @@ -94,7 +94,7 @@ * Get the associated file */ public File getFile() { - return this.m_file; + return super.getFile(); } /** @@ -103,62 +103,62 @@ */ private class FileSourceOutputStream extends FileOutputStream { - private File tmpFile; - private boolean isClosed = false; - private FileSource source; + private File m_tmpFile; + private boolean m_isClosed = false; + private FileSource m_source; public FileSourceOutputStream(File tmpFile, FileSource source) throws IOException { super(tmpFile); - this.tmpFile = tmpFile; - this.source = source; + m_tmpFile = tmpFile; + m_source = source; } public void close() throws IOException { - if (!this.isClosed) { + if (!m_isClosed) { super.close(); try { // Delete destination file - if (this.source.getFile().exists()) { - this.source.getFile().delete(); + if (m_source.getFile().exists()) { + m_source.getFile().delete(); } // Rename temp file to destination file - tmpFile.renameTo(this.source.getFile()); + m_tmpFile.renameTo(m_source.getFile()); } finally { // Ensure temp file is deleted, ie lock is released. // If there was a failure above, written data is lost. - if (tmpFile.exists()) { - tmpFile.delete(); + if (m_tmpFile.exists()) { + m_tmpFile.delete(); } - this.isClosed = true; + m_isClosed = true; } } } public boolean canCancel() { - return !this.isClosed; + return !m_isClosed; } public void cancel() throws Exception { - if (this.isClosed) { + if (m_isClosed) { throw new IllegalStateException("Cannot cancel : outputstrem is already closed"); } - this.isClosed = true; + m_isClosed = true; super.close(); - this.tmpFile.delete(); + m_tmpFile.delete(); } public void finalize() { - if (!this.isClosed && tmpFile.exists()) { + if (!m_isClosed && m_tmpFile.exists()) { // Something wrong happened while writing : delete temp file - tmpFile.delete(); + m_tmpFile.delete(); } } public FileSource getSource() { - return this.source; + return m_source; } } @@ -168,7 +168,7 @@ * @return true if the resource exists. */ public boolean exists() { - return this.m_file.exists(); + return getFile().exists(); } /** @@ -189,19 +189,19 @@ throws IOException, SourceException { // Create a temp file. It will replace the right one when writing terminates, // and serve as a lock to prevent concurrent writes. - File tmpFile = new File(this.m_file.getPath() + ".tmp"); + File tmpFile = new File(getFile().getPath() + ".tmp"); // Ensure the directory exists tmpFile.getParentFile().mkdirs(); // Can we write the file ? - if (this.m_file.exists() && !this.m_file.canWrite()) { - throw new IOException("Cannot write to file " + this.m_file.getPath()); + if (getFile().exists() && !getFile().canWrite()) { + throw new IOException("Cannot write to file " + getFile().getPath()); } // Check if it temp file already exists, meaning someone else currently writing if (!tmpFile.createNewFile()) { - throw new ConcurrentModificationException("File " + this.m_file.getPath() + + throw new ConcurrentModificationException("File " + getFile().getPath() + " is already being written by another thread"); } @@ -254,6 +254,6 @@ * Delete the source. */ public boolean delete() { - return this.m_file.delete(); + return getFile().delete(); } } 1.23 +64 -48 avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/URLSource.java Index: URLSource.java =================================================================== RCS file: /home/cvs/avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/URLSource.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- URLSource.java 29 Mar 2003 18:53:26 -0000 1.22 +++ URLSource.java 31 Mar 2003 14:21:42 -0000 1.23 @@ -98,8 +98,10 @@ /** The connection for a real URL */ protected URLConnection m_connection; - /** The file, if URL is a file */ - protected File m_file; + /** The file, if URL is a file + * @deprecated use the accessor instead (getFile()) + */ + protected File file; /** The SourceParameters used for a post*/ protected SourceParameters m_parameters; @@ -140,11 +142,11 @@ setScheme(systemId.substring(0, pos)); if (systemId.startsWith( FILE )) { - m_file = new File( systemId.substring( FILE.length() ) ); + setFile( new File( systemId.substring( FILE.length() ) ) ); } else { - m_file = null; + setFile( null ); } m_url = url; m_isPost = false; @@ -154,16 +156,16 @@ m_parameters = (SourceParameters)parameters.get( SourceResolver.URI_PARAMETERS ); final String method = (String)parameters.get( SourceResolver.METHOD ); if( "POST".equalsIgnoreCase( method ) ) - this.m_isPost = true; + m_isPost = true; } - if( null == this.m_file - && null != this.m_parameters - && this.m_parameters.hasParameters() - && !this.m_isPost ) + if( null == getFile() + && null != m_parameters + && m_parameters.hasParameters() + && !m_isPost ) { StringBuffer urlBuffer = new StringBuffer( systemId ); String key; - final Iterator i = this.m_parameters.getParameterNames(); + final Iterator i = m_parameters.getParameterNames(); Iterator values; String value; boolean first = ( systemId.indexOf( '?' ) == -1 ); @@ -171,7 +173,7 @@ while( i.hasNext() ) { key = (String)i.next(); - values = this.m_parameters.getParameterValues( key ); + values = m_parameters.getParameterValues( key ); while( values.hasNext() == true ) { value = SourceUtil.encode( (String)values.next() ); @@ -182,12 +184,26 @@ urlBuffer.append( value ); } } - this.m_url = new URL( urlBuffer.toString() ); - this.m_parameters = null; + + m_url = new URL( urlBuffer.toString() ); + m_parameters = null; } } /** + * @param file + */ + protected void setFile(File file) + { + this.file = file; + } + + protected File getFile() + { + return file; + } + + /** * Get the last modification date and content length of the source. * Any exceptions are ignored. * Override this to get the real information @@ -195,27 +211,27 @@ protected void getInfos() { // exists will be set below depending on the m_url type - this.m_exists = false; + m_exists = false; - if( null != this.m_file ) + if( null != getFile() ) { - setLastModified( m_file.lastModified() ); - setContentLength( m_file.length() ); - m_exists = m_file.exists(); + setLastModified( getFile().lastModified() ); + setContentLength( getFile().length() ); + m_exists = getFile().exists(); } else { - if( !this.m_isPost ) + if( !m_isPost ) { try { - if( null == this.m_connection ) + if( null == m_connection ) { - this.m_connection = this.m_url.openConnection(); - String userInfo = this.getUserInfo(); - if( this.m_url.getProtocol().startsWith( "http" ) && userInfo != null ) + m_connection = m_url.openConnection(); + String userInfo = getUserInfo(); + if( m_url.getProtocol().startsWith( "http" ) && userInfo != null ) { - this.m_connection.setRequestProperty( "Authorization", "Basic " + SourceUtil.encodeBASE64( userInfo ) ); + m_connection.setRequestProperty( "Authorization", "Basic " + SourceUtil.encodeBASE64( userInfo ) ); } } setLastModified(m_connection.getLastModified()); @@ -241,8 +257,8 @@ */ public boolean exists() { - this.checkInfos(); - return this.m_exists; + checkInfos(); + return m_exists; } /** @@ -257,38 +273,38 @@ { try { - this.checkInfos(); + checkInfos(); InputStream input = null; - if( null != this.m_file ) + if( null != getFile() ) { - input = new FileInputStream( this.m_file ); + input = new FileInputStream( getFile() ); } else { - if( this.m_connection == null ) + if( m_connection == null ) { - this.m_connection = this.m_url.openConnection(); + m_connection = m_url.openConnection(); /* The following requires a jdk 1.3 */ - String userInfo = this.getUserInfo(); - if( this.m_url.getProtocol().startsWith( "http" ) && userInfo != null ) + String userInfo = getUserInfo(); + if( m_url.getProtocol().startsWith( "http" ) && userInfo != null ) { - this.m_connection.setRequestProperty( "Authorization", "Basic " + SourceUtil.encodeBASE64( userInfo ) ); + m_connection.setRequestProperty( "Authorization", "Basic " + SourceUtil.encodeBASE64( userInfo ) ); } // do a post operation - if( this.m_connection instanceof HttpURLConnection - && this.m_isPost ) + if( m_connection instanceof HttpURLConnection + && m_isPost ) { StringBuffer buffer = new StringBuffer( 2000 ); String key; - Iterator i = this.m_parameters.getParameterNames(); + Iterator i = m_parameters.getParameterNames(); Iterator values; String value; boolean first = true; while( i.hasNext() ) { key = (String)i.next(); - values = this.m_parameters.getParameterValues( key ); + values = m_parameters.getParameterValues( key ); while( values.hasNext() == true ) { value = SourceUtil.encode( (String)values.next() ); @@ -316,12 +332,12 @@ out.close(); } input = httpCon.getInputStream(); - this.m_connection = null; // make sure a new m_connection is created next time + m_connection = null; // make sure a new m_connection is created next time return input; } } - input = this.m_connection.getInputStream(); - this.m_connection = null; // make sure a new m_connection is created next time + input = m_connection.getInputStream(); + m_connection = null; // make sure a new m_connection is created next time } return input; } @@ -393,9 +409,9 @@ return m_cachedValidity; m_cachedLastModificationDate = lm; - if (m_file != null) + if (getFile() != null) { - m_cachedValidity = new FileTimeStampValidity(m_file, lm); + m_cachedValidity = new FileTimeStampValidity(getFile(), lm); } else { @@ -422,9 +438,9 @@ */ public boolean isDirectory() { - if ( null != m_file ) + if ( null != getFile() ) { - return m_file.isDirectory(); + return getFile().isDirectory(); } return false; } @@ -436,9 +452,9 @@ */ public Collection getChildrenLocations() { - if ( null != m_file && m_file.isDirectory() ) + if ( null != getFile() && getFile().isDirectory() ) { - final String[] files = m_file.list(); + final String[] files = getFile().list(); return Arrays.asList(files); } return Collections.EMPTY_LIST; --------------------------------------------------------------------- To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org For additional commands, e-mail: cvs-help@avalon.apache.org