001: /**********************************************************************************
002:
003: Feedzeo!
004: A free and open source RSS/Atom/RDF feed aggregator
005:
006: Copyright (C) 2005-2006 Anand Rao (anandrao@users.sourceforge.net)
007:
008: This library is free software; you can redistribute it and/or
009: modify it under the terms of the GNU Lesser General Public
010: License as published by the Free Software Foundation; either
011: version 2.1 of the License, or (at your option) any later version.
012:
013: This library is distributed in the hope that it will be useful,
014: but WITHOUT ANY WARRANTY; without even the implied warranty of
015: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: Lesser General Public License for more details.
017:
018: You should have received a copy of the GNU Lesser General Public
019: License along with this library; if not, write to the Free Software
020: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
021:
022: ************************************************************************************/package layout;
023:
024: import util.*;
025: import ui.*;
026: import data.DataElement;
027:
028: /**
029: *
030: * @author Anand Rao
031: */
032: public class CellElement {
033:
034: private String DataTypeName; // same as styleelement names
035: // or table name defined by the user
036: private String Data; // String holding the data of the cell
037: private boolean DataIsLink;
038:
039: private String LinkURL;
040: private String LinkPageLayoutname; // link points to a page whose pagelayout
041: // is defined by this pagelayout object name
042:
043: private boolean IsTable;
044: private TableLayout Table;
045:
046: private String generateHTML() {
047:
048: /*
049: System.out.println("genHTML CELL type:"+DataTypeName);
050: if (Data == null) System.out.println(" Cell data null");
051: else System.out.println(" Cell data:"+Data);
052: */
053: HTMLTag cell = new HTMLTag(TagName.TABLE_CELL_TAG);
054:
055: if (Data.length() > 0) { //data is not empty
056:
057: /*
058: * first generate a default tag with class attribute
059: * set to the datatype
060: */
061: String tagName = TagName.getHTMLTagName(DataTypeName);
062: HTMLTag ItemTag = new HTMLTag(tagName);
063:
064: ItemTag.addAttribute("class", DataTypeName);
065:
066: if (DataIsLink) { // the cell data is actually a link
067: HTMLTag link = new HTMLTag(TagName.ANCHOR_TAG);
068: link.addAttribute("href", LinkURL);
069: link.add(Data);
070: ItemTag.add(link);
071: } else {
072:
073: if (DataTypeName
074: .equalsIgnoreCase(DataElement.NEWS_LINK_ELEM)) {
075: ItemTag.addAttribute("href", Data);
076: ItemTag.add("More Details");
077: } else if (DataTypeName
078: .equalsIgnoreCase(DataElement.FEED_IMAGE_ELEM)) {
079: ItemTag.addAttribute("src", Data);
080: ItemTag.addAttribute("alt", "");
081: } else { // this is a normal datatype, just add data to the Tag
082: ItemTag.add(Data);
083: }
084: }
085: cell.add(ItemTag);
086: return cell.toString();
087: } else {
088: return "";
089: }
090: }
091:
092: /** Creates a new instance of CellElement */
093: public CellElement() {
094:
095: }
096:
097: public CellElement(String DataTypename, String Data, String URL) {
098: DataTypeName = DataTypename;
099: if (Data != null)
100: this .Data = Data;
101: if (URL != null) {
102: LinkURL = URL;
103: DataIsLink = true;
104: } else
105: DataIsLink = false;
106: IsTable = false;
107: }
108:
109: // copy constructor
110: public CellElement(CellElement c) {
111: DataTypeName = new String(c.DataTypeName);
112: if (c.Data != null)
113: Data = new String(c.Data);
114: DataIsLink = c.DataIsLink;
115: if (c.LinkURL != null)
116: LinkURL = new String(c.LinkURL);
117: if (c.LinkPageLayoutname != null)
118: LinkPageLayoutname = new String(c.LinkPageLayoutname);
119: IsTable = c.IsTable;
120: if (IsTable)
121: Table = new TableLayout(c.Table);
122: }
123:
124: public void setData(String data) {
125: Data = data;
126: }
127:
128: public void setLinkURL(String URL) {
129: LinkURL = URL;
130: }
131:
132: public void setLinkPageLayout(String pagename) {
133: LinkPageLayoutname = pagename;
134: DataIsLink = true;
135: }
136:
137: public void addTable(TableLayout tbl) {
138: IsTable = true;
139: Table = tbl;
140: }
141:
142: public boolean IsTable() {
143: return IsTable;
144: }
145:
146: public boolean IsDataLinkType() {
147: return DataIsLink;
148: }
149:
150: public String getLinkPageLayoutName() {
151: return LinkPageLayoutname;
152: }
153:
154: public TableLayout getTable() {
155: return Table;
156: }
157:
158: public String getDataType() {
159: return DataTypeName;
160: }
161:
162: public String toHTML() {
163: if (IsTable) {
164: HTMLTag cell = new HTMLTag(TagName.TABLE_CELL_TAG);
165: cell.add(Table.toHTML());
166: return cell.toString();
167: } else {
168: return (generateHTML());
169: }
170: }
171: }
|