001package org.nuxeo.apidoc.documentation; 002 003import java.util.Arrays; 004import java.util.HashMap; 005import java.util.List; 006import java.util.Map; 007 008import org.nuxeo.apidoc.api.AbstractDocumentationItem; 009import org.nuxeo.apidoc.api.BaseNuxeoArtifact; 010import org.nuxeo.apidoc.api.DocumentationItem; 011import org.nuxeo.apidoc.introspection.BundleGroupImpl; 012import org.nuxeo.apidoc.introspection.BundleInfoImpl; 013 014import com.cforcoding.jmd.MarkDownParserAndSanitizer; 015 016public class ResourceDocumentationItem extends AbstractDocumentationItem implements DocumentationItem { 017 018 protected String content; 019 020 protected String filename; 021 022 protected BaseNuxeoArtifact target; 023 024 protected String type; 025 026 public ResourceDocumentationItem(String filename, String content, BundleInfoImpl target, String type) { 027 this.content = content; 028 this.filename = filename; 029 this.target = target; 030 this.type = type; 031 } 032 033 public ResourceDocumentationItem(ResourceDocumentationItem other, BundleGroupImpl target) { 034 this.content = other.content; 035 this.filename = other.filename; 036 this.target = target; 037 this.type = other.type; 038 } 039 040 @Override 041 public String getTitle() { 042 return getCleanName() + " " + target.getId(); 043 } 044 045 protected String getCleanName() { 046 if (filename == null || filename.toLowerCase().startsWith("readme")) { 047 return "ReadMe"; 048 } 049 int idx = filename.indexOf("."); 050 if (idx > 0) { 051 return filename.substring(0, idx); 052 } 053 return filename; 054 } 055 056 @Override 057 public String getContent() { 058 MarkDownParserAndSanitizer parser = new MarkDownParserAndSanitizer(); 059 String xHtml = parser.transform(content); 060 return xHtml; 061 } 062 063 @Override 064 public String getType() { 065 return type; 066 } 067 068 @Override 069 public String getRenderingType() { 070 return "html"; 071 } 072 073 @Override 074 public List<String> getApplicableVersion() { 075 return Arrays.asList(target.getVersion()); 076 } 077 078 @Override 079 public String getTarget() { 080 return target.getId(); 081 } 082 083 @Override 084 public String getTargetType() { 085 return target.getArtifactType(); 086 } 087 088 @Override 089 public boolean isApproved() { 090 return true; 091 } 092 093 @Override 094 public String getId() { 095 return getTargetType() + "--" + filename; 096 } 097 098 @Override 099 public String getUUID() { 100 return null; 101 } 102 103 @Override 104 public Map<String, String> getAttachments() { 105 return new HashMap<String, String>(); 106 } 107 108 @Override 109 public boolean isPlaceHolder() { 110 return true; 111 } 112 113 @Override 114 public String getEditId() { 115 return null; 116 } 117 118 public boolean isReadOnly() { 119 return true; 120 } 121}