001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.text.toc;
011:
012: import org.eclipse.core.resources.IFile;
013: import org.eclipse.pde.internal.core.itoc.ITocConstants;
014: import org.eclipse.pde.internal.core.text.DocumentNodeFactory;
015: import org.eclipse.pde.internal.core.text.IDocumentElementNode;
016: import org.eclipse.pde.internal.core.text.IDocumentNodeFactory;
017:
018: /**
019: * TocDocumentFactory
020: *
021: */
022: public class TocDocumentFactory extends DocumentNodeFactory implements
023: IDocumentNodeFactory {
024: private TocModel fModel;
025:
026: /**
027: * @param model
028: */
029: public TocDocumentFactory(TocModel model) {
030: fModel = model;
031: }
032:
033: /* (non-Javadoc)
034: * @see org.eclipse.pde.internal.core.text.IDocumentNodeFactory#createDocumentNode(java.lang.String, org.eclipse.pde.internal.core.text.IDocumentElementNode)
035: */
036: public IDocumentElementNode createDocumentNode(String name,
037: IDocumentElementNode parent) {
038:
039: // Semantics:
040: // org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_help_toc.html
041:
042: if (isToc(name)) { // Root
043: return (IDocumentElementNode) createToc();
044: }
045:
046: if (isTopic(name)) { // Topic
047: return (IDocumentElementNode) createTocTopic();
048: }
049:
050: if (isLink(name)) { // Link
051: return (IDocumentElementNode) createTocLink();
052: }
053:
054: if (isAnchor(name)) { // Anchor
055: return (IDocumentElementNode) createTocAnchor();
056: }
057:
058: return super .createDocumentNode(name, parent);
059: }
060:
061: /**
062: * @param name
063: * @param elementName
064: * @return
065: */
066: private boolean isTocElement(String name, String elementName) {
067: if (name.equals(elementName)) {
068: return true;
069: }
070: return false;
071: }
072:
073: /**
074: * @param name
075: * @return
076: */
077: private boolean isToc(String name) {
078: return isTocElement(name, ITocConstants.ELEMENT_TOC);
079: }
080:
081: /**
082: * @param name
083: * @return
084: */
085: private boolean isAnchor(String name) {
086: return isTocElement(name, ITocConstants.ELEMENT_ANCHOR);
087: }
088:
089: /**
090: * @param name
091: * @return
092: */
093: private boolean isTopic(String name) {
094: return isTocElement(name, ITocConstants.ELEMENT_TOPIC);
095: }
096:
097: /**
098: * @param name
099: * @return
100: */
101: private boolean isLink(String name) {
102: return isTocElement(name, ITocConstants.ELEMENT_LINK);
103: }
104:
105: /**
106: * @return
107: */
108: public Toc createToc() {
109: return new Toc(fModel);
110: }
111:
112: /**
113: * @param parent
114: * @return
115: */
116: public TocTopic createTocTopic() {
117: return new TocTopic(fModel);
118: }
119:
120: /**
121: * @param parent
122: * @return
123: */
124: public TocLink createTocLink() {
125: return new TocLink(fModel);
126: }
127:
128: /**
129: * @param parent
130: * @return
131: */
132: public TocTopic createTocTopic(IFile file) {
133: return new TocTopic(fModel, file);
134: }
135:
136: /**
137: * @param parent
138: * @return
139: */
140: public TocLink createTocLink(IFile file) {
141: return new TocLink(fModel, file);
142: }
143:
144: /**
145: * @return
146: */
147: public TocAnchor createTocAnchor() {
148: return new TocAnchor(fModel);
149: }
150: }
|