/*
 * Copyright 2003,2004 Jeremias Maerki.
 * 
 * Licensed 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.
 */
package org.krysalis.barcode4j.fop0205;

import java.util.HashMap;

import org.apache.fop.fo.DirectPropertyListBuilder;
import org.apache.fop.fo.ElementMapping;
import org.apache.fop.fo.TreeBuilder;
import org.apache.fop.fo.FObj;

import org.krysalis.barcode4j.BarcodeConstants;

/**
 * Registers the elements covered by Barcode4's namespace.
 * 
 * @author Jeremias Maerki
 * @version $Id$
 */
public class BarcodeElementMapping implements ElementMapping {

    private static final String[] BARCODE_ELEMENTS =
        {"intl2of5", "code39", "codabar", "code128", 
         "upc-a", "upc-e", "ean-13", "ean-8",
         "postnet",
         "height", "module-width", "wide-factor", "quiet-zone",
         "checksum", "human-readable", "interchar-gap-width",
         "tall-bar-height", "short-bar-height", "baseline-alignment"
         };

    private static HashMap foObjs = null;    
    
    protected FObj.Maker getBarcodeElementMaker() {
        return BarcodeElement.maker();
    }
    
    protected FObj.Maker getBarcodeObjMaker(String name) {
        return BarcodeObj.maker(name);
    }
    
    private synchronized void setupBarcodeElements() {
        if (foObjs == null) {
            foObjs = new HashMap();
            foObjs.put("barcode", getBarcodeElementMaker());
            for (int i = 0; i < BARCODE_ELEMENTS.length; i++) {
                foObjs.put(BARCODE_ELEMENTS[i], getBarcodeObjMaker(BARCODE_ELEMENTS[i]));
            }
        }
    }

    public void addToBuilder(TreeBuilder builder) {
        setupBarcodeElements();
        builder.addMapping(BarcodeConstants.NAMESPACE, foObjs);

        builder.addPropertyListBuilder(BarcodeConstants.NAMESPACE, new DirectPropertyListBuilder());
        
        //for compatibility (Krysalis Barcode)
        builder.addMapping(BarcodeConstants.OLD_NAMESPACE, foObjs);
		builder.addPropertyListBuilder(BarcodeConstants.OLD_NAMESPACE, new DirectPropertyListBuilder());
    }
}


@@ -1336,16 +1336,180 @@
 adable%22,
+%0A         %22human-readable-font%22, %22human-readable-size%22,%0A         %22font-name%22, %22font-size%22, %22placement%22, %0A         %22display-start-stop%22, %22display-checksum%22,%0A        
  %22interc

Add missing barcode XML elements.