| 1 |
<!-- |
| 2 |
Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 |
contributor license agreements. See the NOTICE file distributed with |
| 4 |
this work for additional information regarding copyright ownership. |
| 5 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 |
(the "License"); you may not use this file except in compliance with |
| 7 |
the License. You may obtain a copy of the License at |
| 8 |
|
| 9 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
|
| 11 |
Unless required by applicable law or agreed to in writing, software |
| 12 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
See the License for the specific language governing permissions and |
| 15 |
limitations under the License. |
| 16 |
--> |
| 17 |
<!-- $Id$ --> |
| 18 |
<xsl:stylesheet version="1.0" |
| 19 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 20 |
xmlns:lxslt="http://xml.apache.org/xslt"> |
| 21 |
|
| 22 |
<xsl:include href="propinc.xsl"/> |
| 23 |
|
| 24 |
<xsl:output method="text" /> |
| 25 |
|
| 26 |
|
| 27 |
<xsl:template name="genmaker"> |
| 28 |
<xsl:param name="prop" select="."/> |
| 29 |
<xsl:param name="htname"/> |
| 30 |
|
| 31 |
<xsl:variable name="makerclass"> |
| 32 |
<xsl:choose> |
| 33 |
<xsl:when test="$prop/use-generic and count($prop/*)=2"> |
| 34 |
<xsl:value-of select="$prop/use-generic"/> |
| 35 |
</xsl:when> |
| 36 |
<xsl:when test="$prop/class-name"> |
| 37 |
<xsl:value-of select="$prop/class-name"/><xsl:text>Maker</xsl:text> |
| 38 |
</xsl:when> |
| 39 |
<xsl:otherwise> <!-- make from name --> |
| 40 |
<xsl:call-template name="makeClassName"> |
| 41 |
<xsl:with-param name="propstr" select="$prop/name"/> |
| 42 |
</xsl:call-template><xsl:text>Maker</xsl:text> |
| 43 |
</xsl:otherwise> |
| 44 |
</xsl:choose> |
| 45 |
</xsl:variable> |
| 46 |
<xsl:variable name="lcletters" select="'abcdefghijklmnopqrstuvwxyz-:'" /> |
| 47 |
<xsl:variable name="ucletters" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ__'" /> |
| 48 |
<xsl:variable name="enum" select="translate($prop/name, $lcletters, $ucletters)"/> |
| 49 |
<xsl:text> addPropertyName("</xsl:text><xsl:value-of select="$prop/name"/>", PR_<xsl:value-of select="$enum"/>); |
| 50 |
<xsl:text> </xsl:text><xsl:value-of select="$htname"/>[PR_<xsl:value-of select="$enum"/>] =<xsl:value-of select="$makerclass"/>.maker(PR_<xsl:value-of select="$enum"/>); |
| 51 |
</xsl:template> |
| 52 |
|
| 53 |
|
| 54 |
<xsl:template name="genenum"> |
| 55 |
<xsl:param name="prop" select="."/> |
| 56 |
<xsl:variable name="lcletters" select="'abcdefghijklmnopqrstuvwxyz-:'" /> |
| 57 |
<xsl:variable name="ucletters" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ__'" /> |
| 58 |
<xsl:variable name="num" select="count(preceding-sibling::property)"/> |
| 59 |
<xsl:variable name="enum" select="translate($prop/name, $lcletters, $ucletters)"/> |
| 60 |
<!-- |
| 61 |
<xsl:text> public final static short </xsl:text><xsl:value-of select="$enum"/> = <xsl:value-of select="$num"/>; |
| 62 |
--> |
| 63 |
</xsl:template> |
| 64 |
|
| 65 |
|
| 66 |
<xsl:template match="text()"/> |
| 67 |
<xsl:template match="text()" mode="enums"/> |
| 68 |
|
| 69 |
<xsl:template match="property-list"> |
| 70 |
package org.apache.fop.fo.properties; |
| 71 |
|
| 72 |
import java.util.HashMap; |
| 73 |
import java.util.Set; |
| 74 |
import org.apache.fop.fo.Constants; |
| 75 |
import org.apache.fop.fo.Property; |
| 76 |
//import org.apache.fop.svg.*; |
| 77 |
|
| 78 |
public class <xsl:value-of select="@family"/>PropertyMapping implements Constants { |
| 79 |
|
| 80 |
private static Property.Maker[] s_htGeneric = new Property.Maker[PROPERTY_COUNT+1]; |
| 81 |
/* s_htElementLists not currently used; apparently for specifying element-specific |
| 82 |
* property makers (instead of the default maker for a particular property); see |
| 83 |
* former org.apache.fop.fo.PropertyListBuilder |
| 84 |
*/ |
| 85 |
private static HashMap s_htElementLists = new HashMap(); |
| 86 |
private static HashMap s_htSubPropNames = new HashMap(); |
| 87 |
private static HashMap s_htPropNames = new HashMap(); |
| 88 |
private static HashMap s_htPropIds = new HashMap(); |
| 89 |
<xsl:for-each select="element-property-list"> |
| 90 |
private static HashMap s_ht<xsl:value-of select="localname[1]"/>;</xsl:for-each> |
| 91 |
|
| 92 |
<xsl:apply-templates/> |
| 93 |
|
| 94 |
public static Property.Maker[] getGenericMappings() { |
| 95 |
return s_htGeneric; |
| 96 |
} |
| 97 |
|
| 98 |
public static Set getElementMappings() { |
| 99 |
return s_htElementLists.keySet(); |
| 100 |
} |
| 101 |
|
| 102 |
public static Property.Maker[] getElementMapping(int elemName) { |
| 103 |
return (Property.Maker[])s_htElementLists.get(new Integer(elemName)); |
| 104 |
} |
| 105 |
|
| 106 |
public static int getPropertyId(String name) { |
| 107 |
// check to see if base.compound or just base property |
| 108 |
int sepchar = name.indexOf('.'); |
| 109 |
|
| 110 |
if (sepchar > -1) { |
| 111 |
Integer baseId = (Integer) s_htPropNames.get(name.substring(0, sepchar)); |
| 112 |
if (baseId == null) { |
| 113 |
return -1; |
| 114 |
} else { |
| 115 |
int cmpdId = getSubPropertyId(name.substring(sepchar + 1)); |
| 116 |
if (cmpdId == -1) { |
| 117 |
return -1; |
| 118 |
} else { |
| 119 |
return baseId.intValue() + cmpdId; |
| 120 |
} |
| 121 |
} |
| 122 |
} else { |
| 123 |
Integer baseId = (Integer) s_htPropNames.get(name); |
| 124 |
if (baseId == null) |
| 125 |
return -1; |
| 126 |
return baseId.intValue(); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
public static int getSubPropertyId(String name) { |
| 131 |
Integer i = (Integer) s_htSubPropNames.get(name); |
| 132 |
if (i == null) |
| 133 |
return -1; |
| 134 |
return i.intValue(); |
| 135 |
} |
| 136 |
|
| 137 |
// returns a property, compound, or property.compound name |
| 138 |
public static String getPropertyName(int id) { |
| 139 |
if (((id & Constants.COMPOUND_MASK) == 0) |
| 140 |
|| ((id & Constants.PROPERTY_MASK) == 0)) { |
| 141 |
return (String) s_htPropIds.get(new Integer(id)); |
| 142 |
} else { |
| 143 |
return (String) s_htPropIds.get(new Integer( |
| 144 |
id & Constants.PROPERTY_MASK)) + "." + s_htPropIds.get( |
| 145 |
new Integer(id & Constants.COMPOUND_MASK)); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
static { |
| 150 |
addSubPropertyName("length", CP_LENGTH); |
| 151 |
addSubPropertyName("conditionality", CP_CONDITIONALITY); |
| 152 |
addSubPropertyName("block-progression-direction", CP_BLOCK_PROGRESSION_DIRECTION); |
| 153 |
addSubPropertyName("inline-progression-direction", CP_INLINE_PROGRESSION_DIRECTION); |
| 154 |
addSubPropertyName("within-line", CP_WITHIN_LINE); |
| 155 |
addSubPropertyName("within-column", CP_WITHIN_COLUMN); |
| 156 |
addSubPropertyName("within-page", CP_WITHIN_PAGE); |
| 157 |
addSubPropertyName("minimum", CP_MINIMUM); |
| 158 |
addSubPropertyName("maximum", CP_MAXIMUM); |
| 159 |
addSubPropertyName("optimum", CP_OPTIMUM); |
| 160 |
addSubPropertyName("precedence", CP_PRECEDENCE); |
| 161 |
|
| 162 |
} |
| 163 |
|
| 164 |
public static void addPropertyName(String name, int id) { |
| 165 |
s_htPropNames.put(name, new Integer(id)); |
| 166 |
s_htPropIds.put(new Integer(id), name); |
| 167 |
} |
| 168 |
|
| 169 |
public static void addSubPropertyName(String name, int id) { |
| 170 |
s_htSubPropNames.put(name, new Integer(id)); |
| 171 |
s_htPropIds.put(new Integer(id), name); |
| 172 |
} |
| 173 |
} |
| 174 |
</xsl:template> |
| 175 |
|
| 176 |
<xsl:template match="generic-property-list"> |
| 177 |
<xsl:apply-templates mode="enums"/> |
| 178 |
static { |
| 179 |
// Generate the generic mapping |
| 180 |
<xsl:apply-templates> |
| 181 |
<xsl:with-param name="htname" select='"s_htGeneric"'/> |
| 182 |
</xsl:apply-templates> |
| 183 |
} |
| 184 |
</xsl:template> |
| 185 |
|
| 186 |
<xsl:template match="element-property-list"> |
| 187 |
<xsl:variable name="ename" select="localname[1]"/> |
| 188 |
static { |
| 189 |
s_ht<xsl:value-of select="$ename"/> = new HashMap(); |
| 190 |
<xsl:for-each select="localname"> |
| 191 |
s_htElementLists.put("<xsl:value-of select='.'/>", s_ht<xsl:value-of select='$ename'/>); |
| 192 |
</xsl:for-each> |
| 193 |
|
| 194 |
<xsl:apply-templates> |
| 195 |
<xsl:with-param name='htname'>s_ht<xsl:value-of select="$ename"/></xsl:with-param> |
| 196 |
</xsl:apply-templates> |
| 197 |
} |
| 198 |
</xsl:template> |
| 199 |
|
| 200 |
<xsl:template match="property[@type='generic']" mode="enums"> |
| 201 |
/* PROPCLASS = <xsl:call-template name="propclass"/> */ |
| 202 |
</xsl:template> |
| 203 |
|
| 204 |
<xsl:template match="property" mode="enums"> |
| 205 |
<xsl:param name="htname"/> |
| 206 |
<xsl:variable name="refname" select="name"/> |
| 207 |
<xsl:choose> |
| 208 |
<xsl:when test="@type='ref'"> |
| 209 |
<xsl:call-template name="genenum"> |
| 210 |
<xsl:with-param name="htname" select="$htname"/> |
| 211 |
<xsl:with-param name="prop" |
| 212 |
select='document(concat(@family, "properties.xml"))//property[name=$refname]'/> |
| 213 |
</xsl:call-template> |
| 214 |
</xsl:when> |
| 215 |
<xsl:when test="not(@type)"> |
| 216 |
<xsl:call-template name="genenum"> |
| 217 |
<xsl:with-param name="htname" select="$htname"/> |
| 218 |
</xsl:call-template> |
| 219 |
</xsl:when> |
| 220 |
<xsl:otherwise/> |
| 221 |
</xsl:choose> |
| 222 |
</xsl:template> |
| 223 |
|
| 224 |
<xsl:template match="subproperty" mode="enums"> |
| 225 |
<xsl:call-template name="genenum"/> |
| 226 |
</xsl:template> |
| 227 |
|
| 228 |
<xsl:template match="property"> |
| 229 |
<xsl:param name="htname"/> |
| 230 |
<xsl:variable name="refname" select="name"/> |
| 231 |
<xsl:choose> |
| 232 |
<xsl:when test="@type='ref'"> |
| 233 |
<xsl:call-template name="genmaker"> |
| 234 |
<xsl:with-param name="htname" select="$htname"/> |
| 235 |
<xsl:with-param name="prop" |
| 236 |
select='document(concat(@family, "properties.xml"))//property[name=$refname]'/> |
| 237 |
</xsl:call-template> |
| 238 |
</xsl:when> |
| 239 |
<xsl:when test="not(@type)"> |
| 240 |
<xsl:call-template name="genmaker"> |
| 241 |
<xsl:with-param name="htname" select="$htname"/> |
| 242 |
</xsl:call-template> |
| 243 |
</xsl:when> |
| 244 |
<xsl:otherwise/> |
| 245 |
</xsl:choose> |
| 246 |
</xsl:template> |
| 247 |
|
| 248 |
<xsl:template match="property[@type='generic']"> |
| 249 |
/* PROPCLASS = <xsl:call-template name="propclass"/> */ |
| 250 |
</xsl:template> |
| 251 |
|
| 252 |
</xsl:stylesheet> |
| 253 |
|
| 254 |
|