1 9 10 package org.eclipse.help.internal.xhtml; 11 12 import org.eclipse.core.runtime.FileLocator; 13 import org.eclipse.core.runtime.IPath; 14 import org.eclipse.core.runtime.Path; 15 import org.osgi.framework.Bundle; 16 import org.w3c.dom.Document ; 17 import org.w3c.dom.Element ; 18 19 20 public class UATopicExtension extends AbstractUAElement { 21 22 protected static final String TAG_TOPIC_EXTENSION = "topicExtension"; 24 protected static final String ATT_PATH = "path"; private static final String ATT_CONTENT = "content"; 27 private static final Element [] EMPTY_ELEMENT_ARRAY = new Element [0]; 28 29 private String path; 30 private String contentFile; 31 private String contentId; 32 private Element element; 33 34 UATopicExtension(Element element, Bundle bundle) { 35 super(element, bundle); 36 path = getAttribute(element, ATT_PATH); 37 extractFileAndId(getAttribute(element, ATT_CONTENT), bundle); 38 contentFile = BundleUtil.getResolvedResourceLocation(contentFile, bundle, false); 39 this.element = element; 40 } 41 42 45 public String getPath() { 46 return path; 47 } 48 49 57 public Element [] getElements() { 58 UAContentParser parser = new UAContentParser(contentFile); 59 Document dom = parser.getDocument(); 60 if (dom != null) { 61 if (contentId != null) { 62 return new Element [] { dom.getElementById(contentId) }; 64 } 65 else { 66 Element extensionBody = DOMUtil.getBodyElement(dom); 68 return DOMUtil.getElementsByTagName(extensionBody, "*"); } 70 } 71 return EMPTY_ELEMENT_ARRAY; 72 } 73 74 public Element getElement() { 75 return element; 76 } 77 78 87 private void extractFileAndId(String content, Bundle bundle) { 88 IPath resourcePath = new Path(content); 90 if (FileLocator.find(bundle, resourcePath, null) != null) { 91 contentFile = content; 93 } 94 else { 95 int lastSlashIndex = content.lastIndexOf('/'); 97 if (lastSlashIndex != -1) { 98 contentFile = content.substring(0, lastSlashIndex); 99 contentId = content.substring(lastSlashIndex + 1); 100 } 101 else { 102 contentFile = content; 104 } 105 } 106 } 107 } 108 | Popular Tags |