diff options
author | Peter Bernard West <pbwest@apache.org> | 2004-05-29 19:17:36 +0000 |
---|---|---|
committer | Peter Bernard West <pbwest@apache.org> | 2004-05-29 19:17:36 +0000 |
commit | d0f4ff0cad002c245b6f197458e83ad060e69157 (patch) | |
tree | cd2b8266c7387a0d040620024104eb6d3ae817ae | |
parent | 2a6fc4aeefef0c8b7089ede51ef985b22a151479 (diff) | |
download | xmlgraphics-fop-d0f4ff0cad002c245b6f197458e83ad060e69157.tar.gz xmlgraphics-fop-d0f4ff0cad002c245b6f197458e83ad060e69157.zip |
Added refineParsing to implement xml:lang shorthand
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@197658 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/fop/fo/properties/XmlLang.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/java/org/apache/fop/fo/properties/XmlLang.java b/src/java/org/apache/fop/fo/properties/XmlLang.java index 894855723..4f4994a17 100644 --- a/src/java/org/apache/fop/fo/properties/XmlLang.java +++ b/src/java/org/apache/fop/fo/properties/XmlLang.java @@ -20,6 +20,15 @@ */ package org.apache.fop.fo.properties; +import org.apache.fop.datatypes.CountryType; +import org.apache.fop.datatypes.LanguageType; +import org.apache.fop.datatypes.NCName; +import org.apache.fop.datatypes.PropertyValue; +import org.apache.fop.datatypes.PropertyValueList; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.PropNames; +import org.apache.fop.fo.expr.PropertyException; + public class XmlLang extends Property { public static final int dataTypes = SHORTHAND; @@ -46,5 +55,53 @@ public class XmlLang extends Property { return inherited; } + /** + * The value returned from the first stage of parsing must be an NCNAME. + * This can be any valid RFC 3066 language tag. I.e. it must have at least + * a primary-subtag, which may be followed by 0 or more subtags, separated + * by hyphens. The primary subtag must be an ISO 639-1 2-letter or + * ISO 639-2 3-letter code. The second subtag, if it exists, may be an + * ISO 3166 2-letter country code. + * <p>If the primary subtag exists, and is a valid ISO 639 code, it will + * be used to generate a <code>LanguageType</code> + * <code>PropertyValue</code> assigned to the <code>Language</code> + * property. If not, the property assignment is invalid. + * <p>If the second subtag exists, and is a valid ISO 3166 code, it + * will be used to generate a <code>CountryType</code> + * <code>PropertyValue</code> assigned to the <code>Country</code>. + * <p>All text beyond the last valid subtag detected, is ignored. + */ + public PropertyValue refineParsing( + int propindex, FONode foNode, PropertyValue value) + throws PropertyException { + if (value.getType() != PropertyValue.NCNAME) { + throw new PropertyException("xml:lang requires NCNAME"); + } + String text = ((NCName)value).getNCName(); + if (text.charAt(text.length() - 1) == '-') { + throw new PropertyException("Invalid xml:lang code: " + text); + } + String[] bits = text.split("-"); + // bits[0] = lang; if bits[1], bits[1] = country + // Is lang OK? + LanguageType lang = new LanguageType(PropNames.LANGUAGE, bits[0]); + // Is there a country code? + CountryType country = null; + if (bits.length > 1) { + try { + country = new CountryType(PropNames.COUNTRY, bits[1]); + } catch (PropertyException e) { + logger.fine("Invalid country code " + bits[1] + " in " + text); + } + } + if (country == null) { + return lang; + } + PropertyValueList list = new PropertyValueList(PropNames.XML_LANG); + list.add(lang); + list.add(country); + return list; + } + } |