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 css classes. 029 */ 030public abstract class PlainTextCssDecorator { 031 032 final protected PrintWriter out; 033 final protected XHtmlElementToWikiTranslator chain; 034 final protected PlainTextBoldDecorator ptbd; 035 036 protected PlainTextCssDecorator( final PlainTextBoldDecorator ptbd, final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { 037 this.out = out; 038 this.chain = chain; 039 this.ptbd = ptbd; 040 } 041 042 /** 043 * Translates the given XHTML element into wiki markup. 044 * 045 * @param dto XHTML element being translated. 046 */ 047 public void decorate( final XHtmlElementToWikiTranslator.ElementDecoratorData dto ) throws JDOMException { 048 if( dto.cssClass != null && !dto.ignoredCssClass ) { 049 if( MarkupHelper.isHtmlBaseDiv( dto ) ) { 050 out.print( markupCssDivOpen( dto.cssClass ) ); 051 } else if( MarkupHelper.isHtmlBaseSpan( dto ) ) { 052 out.print( markupCssSpanOpen( dto.cssClass ) ); 053 } 054 } 055 ptbd.decorate( dto ); 056 if( dto.cssClass != null && !dto.ignoredCssClass ) { 057 if( MarkupHelper.isHtmlBaseDiv( dto ) ) { 058 out.print( markupCssDivClose( dto.cssClass ) ); 059 } else if( MarkupHelper.isHtmlBaseSpan( dto ) ) { 060 out.print( markupCssSpanClose( dto.cssClass ) ); 061 } 062 } 063 } 064 065 /** 066 * Opening wiki markup for a css element. 067 * 068 * @return Opening wiki markup for a css element. 069 */ 070 protected abstract String markupCssDivOpen( String cssClass ); 071 072 /** 073 * Closing wiki markup for a css element. 074 * 075 * @return Closing wiki markup for a css element. 076 */ 077 protected abstract String markupCssDivClose( String cssClass ); 078 079 /** 080 * Opening wiki markup for a css element. 081 * 082 * @return Opening wiki markup for a css element. 083 */ 084 protected abstract String markupCssSpanOpen( String cssClass ); 085 086 /** 087 * Closing wiki markup for a css element. 088 * 089 * @return Closing wiki markup for a css element. 090 */ 091 protected abstract String markupCssSpanClose( String cssClass ); 092 093}