001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Bogdan Stefanescu 018 * Thierry Delprat 019 */ 020package org.nuxeo.apidoc.introspection; 021 022import java.util.Collections; 023import java.util.List; 024 025import org.apache.commons.logging.Log; 026import org.apache.commons.logging.LogFactory; 027import org.dom4j.DocumentException; 028import org.nuxeo.apidoc.api.BaseNuxeoArtifact; 029import org.nuxeo.apidoc.api.ComponentInfo; 030import org.nuxeo.apidoc.api.ExtensionInfo; 031import org.nuxeo.apidoc.api.VirtualNodesConsts; 032import org.nuxeo.apidoc.documentation.ContributionItem; 033import org.nuxeo.apidoc.documentation.DocumentationHelper; 034import org.nuxeo.apidoc.documentation.XMLContributionParser; 035import org.nuxeo.runtime.model.ComponentName; 036 037import com.fasterxml.jackson.annotation.JsonIgnore; 038import com.fasterxml.jackson.annotation.JsonIgnoreType; 039 040@JsonIgnoreType 041public class ExtensionInfoImpl extends BaseNuxeoArtifact implements ExtensionInfo { 042 043 protected static final Log log = LogFactory.getLog(ExtensionInfoImpl.class); 044 045 protected final String id; 046 047 protected final ComponentInfoImpl component; 048 049 protected final String extensionPoint; 050 051 protected String documentation; 052 053 protected String xml; 054 055 protected ComponentName targetComponentName; 056 057 protected Object[] contribution; 058 059 public ExtensionInfoImpl(ComponentInfoImpl component, String xpoint) { 060 id = component.getId() + "--" + xpoint; 061 this.component = component; 062 extensionPoint = xpoint; 063 } 064 065 @Override 066 public String getExtensionPoint() { 067 return targetComponentName.getName() + "--" + extensionPoint; 068 } 069 070 @Override 071 public String getId() { 072 return id; 073 } 074 075 public void setDocumentation(String documentation) { 076 this.documentation = documentation; 077 } 078 079 @Override 080 public String getDocumentation() { 081 return documentation; 082 } 083 084 @Override 085 public String getDocumentationHtml() { 086 return DocumentationHelper.getHtml(getDocumentation()); 087 } 088 089 @Override 090 public ComponentName getTargetComponentName() { 091 return targetComponentName; 092 } 093 094 public void setTargetComponentName(ComponentName targetComponentName) { 095 this.targetComponentName = targetComponentName; 096 } 097 098 @JsonIgnore 099 public Object[] getContribution() { 100 return contribution; 101 } 102 103 public void setContribution(Object[] contribution) { 104 this.contribution = contribution; 105 } 106 107 @Override 108 public String getXml() { 109 return xml; 110 } 111 112 public void setXml(String xml) { 113 this.xml = xml; 114 } 115 116 @Override 117 public String getVersion() { 118 return component.getVersion(); 119 } 120 121 @Override 122 public String getArtifactType() { 123 return ExtensionInfo.TYPE_NAME; 124 } 125 126 @Override 127 public String getHierarchyPath() { 128 return component.getHierarchyPath() + "/" + VirtualNodesConsts.Contributions_VNODE_NAME + "/" + getId(); 129 } 130 131 @Override 132 public List<ContributionItem> getContributionItems() { 133 try { 134 return XMLContributionParser.extractContributionItems(getXml()); 135 } catch (DocumentException e) { 136 log.error(e, e); 137 return Collections.emptyList(); 138 } 139 } 140 141 @Override 142 public ComponentInfo getComponent() { 143 return component; 144 } 145}