1 11 package org.eclipse.ui.internal.intro.impl.util; 12 13 import java.util.Enumeration ; 14 import java.util.Hashtable ; 15 16 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroContainer; 17 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroElement; 18 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage; 19 import org.eclipse.ui.internal.intro.impl.model.IntroAnchor; 20 import org.eclipse.ui.internal.intro.impl.model.IntroContentProvider; 21 import org.eclipse.ui.internal.intro.impl.model.IntroGroup; 22 import org.eclipse.ui.internal.intro.impl.model.IntroHTML; 23 import org.eclipse.ui.internal.intro.impl.model.IntroHead; 24 import org.eclipse.ui.internal.intro.impl.model.IntroHomePage; 25 import org.eclipse.ui.internal.intro.impl.model.IntroImage; 26 import org.eclipse.ui.internal.intro.impl.model.IntroInclude; 27 import org.eclipse.ui.internal.intro.impl.model.IntroLink; 28 import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot; 29 import org.eclipse.ui.internal.intro.impl.model.IntroPage; 30 import org.eclipse.ui.internal.intro.impl.model.IntroPageTitle; 31 import org.eclipse.ui.internal.intro.impl.model.IntroSeparator; 32 import org.eclipse.ui.internal.intro.impl.model.IntroText; 33 import org.osgi.framework.Bundle; 34 35 38 public class IntroModelSerializer { 39 40 private StringBuffer buffer; 41 private boolean filter; 42 43 public IntroModelSerializer(IntroModelRoot root) { 44 this(root, false); 45 } 46 47 public IntroModelSerializer(IntroModelRoot root, boolean filter) { 48 this.buffer = new StringBuffer (); 49 this.filter = filter; 50 printModelRootInfo(root, buffer); 51 52 IntroHomePage rootPage = root.getHomePage(); 54 printHomePage(rootPage, buffer); 55 printPageChildren(rootPage, buffer); 56 57 IntroPage[] pages = root.getPages(); 58 printPages(pages, buffer); 59 60 buffer.append("\n\n"); printModelFlagTests(root, buffer); 62 } 63 64 69 private String filterURL(String url) { 70 if (filter) { 71 if (url != null && url.startsWith("file:/")) { return "file:/" + "<filtered>" + url.substring(url.lastIndexOf('/')); } 74 } 75 return url; 76 } 77 78 private void printModelRootInfo(IntroModelRoot model, StringBuffer text) { 79 text.append("\nIntro Model Content:"); text.append("\n======================"); text.append("\n\nModel has valid config = " + model.hasValidConfig()); text.append("\nPresentation Kind = " + model.getPresentation().getImplementationKind()); 84 text.append("\nPresentation Shared Style = " + model.getPresentation().getImplementationStyles()); 86 text.append("\nPresentation type = " + model.getPresentation().getType()); 88 text.append("\nHome page id = " + model.getPresentation().getHomePageId()); 90 IntroHead headContent = model.getPresentation().getHead(); 91 if (headContent != null) 92 text.append("\nPresentation Shared Head = " + headContent.getSrc()); text.append("\nNumber of pages (not including Root Page) = " + model.getPages().length); 95 text.append("\nNumber of shared groups = " + model.getChildrenOfType(AbstractIntroElement.GROUP).length); 97 text 98 .append("\nNumber of unresolved extensions = " + model 100 .getChildrenOfType(AbstractIntroElement.CONTAINER_EXTENSION).length); 101 } 102 103 107 private void printHomePage(IntroHomePage rootPage, StringBuffer text) { 108 text.append("\n\nHOME PAGE: "); text.append("\n--------------"); text 111 .append("\n\tis dynamic= " + ((IntroModelRoot) rootPage.getParent()).isDynamic()); 113 text.append("\n\tid = " + rootPage.getId()); text.append("\n\ttitle = " + rootPage.getTitle()); text.append("\n\tstyle = " + filterURL(rootPage.getStyle())); text.append("\n\talt-style = " + filterURL(rootPage.getAltStyle())); text.append("\n\turl = " + rootPage.getUrl()); text.append("\n\tstyle-id = " + rootPage.getStyleId()); printPageStyles(rootPage, text); 120 } 121 122 private void printPageStyles(AbstractIntroPage page, StringBuffer text) { 123 text.append("\n\tpage styles are = "); String [] styles = page.getStyles(); 125 for (int i = 0; i < styles.length; i++) 126 text.append(filterURL(styles[i] + "\n\t\t\t")); text.append("\n\tpage alt-styles are = "); 129 Hashtable altStylesHashtable = page.getAltStyles(); 130 if (altStylesHashtable == null) 131 return; 132 133 Enumeration altStyles = altStylesHashtable.keys(); 134 while (altStyles.hasMoreElements()) { 135 String altStyle = (String ) altStyles.nextElement(); 136 137 Bundle bundle = (Bundle) altStylesHashtable.get(altStyle); 138 text.append(filterURL(altStyle) + " from " + bundle.getSymbolicName()); text.append("\n\t\t"); } 141 } 142 143 private void printPageChildren(AbstractIntroPage page, StringBuffer text) { 144 145 text.append("\n\tpage children = " + page.getChildren().length); text.append("\n"); printContainerChildren(page, text, "\n\t\t"); 149 } 150 151 private void printContainerChildren(AbstractIntroContainer container, 152 StringBuffer text, String indent) { 153 154 AbstractIntroElement[] children = container.getChildren(); 155 for (int i = 0; i < children.length; i++) { 156 int childType = children[i].getType(); 157 switch (childType) { 158 case AbstractIntroElement.ELEMENT: 159 text.append("SHOULD NEVER BE HERE"); break; 161 case AbstractIntroElement.GROUP: 162 printGroup(text, (IntroGroup) children[i], indent); 163 break; 164 case AbstractIntroElement.LINK: 165 printLink(text, (IntroLink) children[i], indent); 166 break; 167 case AbstractIntroElement.TEXT: 168 printText(text, (IntroText) children[i], indent); 169 break; 170 case AbstractIntroElement.IMAGE: 171 printImage(text, (IntroImage) children[i], indent); 172 break; 173 case AbstractIntroElement.HR: 174 printSeparator(text, (IntroSeparator) children[i], indent); 175 break; 176 case AbstractIntroElement.HTML: 177 printHtml(text, (IntroHTML) children[i], indent); 178 break; 179 case AbstractIntroElement.INCLUDE: 180 printInclude(text, (IntroInclude) children[i], indent); 181 break; 182 case AbstractIntroElement.HEAD: 183 printHead(text, (IntroHead) children[i], indent); 184 break; 185 case AbstractIntroElement.PAGE_TITLE: 186 printPageTitle(text, (IntroPageTitle) children[i], indent); 187 break; 188 case AbstractIntroElement.ANCHOR: 189 printAnchor(text, (IntroAnchor) children[i], indent); 190 break; 191 case AbstractIntroElement.CONTENT_PROVIDER: 192 printContentProvidor(text, (IntroContentProvider) children[i], 193 indent); 194 break; 195 196 } 197 } 198 } 199 200 private void printGroup(StringBuffer text, IntroGroup group, String indent) { 201 text.append(indent + "GROUP: id = " + group.getId()); indent = indent + "\t\t"; text.append(indent + "label = " + group.getLabel()); text.append(indent + "children = " + group.getChildren().length); text.append(indent + "style-id = " + group.getStyleId()); printContainerChildren(group, text, indent + "\t\t"); } 208 209 private void printLink(StringBuffer text, IntroLink link, String indent) { 210 text.append(indent + "LINK: id = " + link.getId()); indent = indent + "\t\t"; text.append(indent + "label = " + link.getLabel()); text.append(indent + "text = " + link.getText()); text.append(indent + "url = " + link.getUrl()); text.append(indent + "style-id = " + link.getStyleId()); } 217 218 private void printText(StringBuffer text, IntroText introText, String indent) { 219 text.append(indent + "TEXT: id = " + introText.getId()); indent = indent + "\t\t"; text.append(indent + "text = " + introText.getText()); text.append(indent + "style-id = " + introText.getStyleId()); } 224 225 private void printImage(StringBuffer text, IntroImage image, String indent) { 226 text.append(indent + "IMAGE: id = " + image.getId()); indent = indent + "\t\t"; text.append(indent + "src = " + image.getSrc()); text.append(indent + "alt = " + image.getAlt()); text.append(indent + "style-id = " + image.getStyleId()); } 232 233 private void printSeparator(StringBuffer text, IntroSeparator sep, String indent) { 234 text.append(indent + "HR: id = " + sep.getId()); indent = indent + "\t\t"; text.append(indent + "style-id = " + sep.getStyleId()); } 238 239 private void printHtml(StringBuffer text, IntroHTML html, String indent) { 240 text.append(indent + "HTML: id = " + html.getId()); indent = indent + "\t\t"; text.append(indent + "src = " + html.getSrc()); text.append(indent + "isInlined = " + html.isInlined()); text.append(indent + "style-id = " + html.getStyleId()); if (html.getIntroImage() != null) 246 printImage(text, html.getIntroImage(), indent + "\t\t"); if (html.getIntroText() != null) 248 printText(text, html.getIntroText(), indent + "\t\t"); 250 } 251 252 private void printInclude(StringBuffer text, IntroInclude include, 253 String indent) { 254 text.append(indent + "INCLUDE: configId = " + include.getConfigId()); indent = indent + "\t\t"; text.append(indent + "path = " + include.getPath()); text.append(indent + "merge-style = " + include.getMergeStyle()); } 259 260 private void printHead(StringBuffer text, IntroHead head, String indent) { 261 text.append(indent + "HEAD: src = " + head.getSrc()); } 263 264 private void printPageTitle(StringBuffer text, IntroPageTitle title, 265 String indent) { 266 text.append(indent + "TITLE: id = " + title.getId()); indent = indent + "\t\t"; text.append(indent + "title = " + title.getTitle()); text.append(indent + "style-id = " + title.getStyleId()); } 271 272 private void printAnchor(StringBuffer text, IntroAnchor anchor, 273 String indent) { 274 text.append(indent + "ANCHOR: id = " + anchor.getId()); } 276 277 private void printContentProvidor(StringBuffer text, 278 IntroContentProvider provider, String indent) { 279 text.append(indent + "CONTENT PROVIDER: id = " + provider.getId()); indent = indent + "\t\t"; text.append(indent + "class = " + provider.getClassName()); text.append(indent + "pluginId = " + provider.getPluginId()); if (provider.getIntroText() != null) 284 printText(text, provider.getIntroText(), indent + "\t\t"); 286 } 287 288 293 private void printPages(IntroPage[] pages, StringBuffer text) { 294 for (int i = 0; i < pages.length; i++) { 295 text.append("\n\nPAGE id = " + pages[i].getId()); text.append("\n----------"); text.append("\n\ttitle = " + pages[i].getTitle()); text.append("\n\tstyle = " + filterURL(pages[i].getStyle())); text.append("\n\talt-style = " + filterURL(pages[i].getAltStyle())); text.append("\n\tstyle-id = " + pages[i].getStyleId()); printPageStyles(pages[i], text); 302 printPageChildren(pages[i], text); 303 } 304 } 305 306 private void printModelFlagTests(IntroModelRoot model, StringBuffer text) { 307 text.append("Model Flag Tests: "); text.append("\n----------------"); if (model.getPages().length == 0) { 310 text.append("\nNo first page in model\n\n"); return; 312 } 313 IntroPage firstPage = model.getPages()[0]; 314 text.append("\n\t\tFirst page children are: "); text 316 .append("\n\t\t\tGroups: " + firstPage.getChildrenOfType(AbstractIntroElement.GROUP).length); 318 text 319 .append("\n\t\t\tLinks: " + firstPage.getChildrenOfType(AbstractIntroElement.LINK).length); 321 text 322 .append("\n\t\t\tTexts: " + firstPage.getChildrenOfType(AbstractIntroElement.TEXT).length); 324 text 325 .append("\n\t\t\tHTMLs: " + firstPage.getChildrenOfType(AbstractIntroElement.HTML).length); 327 text 328 .append("\n\t\t\tImages: " + firstPage.getChildrenOfType(AbstractIntroElement.IMAGE).length); 330 text 331 .append("\n\t\t\tIncludes: " + firstPage.getChildrenOfType(AbstractIntroElement.INCLUDE).length); 333 text 334 .append("\n\t\t\tPage Titles: " + firstPage 336 .getChildrenOfType(AbstractIntroElement.PAGE_TITLE).length); 337 text 338 .append("\n\t\t\tPage Heads: " + firstPage.getChildrenOfType(AbstractIntroElement.HEAD).length); 340 text 341 .append("\n\t\t\tModel Elements: " + firstPage.getChildrenOfType(AbstractIntroElement.ELEMENT).length); 343 text 344 .append("\n\t\t\tContainers: " + firstPage 346 .getChildrenOfType(AbstractIntroElement.ABSTRACT_CONTAINER).length); 347 text 348 .append("\n\t\t\tAll Pages: " + firstPage 350 .getChildrenOfType(AbstractIntroElement.ABSTRACT_PAGE).length); 351 text 352 .append("\n\t\t\tAnchors: " + firstPage.getChildrenOfType(AbstractIntroElement.ANCHOR).length); 354 text 355 .append("\n\t\t\tContent providers: " + firstPage 357 .getChildrenOfType(AbstractIntroElement.CONTENT_PROVIDER).length); 358 text 359 .append("\n\t\t\tElements with Text child(AbstractTextElemets): " + firstPage 361 .getChildrenOfType(AbstractIntroElement.ABSTRACT_TEXT).length); 362 363 AbstractIntroElement[] linksAndGroups = (AbstractIntroElement[]) firstPage 364 .getChildrenOfType(AbstractIntroElement.GROUP 365 | AbstractIntroElement.LINK); 366 text.append("\n\t\t\tGroups and Links: " + linksAndGroups.length); } 368 369 372 public String toString() { 373 return buffer.toString(); 374 } 375 } 376 | Popular Tags |