001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.search.handlers.pam;
018:
019: import java.util.Collection;
020: import java.util.HashSet;
021: import java.util.Iterator;
022:
023: import org.apache.commons.collections.MultiHashMap;
024: import org.apache.jetspeed.om.common.LocalizedField;
025: import org.apache.jetspeed.om.common.portlet.PortletApplication;
026: import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
027: import org.apache.jetspeed.search.AbstractObjectHandler;
028: import org.apache.jetspeed.search.BaseParsedObject;
029: import org.apache.jetspeed.search.ParsedObject;
030: import org.apache.jetspeed.util.JetspeedLocale;
031: import org.apache.pluto.om.common.Description;
032: import org.apache.pluto.om.common.DisplayName;
033: import org.apache.pluto.om.common.Language;
034:
035: /**
036: * @author <a href="mailto: jford@apache.org">Jeremy Ford</a>
037: */
038: public class PortletDefinitionHandler extends AbstractObjectHandler {
039: private static final String KEY_PREFIX = "PortletDefinition::";
040: private static final String ID = "ID";
041: private static final String PORTLET_APPLICATION = "portlet_application";
042:
043: {
044: fields.add(ID);
045: fields.add(PORTLET_APPLICATION);
046: }
047:
048: /* (non-Javadoc)
049: * @see org.apache.jetspeed.search.ObjectHandler#parseObject(java.lang.Object)
050: */
051: public ParsedObject parseObject(Object o) {
052: BaseParsedObject result = null;
053: if (o instanceof PortletDefinitionComposite) {
054: result = new BaseParsedObject();
055: PortletDefinitionComposite pd = (PortletDefinitionComposite) o;
056:
057: //need to get Locale here
058: String displayNameText = pd
059: .getDisplayNameText(JetspeedLocale
060: .getDefaultLocale());
061: result.setTitle(displayNameText);
062:
063: String description = pd.getDescriptionText(JetspeedLocale
064: .getDefaultLocale());
065: result.setDescription(description);
066:
067: result.setClassName(pd.getClass().getName());
068: result.setKey(KEY_PREFIX + pd.getUniqueName());
069: result.setType(ParsedObject.OBJECT_TYPE_PORTLET);
070:
071: //TODO: this is common to PAs as well, possible refactor
072: MultiHashMap fieldMap = new MultiHashMap();
073: fieldMap.put(ID, pd.getName());
074:
075: PortletApplication pa = (PortletApplication) pd
076: .getPortletApplicationDefinition();
077: fieldMap.put(PORTLET_APPLICATION, pa.getName());
078:
079: Collection mdFields = pd.getMetadata().getFields();
080: for (Iterator fieldIter = mdFields.iterator(); fieldIter
081: .hasNext();) {
082: LocalizedField field = (LocalizedField) fieldIter
083: .next();
084: fieldMap.put(field.getName(), field.getValue());
085: }
086:
087: //Handle descriptions
088: Iterator descIter = pd.getDescriptionSet().iterator();
089: while (descIter.hasNext()) {
090: Description desc = (Description) descIter.next();
091: fieldMap.put(ParsedObject.FIELDNAME_DESCRIPTION, desc
092: .getDescription());
093: }
094:
095: //Handle keywords and titles
096: Iterator displayNameIter = pd.getDisplayNameSet()
097: .iterator();
098: while (displayNameIter.hasNext()) {
099: DisplayName displayName = (DisplayName) displayNameIter
100: .next();
101: fieldMap.put(ParsedObject.FIELDNAME_TITLE, displayName
102: .getDisplayName());
103: }
104:
105: HashSet keywordSet = new HashSet();
106:
107: Iterator langIter = pd.getLanguageSet().iterator();
108: while (langIter.hasNext()) {
109: Language lang = (Language) langIter.next();
110: fieldMap.put(ParsedObject.FIELDNAME_TITLE, lang
111: .getTitle());
112: fieldMap.put(ParsedObject.FIELDNAME_TITLE, lang
113: .getShortTitle());
114:
115: Iterator keywordIter = lang.getKeywords();
116: if (keywordIter != null) {
117: while (keywordIter.hasNext()) {
118: String keyword = (String) keywordIter.next();
119: keywordSet.add(keyword);
120: }
121: }
122: }
123:
124: String[] temp = new String[keywordSet.size()];
125: result.setKeywords((String[]) keywordSet.toArray(temp));
126: result.setFields(fieldMap);
127: }
128: return result;
129: }
130: }
|