aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorAndreas L. Delmelle <adelmelle@apache.org>2008-02-03 12:05:49 +0000
committerAndreas L. Delmelle <adelmelle@apache.org>2008-02-03 12:05:49 +0000
commitbc7583143625a86bdfd159058fa5b2762f2b64c2 (patch)
tree2f415bd49ee44056fa3b87575e93b22c5e899bd8 /src/java/org/apache
parent8e49549a9f59b5ee87a1c060fa9801916adf153d (diff)
downloadxmlgraphics-fop-bc7583143625a86bdfd159058fa5b2762f2b64c2.tar.gz
xmlgraphics-fop-bc7583143625a86bdfd159058fa5b2762f2b64c2.zip
Added very basic parsing for the xml:lang shorthand.
No validation of the specified value, but the language and country properties now do take the shorthand into account to determine their value. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@617976 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/fo/FOPropertyMapping.java6
-rw-r--r--src/java/org/apache/fop/fo/PropertyList.java6
-rw-r--r--src/java/org/apache/fop/fo/properties/XMLLangShorthandParser.java61
3 files changed, 70 insertions, 3 deletions
diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java
index 695eddc07..434d4acaf 100644
--- a/src/java/org/apache/fop/fo/FOPropertyMapping.java
+++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java
@@ -66,6 +66,7 @@ import org.apache.fop.fo.properties.TextDecorationProperty;
import org.apache.fop.fo.properties.ToBeImplementedProperty;
import org.apache.fop.fo.properties.VerticalAlignShorthandParser;
import org.apache.fop.fo.properties.WhiteSpaceShorthandParser;
+import org.apache.fop.fo.properties.XMLLangShorthandParser;
/**
* This class creates and returns an array of Property.Maker instances
@@ -1060,12 +1061,14 @@ public final class FOPropertyMapping implements Constants {
m = new StringProperty.Maker(PR_COUNTRY);
m.setInherited(true);
m.setDefault("none");
+ m.addShorthand(s_generics[PR_XML_LANG]);
addPropertyMaker("country", m);
// language
m = new StringProperty.Maker(PR_LANGUAGE);
m.setInherited(true);
m.setDefault("none");
+ m.addShorthand(s_generics[PR_XML_LANG]);
addPropertyMaker("language", m);
// script
@@ -2722,9 +2725,10 @@ public final class FOPropertyMapping implements Constants {
addPropertyMaker("white-space", m);
// xml:lang
- m = new ToBeImplementedProperty.Maker(PR_XML_LANG);
+ m = new StringProperty.Maker(PR_XML_LANG);
m.setInherited(true);
m.setDefault("");
+ m.setDatatypeParser(new XMLLangShorthandParser());
addPropertyMaker("xml:lang", m);
}
diff --git a/src/java/org/apache/fop/fo/PropertyList.java b/src/java/org/apache/fop/fo/PropertyList.java
index 1de74e2f0..3d050efed 100644
--- a/src/java/org/apache/fop/fo/PropertyList.java
+++ b/src/java/org/apache/fop/fo/PropertyList.java
@@ -310,11 +310,13 @@ public abstract class PropertyList {
String attributeNS;
FopFactory factory = getFObj().getUserAgent().getFactory();
for (int i = 0; i < attributes.getLength(); i++) {
- /* convert all attributes with the same namespace as the fo element for this fObj */
+ /* convert all attributes with the same namespace as the fo element
+ * the "xml:lang" property is a special case */
attributeNS = attributes.getURI(i);
attributeName = attributes.getQName(i);
attributeValue = attributes.getValue(i);
- if (attributeNS == null || attributeNS.length() == 0) {
+ if (attributeNS == null || attributeNS.length() == 0
+ || "xml:lang".equals(attributeName)) {
convertAttributeToProperty(attributes, attributeName, attributeValue);
} else if (!factory.isNamespaceIgnored(attributeNS)) {
ElementMapping mapping = factory.getElementMappingRegistry().getElementMapping(
diff --git a/src/java/org/apache/fop/fo/properties/XMLLangShorthandParser.java b/src/java/org/apache/fop/fo/properties/XMLLangShorthandParser.java
new file mode 100644
index 000000000..69ca372e5
--- /dev/null
+++ b/src/java/org/apache/fop/fo/properties/XMLLangShorthandParser.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+/* $Id:$ */
+
+package org.apache.fop.fo.properties;
+
+import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.expr.PropertyException;
+
+public class XMLLangShorthandParser extends GenericShorthandParser {
+
+ private static final char HYPHEN_MINUS = '-';
+
+ /** {@inheritDoc} */
+ public Property getValueForProperty(int propId,
+ Property property,
+ PropertyMaker maker,
+ PropertyList propertyList)
+ throws PropertyException {
+
+ String shorthandValue = property.getString();
+ int hyphenIndex = shorthandValue.indexOf(HYPHEN_MINUS);
+ if (propId == Constants.PR_LANGUAGE) {
+ if (hyphenIndex == -1) {
+ /* only language specified; use the whole property */
+ return property;
+ } else {
+ /* use only the primary tag */
+ return StringProperty.getInstance(
+ shorthandValue.substring(0, hyphenIndex));
+ }
+ } else if (propId == Constants.PR_COUNTRY) {
+ if (hyphenIndex != -1) {
+ int nextHyphenIndex = shorthandValue.indexOf(HYPHEN_MINUS, hyphenIndex + 1);
+ if (nextHyphenIndex != -1) {
+ return StringProperty.getInstance(
+ shorthandValue.substring(hyphenIndex + 1, nextHyphenIndex));
+ } else {
+ return StringProperty.getInstance(
+ shorthandValue.substring(hyphenIndex + 1));
+ }
+ }
+ }
+ return null;
+ }
+}