Source Code Cross Referenced for CmsSearchFieldMapping.java in  » Content-Management-System » opencms » org » opencms » search » fields » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » opencms » org.opencms.search.fields 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/search/fields/CmsSearchFieldMapping.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:31 $
004:         * Version: $Revision: 1.6 $
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, 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.search.fields;
033:
034:        import org.opencms.file.CmsObject;
035:        import org.opencms.file.CmsResource;
036:        import org.opencms.i18n.CmsMessageContainer;
037:        import org.opencms.main.CmsException;
038:        import org.opencms.main.CmsRuntimeException;
039:        import org.opencms.search.Messages;
040:        import org.opencms.search.extractors.I_CmsExtractionResult;
041:        import org.opencms.util.CmsStringUtil;
042:
043:        /**
044:         * Describes a mapping of a piece of content from an OpenCms VFS resource to a field of a search index.<p>
045:         * 
046:         * @author Alexander Kandzior 
047:         * 
048:         * @version $Revision: 1.6 $ 
049:         * 
050:         * @since 7.0.0 
051:         */
052:        public class CmsSearchFieldMapping {
053:
054:            /** The configured default value. */
055:            private String m_defaultValue;
056:
057:            /** Pre-calculated hash value. */
058:            private int m_hashCode;
059:
060:            /** The parameter for the mapping type. */
061:            private String m_param;
062:
063:            /** The mapping type. */
064:            private CmsSearchFieldMappingType m_type;
065:
066:            /**
067:             * Public constructor for a new search field mapping.<p>
068:             */
069:            public CmsSearchFieldMapping() {
070:
071:                // no initialization required
072:            }
073:
074:            /**
075:             * Public constructor for a new search field mapping.<p>
076:             * 
077:             * @param type the type to use, see {@link #setType(CmsSearchFieldMappingType)}
078:             * @param param the mapping parameter, see {@link #setParam(String)}
079:             */
080:            public CmsSearchFieldMapping(CmsSearchFieldMappingType type,
081:                    String param) {
082:
083:                this ();
084:                setType(type);
085:                setParam(param);
086:            }
087:
088:            /**
089:             * Two mappings are equal if the type and the parameter is equal.<p>
090:             * 
091:             * @see java.lang.Object#equals(java.lang.Object)
092:             */
093:            public boolean equals(Object obj) {
094:
095:                if (obj == this ) {
096:                    return true;
097:                }
098:                if (obj instanceof  CmsSearchFieldMapping) {
099:                    CmsSearchFieldMapping other = (CmsSearchFieldMapping) obj;
100:                    return CmsStringUtil.isEqual(m_type, other.m_type)
101:                            && CmsStringUtil.isEqual(m_param, other.m_param);
102:                }
103:                return false;
104:            }
105:
106:            /**
107:             * Returns the default value used for this field mapping in case no content is available.<p>
108:             * 
109:             * @return the default value used for this field mapping in case no content is available
110:             */
111:            public String getDefaultValue() {
112:
113:                return m_defaultValue;
114:            }
115:
116:            /**
117:             * Returns the mapping parameter.<p>
118:             *
119:             * The parameter is used depending on the implementation of the rules of 
120:             * the selected {@link CmsSearchFieldMappingType}.<p>
121:             *
122:             * @return the mapping parameter
123:             */
124:            public String getParam() {
125:
126:                return m_param;
127:            }
128:
129:            /**
130:             * Returns the String value extracted form the provided data according to the rules of this mapping type.<p> 
131:             * 
132:             * @param cms the OpenCms context used for building the search index
133:             * @param res the resource that is indexed
134:             * @param extractionResult the plain text extraction result from the resource  
135:             * 
136:             * @return the String value extracted form the provided data according to the rules of this mapping type
137:             */
138:            public String getStringValue(CmsObject cms, CmsResource res,
139:                    I_CmsExtractionResult extractionResult) {
140:
141:                String content = null;
142:                switch (getType().getMode()) {
143:                case 0: // content
144:                    if (extractionResult != null) {
145:                        content = extractionResult.getContent();
146:                    }
147:                    break;
148:                case 1: // property
149:                case 2: // property-search
150:                    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParam())) {
151:                        boolean search = (getType() == CmsSearchFieldMappingType.PROPERTY_SEARCH);
152:                        try {
153:                            content = cms.readPropertyObject(res, getParam(),
154:                                    search).getValue();
155:                        } catch (CmsException e) {
156:                            // ignore, continue without content
157:                        }
158:                    }
159:                    break;
160:                case 3: // item
161:                    if (extractionResult != null
162:                            && CmsStringUtil
163:                                    .isNotEmptyOrWhitespaceOnly(getParam())) {
164:                        content = (String) extractionResult.getContentItems()
165:                                .get(getParam());
166:                    }
167:                    break;
168:                default:
169:                    // noop, content is already null
170:                }
171:                if (content == null) {
172:                    // in case the content is not available, use the default value for this mapping
173:                    content = getDefaultValue();
174:                }
175:                return content;
176:            }
177:
178:            /**
179:             * Returns the mapping type.<p>
180:             *
181:             * @return the mapping type
182:             */
183:            public CmsSearchFieldMappingType getType() {
184:
185:                return m_type;
186:            }
187:
188:            /**
189:             * The hash code depends on the type and the parameter.<p>
190:             * 
191:             * @see java.lang.Object#hashCode()
192:             */
193:            public int hashCode() {
194:
195:                if (m_hashCode == 0) {
196:                    int hashCode = 73 * ((m_type == null) ? 29 : m_type
197:                            .hashCode());
198:                    if (m_param != null) {
199:                        hashCode += m_param.hashCode();
200:                    }
201:                    m_hashCode = hashCode;
202:                }
203:                return m_hashCode;
204:            }
205:
206:            /**
207:             * Sets the default value for this field mapping in case no content is available.<p> 
208:             * 
209:             * @param defaultValue the default value to set
210:             */
211:            public void setDefaultValue(String defaultValue) {
212:
213:                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(defaultValue)) {
214:                    m_defaultValue = defaultValue.trim();
215:                } else {
216:                    m_defaultValue = null;
217:                }
218:            }
219:
220:            /**
221:             * Sets the mapping parameter.<p>
222:             *
223:             * The parameter is used depending on the implementation of the rules of 
224:             * the selected {@link CmsSearchFieldMappingType}.<p>
225:             *
226:             * @param param the parameter to set
227:             */
228:            public void setParam(String param) {
229:
230:                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(param)) {
231:                    m_param = param.trim();
232:                } else {
233:                    m_param = null;
234:                }
235:            }
236:
237:            /**
238:             * Sets the mapping type.<p>
239:             *
240:             * @param type the type to set
241:             */
242:            public void setType(CmsSearchFieldMappingType type) {
243:
244:                m_type = type;
245:            }
246:
247:            /**
248:             * Sets the mapping type as a String.<p>
249:             *
250:             * @param type the name of the type to set
251:             */
252:            public void setType(String type) {
253:
254:                CmsSearchFieldMappingType mappingType = CmsSearchFieldMappingType
255:                        .valueOf(type);
256:                if (mappingType == null) {
257:                    // invalid mapping type has been used, throw an exception
258:                    throw new CmsRuntimeException(new CmsMessageContainer(
259:                            Messages.get(), Messages.ERR_FIELD_TYPE_UNKNOWN_1,
260:                            new Object[] { type }));
261:                }
262:                setType(mappingType);
263:            }
264:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.