001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/staticexport/CmsLinkTable.java,v $
003: * Date : $Date: 2008-02-27 12:05:47 $
004: * Version: $Revision: 1.15 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.staticexport;
033:
034: import org.opencms.relations.CmsLink;
035: import org.opencms.relations.CmsRelationType;
036:
037: import java.util.HashMap;
038: import java.util.Iterator;
039:
040: /**
041: * Maintains a table of links for an element of a CmsXmlPage.<p>
042: *
043: * @author Carsten Weinholz
044: *
045: * @version $Revision: 1.15 $
046: *
047: * @since 6.0.0
048: */
049: public class CmsLinkTable {
050:
051: /** Prefix to identify a link in the content. */
052: private static final String LINK_PREFIX = "link";
053:
054: /** The map to store the link table in. */
055: private HashMap m_linkTable;
056:
057: /**
058: * Creates a new CmsLinkTable.<p>
059: */
060: public CmsLinkTable() {
061:
062: m_linkTable = new HashMap();
063: }
064:
065: /**
066: * Adds a new link with a given internal name and internal flag to the link table.<p>
067: *
068: * @param link the <code>CmsLink</code> to add
069: * @return the new link entry
070: */
071: public CmsLink addLink(CmsLink link) {
072:
073: m_linkTable.put(link.getName(), link);
074: return link;
075: }
076:
077: /**
078: * Adds a new link to the link table.<p>
079: *
080: * @param type type of the link
081: * @param targetUri link destination
082: * @param internal flag to indicate if the link is a local link
083: *
084: * @return the new link entry
085: */
086: public CmsLink addLink(CmsRelationType type, String targetUri,
087: boolean internal) {
088:
089: CmsLink link = new CmsLink(LINK_PREFIX + m_linkTable.size(),
090: type, targetUri, internal);
091: m_linkTable.put(link.getName(), link);
092: return link;
093: }
094:
095: /**
096: * Returns the CmsLink Entry for a given name.<p>
097: *
098: * @param name the internal name of the link
099: * @return the CmsLink entry
100: */
101: public CmsLink getLink(String name) {
102:
103: return (CmsLink) m_linkTable.get(name);
104: }
105:
106: /**
107: * Returns if the link table is empty.<p>
108: *
109: * @return true if the link table is empty, false otherwise
110: */
111: public boolean isEmpty() {
112:
113: return m_linkTable.isEmpty();
114: }
115:
116: /**
117: * Returns an iterator over the links in the table.<p>
118: *
119: * The objects iterated are of type <code>{@link CmsLink}</code>.
120: *
121: * @return a string iterator for internal link names
122: */
123: public Iterator iterator() {
124:
125: return m_linkTable.values().iterator();
126: }
127:
128: /**
129: * Returns the size of this link table.<p>
130: *
131: * @return the size of this link table
132: */
133: public int size() {
134:
135: return m_linkTable.size();
136: }
137: }
|