From 9beb8521bd3558ba8beda70ba1e1ec8ca1d42c10 Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Mon, 2 Jul 2001 10:45:35 +0000 Subject: [PATCH] handles key values a bit better git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194323 13f79535-47bb-0310-9956-ffa450edef68 --- .../configuration/ConfigurationParser.java | 180 ++++++++++-------- 1 file changed, 97 insertions(+), 83 deletions(-) diff --git a/src/org/apache/fop/configuration/ConfigurationParser.java b/src/org/apache/fop/configuration/ConfigurationParser.java index 1dab0e2b7..e06b99f43 100644 --- a/src/org/apache/fop/configuration/ConfigurationParser.java +++ b/src/org/apache/fop/configuration/ConfigurationParser.java @@ -1,7 +1,7 @@ -/* +/* * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources." + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ @@ -24,7 +24,6 @@ import org.apache.fop.messaging.MessageHandler; * SAX2 Handler which retrieves the configuration information and stores them in Configuration. * Normally this class doesn't need to be accessed directly. */ - public class ConfigurationParser extends DefaultHandler { private final int OUT = 0; private final int IN_ENTRY = 1; @@ -33,8 +32,8 @@ public class ConfigurationParser extends DefaultHandler { private final int IN_LIST = 8; private final int IN_SUBENTRY = 16; private final int IN_SUBKEY = 32; - private final int IN_FONTS = 64; - private final int IN_FONT = 128; + private final int IN_FONTS = 64; + private final int IN_FONT = 128; private final int STRING = 0; private final int LIST = 1; @@ -50,6 +49,7 @@ public class ConfigurationParser extends DefaultHandler { //stores key for new config entry private String key = ""; + private Vector keyStack = new Vector(); //stores string value private String value = ""; @@ -71,21 +71,21 @@ public class ConfigurationParser extends DefaultHandler { //stores fonts private Vector fontList = null; - + //stores information on one font private FontInfo fontInfo = null; - //stores information on a font triplet - private FontTriplet fontTriplet = null; - - //information on a font - private String fontName, metricsFile, embedFile, kerningAsString; - private boolean kerning; - private Vector fontTriplets; - - //information on a font triplet - private String fontTripletName, weight, style; - + //stores information on a font triplet + private FontTriplet fontTriplet = null; + + //information on a font + private String fontName, metricsFile, embedFile, kerningAsString; + private boolean kerning; + private Vector fontTriplets; + + //information on a font triplet + private String fontTripletName, weight, style; + public void startDocument() { configuration = Configuration.getConfiguration(); } @@ -96,8 +96,8 @@ public class ConfigurationParser extends DefaultHandler { } /** - * extracts the element and attribute name and sets the fitting status and datatype values - * */ + * extracts the element and attribute name and sets the fitting status and datatype values + */ public void startElement(String uri, String localName, String qName, Attributes attributes) { if (localName.equals("key")) { @@ -108,34 +108,34 @@ public class ConfigurationParser extends DefaultHandler { status += IN_LIST; } else if (localName.equals("subentry")) { status += IN_SUBENTRY; - } else if (localName.equals("entry")) { + } else if (localName.equals("entry")) { //role=standard as default if (attributes.getLength() == 0) { role = "standard"; - //retrieve attribute value for "role" which determines configuration target + //retrieve attribute value for "role" which determines configuration target } else { role = attributes.getValue("role"); } - } else if (localName.equals("configuration") ) { - } else if (localName.equals("fonts") ) { //list of fonts starts - fontList = new Vector (10); - } else if (localName.equals("font") ) { - kerningAsString = attributes.getValue("kerning"); - if (kerningAsString.equalsIgnoreCase("yes")) { - kerning = true; - } else { - kerning = false; - } - metricsFile = attributes.getValue("metrics-file"); - embedFile = attributes.getValue("embed-file"); - fontName = attributes.getValue("name"); - fontTriplets = new Vector(5); - } else if (localName.equals("font-triplet") ) { - fontTripletName = attributes.getValue("name"); - weight = attributes.getValue("weight"); - style = attributes.getValue("style"); - fontTriplet = new FontTriplet(fontTripletName,weight,style); - fontTriplets.addElement(fontTriplet); + } else if (localName.equals("configuration")) { + } else if (localName.equals("fonts")) { //list of fonts starts + fontList = new Vector (10); + } else if (localName.equals("font")) { + kerningAsString = attributes.getValue("kerning"); + if (kerningAsString.equalsIgnoreCase("yes")) { + kerning = true; + } else { + kerning = false; + } + metricsFile = attributes.getValue("metrics-file"); + embedFile = attributes.getValue("embed-file"); + fontName = attributes.getValue("name"); + fontTriplets = new Vector(5); + } else if (localName.equals("font-triplet")) { + fontTripletName = attributes.getValue("name"); + weight = attributes.getValue("weight"); + style = attributes.getValue("style"); + fontTriplet = new FontTriplet(fontTripletName, weight, style); + fontTriplets.addElement(fontTriplet); } else { //to make sure that user knows about false tag MessageHandler.errorln( @@ -160,38 +160,54 @@ public class ConfigurationParser extends DefaultHandler { } status = OUT; role = "standard"; - key = ""; - value = ""; - } else if (localName.equals("subentry")) { - map.put(subkey, value); - status -= IN_SUBENTRY; - key = ""; - value = ""; - } else if (localName.equals("key")) { - status -= IN_KEY; - } else if (localName.equals("list")) { - status -= IN_LIST; - value = ""; - } else if (localName.equals("value")) { - status -= IN_VALUE; - } else if (localName.equals("fonts") ) { - this.store("standard", "fonts", fontList); - } else if (localName.equals("font") ) { - fontInfo = new FontInfo(fontName,metricsFile,kerning,fontTriplets,embedFile); - fontList.addElement(fontInfo); - fontTriplets = null; - metricsFile = null; - embedFile = null; - fontName = null; - kerningAsString = ""; - } else if (localName.equals("font-triplet") ) { + if (keyStack.size() > 0) { + keyStack.removeElementAt(keyStack.size() - 1); + } + if (keyStack.size() > 0) { + key = (String) keyStack.elementAt(keyStack.size() - 1); + } else { + key = ""; + } + value = ""; + } else if (localName.equals("subentry")) { + map.put(subkey, value); + status -= IN_SUBENTRY; + if (keyStack.size() > 0) { + keyStack.removeElementAt(keyStack.size() - 1); + } + if (keyStack.size() > 0) { + key = (String) keyStack.elementAt(keyStack.size() - 1); + } else { + key = ""; + } + value = ""; + } else if (localName.equals("key")) { + status -= IN_KEY; + keyStack.addElement(key); + } else if (localName.equals("list")) { + status -= IN_LIST; + value = ""; + } else if (localName.equals("value")) { + status -= IN_VALUE; + } else if (localName.equals("fonts")) { + this.store("standard", "fonts", fontList); + } else if (localName.equals("font")) { + fontInfo = new FontInfo(fontName, metricsFile, kerning, + fontTriplets, embedFile); + fontList.addElement(fontInfo); + fontTriplets = null; + metricsFile = null; + embedFile = null; + fontName = null; + kerningAsString = ""; + } else if (localName.equals("font-triplet")) { } } /** - * extracts characters from text nodes and puts them into their respective - * variables - */ + * extracts characters from text nodes and puts them into their respective + * variables + */ public void characters(char[] ch, int start, int length) { char characters [] = new char [length]; System.arraycopy(ch, start, characters, 0, length); @@ -218,23 +234,21 @@ public class ConfigurationParser extends DefaultHandler { } } //end characters - /** - * stores configuration entry into configuration hashtable according to the role - * - * @param role a string containing the role / target for this configuration information - * @param key a string containing the key value for the configuration - * @param value a string containing the value for the configuration - */ + * stores configuration entry into configuration hashtable according to the role + * + * @param role a string containing the role / target for this configuration information + * @param key a string containing the key value for the configuration + * @param value a string containing the value for the configuration + */ private void store (String role, String key, Object value) { activeConfiguration = (Hashtable) configuration.get(role); if (activeConfiguration != null) { - activeConfiguration.put(key,value); + activeConfiguration.put(key, value); } else { - MessageHandler.errorln("Unknown role >" + role + "< for new configuration entry. \n" - +"Putting configuration with key:" + key + " into standard configuration."); - } + MessageHandler.errorln("Unknown role >" + role + + "< for new configuration entry. \n" + + "Putting configuration with key:" + key + " into standard configuration."); + } } - - } -- 2.39.5