001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.marshall.markdown; 018 019import org.apache.juneau.commons.bean.*; 020import org.apache.juneau.commons.reflect.*; 021import org.apache.juneau.marshall.*; 022 023/** 024 * Metadata on bean properties specific to the Markdown serializers and parsers pulled from the 025 * {@link Markdown @Markdown} annotation on the bean property. 026 * 027 */ 028public class MarkdownBeanPropertyMeta extends ExtendedBeanPropertyMeta { 029 030 /** 031 * Default instance. 032 */ 033 public static final MarkdownBeanPropertyMeta DEFAULT = new MarkdownBeanPropertyMeta(); 034 035 private final MarkdownFormat format; 036 private final String heading; 037 private final boolean noTables; 038 private final boolean noHeaders; 039 private final boolean code; 040 private final String link; 041 042 /** 043 * Constructor. 044 * 045 * @param bpm The metadata of the bean property of this additional metadata. 046 * @param mp Markdown metadata provider (for finding information about other artifacts). 047 */ 048 public MarkdownBeanPropertyMeta(BeanPropertyMeta bpm, MarkdownMetaProvider mp) { 049 super(bpm); 050 var a = bpm.getAnnotations(Markdown.class).map(AnnotationInfo::inner).reduce((first, second) -> second).orElse(null); 051 format = a != null ? a.format() : MarkdownFormat.DEFAULT; 052 heading = a != null ? a.heading() : ""; 053 noTables = a != null && a.noTables(); 054 noHeaders = a != null && a.noHeaders(); 055 code = a != null && a.code(); 056 link = a != null ? a.link() : ""; 057 } 058 059 private MarkdownBeanPropertyMeta() { 060 super(null); 061 format = MarkdownFormat.DEFAULT; 062 heading = ""; 063 noTables = false; 064 noHeaders = false; 065 code = false; 066 link = ""; 067 } 068 069 /** 070 * Returns the rendering format for this property. 071 * 072 * @return The format. 073 */ 074 public MarkdownFormat getFormat() { 075 return format; 076 } 077 078 /** 079 * Returns the custom heading text for document-mode rendering. 080 * 081 * @return The heading, or empty string if not specified. 082 */ 083 public String getHeading() { 084 return heading; 085 } 086 087 /** 088 * Returns whether tables should be suppressed for this property's collection value. 089 * 090 * @return Whether no-tables is set. 091 */ 092 public boolean isNoTables() { 093 return noTables; 094 } 095 096 /** 097 * Returns whether table header rows should be suppressed. 098 * 099 * @return Whether no-headers is set. 100 */ 101 public boolean isNoHeaders() { 102 return noHeaders; 103 } 104 105 /** 106 * Returns whether the value should be rendered as inline code. 107 * 108 * @return Whether code rendering is enabled. 109 */ 110 public boolean isCode() { 111 return code; 112 } 113 114 /** 115 * Returns the link template for rendering this property as a Markdown link. 116 * 117 * @return The link template, or empty string if not specified. 118 */ 119 public String getLink() { 120 return link; 121 } 122}