View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/infomodel/LocalizedStringImpl.java,v 1.5 2003/03/14 16:04:33 farrukh_najmi Exp $ 3 * 4 * 5 */ 6 7 package com.sun.xml.registry.ebxml.infomodel; 8 9 import javax.xml.registry.*; 10 import javax.xml.registry.infomodel.*; 11 import java.util.*; 12 13 import com.sun.xml.registry.ebxml.LifeCycleManagerImpl; 14 15 //import org.oasis.ebxml.registry.bindings.rim.*; 16 17 18 /*** 19 * Class Declaration for Class1 20 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 21 */ 22 public class LocalizedStringImpl implements LocalizedString { 23 24 private Locale locale = null; 25 private String value = null; 26 private String charsetName = null; 27 28 public static final String DEFAULT_CHARSET_NAME = "UTF-8"; 29 30 public LocalizedStringImpl(LifeCycleManagerImpl lcm) { 31 } 32 33 public LocalizedStringImpl(LifeCycleManagerImpl lcm, 34 org.oasis.ebxml.registry.bindings.rim.LocalizedStringType ebObj) 35 { 36 this(lcm); 37 38 //Need to parse language and country from lang 39 String xsdLang = ebObj.getLang(); 40 locale = xsdLang2Locale(xsdLang); 41 42 value = ebObj.getValue(); 43 charsetName = ebObj.getCharset(); 44 } 45 46 private Locale xsdLang2Locale(String xsdLang) { 47 Locale locale = null; 48 49 //Need to see if following is robust enough for all cases. 50 //For now assuming to formats, xx or xx-yy where xx is language and yy is country 51 String country = null; 52 String language = xsdLang.substring(0, 2); 53 if (xsdLang.length() == 5) { 54 country = xsdLang.substring(3, 5); 55 locale = new Locale(language, country); 56 } 57 else { 58 locale = new Locale(language); 59 } 60 61 return locale; 62 } 63 64 private String locale2xsdLang(Locale locale) { 65 String xsdLang = locale.getLanguage(); 66 67 if (xsdLang.length() == 0) { 68 xsdLang = "en"; 69 } 70 71 String country = locale.getCountry(); 72 if (country.length() != 0) { 73 xsdLang = xsdLang + "-" + country; 74 } 75 76 return xsdLang; 77 } 78 79 public String getCharsetName() throws JAXRException { 80 String csName = null; 81 if (charsetName == null) { 82 csName = DEFAULT_CHARSET_NAME; 83 } 84 else { 85 csName = charsetName; 86 } 87 return csName; 88 } 89 90 public Locale getLocale() throws JAXRException { 91 Locale l = null; 92 if (locale == null) { 93 l = Locale.getDefault(); 94 } 95 else { 96 l = locale; 97 } 98 return l; 99 } 100 101 public String getValue() throws JAXRException { 102 return value; 103 } 104 105 public void setCharsetName(String par1) throws JAXRException { 106 charsetName = par1; 107 } 108 109 public void setLocale(Locale par1) throws JAXRException { 110 locale = par1; 111 } 112 113 public void setValue(String par1) throws JAXRException { 114 value = par1; 115 } 116 117 public org.oasis.ebxml.registry.bindings.rim.LocalizedString toBindingObject() throws JAXRException 118 { 119 org.oasis.ebxml.registry.bindings.rim.LocalizedString ebLS = 120 new org.oasis.ebxml.registry.bindings.rim.LocalizedString(); 121 122 ebLS.setLang(locale2xsdLang(locale)); 123 ebLS.setValue(getValue()); 124 ebLS.setCharset(getCharsetName()); 125 126 return ebLS; 127 } 128 129 }

This page was automatically generated by Maven