001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.directory; 021 022import java.util.HashMap; 023import java.util.HashSet; 024import java.util.Map; 025import java.util.Set; 026 027public class DirectoryFieldMapper { 028 029 private final Map<String, String> fieldMapping; 030 031 public DirectoryFieldMapper(Map<String, String> fieldMapping) { 032 this.fieldMapping = fieldMapping; 033 } 034 035 public DirectoryFieldMapper() { 036 fieldMapping = new HashMap<String, String>(); 037 } 038 039 // Direct Mapping 040 public String getBackendField(String fieldName) { 041 String backendField = fieldMapping.get(fieldName); 042 if (backendField != null) { 043 return backendField; 044 } else { 045 return fieldName; 046 } 047 } 048 049 // Reverse Mapping 050 public String getDirectoryField(String backEndFieldName) { 051 if (fieldMapping.containsValue(backEndFieldName)) { 052 for (String key : fieldMapping.keySet()) { 053 if (fieldMapping.get(key).equals(backEndFieldName)) { 054 return key; 055 } 056 } 057 } 058 return backEndFieldName; 059 } 060 061 // Direct Mapping for a set 062 public Set<String> getBackendFields(Set<String> fieldNames) { 063 Set<String> mappedFields = new HashSet<String>(); 064 for (String fieldName : fieldNames) { 065 mappedFields.add(getBackendField(fieldName)); 066 } 067 return mappedFields; 068 } 069 070}