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 037public class ExtensionInfoImpl extends BaseNuxeoArtifact implements ExtensionInfo { 038 039 protected static final Log log = LogFactory.getLog(ExtensionInfoImpl.class); 040 041 protected final String id; 042 043 protected final ComponentInfoImpl component; 044 045 protected final String extensionPoint; 046 047 protected String documentation; 048 049 protected String xml; 050 051 protected ComponentName targetComponentName; 052 053 protected Object[] contribution; 054 055 public ExtensionInfoImpl(ComponentInfoImpl component, String xpoint) { 056 this.id = component.getId() + "--" + xpoint; 057 this.component = component; 058 this.extensionPoint = xpoint; 059 } 060 061 @Override 062 public String getExtensionPoint() { 063 return targetComponentName.getName() + "--" + extensionPoint; 064 } 065 066 @Override 067 public String getId() { 068 return id; 069 } 070 071 public void setDocumentation(String documentation) { 072 this.documentation = documentation; 073 } 074 075 @Override 076 public String getDocumentation() { 077 return documentation; 078 } 079 080 @Override 081 public String getDocumentationHtml() { 082 return DocumentationHelper.getHtml(getDocumentation()); 083 } 084 085 @Override 086 public ComponentName getTargetComponentName() { 087 return targetComponentName; 088 } 089 090 public void setTargetComponentName(ComponentName targetComponentName) { 091 this.targetComponentName = targetComponentName; 092 } 093 094 public Object[] getContribution() { 095 return contribution; 096 } 097 098 public void setContribution(Object[] contribution) { 099 this.contribution = contribution; 100 } 101 102 @Override 103 public String getXml() { 104 return xml; 105 } 106 107 public void setXml(String xml) { 108 this.xml = xml; 109 } 110 111 @Override 112 public String getVersion() { 113 return component.getVersion(); 114 } 115 116 @Override 117 public String getArtifactType() { 118 return ExtensionInfo.TYPE_NAME; 119 } 120 121 @Override 122 public String getHierarchyPath() { 123 return component.getHierarchyPath() + "/" + VirtualNodesConsts.Contributions_VNODE_NAME + "/" + getId(); 124 } 125 126 public List<ContributionItem> getContributionItems() { 127 try { 128 return XMLContributionParser.extractContributionItems(getXml()); 129 } catch (DocumentException e) { 130 log.error(e, e); 131 return Collections.emptyList(); 132 } 133 } 134 135 public ComponentInfo getComponent() { 136 return component; 137 } 138}