Search in sources :

Example 1 with MimeType

use of com.twinsoft.convertigo.engine.enums.MimeType in project convertigo by convertigo.

the class RewriteAbsoluteUrl method applyOnResponse.

@Override
public boolean applyOnResponse(Shuttle shuttle) {
    try {
        MimeType mimeType = MimeType.parse(shuttle.getResponseMimeType());
        Pattern pattern = null;
        if (rewriteHtml && htmlTypes.contains(mimeType)) {
            if (rewriteCss && cssTypes.contains(mimeType)) {
                Engine.logSiteClipper.trace("(RewriteAbsoluteUrl) Prepare rewriting to use Html + Css replacement pattern");
                pattern = htmlCssPattern;
            } else {
                Engine.logSiteClipper.trace("(RewriteAbsoluteUrl) Prepare rewriting to use Html replacement pattern");
                pattern = htmlPattern;
            }
        } else {
            if (rewriteCss && cssTypes.contains(mimeType)) {
                Engine.logSiteClipper.trace("(RewriteAbsoluteUrl) Prepare rewriting to use Css replacement pattern");
                pattern = cssPattern;
            }
        }
        if (pattern != null) {
            replace(pattern, shuttle);
            return true;
        } else {
            Engine.logSiteClipper.trace("(RewriteAbsoluteUrl) Do not rewrite this resource");
        }
    } catch (Exception e) {
        Engine.logSiteClipper.warn("Unable to apply 'RewriteRule' rule : " + getName(), e);
    }
    return false;
}
Also used : Pattern(java.util.regex.Pattern) MimeType(com.twinsoft.convertigo.engine.enums.MimeType) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

MimeType (com.twinsoft.convertigo.engine.enums.MimeType)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Pattern (java.util.regex.Pattern)1