1 22 23 package org.xquark.extractor.metadata; 24 25 import java.util.Properties ; 26 27 import org.xquark.extractor.common.Constants; 28 29 33 public class CustomizedEncoder implements QNameEncoder, Constants { 34 35 private static final String RCSRevision = "$Revision: 1.3 $"; 36 private static final String RCSName = "$Name: $"; 37 38 private Properties _substitutionMap = new Properties (); 39 private int _nameCase = CASE_MIXED; 40 41 public CustomizedEncoder() {} 42 43 public void addSubstitution(char aChar, String subtituteWith) { 44 _substitutionMap.setProperty(String.valueOf(aChar), subtituteWith); 45 } 46 47 public void setSubstitutionMap(Properties map) { 48 _substitutionMap = map; 49 } 50 51 public void setNameCase(int nameCase) { 52 _nameCase = nameCase; 53 } 54 55 public String encode(String dbObjectName) { 56 57 String retVal = null; 58 if (null == _substitutionMap) { 59 retVal = dbObjectName; 60 } else { 61 StringBuffer retBuf = new StringBuffer (); 62 63 char[] name = dbObjectName.toCharArray(); 64 String aChar = null; 65 String substitution = null; 66 for (int i = 0; i < name.length; i++) { 67 aChar = String.valueOf(name[i]); 68 substitution = _substitutionMap.getProperty(aChar); 69 if (null == substitution) { 70 retBuf.append(aChar); 71 } else { 72 retBuf.append(substitution); 73 } 74 } 75 retVal = retBuf.toString(); 76 } 77 78 if (CASE_MIXED == _nameCase) { 79 } else if (CASE_LOWER == _nameCase) { 80 retVal = retVal.toLowerCase(); 81 } else { 82 retVal = retVal.toUpperCase(); 83 } 84 85 return retVal; 86 } 87 } 88 | Popular Tags |