001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/help/tags/sakai_2-4-1/help-component/src/java/org/sakaiproject/component/app/help/DefaultGlossary.java $
003: * $Id: DefaultGlossary.java 7653 2006-04-12 12:10:02Z marquard@ched.uct.ac.za $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.component.app.help;
021:
022: import java.io.IOException;
023: import java.net.URL;
024: import java.util.Collection;
025: import java.util.Enumeration;
026: import java.util.Map;
027: import java.util.Properties;
028: import java.util.TreeMap;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.sakaiproject.api.app.help.Glossary;
033: import org.sakaiproject.api.app.help.GlossaryEntry;
034: import org.sakaiproject.component.app.help.model.GlossaryEntryBean;
035:
036: /**
037: * default glossary
038: * @version $Id: DefaultGlossary.java 7653 2006-04-12 12:10:02Z marquard@ched.uct.ac.za $
039: */
040: public class DefaultGlossary implements Glossary {
041:
042: private String file;
043: private String url;
044: private Map glossary = new TreeMap();
045: private boolean initialized = false;
046: protected final Log logger = LogFactory.getLog(getClass());
047:
048: /**
049: * initialize glossary
050: */
051: protected void init() {
052: URL glossaryFile = this .getClass().getResource(getFile());
053: Properties glossaryTerms = new Properties();
054: try {
055: glossaryTerms.load(glossaryFile.openStream());
056: for (Enumeration i = glossaryTerms.propertyNames(); i
057: .hasMoreElements();) {
058: String term = (String) i.nextElement();
059: glossary.put(term.toLowerCase(), new GlossaryEntryBean(
060: term.toLowerCase(), glossaryTerms
061: .getProperty(term)));
062: }
063: initialized = true;
064: } catch (IOException e) {
065: logger.error(e);
066: }
067: }
068:
069: /**
070: * @see org.sakaiproject.api.app.help.Glossary#find(java.lang.String)
071: */
072: public GlossaryEntry find(String keyword) {
073: if (!initialized)
074: init();
075: return (GlossaryEntryBean) glossary.get(keyword.toLowerCase());
076: }
077:
078: /**
079: * @see org.sakaiproject.api.app.help.Glossary#findAll()
080: */
081: public Collection findAll() {
082: if (!initialized)
083: init();
084: return glossary.values();
085: }
086:
087: /**
088: * @see org.sakaiproject.api.app.help.Glossary#getUrl()
089: */
090: public String getUrl() {
091: return url;
092: }
093:
094: /**
095: * set url
096: * @param url
097: */
098: public void setUrl(String url) {
099: this .url = url;
100: }
101:
102: /**
103: * get file
104: * @return file name
105: */
106: public String getFile() {
107: return file;
108: }
109:
110: /**
111: * set file name
112: * @param file
113: */
114: public void setFile(String file) {
115: if (!file.startsWith("/")) {
116: this .file = "/" + file;
117: } else {
118: this.file = file;
119: }
120: }
121: }
|