aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--src/documentation/content/xdocs/compliance.ihtml8
-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
-rw-r--r--status.xml3
-rw-r--r--test/fotree/testcases/xml-lang_shorthand-expansion.fo35
6 files changed, 112 insertions, 7 deletions
diff --git a/src/documentation/content/xdocs/compliance.ihtml b/src/documentation/content/xdocs/compliance.ihtml
index 4b6dc024f..27ca74a63 100644
--- a/src/documentation/content/xdocs/compliance.ihtml
+++ b/src/documentation/content/xdocs/compliance.ihtml
@@ -1223,7 +1223,7 @@
yes </td>
<td class="yes">
yes </td>
- <td align="center">&nbsp; </td>
+ <td align="center">&nbsp;</td>
</tr>
<tr>
<td>
@@ -5612,9 +5612,9 @@
<td class="no"> no </td>
<td class="no">
no </td>
- <td class="no">
- no </td>
- <td align="center">&nbsp; </td>
+ <td class="yes">
+ yes </td>
+ <td align="center">[dev] Very basic parsing; no validation of the specified value.</td>
</tr>
</table>
<h1><a name="fo-function-core-library-section">XSL-FO Core Function Library Support Table</a> (<a href="http://www.w3.org/TR/2001/REC-xsl-20011015/slice5.html#section-N8434-Core-Function-Library">&sect;5.10</a>)</h1>
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;
+ }
+}
diff --git a/status.xml b/status.xml
index e03893424..4615f42d0 100644
--- a/status.xml
+++ b/status.xml
@@ -28,6 +28,9 @@
<changes>
<release version="FOP Trunk">
+ <action context="Code" dev="AD" type="add">
+ Added very basic parsing for the xml:lang shorthand.
+ </action>
<action context="Code" dev="AD" type="fix" fixes-bug="44343">
Fixed a bug when using relative font-size (smaller/larger) in combination
with percentages.
diff --git a/test/fotree/testcases/xml-lang_shorthand-expansion.fo b/test/fotree/testcases/xml-lang_shorthand-expansion.fo
new file mode 100644
index 000000000..ed8c13d8f
--- /dev/null
+++ b/test/fotree/testcases/xml-lang_shorthand-expansion.fo
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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$ -->
+ <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:test="http://xmlgraphics.apache.org/fop/test">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="normal" page-width="5in" page-height="5in">
+ <fo:region-body/>
+ </fo:simple-page-master>
+ </fo:layout-master-set>
+ <fo:page-sequence master-reference="normal" xml:lang="en-US">
+ <fo:flow flow-name="xsl-region-body">
+ <fo:block white-space="normal">
+ <test:assert property="language" expected="en" />
+ <test:assert property="country" expected="US" />
+ Block 1
+ </fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+ </fo:root>
+