use of com.helger.commons.mime.MimeTypeParserException in project ph-web by phax.
the class MockHttpServletResponse method setContentType.
public void setContentType(@Nullable final String sContentType) {
m_sContentType = sContentType;
if (sContentType != null) {
try {
final IMimeType aContentType = MimeTypeParser.parseMimeType(sContentType);
final String sEncoding = MimeTypeHelper.getCharsetNameFromMimeType(aContentType);
if (sEncoding != null)
setCharacterEncoding(sEncoding);
} catch (final MimeTypeParserException ex) {
LOGGER.warn("Passed content type '" + sContentType + "' cannot be parsed as a MIME type");
}
}
}
use of com.helger.commons.mime.MimeTypeParserException in project phase4 by phax.
the class PModePayloadProfileJsonConverter method convertToNative.
@Nonnull
public static PModePayloadProfile convertToNative(final IJsonObject aElement) {
final String sName = aElement.getAsString(NAME);
final String sMimeType = aElement.getAsString(MIME_TYPE);
final IMimeType aMimeType;
try {
aMimeType = MimeTypeParser.parseMimeType(sMimeType);
} catch (final MimeTypeParserException ex) {
throw new IllegalArgumentException("Failed to parse MIME Type '" + sMimeType + "'", ex);
}
final String sXSDFilename = aElement.getAsString(XSD_FILENAME);
final Integer aMaxSizeKB = aElement.getAsIntObj(MAX_SIZE_KB);
final EMandatory eMandatory = EMandatory.valueOf(aElement.getAsBoolean(MANDATORY, PModePayloadProfile.DEFAULT_MANDATORY));
return new PModePayloadProfile(sName, aMimeType, sXSDFilename, aMaxSizeKB, eMandatory);
}
use of com.helger.commons.mime.MimeTypeParserException in project phase4 by phax.
the class PModePayloadProfileMicroTypeConverter method convertToNative.
@Nonnull
public PModePayloadProfile convertToNative(final IMicroElement aElement) {
final String sName = aElement.getAttributeValue(ATTR_NAME);
final String sMimeType = aElement.getAttributeValue(ATTR_MIME_TYPE);
final IMimeType aMimeType;
try {
aMimeType = MimeTypeParser.parseMimeType(sMimeType);
} catch (final MimeTypeParserException ex) {
throw new IllegalArgumentException("Failed to parse MIME Type '" + sMimeType + "'", ex);
}
final String sXSDFilename = aElement.getAttributeValue(ATTR_XSD_FILENAME);
final Integer aMaxSizeKB = aElement.getAttributeValueWithConversion(ATTR_MAX_SIZE_KB, Integer.class);
final EMandatory eMandatory = EMandatory.valueOf(aElement.getAttributeValueAsBool(ATTR_MANDATORY, PModePayloadProfile.DEFAULT_MANDATORY));
return new PModePayloadProfile(sName, aMimeType, sXSDFilename, aMaxSizeKB, eMandatory);
}
use of com.helger.commons.mime.MimeTypeParserException in project ph-commons by phax.
the class MimeTypeInfoMicroTypeConverter method convertToNative.
@Nullable
public MimeTypeInfo convertToNative(@Nonnull final IMicroElement aElement) {
final ICommonsOrderedSet<MimeTypeWithSource> aMimeTypes = new CommonsLinkedHashSet<>();
for (final IMicroElement eMimeType : aElement.getAllChildElements(ELEMENT_MIMETYPE)) {
try {
final MimeType aMimeType = MimeTypeParser.parseMimeType(eMimeType.getTextContentTrimmed());
final String sSource = eMimeType.getAttributeValue(ATTR_SOURCE);
aMimeTypes.add(new MimeTypeWithSource(aMimeType, sSource));
} catch (final MimeTypeParserException ex) {
throw new IllegalStateException("Failed to parse MIME type", ex);
}
}
final String sComment = MicroHelper.getChildTextContent(aElement, ELEMENT_COMMENT);
final ICommonsOrderedSet<String> aParentTypes = new CommonsLinkedHashSet<>();
for (final IMicroElement eParentType : aElement.getAllChildElements(ELEMENT_PARENT_TYPE)) aParentTypes.add(eParentType.getTextContentTrimmed());
final ICommonsOrderedSet<String> aGlobs = new CommonsLinkedHashSet<>();
for (final IMicroElement eGlob : aElement.getAllChildElements(ELEMENT_GLOB)) aGlobs.add(eGlob.getTextContentTrimmed());
final ICommonsOrderedSet<ExtensionWithSource> aExtensions = new CommonsLinkedHashSet<>();
for (final IMicroElement eExtension : aElement.getAllChildElements(ELEMENT_EXTENSION)) {
// May be null if the empty extension ("") is used
final String sExtension = StringHelper.getNotNull(eExtension.getTextContentTrimmed());
final String sSource = eExtension.getAttributeValue(ATTR_SOURCE);
aExtensions.add(new ExtensionWithSource(sExtension, sSource));
}
final String sSource = aElement.getAttributeValue(ATTR_SOURCE);
return new MimeTypeInfo(aMimeTypes, sComment, aParentTypes, aGlobs, aExtensions, sSource);
}
Aggregations