001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Bogdan Stefanescu 016 * Thierry Delprat 017 */ 018package org.nuxeo.apidoc.introspection; 019 020import java.util.Collections; 021import java.util.List; 022 023import org.apache.commons.logging.Log; 024import org.apache.commons.logging.LogFactory; 025import org.dom4j.DocumentException; 026import org.nuxeo.apidoc.api.BaseNuxeoArtifact; 027import org.nuxeo.apidoc.api.ComponentInfo; 028import org.nuxeo.apidoc.api.ExtensionInfo; 029import org.nuxeo.apidoc.api.VirtualNodesConsts; 030import org.nuxeo.apidoc.documentation.ContributionItem; 031import org.nuxeo.apidoc.documentation.DocumentationHelper; 032import org.nuxeo.apidoc.documentation.XMLContributionParser; 033import org.nuxeo.runtime.model.ComponentName; 034 035public class ExtensionInfoImpl extends BaseNuxeoArtifact implements ExtensionInfo { 036 037 protected static final Log log = LogFactory.getLog(ExtensionInfoImpl.class); 038 039 protected final String id; 040 041 protected final ComponentInfoImpl component; 042 043 protected final String extensionPoint; 044 045 protected String documentation; 046 047 protected String xml; 048 049 protected ComponentName targetComponentName; 050 051 protected Object[] contribution; 052 053 public ExtensionInfoImpl(ComponentInfoImpl component, String xpoint) { 054 this.id = component.getId() + "--" + xpoint; 055 this.component = component; 056 this.extensionPoint = xpoint; 057 } 058 059 @Override 060 public String getExtensionPoint() { 061 return targetComponentName.getName() + "--" + extensionPoint; 062 } 063 064 @Override 065 public String getId() { 066 return id; 067 } 068 069 public void setDocumentation(String documentation) { 070 this.documentation = documentation; 071 } 072 073 @Override 074 public String getDocumentation() { 075 return documentation; 076 } 077 078 @Override 079 public String getDocumentationHtml() { 080 return DocumentationHelper.getHtml(getDocumentation()); 081 } 082 083 @Override 084 public ComponentName getTargetComponentName() { 085 return targetComponentName; 086 } 087 088 public void setTargetComponentName(ComponentName targetComponentName) { 089 this.targetComponentName = targetComponentName; 090 } 091 092 public Object[] getContribution() { 093 return contribution; 094 } 095 096 public void setContribution(Object[] contribution) { 097 this.contribution = contribution; 098 } 099 100 @Override 101 public String getXml() { 102 return xml; 103 } 104 105 public void setXml(String xml) { 106 this.xml = xml; 107 } 108 109 @Override 110 public String getVersion() { 111 return component.getVersion(); 112 } 113 114 @Override 115 public String getArtifactType() { 116 return ExtensionInfo.TYPE_NAME; 117 } 118 119 @Override 120 public String getHierarchyPath() { 121 return component.getHierarchyPath() + "/" + VirtualNodesConsts.Contributions_VNODE_NAME + "/" + getId(); 122 } 123 124 public List<ContributionItem> getContributionItems() { 125 try { 126 return XMLContributionParser.extractContributionItems(getXml()); 127 } catch (DocumentException e) { 128 log.error(e, e); 129 return Collections.emptyList(); 130 } 131 } 132 133 public ComponentInfo getComponent() { 134 return component; 135 } 136}