All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.enhydra.xml.xmlc.html.parsers.HTMLParserBase Maven / Gradle / Ivy

The newest version!
/*
 * Enhydra Java Application Server Project
 * 
 * The contents of this file are subject to the Enhydra Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License on
 * the Enhydra web site ( http://www.enhydra.org/ ).
 * 
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
 * the License for the specific terms governing rights and limitations
 * under the License.
 * 
 * The Initial Developer of the Enhydra Application Server is Lutris
 * Technologies, Inc. The Enhydra Application Server and portions created
 * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
 * All Rights Reserved.
 * 
 * Contributor(s):
 * 
 * $Id: HTMLParserBase.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
 */

package org.enhydra.xml.xmlc.html.parsers;

import org.enhydra.xml.io.ErrorReporter;
import org.enhydra.xml.xmlc.XMLCException;
import org.enhydra.xml.xmlc.dom.XMLCDocument;
import org.enhydra.xml.xmlc.metadata.MetaData;
import org.enhydra.xml.xmlc.metadata.Parser;
import org.enhydra.xml.xmlc.metadata.ParserType;
import org.enhydra.xml.xmlc.parsers.XMLCParser;

/**
 * Abstract class used to constructor XMLCParser objects for HTML.
 * Methods in this class are the only ones that do DOM implementation-
 * specific operations.
 */
abstract public class HTMLParserBase implements XMLCParser {
    /**
     * Table of HTML 4.0 elements that have a content model including #PCDATA.
     */
    private static final String[] PCDATA_ELEMENTS = {
        // From strict DTD
        "A", "ABBR", "ACRONYM", "ADDRESS", "B", "BDO", "BIG", "BUTTON",
        "CAPTION", "CITE", "CODE", "DD", "DEL", "DFN", "DIV", "DT", "EM",
        "FIELDSET", "H1", "H2", "H3", "H4", "H5", "H6", "I", "INS", "KBD",
        "LABEL", "LEGEND", "LI", "OBJECT", "OPTION", "P", "PRE", "Q", "SAMP",
        "SCRIPT", "SMALL", "SPAN", "STRONG", "STYLE", "SUB", "SUP", "TD",
        "TEXTAREA", "TH", "TITLE", "TT", "VAR",

        // Added by transitional and frameset DTDs
        "APPLET", "BLOCKQUOTE", "BODY", "CENTER", "FONT", "FORM", "IFRAME",
        "NOSCRIPT", "S", "STRIKE", "U",

        // Added by transitional DTD
        "NOFRAMES"
    };

    /**
     * Common validation of configuration.
     */
    protected void validateConf(ParserType parserType,
                                MetaData metaData) throws XMLCException {
        Parser parser = metaData.getParser();

        Boolean validate = parser.getValidate();
        if ((validate != null) && (!validate.booleanValue())) {
            throw new XMLCException(parserType.getName() + " parser can't disable document validation");
        }
        
        if (parser.getXCatalogURLs().length != 0) {
            throw new XMLCException("XCatalog not support for HTML");
        }
    }

    /**
     * Generate error exception for parse errors.
     */
    protected void handleParseErrors(ErrorReporter reporter) throws XMLCException {
        throw new XMLCException("" + reporter.getErrorCnt()
                                + " parse "
                                + ((reporter.getErrorCnt() > 1) ? "errors" : "error") 
                                + " in HTML file");
    }

    /**
     * Add elements that have #PCDATA as part of its content model
     * to the XMLCDocument description.
     */
    protected void addPCDataContentElements(XMLCDocument xmlcDocument) {
        for (int idx = 0; idx < PCDATA_ELEMENTS.length; idx++) {
            xmlcDocument.addPCDataContentElement(PCDATA_ELEMENTS[idx]);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy