1 /* 2 * Copyright 2010-2013 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package de.smartics.testdoc.maven.export.sink; 17 18 import org.apache.maven.doxia.sink.Sink; 19 20 import de.smartics.maven.util.report.MessageHelper; 21 import de.smartics.maven.util.report.link.ExternalReport; 22 import de.smartics.testdoc.core.doc.TestMethodDoc; 23 import de.smartics.testdoc.core.doc.Type; 24 25 /** 26 * Base implementation of helper to render links to other reports. 27 * 28 * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a> 29 * @version $Revision:591 $ 30 */ 31 abstract class AbstractLinkRenderer 32 { 33 // ********************************* Fields ********************************* 34 35 // --- constants ------------------------------------------------------------ 36 37 // --- members -------------------------------------------------------------- 38 39 /** 40 * The sink to write to. 41 */ 42 protected final Sink sink; 43 44 /** 45 * The resource bundles with messages to display as labels in the generated 46 * report. 47 */ 48 protected final MessageHelper messages; 49 50 // ****************************** Initializer ******************************* 51 52 // ****************************** Constructors ****************************** 53 54 /** 55 * Default constructor. 56 * 57 * @param sink the sink to write to. 58 * @param messages the resource bundles with messages to display as labels in 59 * the generated report. 60 */ 61 protected AbstractLinkRenderer(final Sink sink, final MessageHelper messages) 62 { 63 this.sink = sink; 64 this.messages = messages; 65 } 66 67 // ****************************** Inner Classes ***************************** 68 69 // ********************************* Methods ******************************** 70 71 // --- init ----------------------------------------------------------------- 72 73 // --- get&set -------------------------------------------------------------- 74 75 // --- business ------------------------------------------------------------- 76 77 void renderTestMethodLink(final ExternalReport report) 78 { 79 final String messageKey = report.getLabelKey(); 80 final Type type = getType(); 81 final String link = 82 report.constructLink(type.getPackageName(), type.getTypeName(), 83 getTestMethod()); 84 if (link != null) 85 { 86 sink.link(link); 87 final String label = messages.getLabel(messageKey); 88 sink.text(label); 89 sink.link_(); 90 } 91 } 92 93 abstract Type getType(); 94 95 abstract TestMethodDoc getTestMethod(); 96 97 // --- object basics -------------------------------------------------------- 98 99 }