001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.taglib.util;
016    
017    import com.liferay.portal.kernel.servlet.taglib.BaseBodyTagSupport;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.kernel.util.Validator;
020    
021    import javax.servlet.http.HttpServletRequest;
022    import javax.servlet.jsp.tagext.BodyTag;
023    
024    /**
025     * @author Eduardo Lundgren
026     */
027    public class PositionTagSupport extends BaseBodyTagSupport implements BodyTag {
028    
029            public String getPosition() {
030                    return getPositionValue();
031            }
032    
033            public boolean isPositionAuto() {
034                    String position = getPosition();
035    
036                    if (position.equals(_POSITION_AUTO)) {
037                            return true;
038                    }
039                    else {
040                            return false;
041                    }
042            }
043    
044            public boolean isPositionInLine() {
045                    String position = getPosition();
046    
047                    if (position.equals(_POSITION_INLINE)) {
048                            return true;
049                    }
050                    else {
051                            return false;
052                    }
053            }
054    
055            public void setPosition(String position) {
056                    _position = position;
057            }
058    
059            protected void cleanUp() {
060                    _position = null;
061            }
062    
063            protected String getPositionValue() {
064                    HttpServletRequest request =
065                            (HttpServletRequest)pageContext.getRequest();
066    
067                    String position = _position;
068    
069                    String fragmentId = ParamUtil.getString(request, "p_f_id");
070    
071                    if (Validator.isNotNull(fragmentId)) {
072                            position = _POSITION_INLINE;
073                    }
074    
075                    if (Validator.isNull(position)) {
076                            position = _POSITION_AUTO;
077                    }
078    
079                    return position;
080            }
081    
082            private static final String _POSITION_AUTO = "auto";
083    
084            private static final String _POSITION_INLINE = "inline";
085    
086            private String _position;
087    
088    }