For demonstration purposes, I created a page that functions similar to the delivered Branding Framework pages. This page will have a few input fields to specify the needed attributes to create an HTML or Style Sheet object definition.
In this example, I am creating an HTML object. There are only three required fields for HTML object definitions and they are the object name, object description, and the content the object should store. After populating the values and clicking the OK button, a small piece of PeopleCode fires.
/* Create HTML Object */ import PT_METADATA:MetaDataAPI:HTMLDefn; Local string &sHTMLObjName = PSM_WRK0.CONTNAME.Value; Local string &sHTMLObjContent = PSM_WRK0.CONTDATA.Value; Local string &sHTMLObjDescr = PSM_WRK0.DESCR.Value; Local PT_METADATA:MetaDataAPI:HTMLDefn &oHTMLMetaData; &oHTMLMetaData = create PT_METADATA:MetaDataAPI:HTMLDefn(&sHTMLObjName); If (&oHTMLMetaData.Open()) Then &oHTMLMetaData.ContentData = &sHTMLObjContent; &oHTMLMetaData.Description = &sHTMLObjDescr; If (&oHTMLMetaData.Save()) Then MessageBox(0, "", 0, 0, "Saved"); Else MessageBox(0, "", 0, 0, "Save failed"); End-If; Else Error MsgGetText(0, 0, "Open failed"); End-If;
This code is using the HTMLDefn class to create and store all of the meta-data for the HTML object definition. This is essentially the same code that fires on the Branding Objects page when you create a new object. After the code fires, the new object can be seen in App Designer.
It is worth noting that this same code can be used to edit an existing HTML definition. So in this example, if the PSM_MY_HTML object already existed, then this code would’ve overwritten the object’s description and content with the values that were specified in the input fields.
Style Sheets can be created/updated in the same fashion that the HTML objects can. There is a separate class named StylesheetDefn that is used for Style Sheet objects. Below is sample usage of this class. As you can see, this class operates similar to the HTMLDefn class.
/* Create Style Object */ import PT_METADATA:StylesheetDefn; Local PT_METADATA:StylesheetDefn &oSSMetaData; Local string &sSSObjName = PSM_WRK0.CONTNAME.Value; Local string &sSSObjContent = PSM_WRK0.CONTDATA.Value; Local string &sSSObjDescr = PSM_WRK0.DESCR.Value; &oSSMetaData = create PT_METADATA:StylesheetDefn(&sSSObjName); If (&oSSMetaData.Open()) Then &oSSMetaData.ExtStyleSheetStr = &sSSObjContent; &oSSMetaData.Descr = &sSSObjDescr; If (&oSSMetaData.Save()) Then MessageBox(0, "", 0, 0, "Saved"); Else MessageBox(0, "", 0, 0, "Save failed"); End-If; Else Error MsgGetText(0, 0, "Open failed"); End-If;
Other than providing some exposure to an under documented PeopleTools gem, my usage of the PT_METADATA app package to create objects in this example is not very useful as it mimics delivered functionality. However, I think there can be practical usages of this library in different contexts that can allow for enhancing the process of object/data management.
In my next post, I will provide an example of using this library to create image objects. While doing this, I will provide a technique of how this library can provide an avenue to communicate data to be cached on the web server.