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

Home > Articles > Web Design & Development > Adobe ColdFusion

  • Print
  • + Share This
This chapter is from the book

PSML Reader

The next item on Victor's list was the PSML reader component, which would be responsible for reading a user's PSML file. This component would use Jetspeed's Java classes to return this information to ColdFusion.

JAR Files and Setup

The first part of the process is to make the Jetspeed classes available to ColdFusion. To do this, it is necessary to copy all of the JAR, or Java Archive files, from Jetspeed's {Jetspeed-root}/WEB-INF/lib directory to the {ColdFusion_Root}/wwwroot/WEB-INF/ directory. JAR files are essentially Zip files that contain Java classes and other files and directories. The Jetspeed JAR files contain all of the Java classes used by Jetspeed, and placing them in the /WEB-INF/lib directory will make them available to applications in ColdFusion. ColdFusion Server will need to be restarted to finalize this process.

Building the Components Using Java Objects

The primary objective of this component is to read a user's PSML file and return information from it. As such, the Project Omega team decided the following methods should be included:

  • getUserPSML(). Returns a ColdFusion XML document object for debugging purposes.

  • getTabs(). Project Omega had decided to allow users to have a number of pages within the portal; these were called "tabs," and each tab could contain a number of portlets (the user could choose these). This method returns an array including all of the users' tabs.

  • getPortlets(). Returns a two-dimensional array including all of the users' portlets for each tab.

  • getController(). Returns the controller for each tab.

  • getUserSkin(). Returns the user's skin, which could be further looked up in the skin registry to define the portal design.

  • getLog-in(). Project Omega decided to store the user's log-in (encrypted) for different portlets in the user's PSML file. This method returns the user's user name and password (unencrypted).

The first method was straightforward. XmlParse() was used to create the XML document object, and then this was returned to the user. However, while Jim was developing this method he had an idea and emailed Victor about it:

New component


email

Date: June 10

To: Victor

From: Jim

Subject: New component

Hi Victor—

I was working on PSMLReader.cfc—just getting started, and I thought of something. We are going to need to have the location of the user's PSML file. Based on our review of Jetspeed, that could be complex—especially if we add on any localization or WML features in the future.

What we should do is create a method that will return a directory location if the user name, language, and any other relevant information is passed to it. That way, if we ever change how the PSML directory is structured or used, we can just re-write the one method instead of replacing hardcoded directory locations in multiple templates.

What do you think?

Jim

Figure 3-5 Figure I-3.5 Because the development team used a function to return the directory location of PSML files, future changes in directory structure will only require changing this function.

Now it was time to really get down and dirty with the PSMLReader component. The getTab() method included the use of ColdFusion's J2EE integration features. The start of this tag declares the function and arguments and creates Java objects to use:

<CFFUNCTION ACCESS="PUBLIC"
                            NAME="getTabs"
                            RETURNTYPE="ARRAY">
    <CFARGUMENT NAME="User" REQUIRED="TRUE" TYPE="STRING">
    <CFARGUMENT NAME="Language DEFAULT="EN" TYPE="STRING">
    <CFARGUMENT NAME="Media" DEFAULT="HTML" TYPE="STRING">
    <!--- use Jetspeed object for accessing PSML --->
    <CFOBJECT ACTION="CREATE"
                           TYPE="JAVA"

CLASS="org.apache.jetspeed.xml.api.portletmarkup.Portlets"
                       NAME="PortletObject">
    <!--- read the user's PSML file --->
    <CFINVOKE COMPONENT="portal.components.userinfo"
                           METHOD="getUserPSML"
                           USER="#ARGUMENTS.User#"
                           MEDIA="#ARGUMENTS.Media#"
                           LANGUAGE="#ARGUMENTS.Language#"
                           RETURNVARIABLE="PSMLLocation">
    <!--- get file object to retrieve PSML
             file as java.io.Reader, initialize... --->
    <CFOBJECT ACTION="CREATE"
                           TYPE="JAVA"
                           CLASS="java.io.FileReader"
                           NAME="PSMLFile">
          <CFSET PSMLFile.init("#PSMLLocation#")>
    <CFSET ProcessPortlets =
PortletObject.unmarshal(PSMLFile)>
    <CFSET CurrentPortlets = ProcessPortlets.getPortlets()>

After declaring the function, all of the arguments are declared. Note that the arguments enclosed are primarily to be passed to the getUserPSML() method that will return the location of the user's PSML file. <CFINVOKE> invokes this method, and the result is set to the variable, PSMLLocation.

Next, an object of type org.apache.jetspeed.xml.api.portlet-markup.Portlets is created using <CFOBJECT>. When working with Java objects, this tag requires that the TYPE attribute be set to JAVA and the ACTION attribute set to CREATE. The CLASS attribute specifies the class of the object that will be created, and the NAME attribute specifies the name that will be used to access the object within the page. An instance of this object is created because its methods will need to be accessed later in this function. Many objects will require arguments when they are created. This is the case with the java.io.FileReader object in the next <CFOBJECT> tag. It requires that a String object containing the directory location of the file be passed to it. In such cases, the ColdFusion init() method is used. Here, the <CFSET> tag calls the init() method, passing the argument PSMLLocation output in quotes, as is required of string values in Java. Note that this method is called as if it were a method of the PSMLFile object. Assuming the value of PSMLLocation is "c:\default.psml", the Java equivalence of the above object creation would look like this:

java.io.FileReader PSMLFile = new java.io.FileReader("c:\default.psml"); 

The java.io package has a number of classes within it that are used for inputting and outputting to and from Java programs (io stands for input/output). The FileReader class, specifically, creates a character stream (actually a java.io.Reader object) which contains the contents of the file whose location is passed as an argument. This works much like <CFFILE> does when reading files. So now, the PSML file is imported into the application as this Java object.

Java object methods can be called on directly in the <CFSET> tag. The first of the next two <CFSET> tags creates a variable called ProcessPortlets and sets it to the value returned by PortletObject.unmarshal(PSML-File), which executes the unmarshal() method of the PortletObject object that was created by the first <CFOBJECT> tag. Note that the PSML-File variable is passed to this method. Project Omega knew this was required by looking at the Jetspeed API. Figure I-3.6 shows the Javadoc for this method from the Jetspeed API.

instant message

When Java objects require arguments to be created, the arguments are passed using init() immediately after the <CFOBJECT> tag is used to create the object.

Figure 3-6 Figure I-3.6 The Javadoc from the Jetspeed API shows what is required to call a method and what it will return.

In all Javadoc API documents, a list of methods for any given object will be illustrated in this manner. On the left side of the table is what the object will return, in this case, an array of Portlets objects. This method returns an object of type org.apache.jetspeed.xml.api.portlet-markup.Portlets, also written as Portlets (if referred to from within the same package: org.apache.jetspeed.xml.api.portletmarkup) This item can be clicked on, and the API document for the object type will be brought up. On the right side of this table, the method is listed and within the parenthesis any arguments that must be passed to the method, and the name of that argument. Here, a java.io.Reader object called reader needs to be passed to it.

So, the unmarshal() method uses the java.io.Reader object returned by the FileReader call and returns an object of type Portlets. Because the results are returned to the ProcessPortlets variable, this variable becomes a Java object of this type—hence another way to create Java objects, using Java objects. The Portlets object is used by Jetspeed as an abstraction of the PSML file—much as ColdFusion's XML document object creates an abstraction of XML files. A number of additional methods are available to this object to obtain additional information about all of the items within the <portlets> element of the PSML file.

This can be seen in the next <CFSET> where a new variable, Current-Portlets, is set to the value returned by ProcessPortlets. getPortlets(). The getPortlets() method returns an array of Portlets objects—actually this array will represent the <portlets> objects within the root <portlets> tag, the children. In this application, these represent a tab. So if there are three <portlets> child elements, this method will return an array containing three Portlets objects. In turn, each of these Portlets objects will represent one of the three tabs that will be displayed for a user of the portal.

The rest of the function creates the array of tabs that will ultimately be returned to the calling template:

<CFSET TabNames = ArrayNew(1)>
<CFLOOP FROM="1" TO="#ArrayLen(CurrentPortlets)#"
                   INDEX="i">
   <!---
                   build the array of title values in the metainfo
                   section of XML template. CurrentPortlets[i]
                   returns a Portlets object, which then calls on
                   the getTitle() method which returns a String
                   value to add to the list
   --->
  <CFIF CurrentPortlets[i].getMetaInfo() NEQ "">
       <CFSET ArrayAppend(TabNames,

CurrentPortlets[i].getMetaInfo().getTitle())>
   </CFIF>
      </CFLOOP>
      <CFRETURN TabNames>
</CFFUNCTION>

A new array is created, TabNames, using the ArrayNew() function. Next, a <CFLOOP> tag loops through the CurrentPortlets array of Portlets objects. ColdFusion recognizes that CurrentPortlets is an array, nicely allowing Jim to use array functions on it, specifically ArrayLen() to determine the length of the array.

Within the <CFLOOP>, a <CFIF> checks to see if the current Portlets object returns any value for getMetaInfo(). Because the item at Cur-rentPortlets[i] is an object, methods of that object can be called on directly. The getMetaInfo() returns a new object (called a MetaInfo object), which has methods to return information from within the <meta-info> element of a <portlets> element. If this method returns an empty string, that would signify that there is no <meta-info> element, and this <CFIF> block would be ignored.

If it isn't an empty string, the TabNames array is appended with the results of an interesting method call. Basically, the CurrentPortlets[i] array returns a Portlets object; the getMetaInfo() method of that object is called on which returns a MetaInfo object. Finally, the getTitle() method of that object is called on. This will return a string value containing the title of the current <portlets> element, as represented by an item in the CurrentPortlets array of Portlets.

Jim was a bit overwhelmed at first, but as he developed the other functions for this component—all of which used the same basic principles—it actually turned out to be rather easy. Every element of the PSML file had a corresponding object that represented it. And methods within each of these objects could return information that was embedded within them. For example, when he needed to obtain the name for a portlet entry, he would obtain the appropriate Portlets object, use the getEntry() method to return an Entry object, then use the getName() method of that object to return the portlet name.

  • + Share This
  • 🔖 Save To Your Account

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