📄 ifnotimagetag.java
字号:
package org.jahia.taglibs.field.file;import org.jahia.data.JahiaData;import org.jahia.data.files.JahiaFileField;import org.jahia.exceptions.JahiaException;import org.jahia.utils.JahiaConsole;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;/** * Class IfNotImageTag : displays the tag body if the enclosing FileFieldTag is not an image * * @author Jerome Tamiotti */public class IfNotImageTag extends BodyTagSupport { public int doAfterBody() { ServletRequest request = pageContext.getRequest(); BodyContent body = getBodyContent(); try { JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); if (jData == null) { HashMap tempEngineMap = (HashMap) request.getAttribute("org.jahia.engines.EngineHashMap"); jData = (JahiaData) tempEngineMap.get("jData"); } // retrieves the enclosing file field FileFieldTag fileTag = (FileFieldTag) findAncestorWithClass(this, FileFieldTag.class); if (fileTag != null) { JahiaFileField fileField = fileTag.getFile(); if (!isImage(fileField)) { JspWriter out = body.getEnclosingWriter(); out.print(body.getString()); } } } catch (IOException ioe) { JahiaConsole.println("IfNotImageTag: doAfterBody ", ioe.toString()); } return SKIP_BODY; } private boolean isImage( JahiaFileField theFile ) { if (theFile != null) { if (theFile.getType().equals("")) { // not set yet, so test the default value of the tag String name = theFile.getDownloadUrl(); if (name != null) { name = name.toUpperCase(); return ((name.indexOf("JPG") != -1) || (name.indexOf("PNG") != -1) || (name.indexOf("GIF") != -1) || (name.indexOf("JPEG") != -1)); } } else { // the file field has already been set up // so perform the real test return theFile.getType().startsWith("image"); } } return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -