    001/*
    002    Licensed to the Apache Software Foundation (ASF) under one
    003    or more contributor license agreements.  See the NOTICE file
    004    distributed with this work for additional information
    005    regarding copyright ownership.  The ASF licenses this file
    006    to you under the Apache License, Version 2.0 (the
    007    "License"); you may not use this file except in compliance
    008    with the License.  You may obtain a copy of the License at
    009
    010       http://www.apache.org/licenses/LICENSE-2.0
    011
    012    Unless required by applicable law or agreed to in writing,
    013    software distributed under the License is distributed on an
    014    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015    KIND, either express or implied.  See the License for the
    016    specific language governing permissions and limitations
    017    under the License.
    018 */
    019package org.apache.wiki.htmltowiki.syntax;
    020
    021import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator;
    022import org.jdom2.JDOMException;
    023
    024import java.io.PrintWriter;
    025
    026
    027/**
    028 * Translates to wiki syntax from a plain text handling special css.
    029 */
    030public abstract class PlainTextCssSpecialDecorator {
    031
    032    final protected PrintWriter out;
    033    final protected XHtmlElementToWikiTranslator chain;
    034
    035    protected PlainTextCssSpecialDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) {
    036        this.out = out;
    037        this.chain = chain;
    038    }
    039
    040    /**
    041     * Translates the given XHTML element into wiki markup.
    042     *
    043     * @param dto XHTML element being translated.
    044     */
    045    public void decorate( final XHtmlElementToWikiTranslator.ElementDecoratorData dto ) throws JDOMException {
    046        if( dto.cssSpecial != null ) {
    047            if( MarkupHelper.isHtmlBaseDiv( dto ) ) {
    048                out.print( markupCssSpecialDivOpen( dto.cssSpecial ) );
    049            } else {
    050                out.print( markupCssSpecialOpen( dto.cssSpecial ) );
    051            }
    052        }
    053        chain.translateChildren( dto.base );
    054        if( dto.cssSpecial != null ) {
    055            if( MarkupHelper.isHtmlBaseDiv( dto ) ) {
    056                out.print( markupCssSpecialDivClose( dto.cssSpecial ) );
    057            } else {
    058                out.print( markupCssSpecialClose( dto.cssSpecial ) );
    059            }
    060        }
    061    }
    062
    063    /**
    064     * Opening wiki markup for a css style element.
    065     *
    066     * @param cssStyle css styles to apply
    067     * @return Opening wiki markup for a css style element.
    068     */
    069    protected abstract String markupCssSpecialDivOpen( String cssStyle );
    070
    071    /**
    072     * Closing wiki markup for a css style element.
    073     *
    074     * @param cssStyle css styles to apply
    075     * @return Closing wiki markup for a css style element.
    076     */
    077    protected abstract String markupCssSpecialDivClose( String cssStyle );
    078
    079    /**
    080     * Opening wiki markup for a css style element.
    081     *
    082     * @param cssStyle css styles to apply
    083     * @return Opening wiki markup for a css style element.
    084     */
    085    protected abstract String markupCssSpecialOpen( String cssStyle );
    086
    087    /**
    088     * Closing wiki markup for a css style element.
    089     *
    090     * @param cssStyle css styles to apply
    091     * @return Closing wiki markup for a css style element.
    092     */
    093    protected abstract String markupCssSpecialClose( String cssStyle );
    094
    095}