1 /* 2 * Copyright 2012-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.properties.reports; 17 18 import java.io.IOException; 19 import java.io.OutputStream; 20 21 import javax.annotation.concurrent.NotThreadSafe; 22 23 import org.jdom.Document; 24 25 import de.smartics.properties.api.core.domain.DocumentMetaData; 26 import de.smartics.properties.report.data.PropertyReportSet; 27 import de.smartics.properties.utils.HtmlUtils; 28 29 /** 30 * Helper to construct a projectdoc property set document. 31 */ 32 @NotThreadSafe 33 class PropertySetReporter extends AbstractReporter 34 { 35 // ********************************* Fields ********************************* 36 37 // --- constants ------------------------------------------------------------ 38 39 /** 40 * The namespace of the document that is created. 41 */ 42 private static final String NAMESPACE = 43 "http://www.smartics.de/schema/projectdoc/doctype/property-set/1"; 44 45 // --- members -------------------------------------------------------------- 46 47 /** 48 * The information to be set to the report. 49 */ 50 private final PropertyReportSet reportSet; 51 52 /** 53 * The helper to cleanup HTML fragments. 54 */ 55 private final HtmlUtils htmlUtils = new HtmlUtils("UTF-8"); // TODO encoding 56 57 // ****************************** Initializer ******************************* 58 59 // ****************************** Constructors ****************************** 60 61 PropertySetReporter(final PropertyReportSet reportSet) 62 { 63 super(NAMESPACE); 64 this.reportSet = reportSet; 65 } 66 67 // ****************************** Inner Classes ***************************** 68 69 // ********************************* Methods ******************************** 70 71 // --- init ----------------------------------------------------------------- 72 73 // --- get&set -------------------------------------------------------------- 74 75 // --- business ------------------------------------------------------------- 76 77 void write(final OutputStream out) throws IOException 78 { 79 final Document document = buildDocument("property-set"); 80 final String comment = htmlUtils.clean(getComment()); 81 writeSpecification(comment); 82 writeXml(out, document); 83 } 84 85 /** 86 * {@inheritDoc} 87 * 88 * @see de.smartics.properties.reports.AbstractReporter#getMetaData() 89 */ 90 @Override 91 protected DocumentMetaData getMetaData() 92 { 93 return reportSet.getMetaData(); 94 } 95 96 /** 97 * {@inheritDoc} 98 * 99 * @see de.smartics.properties.reports.AbstractReporter#getComment() 100 */ 101 @Override 102 protected String getComment() 103 { 104 final String comment = reportSet.getComment(); 105 final String cleanComment = htmlUtils.clean(comment); 106 return cleanComment; 107 } 108 109 /** 110 * {@inheritDoc} 111 * 112 * @see de.smartics.properties.reports.AbstractReporter#getName() 113 */ 114 @Override 115 protected String getName() 116 { 117 return reportSet.getName(); 118 } 119 120 /** 121 * {@inheritDoc} 122 * 123 * @see de.smartics.properties.reports.AbstractReporter#getSpace() 124 */ 125 @Override 126 protected String getSpace() 127 { 128 return reportSet.getSpace(); 129 } 130 131 /** 132 * {@inheritDoc} 133 * 134 * @see de.smartics.properties.reports.AbstractReporter#getTitle() 135 */ 136 @Override 137 protected String getTitle() 138 { 139 return reportSet.getTitle(); 140 } 141 142 // --- object basics -------------------------------------------------------- 143 144 }