Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > PHP/MySQL/Scripting

This chapter is from the book

Portlet Rendering

The first step was drawing an individual portlet. This would be done using the <CF_PORTLET> custom tag along with a registry component that would read relevant information from the PSML registry, such as the type of portlet being rendered (CFML, HTML, etc.) and the title of the portlet.

Building the Registry Component

First, the component needed to be developed to read important information about portlets from the registry. This component would have the following methods within it:

  • getEntry(). Returns a ColdFusion XML Document object of the entry—to be used mainly for debugging purposes.

  • getEntryIndex(). Returns the array location in the ColdFusion XML Document object for the specified registry (this is mainly used internally).

  • getEntryNames(). Returns all entries in the specified registry.

  • getParameter(). Returns the value the parameter specified for a particular entry.

  • getPortletParent(). Returns the parent type of the portlet—this is the type, such as HTML, JSP, CFML, or servlet.

  • getPortletTemplate(). Returns the actual template of an entry.

  • getTitle(). Returns the title of the entry.

  • getURL(). Returns the URL of an entry of the type, HTML.

When talking about components, the terms method and function are synonymous. The coding of this CFC was fairly straightforward, using the CFC constructs, as well as ColdFusion MX's new XML features. One of these, the XmlSearch() function, proved especially valuable. This function allows developers to search XML documents using XPath syntax.

The getEntryNames() method primarily used the XmlSearch() function to retrieve the entries:

<CFFUNCTION ACCESS="REMOTE" NAME="getEntryNames"
   RETURNTYPE="ARRAY">
   <CFARGUMENT NAME="Registry" DEFAULT="demo-portlets"
                                 TYPE="STRING">
   <CFARGUMENT NAME="RegistryType" DEFAULT="portlet"
                                 TYPE="STRING">

   <!--- read the appropriate file --->
   <CFSET RegistryLocation = Server.ColdFusion.RootDir
                          & "\wwwroot\WEB-INF\portal\conf\"
                          & ARGUMENTS.Registry &".xreg">
   <CFFILE ACTION="READ"
                   FILE="#RegistryLocation#"
                   VARIABLE="XMLReg">
   <!--- parse the xml into DOM --->
   <CFSET Registry = XMLParse(XMLReg)>
   <!--- get only the child nodes necessary for this
   function --->
   <CFSET SelectedElements = XmlSearch(Registry,
             "/registry/" & ARGUMENTS.RegistryType & "-entry")>
   <!--- build array --->
   <CFSET ReturnArray = ArrayNew(1)>
   <CFLOOP FROM="1"
                     TO="#ArrayLen(SelectedElements)#"
                     INDEX="i">
       <CFSET ArrayAppend(ReturnArray,
                            selectedElements[i].XmlAttributes.name)>
   </CFLOOP>

   <CFRETURN ReturnArray>

</CFFUNCTION>

After the initial function and arguments are declared using the <CFFUNCTION> and <CFARGUMENT> tags, the exact location of the registry is set using the relevant variables, and then retrieved using <CFFILE>. The XmlParse() function parses the XML into a ColdFusion document object. Then a variable called SelectedElements is set to the value returned by XmlSearch(). This function has two arguments: the first is the XML document object to be searched, and the second is a string containing the XPath search parameters.

One of the ways XPath can refer to XML documents is similar to a directory structure, which is what is used here. If the user were searching through the portlet directory, the value of ARGUMENTS.RegistryType would be "portlet," and the search syntax would be "/registry/portal-entry." In this type of XPath search, think of XML as a directory tree. The <registry> tag is the root of a registry document, and <portlet-entry> elements are its children. So this search would return an array including all of the <portal-entry> elements (and their XML contents) that are under the <registry> element.

This array is then looped through, and a new array is created containing only the value in the name attribute of each <portlet-entry> element. The array is what is returned to the calling template.

When this component was completed, Project Omega was able to use ColdFusion's introspective feature to list the methods within it and all

instant message

XPath offers a number of search methods and has a syntax all its own. This can be an extremely powerful tool for finding information within XML documents. For more information on XPath, please visit http://www.w3c.org/TR/xpath. relevant details. The details would include all of the methods, what arguments they took, and what they would return. In addition, whether they were available remotely and any other information would also be included. It would all display in an HTML page by calling on the CFC directly (see Figure I-3.4). The Project Omega team could refer to it to see what methods were available.

Figure 3-4 Figure I-3.4 The contents of a ColdFusion component can be easily viewed through a browser.

Once this component was completed, the <CF_PORTLET> tag would need to be developed. This tag would take the following attributes:

ID. The unique name of the portlet as listed in the registry.

DISPLAY. This could take the value of MAXIMIZED, MINIMIZED, NORMAL, or CLOSED.

WIDTH. This would represent the percentage width a portlet would take up in its window; the default is 95 percent.

In addition to these attributes, the SESSION.Registry variable needs to be set, holding the user's registry. The APPLICATION.PortletDirectory variable will also be required to know where to obtain the actual portlet templates.

This tag first checks for attributes and either exits or sets default values. Once this is completed, The DISPLAY attribute is checked; if it is CLOSED, then the tag exits using <CFEXIT>, as there is no need to render the portlet.

<CFIF ATTRIBUTES.Display EQ "CLOSED">
     <CFEXIT METHOD="EXITTAG">
</CFIF>

Next, the title is retrieved from the registry component using its getTitle() method using the <CFINVOKE> tag:

<CFINVOKE COMPONENT="portal.components.registry"
                       METHOD="getTitle"
                       RETURNVARIABLE="Title"
                       REGISTRY="#SESSION.Registry#"
                       ENTRYNAME="#ATTRIBUTES.ID#">

Because the components are in the /portal/components/ directory, and this is the registry.cfc component, the component is called on using the appropriate dot notation: portal.components.registry. This is the directory location, with folders separated by dots instead of forward slashes, and the component name without the .cfc ending. The method you want to call is specified in the METHOD attribute: getTitle. The return value will be set to a new variable called Title, as specified in the RETURNVARIABLE attribute. The remaining attributes are specific to the method called.

Following this, the actual design of the portlet is started by creating an HTML table containing the portlets title and the appropriate buttons to minimize, maximize, or close the portlet. Once the skins portion of the application is completed, this table will be updated to reflect the styles in a user's preferences. This table header is all that will be displayed if the port-let is minimized; otherwise, the main table cell contains the portlet itself.

Next, the getPortletParent() method of the registry component is called on to return the type of portlet that is to be displayed:

<CFINVOKE COMPONENT="portal.components.registry"
                        METHOD="getPortletParent"
                        RETURNVARIABLE="Type"
                        REGISTRY="#SESSION.Registry#"
                        ENTRYNAME="#ATTRIBUTES.ID#">

The variable returned by this is used to execute a <CFSWITCH> statement. Each case within this switch block will represent a supported value: HTML, CFML, JSP, and Servlet.

<CFSWITCH EXPRESSION="#Type#"> 

Embedding HTML Portlets

The HTML case uses <CFHTTP> to retrieve the appropriate URL:

<CFCASE VALUE="HTML">
     <!--- get HTML file for this portlet --->
     <CFINVOKE COMPONENT="portal.components.registry"
                             METHOD="getURL"
                             RETURNVARIABLE="URLResource"
                             ENTRYNAME="#ATTRIBUTES.ID#"
                REGISTRY="#SESSION.Registry#">
     <CFTRY>
     <!--- check for local files - add server info --->
     <CFIF URLResource DOES NOT CONTAIN "http://">
       <CFSET Resource = "http://" & HTTP_HOST &
URLResource>
     <CFELSE>
       <CFSET Resource = URLResource>
     </CFIF>
     <!--- get URL --->
     <CFHTTP URL="#Resource#"
                       METHOD="get"
                       RESOLVEURL="yes"
                       THROWONERROR="YES"
                       REDIRECT="YEs"></CFHTTP>
                    <!--- display URL, but replace links to open new
                    window... --->
                   <CFOUTPUT>#ReplaceNoCase(CFHTTP.FileContent,
                   "<A ",
                   "<A TARGET=_BLANK ",
                   "ALL")#</CFOUTPUT>
     <CFCATCH TYPE="ANY">
     This web page is currently unavailable.
     </CFCATCH>
     </CFTRY>
</CFCASE>
     This web page is currently unavailable. 
     </CFCATCH> 
     </CFTRY>
</CFCASE> 

Within this case, first the URL is obtained by calling on the getURL() method of the registry component. Next, a <CFTRY> block tries to retrieve the URL (adding http:// if necessary) using <CFHTTP>. In the retrieved page, all instances of "<A" are replaced with "<A TARGET=_BLANK ". This will open new windows for all links. A <CFCATCH> block catches any errors and outputs a friendly message.

Embedding JSP Portlets

JSP portlets work in a similar way:

<CFCASE VALUE="JSP">
     <CFTRY>
     <!--- first, get template --->
     <CFINVOKE COMPONENT="portal.components.registry"
                             METHOD="getPortletTemplate"
                             RETURNVARIABLE="Resource"
                             ENTRYNAME="#ATTRIBUTES.ID#"
                             REGISTRY="#SESSION.Registry#">
     <CFSET Resource = APPLICATION.PortletDirectory &
Resource>
     <!--- include JSP template using getContext --->
     <CFSCRIPT>
          getPageContext().include(Resource);
     </CFSCRIPT>
     <CFCATCH TYPE="ANY">
     This application is currently unavailable.
     </CFCATCH>
     </CFTRY>
     </CFCASE>
     This application is currently unavailable.
     </CFCATCH>
     </CFTRY>
</CFCASE> 

The same <CFTRY> and <CFCATCH> method is used to gracefully control errors. The Project Omega team was surprised at the efficiency with which both JSP and Servlets could be absorbed into a ColdFusion page. The getPageContext() methods made this quite simple. To include a JSP page, the include(), method is called on and works just like a <CFINCLUDE> would with a ColdFusion page.

Embedding Servlet Portlets

instant message

ColdFusion MX is actually a giant J2EE application, and altering or removing any existing entries in the web.xml file can really screw up your ColdFusion server installation.

The Servlet code was literally identical to the JSP code. However, because Servlets were really just Java class files, their location had to be mapped into the Web application. Servlet mapping associates the appropriate Java class with a URL that can be called on by a browser or a ColdFusion template.

To map a Servlet, it's necessary to edit the web.xml file in the {ColdFusion_Root}/wwwroot/WEB-INF/ directory. This file controls the setup of a J2EE application when the application server is initialized.

To set up a server, a number of lines must be added to this file:

<servlet>
   <servlet-name>SnoopServlet</servlet-name>
   <servlet-class>com.mishugana.Snooper</servlet-class>
   <display-name>Snoop Servlet</display-name>
   <description>Outputs all variables in all
scopes</description>
</servlet>

<servlet-mapping>
   <servlet-name>SnoopServlet</servlet-name>
   <url-pattern>/servlets/Snoop</url-pattern>
</servlet-mapping>

instant message

For more information on the web.xml file and its uses, please visit the Macromedia Tech Note Understanding web. xml Files at http://www.macromedia.com/v1/handlers/index.cfm?id=19399&method=full.

There are two primary elements that contain Servlet information: the <servlet> element, which contains primary information about a Servlet, and the <servlet-mapping> element, which maps the Servlet to a URL.

Within the <servlet> element are four primary child elements:

  • servlet-name> contains the name this Servlet will be referred to as.

  • servlet-class> contains the actual Java class file in dot notation.

  • Generally Servlets are placed within the {ColdFusion_Root}/wwwroot/ WEB-INF/classes/ directory.

  • <display-name> contains a user-friendly name for the Servlet. This is often used by J2EE application server administrative consoles.

  • <description> contains a description of the Servlet. This is also often used by J2EE application server administrative consoles.

    instant message

    The <servlet-mapping> element has only two child elements:

    The method getPageContext(). include() shows how Java stacks methods using the dot notation. Here, the include() method will be run on results of the getPageContext() method. This is different from the way ColdFusion has methods within methods, such as DollarFormat(Rand() ), which will run the DollarFormat() function on the results of the Rand() function.

  • <servlet-name>. This element links the mapping to the appropriate Servlet. This must match the <servlet-name> of a <servlet> element in the same web.xml file.

  • <url-pattern>. This element tells the application server what URL pattern to pass through the Servlet. This example refers to a specific URL (/servlets/Snoop), but other patterns may be used. For example, one could map all files with a .do ending using *.do as the URL pattern.

Once a Servlet is mapped, it can be called on using getPageContext() .include(ServletMapping). Which is precisely how Project Omega set up the Servlet type to work.

During this development phase, the Project Omega team discovered that another method, getPageContext().forward(), could perform server-side forwarding. This is different from <CFLOCATION>, which performs client-side redirects. By redirecting on the server side, an application can be more tightly controlled before information is sent out to the client.

Embedding CFML Portlets

Finally, the CFML portlet case was created. This was undoubtedly the simplest. The code was almost identical to the JSP and Servlet types, however, instead of the getPageContext().include() method, the <CFINCLUDE> tag is used to include the ColdFusion template.

Once this was developed and tested, the Project Omega team worked together to build some simple portlets. They created several simple portlets of every type that performed simple tasks, such as searching the registry, outputting variables using <CFDUMP>, and basic text output. These portlets were then added to the demo-portlets.xreg, and an anonymous user default.psml file was created following Jetspeed's user PSML format, with Victor's modifications. This dummy data could now be used to further develop the portal application.

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.peachpit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020