001: //=============================================================================
002: //=== Copyright (C) 2001-2005 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: GeoNetwork@fao.org
022: //==============================================================================
023:
024: package org.fao.geonet.services.thesaurus;
025:
026: import java.util.Hashtable;
027:
028: import jeeves.server.UserSession;
029: import jeeves.server.context.ServiceContext;
030: import jeeves.utils.Util;
031:
032: import org.fao.geonet.GeonetContext;
033: import org.fao.geonet.constants.Geonet;
034: import org.fao.geonet.constants.Params;
035: import org.fao.geonet.kernel.DataManager;
036: import org.fao.geonet.kernel.ThesaurusManager;
037: import org.jdom.Element;
038:
039: //=============================================================================
040:
041: /** Utilities
042: */
043:
044: class EditUtils {
045: //--------------------------------------------------------------------------
046: //---
047: //--- API methods
048: //---
049: //--------------------------------------------------------------------------
050:
051: /** Perform common editor preprocessing tasks
052: */
053:
054: static void preprocessUpdate(Element params,
055: ServiceContext context, String operation) throws Exception {
056: GeonetContext gc = (GeonetContext) context
057: .getHandlerContext(Geonet.CONTEXT_NAME);
058: ThesaurusManager thesaurusMan = gc.getThesaurusManager();
059:
060: UserSession session = context.getUserSession();
061:
062: // Paramètres : thesaurus
063: String name = Util.getParam(params, Params.NAME);
064: String dir = Util.getParam(params, Params.DIR)
065: .replace('.', '/');
066: String fname = Util.getParam(params, Params.FNAME);
067:
068: // //-----------------------------------------------------------------------
069: // //--- handle current tab
070: //
071: // Element elCurrTab = params.getChild(Params.CURRTAB);
072: //
073: // if (elCurrTab != null)
074: // session.setProperty(Geonet.Session.METADATA_SHOW, elCurrTab.getText());
075:
076: //-----------------------------------------------------------------------
077: //--- check access
078:
079: if (!thesaurusMan.existsThesaurus(name))
080: throw new IllegalArgumentException(
081: "Thesaurus not found --> " + name);
082: }
083:
084: //--------------------------------------------------------------------------
085: /** Update metadata content
086: */
087:
088: public static void updateContent(ThesaurusManager thesaurusMan,
089: Element params, ServiceContext context) throws Exception {
090: GeonetContext gc = (GeonetContext) context
091: .getHandlerContext(Geonet.CONTEXT_NAME);
092: DataManager dataMan = gc.getDataManager();
093:
094: String name = Util.getParam(params, Params.NAME);
095: String dir = Util.getParam(params, Params.DIR)
096: .replace('.', '/');
097: String fname = Util.getParam(params, Params.FNAME);
098:
099: //--- build hashtable with changes
100: //--- each change is a couple (pos, value)
101:
102: Hashtable htChanges = new Hashtable(100);
103:
104: java.util.List list = params.getChildren();
105:
106: for (int i = 0; i < list.size(); i++) {
107: Element el = (Element) list.get(i);
108:
109: String sPos = el.getName();
110: String sVal = el.getText();
111:
112: if (sPos.startsWith("_"))
113: htChanges.put(sPos.substring(1), sVal);
114: }
115:
116: //-----------------------------------------------------------------------
117: //--- update element and return status
118:
119: // if (!thesaurusMan.updateThesaurus(name, htChanges))
120: // throw new UpdateException(name);
121: }
122:
123: //--------------------------------------------------------------------------
124:
125: public static void updateContent(Element params,
126: ServiceContext context) throws Exception {
127: updateContent(params, context);
128: }
129: }
130:
131: //=============================================================================
|