Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2004, 2009 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
  
  package org.eclipse.ui.internal.intro.impl.html;
  
  import java.net.URL;
  
  
  public class IntroHTMLGenerator {
  
  
Generates the HTML code that will be presented in the browser widget for the provided intro page.

Parameters:
page the page to generate HTML for
presentation the presentation associated with this page.
  
  		if (page == null)
  			return null;
  		this. = page;
  		this. = providerSite;
  
  		// generate and add the appropriate encoding to the top of the document
  		// generateEncoding();
  		// create the main HTML element, and all of its contents.
  		return generateHTMLElement();
  	}
  
  	/*
  	 * private HTMLElement generateEncoding() { HTMLElement encoding = new HTMLElement("");
  	 * //$NON-NLS-1$ // TODO: figure out how to handle locale based encoding // As far as the HTML
  	 * generator is concerned, this is probably as // simple as asking the model for the information
  	 * return encoding; }
  	 */

Generates the HTML element and its content:
   
                        <HTML>
                        <HEAD>
                        head content
                        </HEAD>
                        <BODY>
                        body content
                        </BODY>
                        </HTML>
    
 

Returns:
the html HTMLElement
  
  		// this is the outermost element, so it has no indent
 		int indentLevel = 0;
 		HTMLElement html = new FormattedHTMLElement(.indentLeveltrue);
 		HTMLElement head = generateHeadElement(indentLevel + 1);
 		HTMLElement body = generateBodyElement(indentLevel + 1, head);
 		html.addContent(head);
 		html.addContent(body);
 		return html;
 	}

Generates the HEAD element and its content:
   
                
                        <HEAD>
                        <BASE href="base_plugin_location>
                        <style type="text/css">HTML, IMG { border: 0px; } </style>
                        <TITLE>page title </TITLE>
                        <LINK href="style sheet">
                        additional head content, if specified
                        </HEAD>
    
 

Parameters:
indentLevel the number of indents to insert before the element when it is printed
Returns:
the head HTMLElement
 
 	private HTMLElement generateHeadElement(int indentLevel) {
 		HTMLElement head = new FormattedHTMLElement(.indentLeveltrue);
 		// add the title
 		head.addContent(generateTitleElement(.getTitle(), indentLevel + 1));
 		// create the BASE element
 		HTMLElement base = generateBaseElement(indentLevel + 1, basePath);
 		if (base != null)
 			head.addContent(base);
 		// create the HTML style block
 		head.addContent(generateStyleElement(indentLevel + 1));
 		// add the presentation style
 		String[] presentationStyles = IntroPlugin.getDefault().getIntroModelRoot().getPresentation()
 		if (presentationStyles != null && .injectSharedStyle()) {
 			for (int i=0; i<presentationStyles.lengthi++)
 				head.addContent(generateLinkElement(presentationStyles[i], indentLevel + 1));
 		}
 		String pageStyle = .getStyle();
 		if (pageStyle != null)
 			head.addContent(generateLinkElement(pageStyleindentLevel + 1));
 		// add javascript
 		head.addContent(generateJavascriptElement(indentLevel + 1));
 
 		// add the page's inherited style(s)
 		String[] pageStyles = .getStyles();
 		for (int i = 0; i < pageStyles.lengthi++) {
 			pageStyle = pageStyles[i];
 			if (pageStyle != null)
 				head.addContent(generateLinkElement(pageStyleindentLevel + 1));
 		}
 		// if there is additional head conent specified in an external file,
 		// include it. Additional head content can be specified at the
 		// implementation level (which would apply to ALL pages) and at the
 		// page level (which would apply only to that particular page).
 		// For the implementation's head contribution:
 		StringBuffer content = null;
 		IntroHead introHead = IntroPlugin.getDefault().getIntroModelRoot().getPresentation().getHead();
 		if (introHead != null) {
 			content = readFromFile(introHead.getSrc(), introHead.getInlineEncoding());
 			if (content != null)
 				head.addContent(content);
 		}
 		// For the page's head contribution:
 		// TODO: there should only be one of these at the page level, not a
 		// collection..
 		IntroHead[] htmlHeads = .getHTMLHeads();
 		for (int i = 0; i < htmlHeads.lengthi++) {
 			introHead = htmlHeads[i];
 			if (introHead != null) {
 				content = readFromFile(introHead.getSrc(), introHead.getInlineEncoding());
 				if (content != null)
 					head.addContent(content);
 			}
 		}
 		return head;
 	}
 
 	private HTMLElement generateJavascriptElement(int indentLevel) {
 		String rel = "javascript/common.js"//$NON-NLS-1$
 		String abs = BundleUtil.getResolvedResourceLocation(rel, IntroPlugin.getDefault().getBundle());
 		HTMLElement jselement = new FormattedHTMLElement("script"indentLevelfalse); //$NON-NLS-1$
 		jselement.addAttribute("type""text/javascript"); //$NON-NLS-1$ //$NON-NLS-2$
 		jselement.addAttribute("src"abs); //$NON-NLS-1$
 		return jselement;
 	}

Generates the BODY element and its content:
   
               
                        <BODY>
                        <DIV id="pageId" class="pageClass">
                        page content
                        </DIV>
                        </BODY>
    
 

Parameters:
indentLevel the number of indents to insert before the element when it is printed
Returns:
the body HTMLElement
 
 	private HTMLElement generateBodyElement(int indentLevelHTMLElement head) {
 		HTMLElement body = new FormattedHTMLElement(.indentLeveltrue);
 		// Create the div that contains the page content
 		String pageId = (.getId() != null) ? .getId() : .;
 		HTMLElement pageContentDiv = generateDivElement(pageIdindentLevel + 1);
 		if (.getStyleId() != null)
 		if (.getBackgroundImage() != null)
 					"background-image : url(" + .getBackgroundImage() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
 
 		// Add any children of the page, in the order they are defined
 		for (int i = 0; i < children.lengthi++) {
 			AbstractIntroElement child = children[i];
 			// use indentLevel + 2 here, since this element is contained within
 			// the pageContentDiv
 			HTMLElement childElement = generateIntroElement(childindentLevel + 2);
 			if (childElement != null) {
 				addMixinStyle(childElementchild.getMixinStyle());
 				pageContentDiv.addContent(childElement);
 			}
 		}
 		body.addContent(pageContentDiv);
 		return body;
 	}

Given an IntroElement, generate the appropriate HTMLElement

Parameters:
element the IntroElement
indentLevel the number of indents to insert before the element when it is printed
Returns:
an HTMLElement
 
 	private HTMLElement generateIntroElement(AbstractIntroElement elementint indentLevel) {
 		if (element == null)
 			return null;
 		// check to see if this element should be filtered from the HTML
 		// presentation
 		if (filteredFromPresentation(element))
 			return null;
 		switch (element.getType()) {
 			return generateIntroDiv((IntroGroupelementindentLevel);
 			return generateIntroLink((IntroLinkelementindentLevel);
 			return generateIntroHTML((IntroHTMLelementindentLevel);
 			return generateIntroContent((IntroContentProviderelementindentLevel);
 			return generateIntroImage((IntroImageelementindentLevel);
 			return generateIntroSeparator((IntroSeparatorelementindentLevel);			
 			return generateIntroText((IntroTextelementindentLevel);
 			return generateIntroTitle((IntroPageTitleelementindentLevel);
 			return generateIntroInjectedIFrame((IntroInjectedIFrameelementindentLevel);
 		default:
 			return null;
 		}
 	}

Create a div element and its content from an IntroDiv:
   
                    
                        <div id="attrvalue">
                        <h4><span class="div-label">attrvalue</span><h4>
                        any defined divs, links, html, images, text, includes
                        </div>
    
 

Parameters:
element the IntroDiv
indentLevel the number of indents to insert before the element when it is printed
Returns:
a div HTMLElement
 
 	private HTMLElement generateIntroDiv(IntroGroup elementint indentLevel) {
 		// Create the outer div element
 		HTMLElement divElement = generateDivElement(element.getId(), indentLevel);
 		HTMLElement childContainer = divElement;
 		// if a div class was specified, add it
 		if (element.getStyleId() != null)
 		// Create the div label, if specified
 		if (element.getLabel() != null) {
 			if (element.isExpandable()) {
 						indentLevel + 2, false);
 				divLabel.addContent(element.getLabel());
 												"section-title");//$NON-NLS-1$
 				String clientId = element.getId() + "-content"//$NON-NLS-1$
 				String toggleClosedId = element.getId() + "-toggle-closed"//$NON-NLS-1$
 				String toggleOpenId = element.getId() + "-toggle-open"//$NON-NLS-1$
 				String href = "#"//$NON-NLS-1$
 						indentLevel + 1, true);
 				link.addAttribute(."section-title-link"); //$NON-NLS-1$
 				StringBuffer call = new StringBuffer();
 				call.append("return (toggleSection('");//$NON-NLS-1$
 				call.append(clientId);
 				call.append("','");//$NON-NLS-1$ 
 				call.append(toggleClosedId);
 				call.append("','");//$NON-NLS-1$ 
 				call.append(toggleOpenId);
 				call.append("'))"); //$NON-NLS-1$ 
 				link.addAttribute("onClick"call.toString()); //$NON-NLS-1$
 				link.addContent(divLabel);
 				divElement.addContent(link);
 				// Add toggle images
 						indentLevel + 2, falsefalse);
 				toggleImageClosed.addAttribute(.toggleClosedId);
 				toggleImageClosed.addAttribute(., BundleUtil
 				toggleImageClosed.addAttribute(."section-toggle-image-closed"); //$NON-NLS-1$
 				if (element.isExpanded())
 					toggleImageClosed.addAttribute(."display: none"); //$NON-NLS-1$
 				link.addContent(toggleImageClosed);
 						indentLevel + 2, falsefalse);
 				toggleImageOpen.addAttribute(.toggleOpenId);
 				toggleImageOpen.addAttribute(., BundleUtil
 				toggleImageOpen.addAttribute(."section-toggle-image-open"); //$NON-NLS-1$
 				if (element.isExpanded())
 					toggleImageOpen.addAttribute(."display: inline"); //$NON-NLS-1$				
 				link.addContent(toggleImageOpen);
 				childContainer = generateDivElement(clientIdindentLevel + 1);
 				childContainer.addAttribute("class""section-body"); //$NON-NLS-1$//$NON-NLS-2$
 				if (element.isExpanded())
 					childContainer.addAttribute(."display: block"); //$NON-NLS-1$
 				divElement.addContent(childContainer);
 			} else {
 						.element.getLabel(), indentLevel + 1);
 				divElement.addContent(divLabel);
 			}
 		}
 		if (element.getBackgroundImage() != null) {
 			String imageUrl = element.getBackgroundImage();
 			imageUrl = BundleUtil.getResolvedResourceLocation(element.getBase(), imageUrlelement
 					.getBundle());
 			String style;
 			if (Platform.getWS().equals(.) && imageUrl.toLowerCase().endsWith(".png")) { //$NON-NLS-1$
 				// IE 5.5+ does not handle alphas in PNGs without
 				// this hack. Remove when IE7 becomes widespread
 				style = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imageUrl + "', sizingMethod='crop');"//$NON-NLS-1$ //$NON-NLS-2$
 			} else {
 				style = "background-image : url(" + imageUrl + ")"//$NON-NLS-1$ //$NON-NLS-2$
 			}
 		}
 		// Add any children of the div, in the order they are defined
 		AbstractIntroElement[] children = element.getChildren();
 		for (int i = 0; i < children.lengthi++) {
 			AbstractIntroElement child = children[i];
 			HTMLElement childElement = generateIntroElement(childindentLevel + 1);
 			if (childElement != null) {
 				addMixinStyle(childElementchild.getMixinStyle());
 				childContainer.addContent(childElement);
 			}
 		}
 		return divElement;
 	}
 
 	private void addMixinStyle(HTMLElement elementString mixinStyle) {
 		if (mixinStyle == null)
 			return;
 		String key = "class"//$NON-NLS-1$
 		String original = (Stringelement.getElementAttributes().get(key);
 		if (original == null)
 			original = mixinStyle;
 		else
 			original += " " + mixinStyle//$NON-NLS-1$
 		element.addAttribute(keyoriginal);
 	}

Generates an anchor (link) element and its content from an IntroLink:
   
                        <A id=linkId class="link" href=linkHref>
                        <IMG src="blank.gif">
                        <SPAN class="link-label">linkLabel </SPAN>
                        <P><SPAN>text</SPAN></P>
                        </A>
    
 

Parameters:
element the IntroLink
indentLevel the number of indents to insert before the element when it is printed
Returns:
an anchor (<A>) HTMLElement
 
 	private HTMLElement generateIntroLink(IntroLink elementint indentLevel) {
 		String styleId = element.getStyleId();
 		boolean useTable = ProductPreferences.isRTL() && "content-link".equals(styleId); //$NON-NLS-1$
 		HTMLElement anchor1 = generateAnchorElement(elementindentLevel);
 		HTMLElement anchor2 = null;
 		HTMLElement labelAnchor = anchor1;
 		int indentBase = indentLevel;
 		if (useTable) {
 			indentBase = indentLevel + 1;
 		    anchor2 = generateAnchorElement(elementindentLevel + 1);
 		    labelAnchor = anchor2;
 		}
 		// add <IMG src="blank.gif">
 		if (blankImageURL != null) {
 			anchor1.addContent(generateImageElement(blankImageURLnullnull.,
 					indentBase + 1));
 		}
 		// add link image, if one is specified
 		if (element.getImg() != null) {
 			HTMLElement img = generateIntroElement(element.getImg(), indentBase + 1);
 			if (img != null)
 				anchor1.addContent(img);
 		}
 		if (!useTable) {
 			HTMLElement imageDiv = new FormattedHTMLElement(.indentBase+1, false);
 			anchor1.addContent(imageDiv);
 		}
 		// add <SPAN class="link-label">linkLabel</SPAN>
 		if (element.getLabel() != null) {
 					indentBase + 2);
 			label.addContent(element.getLabel());			
 			labelAnchor.addContent(label);
 		}
 		IntroText linkText = element.getIntroText();
 		if (linkText != null && linkText.getText() != null) {
 			HTMLElement text = generateIntroElement(linkTextindentBase + 3);
 			if (text != null)
 				labelAnchor.addContent(text);
 		}
 		if (!useTable) {
 			return anchor1;
 		}
 		HTMLElement table = new FormattedHTMLElement(.indentLevelfalse);
 		HTMLElement tr = new FormattedHTMLElement(.indentLevel + 1, false);
 		table.addContent(tr);
 		HTMLElement td1 = new FormattedHTMLElement(.indentLevel + 1, false);
 		HTMLElement td2 = new FormattedHTMLElement(.indentLevel + 1, false);
 		tr.addContent(td1);
 		tr.addContent(td2);
 		td1.addContent(anchor1);
 		td2.addContent(anchor2);
 		return table;
 	}

Generate the appropriate HTML from an IntroHTML. If the IntroHTML type is "inline", then the content from the referenced file is emitted as-is into a div element. If the type is "embed", an OBJECT html element is created whose data attribute is equal to the IntroHTML's src value

Parameters:
element the IntroHTML
indentLevel the number of indents to insert before the element when it is printed
Returns:
an HTMLElement
 
 	private HTMLElement generateIntroHTML(IntroHTML elementint indentLevel) {
 		if (element.isInlined())
 			return generateInlineIntroHTML(elementindentLevel);
 
 		return generateEmbeddedIntroHTML(elementindentLevel);
 	}

Generate an image element from an IntroImage:
   
                        <IMG src=imageSrc id=imageId>
    
 

Parameters:
element the IntroImage
indentLevel the number of indents to insert before the element when it is printed
Returns:
an img HTMLElement
 
 	private HTMLElement generateIntroImage(IntroImage elementint indentLevel) {
 		HTMLElement imageElement = generateImageElement(element.getSrc(), element.getAlt(),element.getTitle(), element
 				.getStyleId(), indentLevel);
 		if (element.getId() != null)
 		return imageElement;
 	}
 	
 	private HTMLElement generateIntroSeparator(IntroSeparator elementint indentLevel) {
 		HTMLElement hrElement = new FormattedHTMLElement(.indentLevelfalse);
 		if (element.getId() != null)
 		if (element.getStyleId() != null)
 		return hrElement;
 	}

Generate a paragraph (<P>) element from an IntroText. The paragraph element will contain a span element that will contain the actual text. Providing the span element provides additional flexibility for CSS designers.
              
               
                        <P><SPAN>spanContent</SPAN></P>
                 
 

Parameters:
element the IntroText
indentLevel the number of indents to insert before the element when it is printed
Returns:
a paragraph HTMLElement
 
 	private HTMLElement generateIntroText(IntroText elementint indentLevel) {
 		String spanClass = (element.getStyleId() != null) ? element.getStyleId()
 				spanClasselement.getText(), indentLevel);
 		return textElement;
 	}

Parameters:
element
indentLevel
Returns:
 
 	private HTMLElement generateIntroInjectedIFrame(IntroInjectedIFrame elementint indentLevel) {
 		HTMLElement iframe = generateIFrameElement(element.getIFrameURL(), "0"//$NON-NLS-1$
 				"auto"indentLevel); //$NON-NLS-1$
 		return iframe;
 	}

Parameters:
element
indentLevel
Returns:
 
 	private HTMLElement generateIntroTitle(IntroPageTitle elementint indentLevel) {
 		HTMLElement titleElement = generateHeaderDiv(element.getId(), element.getStyleId(),
 				.element.getTitle(), indentLevel);
 		return titleElement;
 	}

Generate "inline" content from an IntroHTML. The content from the file referenced by the IntroHTML's src attribute is emitted as-is into a div element:
               
                    
                        <div id="attrvalue" class="attrvalue2">
                        content from file specified in src attribute
                        </div>
                
 

Parameters:
element the IntroHTML
indentLevel the number of indents to insert before the element when it is printed
Returns:
a div HTMLElement, or null if there was a problem reading from the file
 
 	private HTMLElement generateInlineIntroHTML(IntroHTML elementint indentLevel) {
 		// make sure to ask model for encoding. If encoding is null (ie: not
 		// specified in
 		// markup, local encoding is used.
 		StringBuffer content = readFromFile(element.getSrc(), element.getInlineEncoding());
 		if (content != null && content.length() > 0) {
 			// Create the outer div element
 			String divClass = (element.getStyleId() != null) ? element.getStyleId()
 			HTMLElement divElement = generateDivElement(element.getId(), divClassindentLevel);
 			// add the content of the specified file into the div element
 			divElement.addContent(content);
 			return divElement;
 		}
 		return null;
 	}

Includes HTML content that is created by an IIntroContentProvider implementation.

Parameters:
element
indentLevel
Returns:
 
 	private HTMLElement generateIntroContent(IntroContentProvider elementint indentLevel) {
 		// create a new div to wrap the content
 		HTMLElement divElement = generateDivElement(element.getId(),
 
 		// If we've already loaded the content provider for this element,
 		// retrieve it, otherwise load the class
 		IIntroContentProvider providerClass = ContentProviderManager.getInst().getContentProvider(element);
 		if (providerClass == null)
 			// content provider never created before, create it.
 			providerClass = ContentProviderManager.getInst().createContentProvider(element);
 
 		if (providerClass != null) {
 			StringWriter stringWriter = new StringWriter();
 			PrintWriter pw = new PrintWriter(stringWriter);
 			// create the specialized content
 			providerClass.createContent(element.getId(), pw);
 			// add the content of the specified file into the div element
 			stringWriter.flush();
 			divElement.addContent(stringWriter.toString());
 			pw.close();
 		} else {
 			// we couldn't load the content provider, so add any alternate
 			// text content if there is any
 			IntroText htmlText = element.getIntroText();
 			if (htmlText != null && htmlText.getText() != null) {
 				String textClass = (htmlText.getStyleId() != null) ? htmlText.getStyleId()
 						.getId(), textClasselement.getText(), indentLevel);
 				if (text != null)
 					divElement.addContent(text);
 			}
 		}
 		return divElement;
 	}

Generate "embedded" content from an IntroHTML. An OBJECT html element is created whose data attribute is equal to the IntroHTML's src value.
                
                        <OBJECT type="text/html" data="attrvalue">
                        alternative text in case the object can not be rendered
                        </OBJECT> 
     
 

Parameters:
element the IntroHTML
indentLevel the number of indents to insert before the element when it is printed
Returns:
an object HTMLElement
 
 	private HTMLElement generateEmbeddedIntroHTML(IntroHTML elementint indentLevel) {
 		HTMLElement objectElement = new FormattedHTMLElement(.indentLevel,
 				true);
 		if (element.getId() != null)
 			objectElement.addAttribute(.element.getId());
 		if (element.getSrc() != null)
 		if (element.getStyleId() != null)
 		// The alternative content is added in case the browser can not render
 		// the specified content.
 		IntroText htmlText = element.getIntroText();
 		if (htmlText != null && htmlText.getText() != null) {
 			String textClass = (htmlText.getStyleId() != null) ? htmlText.getStyleId()
 					textClasselement.getText(), indentLevel);
 			if (text != null)
 				objectElement.addContent(text);
 		}
 		if (element.getIntroImage() != null) {
 			HTMLElement img = generateIntroImage(element.getIntroImage(), indentLevel);
 			if (img != null)
 				objectElement.addContent(img);
 		}
 		return objectElement;
 	}

Generates the BASE element for the head of the html document. Each document can have only one base element
   
                
                       <BASE href=baseURL>
 

Parameters:
indentLevel
baseURL
Returns:
 
 	private HTMLElement generateBaseElement(int indentLevelString baseURL) {
 				false);
 		if (baseURL != null)
 		return base;
 	}

Generates the style element that goes into HEAD:
                
                        <style type="text/css">HTML, IMG { border: 0px; } </style>
                   
 

Parameters:
indentLevel the number of indents to insert before the element when it is printed
Returns:
the style HTMLElement
 
 	private HTMLElement generateStyleElement(int indentLevel) {
 		HTMLElement style = new FormattedHTMLElement(.indentLevelfalse);
 		if (theme != null && theme.isScalable() 
 		    String sizeStyle = FontSelection.generatePageFontStyle(); 
             style.addContent(sizeStyle);
 		}
 		return style;
 	}

Generates the title element and its content:
   
                        <TITLE>intro title</TITLE>
                     
 

Parameters:
title the title of this intro page
indentLevel the number of indents to insert before the element when it is printed
Returns:
the title HTMLElement
 
 	private HTMLElement generateTitleElement(String titleint indentLevel) {
 		HTMLElement titleElement = new FormattedHTMLElement(.indentLevel,
 				false);
 		if (title != null)
 			titleElement.addContent(title);
 		return titleElement;
 	}

Generates a link element that refers to a cascading style sheet (CSS):
                
                    
                        <LINK rel="stylesheet" style="text/css" href="style sheet">
 

Parameters:
href the value of the href attribute for this link element
indentLevel the number of indents to insert before the element when it is printed
Returns:
a link HTMLElement
 
 	private HTMLElement generateLinkElement(String hrefint indentLevel) {
 				false);
 		if (href != null)
 		return link;
 	}

Generate an anchor element:
   
                        <A id=linkId class=linkClass href=linkHref> </A>
                     
 

Parameters:
link the IntroLink element that contains the value for the id and href attributes
indentLevel the number of indents to insert before the element when it is printed
Returns:
an anchor (<A>) HTMLElement
 
 	private HTMLElement generateAnchorElement(IntroLink linkint indentLevel) {
 		HTMLElement anchor = new FormattedHTMLElement(.indentLeveltrue);
 		if (link.getId() != null)
 		if (link.getUrl() != null)
 		if (link.getStyleId() != null)
 		else
 		return anchor;
 	}

Generates a div block that contains a header and span element:
   
                      
                        <DIV id=divId>
                        <H><SPAN>spanContent </SPAN> </H>
                        </DIV>
                     
 

Parameters:
divId the id of the div to create
divClass the class of the div
headerType what type of header to create (e.g., H1, H2, etc)
spanContent the span content
indentLevel the number of indents to insert before the element when it is printed
Returns:
a div HTMLElement that contains a header
 
 	private HTMLElement generateHeaderDiv(String divIdString divClassString headerType,
 			String spanContentint indentLevel) {
 		// create the text element: <P><SPAN>spanContent</SPAN></P>
 		HTMLElement text = generateTextElement(headerTypenullnullspanContentindentLevel + 1);
 		// create the containing div element
 		HTMLElement div = generateDivElement(divIddivClassindentLevel);
 		div.addContent(text);
 		return div;
 	}

Generates a span element inside a text element, where the text element can be a P (paragraph), or any of the H (Header) elements. Providing the span element provides additional flexibility for CSS designers.
                
                        <P><SPAN>spanContent</SPAN></P>
                    
 

Parameters:
type the type of text element to create (e.g., P, H1, H2, etc)
spanID the id of the span element, or null
spanClass the class of the span element, or null
spanContent the span content
indentLevel the number of indents to insert before the element when it is printed
Returns:
a text HTMLElement that contains a span element
 
 	private HTMLElement generateTextElement(String typeString spanIDString spanClassString spanContent,
 			int indentLevel) {
 		// Create the span: <SPAN>spanContent</SPAN>
 		if (spanID != null)
 		if (spanClass != null)
 		if (spanContent != null)
 			span.addContent(spanContent);
 		if (type != null) {
 		// Create the enclosing text element: <P><SPAN>spanContent</SPAN></P>
 		HTMLElement text = new FormattedHTMLElement(typeindentLevelfalse);
 		text.addContent(span);
 		return text;
 		} else {
 			return span;
 		}
 	}

Generates a DIV element with the provided indent, id, and class.

Parameters:
divId value for the div's id attribute
divClass value for the div's class attribute
indentLevel the number of indents to insert before the element when it is printed
Returns:
a div HTMLElement
 
 	private HTMLElement generateDivElement(String divIdString divClassint indentLevel) {
 		HTMLElement div = generateDivElement(divIdindentLevel);
 		return div;
 	}

Generates a DIV element with the provided indent and id.

Parameters:
divId value for the div's id attribute
indentLevel the number of indents to insert before the element when it is printed
Returns:
a div HTMLElement
 
 	private HTMLElement generateDivElement(String divIdint indentLevel) {
 		HTMLElement div = new FormattedHTMLElement(.indentLeveltrue);
 		if (divId != null)
 		return div;
 	}

Generates an IMG element:
   
                      
                        <IMG src=imageSrc alt=altText>
                     
 

Parameters:
imageSrc the value to be supplied to the src attribute
indentLevel the number of indents to insert before the element when it is printed
Returns:
an img HTMLElement
 
 	private HTMLElement generateImageElement(String imageSrcString altTextString titleString imageClass,
 			int indentLevel) {
 		HTMLElement image = new FormattedHTMLElement(.indentLeveltrue,
 				false);
 		boolean pngOnWin32 = imageSrc != null && Platform.getWS().equals(.)
 				&& imageSrc.toLowerCase().endsWith(".png"); //$NON-NLS-1$
 		if (imageSrc == null || pngOnWin32) {
 			// we must handle PNGs here - IE does not support alpha blanding well.
 			// We will set the alpha image loader and load the real image
 			// that way. The 'src' attribute in the image itself will
 			// get the blank image.
 			String blankImageURL = BundleUtil.getResolvedResourceLocation(
 			if (blankImageURL != null) {
 				if (pngOnWin32) {
 					String style = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imageSrc + "', sizingMethod='image')"//$NON-NLS-1$//$NON-NLS-2$
 				}
 			}
 		} else
 		if (altText == null)
 			altText = ""//$NON-NLS-1$
 		if (title != null) {
 		}
 		if (imageClass != null)
 		return image;
 	}

Generate a span element
   
                        <SPAN class=spanClass> </SPAN>
      
    
 

Parameters:
spanClass the value to be supplied to the class attribute
indentLevel the number of indents to insert before the element when it is printed
Returns:
a span HTMLElement
	private HTMLElement generateSpanElement(String spanClassint indentLevel) {
		return span;
	}

Generate a span element
   
                     <iframe src="localPage1.xhtml" frameborder="1" scrolling="auto" longdesc="localPage1.xhtml">
 

Parameters:
spanClass the value to be supplied to the class attribute
indentLevel the number of indents to insert before the element when it is printed
Returns:
a span HTMLElement
	private HTMLElement generateIFrameElement(String srcString frameborderString scrolling,
			int indentLevel) {
		if (src != null)
		if (frameborder != null)
		if (scrolling != null)
		return iframe;
	private boolean filteredFromPresentation(AbstractIntroElement element) {
			return ((AbstractBaseIntroElementelement).isFiltered();
		return false;
	}

Reads the content of the file referred to by the src parameter and returns the content in the form of a StringBuffer. If the file read contains substitution segments of the form $plugin:plugin_id$ then this method will make the proper substitution (the segment will be replaced with the absolute path to the plugin with id plugin_id).

Parameters:
src - the file that contains the target conent
charsetName - the encoding of the file to be read. If null, local encoding is used. But the default of the model is UTF-8, so we should not get a null encoding.
Returns:
a StringBuffer containing the content in the file, or null
	private StringBuffer readFromFile(String srcString charsetName) {
		if (src == null)
			return null;
		InputStream stream = null;
		StringBuffer content = new StringBuffer();
		BufferedReader reader = null;
		try {
			URL url = new URL(src);
			stream = url.openStream();
			// TODO: Do we need to worry about the encoding here? e.g.:
			// reader = new BufferedReader(new InputStreamReader(stream,
			// ResourcesPlugin.getEncoding()));
			if (charsetName == null)
				reader = new BufferedReader(new InputStreamReader(stream));
			else
				reader = new BufferedReader(new InputStreamReader(streamcharsetName));
			while (true) {
				int character = reader.read();
				if (character == -1) // EOF
					break// done reading file
				else if (character == .) { // possible
					// substitution
					PluginIdParser parser = new PluginIdParser(characterreader);
					// If a valid plugin id was found in the proper format, text
					// will be the absolute path to that plugin. Otherwise, text
					// will simply be all characters read up to (but not
					// including)
					// the next dollar sign that follows the one just found.
					String text = parser.parsePluginId();
					if (text != null)
						content.append(text);
else {
					// make sure character is in char range before making cast
					if (character > 0x00 && character < 0xffff)
						content.append((charcharacter);
					else
						content.append(character);
catch (Exception exception) {
			Log.error("Error reading from file"exception); //$NON-NLS-1$
finally {
			try {
				if (reader != null)
					reader.close();
				if (stream != null)
					stream.close();
catch (IOException e) {
				Log.error("Error closing input stream"e); //$NON-NLS-1$
				return null;
		return content;
	}

A helper class to help identify substitution strings in a content file. A properly formatted substitution string is of the form: $plugin:plugin_id$ where plugin_id is the valid id of an installed plugin. The substitution string will be replaced with the absolute path to the plugin. An example usage of the string substution: The html file inline.html is included in your intro via the html inline mechanism . This file needs to reference a resource that is located in another plugin. The following might be found in inline.html: link to file When this file is read in, the relevant section will be replaced as follows: link to file
	private static class PluginIdParser {
		private static final char SUBSTITUTION_BEGIN = '$';
		private static final char SUBSTITUTION_END = '$';
		// tokenContent will contain all characters read by the parser, starting
		// with and including the initial $ token.
		// pluginId will contain the content between the "$plugin:" segment
		// and the closing "$" token
		protected PluginIdParser(int tokenBeginBufferedReader bufferedreader) {
			 = bufferedreader;
			// make sure tokenBegin is in char range before making cast
			if (tokenBegin > 0x00 && tokenBegin < 0xffff)
				.append((chartokenBegin);
		}

This method should be called after the initial substitution identifier has been read in (the substition string begins and ends with the "$" character). A properly formatted substitution string is of the form: "$plugin:plugin_id$- the initial "$" is immediately followed by the "plugin:" segment - the plugin_id refers to a valid, installed plugin - the substitution string is terminated by a closing "$" If the above conditions are not met, no substitution occurs. If the above conditions are met, the content between (and including) the opening and closing "$" characters will be replaced by the absolute path to the plugin

Returns:
		protected String parsePluginId() {
			if ( == null ||  == null ||  == null)
				return null;
			try {
				// Mark the current position of the reader so we can roll
				// back to this point if the proper "plugin:" segment is not
				// found.
				// Use 1024 as our readAheadLimit
				.mark(0x400);
					String pluginPath = getPluginPath();
					if (pluginPath == null) {
						// Didn't find a valid plugin id.
						// return tokenContent, which contains all characters
						// read up to (not including) the last $. (if the
						// last $ is part of a subsequent "$plugin:" segment
						// it can still be processed properly)
					return pluginPath;
				// The "plugin:" segment was not found. Reset the reader
				// so we can continue reading character by character.
catch (IOException exception) {
				Log.error("Error reading from file"exception); //$NON-NLS-1$
		}

This method should be called after an initial substitution character has been found (that is, after a $). It looks at the subsequent characters in the input stream to determine if they match the expected plugin: segment of the substitution string. If the expected characters are found, they will be appended to the tokenContent StringBuffer and the method will return true. If they are not found, false is returned and the caller should reset the BufferedReader to the position it was in before this method was called. Resetting the reader ensures that the characters read in this method can be re-examined in case one of them happens to be the beginning of a valid substitution segment.

Returns:
true if the next characters match plugin:, and false otherwise.
		private boolean findValidPluginSegment() {
			final char[] PLUGIN_SEGMENT = { 'p''l''u''g''i''n'':' };
			char[] streamContent = new char[PLUGIN_SEGMENT.length];
			try {
				int peek = .read(streamContent, 0, PLUGIN_SEGMENT.length);
				if ((peek == PLUGIN_SEGMENT.length)
						&& (HTMLUtil.equalCharArrayContent(streamContentPLUGIN_SEGMENT))) {
					// we have found the "$plugin:" segment
					.append(streamContent);
					return true;
				// The "plugin:" segment did not immediately follow the initial
				// $.
				return false;
catch (IOException exception) {
				Log.error("Error reading from file"exception); //$NON-NLS-1$
				return false;
		}

This method continues to read from the input stream until either the end of the file is reached, or until a character is found that indicates the end of the substitution. If the SUBSTITUTION_END character is found, the method looks up the plugin id that has been built up to see if it is a valid id. If so, return the absolute path to that plugin. If not, return null. This method assumes that the reader is positioned just after a valid plugin: segment in a substitution string.

Returns:
absolute path of the plugin id, if valid. null otherwise
		private String getPluginPath() {
			try {
				while (true) {
					int nextChar = .read();
					if (nextChar == -1) {
						// reached EOF while looking for closing $
						return null;
else if (nextChar == ) { // end of plugin
						// id
						// look up the plugin id. If it is a valid id
						// return the absolute path to this plugin.
						// otherwise return null.
						// If the plugin id was not valid, reset reader to the
						// previous mark. The mark should be at the character
						// just before the last dollar sign.
						if (path == null)
						return path;
else { // we have a regular character
						// mark the most recent non-dollar char in case we don't
						// find a valid plugin id and have to roll back
						// Use 1024 as our readAheadLimit
						.mark(0x400);
						// Add this character to the pluginId and tokenContent
						// String.
						// make sure we have a valid character before performing
						// cast
						if (nextChar > 0x00 && nextChar < 0xffff) {
							.append((charnextChar);
							// only include non-whitespace characters in plugin
							// id
							if (!Character.isWhitespace((charnextChar))
								.append((charnextChar);
else {
							.append(nextChar);
catch (IOException exception) {
				Log.error("Error reading from file"exception); //$NON-NLS-1$
				return null;
New to GrepCode? Check out our FAQ X