/*******************************************************************************
 * Copyright (c) 2008 IGA Tosiki, NTT DATA BUSINESS BRAINS Corp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    IGA Tosiki (NTT DATA BUSINESS BRAINS Corp.) - initial API and implementation
 *******************************************************************************/
/*
 * blanco Framework
 * Copyright (C) 2008 NTT DATA BUSINESS BRAINS CORPORATION
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 */
package blanco.html.normalizer.parser.helper;

import java.io.BufferedWriter;
import java.io.IOException;
import java.util.List;

import blanco.html.parser.BlancoHtmlContentHandler;
import blanco.html.parser.BlancoHtmlContentSerializer;
import blanco.html.parser.valueobject.BlancoHtmlAttribute;

/**
 * クオートを正常化するハンドラ。
 */
public class BlancoHtmlNormalizeQuoteContentHandler implements
        BlancoHtmlContentHandler {
    final BlancoHtmlContentSerializer serializer = new BlancoHtmlContentSerializer();

    protected BufferedWriter fWriter;

    public void setWriter(final BufferedWriter writer) {
        serializer.setWriter(writer);
    }

    public BufferedWriter getWriter() {
        return serializer.getWriter();
    }

    public void startDocument() throws IOException {
        serializer.startDocument();
    }

    public void endDocument() throws IOException {
        serializer.endDocument();
    }

    public void startElement(final String name,
            final List<BlancoHtmlAttribute> attrs) throws IOException {
        for (BlancoHtmlAttribute attr : attrs) {
            if (attr.getQuote() == 0) {
                // クオートがない場合にはクオートをセット。
                // TODO アトリビュート中にクオートがある場合の処理が欠落。
                attr.setQuote(2);
            }
        }
        serializer.startElement(name, attrs);
    }

    public void endElement(final String name) throws IOException {
        serializer.endElement(name);
    }

    public void characters(final String argCharacters) throws IOException {
        serializer.characters(argCharacters);
    }

    public void comments(final String argComments, final int argType)
            throws IOException {
        serializer.comments(argComments, argType);
    }
}
