From: markt Date: Thu, 21 Jan 2010 02:38:20 +0000 (+0000) Subject: Rename X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=af81f0732eee714098885bca37ee981017262611;p=tomcat7.0 Rename git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@901503 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/ApplicationPart.java b/java/org/apache/catalina/core/ApplicationPart.java new file mode 100644 index 000000000..171b4750c --- /dev/null +++ b/java/org/apache/catalina/core/ApplicationPart.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.catalina.core; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; + +import javax.servlet.MultipartConfigElement; +import javax.servlet.http.Part; + +import org.apache.tomcat.util.http.fileupload.DiskFileItem; +import org.apache.tomcat.util.http.fileupload.FileItem; + +/** + * Adaptor to allow {@link FileItem} objects generated by the package renamed + * commons-upload to be used by the Servlet 3.0 upload API that expects + * {@link Part}s. + */ +public class ApplicationPart implements Part { + + private FileItem fileItem; + private MultipartConfigElement mce; + + public ApplicationPart(FileItem fileItem, MultipartConfigElement mce) { + this.fileItem = fileItem; + this.mce = mce; + } + + @Override + public void delete() throws IOException { + fileItem.delete(); + } + + @Override + public String getContentType() { + return fileItem.getContentType(); + } + + @Override + public String getHeader(String name) { + if (fileItem instanceof DiskFileItem) { + return ((DiskFileItem) fileItem).getHeaders().getHeader(name); + } + return null; + } + + @Override + public Collection getHeaderNames() { + if (fileItem instanceof DiskFileItem) { + HashSet headerNames = new HashSet(); + Iterator iter = + ((DiskFileItem) fileItem).getHeaders().getHeaderNames(); + while (iter.hasNext()) { + headerNames.add(iter.next()); + } + return headerNames; + } + return Collections.emptyList(); + } + + @Override + public Collection getHeaders(String name) { + if (fileItem instanceof DiskFileItem) { + HashSet headers = new HashSet(); + Iterator iter = + ((DiskFileItem) fileItem).getHeaders().getHeaders(name); + while (iter.hasNext()) { + headers.add(iter.next()); + } + return headers; + } + return Collections.emptyList(); + } + + @Override + public InputStream getInputStream() throws IOException { + return fileItem.getInputStream(); + } + + @Override + public String getName() { + return fileItem.getFieldName(); + } + + @Override + public long getSize() { + return fileItem.getSize(); + } + + @Override + public void write(String fileName) throws IOException { + File file = new File(fileName); + if (!file.isAbsolute()) { + file = new File(mce.getLocation(), fileName); + } + try { + fileItem.write(file); + } catch (Exception e) { + throw new IOException(e); + } + } + +} diff --git a/java/org/apache/catalina/core/StandardPart.java b/java/org/apache/catalina/core/StandardPart.java deleted file mode 100644 index b4bdb1cb6..000000000 --- a/java/org/apache/catalina/core/StandardPart.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.catalina.core; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; - -import javax.servlet.MultipartConfigElement; -import javax.servlet.http.Part; - -import org.apache.tomcat.util.http.fileupload.DiskFileItem; -import org.apache.tomcat.util.http.fileupload.FileItem; - -/** - * Adaptor to allow {@link FileItem} objects generated by the package renamed - * commons-upload to be used by the Servlet 3.0 upload API that expects - * {@link Part}s. - */ -public class StandardPart implements Part { - - private FileItem fileItem; - private MultipartConfigElement mce; - - public StandardPart(FileItem fileItem, MultipartConfigElement mce) { - this.fileItem = fileItem; - this.mce = mce; - } - - @Override - public void delete() throws IOException { - fileItem.delete(); - } - - @Override - public String getContentType() { - return fileItem.getContentType(); - } - - @Override - public String getHeader(String name) { - if (fileItem instanceof DiskFileItem) { - return ((DiskFileItem) fileItem).getHeaders().getHeader(name); - } - return null; - } - - @Override - public Collection getHeaderNames() { - if (fileItem instanceof DiskFileItem) { - HashSet headerNames = new HashSet(); - Iterator iter = - ((DiskFileItem) fileItem).getHeaders().getHeaderNames(); - while (iter.hasNext()) { - headerNames.add(iter.next()); - } - return headerNames; - } - return Collections.emptyList(); - } - - @Override - public Collection getHeaders(String name) { - if (fileItem instanceof DiskFileItem) { - HashSet headers = new HashSet(); - Iterator iter = - ((DiskFileItem) fileItem).getHeaders().getHeaders(name); - while (iter.hasNext()) { - headers.add(iter.next()); - } - return headers; - } - return Collections.emptyList(); - } - - @Override - public InputStream getInputStream() throws IOException { - return fileItem.getInputStream(); - } - - @Override - public String getName() { - return fileItem.getFieldName(); - } - - @Override - public long getSize() { - return fileItem.getSize(); - } - - @Override - public void write(String fileName) throws IOException { - File file = new File(fileName); - if (!file.isAbsolute()) { - file = new File(mce.getLocation(), fileName); - } - try { - fileItem.write(file); - } catch (Exception e) { - throw new IOException(e); - } - } - -}