001    /**
002     * Copyright (c) 2000-2013 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.portal.sharepoint;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.util.StringPool;
019    
020    /**
021     * @author Bruno Farache
022     */
023    public class Leaf implements ResponseElement {
024    
025            public static final String OPEN_LI = "<li>";
026    
027            public Leaf(String key, ResponseElement value) {
028                    this(key, StringPool.NEW_LINE + value.parse(), true, false);
029            }
030    
031            public Leaf(String key, String value, boolean useEqualSymbol) {
032                    this(key, value, useEqualSymbol, true);
033            }
034    
035            public Leaf(
036                    String key, String value, boolean useEqualSymbol, boolean newLine) {
037    
038                    _key = key;
039                    _value = value;
040                    _useEqualSymbol = useEqualSymbol;
041                    _newLine = newLine;
042            }
043    
044            @Override
045            public String parse() {
046                    StringBundler sb = new StringBundler(7);
047    
048                    if (_useEqualSymbol) {
049                            sb.append(OPEN_LI);
050    
051                            sb.append(_key);
052                            sb.append(StringPool.EQUAL);
053                            sb.append(_value);
054                    }
055                    else {
056                            sb.append(OPEN_LI);
057                            sb.append(_key);
058    
059                            sb.append(StringPool.NEW_LINE);
060    
061                            sb.append(OPEN_LI);
062                            sb.append(_value);
063                    }
064    
065                    if (_newLine) {
066                            sb.append(StringPool.NEW_LINE);
067                    }
068    
069                    return sb.toString();
070            }
071    
072            private String _key;
073            private boolean _newLine;
074            private boolean _useEqualSymbol;
075            private String _value;
076    
077    }