You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by tv...@apache.org on 2018/08/01 12:15:21 UTC
svn commit: r1837229 - in /turbine/fulcrum/trunk/intake/src:
java/org/apache/fulcrum/intake/validator/FileValidator.java
test/TestComponentConfig.xml test/TestRoleConfig.xml
Author: tv
Date: Wed Aug 1 12:15:21 2018
New Revision: 1837229
URL: http://svn.apache.org/viewvc?rev=1837229&view=rev
Log:
Remove dependency on fulcrum-upload
Modified:
turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FileValidator.java
turbine/fulcrum/trunk/intake/src/test/TestComponentConfig.xml
turbine/fulcrum/trunk/intake/src/test/TestRoleConfig.xml
Modified: turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FileValidator.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FileValidator.java?rev=1837229&r1=1837228&r2=1837229&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FileValidator.java (original)
+++ turbine/fulcrum/trunk/intake/src/java/org/apache/fulcrum/intake/validator/FileValidator.java Wed Aug 1 12:15:21 2018
@@ -1,28 +1,16 @@
package org.apache.fulcrum.intake.validator;
-/*
- * 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.
- */
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
-import org.apache.commons.fileupload.FileItem;
+import javax.servlet.http.Part;
/**
- * A validator that will compare a FileItem testValue against the following
+ * A validator that will compare a Part testValue against the following
* constraints in addition to those listed in DefaultValidator.
*
* This validator can serve as the base class for more specific validators
@@ -33,8 +21,10 @@ import org.apache.commons.fileupload.Fil
* @version $Id$
*/
public class FileValidator
- extends DefaultValidator<FileItem>
+ extends DefaultValidator<Part>
{
+ private final static Pattern charsetPattern = Pattern.compile(".+charset\\s*=\\s*(.+)");
+
/**
* Default constructor
*/
@@ -47,13 +37,45 @@ public class FileValidator
* Determine whether a testValue meets the criteria specified
* in the constraints defined for this validator
*
- * @param testValue a <code>FileItem</code> to be tested
+ * @param testValue a <code>Part</code> to be tested
* @throws ValidationException containing an error message if the
* testValue did not pass the validation tests.
*/
- public void assertValidity(FileItem testValue)
+ public void assertValidity(Part testValue)
throws ValidationException
{
- super.assertValidity(testValue.getString());
+ byte[] fileData = new byte[(int) testValue.getSize()];
+ String contentType = testValue.getContentType();
+ String charset = Charset.defaultCharset().name();
+
+ if (contentType.contains("charset"))
+ {
+ Matcher matcher = charsetPattern.matcher(contentType);
+ if (matcher.matches())
+ {
+ charset = matcher.group(1);
+ }
+ }
+
+ try (InputStream fis = testValue.getInputStream())
+ {
+ fis.read(fileData);
+ }
+ catch (IOException e)
+ {
+ fileData = null;
+ }
+
+ String content;
+ try
+ {
+ content = new String(fileData, charset);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new ValidationException("Invalid charset " + charset);
+ }
+
+ super.assertValidity(content);
}
}
Modified: turbine/fulcrum/trunk/intake/src/test/TestComponentConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/test/TestComponentConfig.xml?rev=1837229&r1=1837228&r2=1837229&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/test/TestComponentConfig.xml (original)
+++ turbine/fulcrum/trunk/intake/src/test/TestComponentConfig.xml Wed Aug 1 12:15:21 2018
@@ -18,13 +18,11 @@
under the License.
-->
<componentConfig>
-
<factory/>
<parser>
<parameterEncoding>utf-8</parameterEncoding>
<automaticUpload>true</automaticUpload>
</parser>
- <upload repository="target" sizeMax="1048576" sizeThreshold="10240"/>
<intake>
<serialDataPath>target/appData.ser</serialDataPath>
<xmlPaths>
Modified: turbine/fulcrum/trunk/intake/src/test/TestRoleConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/intake/src/test/TestRoleConfig.xml?rev=1837229&r1=1837228&r2=1837229&view=diff
==============================================================================
--- turbine/fulcrum/trunk/intake/src/test/TestRoleConfig.xml (original)
+++ turbine/fulcrum/trunk/intake/src/test/TestRoleConfig.xml Wed Aug 1 12:15:21 2018
@@ -20,11 +20,6 @@
<!-- This configuration file for Avalon components is used for testing the TestComponent -->
<role-list>
<role
- name="org.apache.fulcrum.upload.UploadService"
- shorthand="upload"
- default-class="org.apache.fulcrum.upload.DefaultUploadService"
- />
- <role
name="org.apache.fulcrum.pool.PoolService"
shorthand="parser"
default-class="org.apache.fulcrum.pool.DefaultPoolService"