You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2018/01/04 21:15:56 UTC
svn commit: r1820214 - in /webservices/axiom/trunk/axiom-api: ./
src/main/java/org/apache/axiom/mime/ src/main/java/org/apache/axiom/om/impl/
src/main/java/org/apache/axiom/om/util/ src/test/java/org/apache/axiom/mime/
Author: veithen
Date: Thu Jan 4 21:15:56 2018
New Revision: 1820214
URL: http://svn.apache.org/viewvc?rev=1820214&view=rev
Log:
Deprecate CommonUtils.isTextualPart.
Modified:
webservices/axiom/trunk/axiom-api/pom.xml
webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/ContentType.java
webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java
webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java
webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java
webservices/axiom/trunk/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java
webservices/axiom/trunk/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java
Modified: webservices/axiom/trunk/axiom-api/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/pom.xml?rev=1820214&r1=1820213&r2=1820214&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/pom.xml (original)
+++ webservices/axiom/trunk/axiom-api/pom.xml Thu Jan 4 21:15:56 2018
@@ -334,8 +334,6 @@
org.apache.axiom.om.ds.AbstractPushOMDataSource -> org.apache.axiom.om.util.StAXUtils,
org.apache.axiom.om.ds.BlobOMDataSource -> org.apache.axiom.om.util.StAXUtils,
org.apache.axiom.om.ds.StringOMDataSource -> org.apache.axiom.om.util.StAXUtils,
- <!-- TODO -->
- org.apache.axiom.om.impl.OMMultipartWriter -> org.apache.axiom.om.util.CommonUtils,
<!-- Incorrect layering -->
org.apache.axiom.om.util.StAXParserConfiguration -> org.apache.axiom.util.stax.dialect.StAXDialect
</ignore>
Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/ContentType.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/ContentType.java?rev=1820214&r1=1820213&r2=1820214&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/ContentType.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/ContentType.java Thu Jan 4 21:15:56 2018
@@ -254,6 +254,16 @@ public final class ContentType {
}
/**
+ * Check if the content type is textual, i.e. if an entity with this content type should be
+ * human readable. This information may be used to select a content transfer encoding.
+ *
+ * @return whether the content type is textual
+ */
+ public boolean isTextual() {
+ return mediaType.hasPrimaryType("text") || mediaType.isXML() || getParameter("charset") != null;
+ }
+
+ /**
* Create a string representation of this content type suitable as the value for a
* <tt>Content-Type</tt> header as specified by RFC 2045. Note that this method serializes all
* parameter values as quoted strings, even values that could be represented as tokens. This is
Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java?rev=1820214&r1=1820213&r2=1820214&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/mime/MediaType.java Thu Jan 4 21:15:56 2018
@@ -116,6 +116,41 @@ public final class MediaType {
return subType;
}
+ /**
+ * Check if this media type has the given primary type.
+ *
+ * @param type
+ * the primary type to check against
+ * @return whether the primary type matches
+ */
+ public boolean hasPrimaryType(String type) {
+ return primaryType.equalsIgnoreCase(type);
+ }
+
+ /**
+ * Check if this media type has the given sub type.
+ *
+ * @param type
+ * the sub type to check against
+ * @return whether the sub type matches
+ */
+ public boolean hasSubType(String type) {
+ return subType.equalsIgnoreCase(type);
+ }
+
+ /**
+ * Check if this media type describes XML content as defined in
+ * <a href="http://tools.ietf.org/html/rfc7303">RFC 7303</a>.
+ *
+ * @return whether the content expected for this media type is XML
+ */
+ public boolean isXML() {
+ return equals(TEXT_XML)
+ || hasPrimaryType("application") && (
+ hasSubType("xml")
+ || subType.length() > 4 && subType.substring(subType.length() - 4).equalsIgnoreCase("+xml"));
+ }
+
@Override
public int hashCode() {
int hash = 0;
Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java?rev=1820214&r1=1820213&r2=1820214&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java Thu Jan 4 21:15:56 2018
@@ -21,15 +21,16 @@ package org.apache.axiom.om.impl;
import java.io.IOException;
import java.io.OutputStream;
+import java.text.ParseException;
import java.util.List;
import javax.activation.DataHandler;
import org.apache.axiom.attachments.ConfigurableDataHandler;
+import org.apache.axiom.mime.ContentType;
import org.apache.axiom.mime.Header;
import org.apache.axiom.mime.MultipartBodyWriter;
import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.util.CommonUtils;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
@@ -66,8 +67,16 @@ public class OMMultipartWriter {
}
}
+ private static boolean isTextual(String contentType) {
+ try {
+ return new ContentType(contentType).isTextual();
+ } catch (ParseException ex) {
+ return false;
+ }
+ }
+
private String getContentTransferEncoding(String contentType) {
- if (useCTEBase64 && !CommonUtils.isTextualPart(contentType)) {
+ if (useCTEBase64 && !isTextual(contentType)) {
return "base64";
} else {
return "binary";
Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java?rev=1820214&r1=1820213&r2=1820214&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java Thu Jan 4 21:15:56 2018
@@ -19,6 +19,9 @@
package org.apache.axiom.om.util;
+import java.text.ParseException;
+
+import org.apache.axiom.mime.ContentType;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.commons.logging.Log;
@@ -165,13 +168,14 @@ public class CommonUtils {
*
* @param contentType
* @return true if text, false otherwise
+ *
+ * @deprecated Use {@link ContentType#isTextual()} instead.
*/
public static boolean isTextualPart(String contentType) {
- String ct = contentType.trim();
- // REVIEW: What about content-type with a type of "message"
- return ct.startsWith("text/") ||
- ct.startsWith("application/soap") ||
- ct.startsWith("application/xml") ||
- ct.indexOf("charset") != -1;
+ try {
+ return new ContentType(contentType).isTextual();
+ } catch (ParseException ex) {
+ return false;
+ }
}
}
Modified: webservices/axiom/trunk/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java?rev=1820214&r1=1820213&r2=1820214&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java (original)
+++ webservices/axiom/trunk/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java Thu Jan 4 21:15:56 2018
@@ -18,6 +18,8 @@
*/
package org.apache.axiom.mime;
+import static com.google.common.truth.Truth.assertThat;
+
import java.text.ParseException;
import junit.framework.TestCase;
@@ -148,4 +150,16 @@ public class ContentTypeTest extends Tes
"filename", "c:\\temp\\test.dat");
assertEquals("application/x-some-format; filename=\"c:\\\\temp\\\\test.dat\"", ct.toString());
}
+
+ private static boolean isTextual(String contentType) throws Exception {
+ return new ContentType(contentType).isTextual();
+ }
+
+ public void testIsTextual() throws Exception {
+ assertThat(isTextual("text/xml")).isTrue();
+ assertThat(isTextual("application/xml")).isTrue();
+ assertThat(isTextual("application/soap+xml")).isTrue();
+ assertThat(isTextual("foo/bar; charset=UTF-8")).isTrue();
+ assertThat(isTextual("image/gif")).isFalse();
+ }
}
Modified: webservices/axiom/trunk/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java?rev=1820214&r1=1820213&r2=1820214&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java (original)
+++ webservices/axiom/trunk/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java Thu Jan 4 21:15:56 2018
@@ -18,6 +18,8 @@
*/
package org.apache.axiom.mime;
+import static com.google.common.truth.Truth.assertThat;
+
import java.text.ParseException;
import junit.framework.TestCase;
@@ -92,4 +94,15 @@ public class MediaTypeTest extends TestC
// Expected
}
}
+
+ public void testIsXML() throws Exception {
+ assertThat(MediaType.TEXT_XML.isXML()).isTrue();
+ assertThat(MediaType.APPLICATION_XML.isXML()).isTrue();
+ assertThat(MediaType.APPLICATION_SOAP_XML.isXML()).isTrue();
+ assertThat(MediaType.APPLICATION_XOP_XML.isXML()).isTrue();
+ assertThat(MediaType.MULTIPART_RELATED.isXML()).isFalse();
+ assertThat(MediaType.APPLICATION_OCTET_STREAM.isXML()).isFalse();
+ assertThat(MediaType.TEXT_PLAIN.isXML()).isFalse();
+ assertThat(new MediaType("application/foo").isXML()).isFalse();
+ }
}