!
! (c) Copyright 2006, Sage Software Canada Ltd. (Ontario, Canada)
! %Id: XML_Convert.pvc.pvt,v 1.25 2007/05/16 12:54:19 fred.mcguirk Exp %
/*
* Build information:
! ** @Author Fred McGuirk
! ** @Date Feb 6, 2007
! ** @Password
! ** @Owner
! ** @Flags
! ** @OutputFile XML_Convert.pvc
! ** @ForceLineNumbers false
! ** This is a Post-Process observer that will convert ProvideX data files to/from XML. It will also
! ** be registered as a contributed tool and will be added to that list under the 'ProvideX' item on
! ** the menu bar.
! ** @LIKE
! ** @TODO
*/
!
def class "XML_Convert"
like "EventManagerObserver"
like "AbstractActionListener"
/*
! ** This method will be called when the action is triggered from the contributed tools menu.
! **
! ** @param inActionEventID This is a reference to %JavaClass(eventmanager/ExtCommand)%
*/
function actionPerformed(inActionEventID) do_ActionPerformed
! ** This method is used to describe the purpose of this observer. The text will be placed on the observers preference page to describe and should be limited to 80 characters (at most).
function getDescription$() getDescription
/*
! ** Get the flag that will be used to trigger the 'update()' method during execution of the built-in events for the plug-in.
! **
! ** If this observer is not a Post-process observer, the return value of this method should be set to one of the following values:
! ** @value _pvxConstants'_ideNone Do not register as an observer
! ** @value _pvxConstants'_idePreProcess Register as a Pre-Process observer
! ** @value _pvxConstants'_idePrePostProcess Register as both a Pre-Process and Post-Process observer.
! ** @value _pvxConstants'_idePostProcess Register as a Post-Process observer
*/
function getEventNotificationFlag() getEventNotificationFlag
! ** Initialize an observer.
function init() init
! ** The logic to be executed when the observer is triggered. This logic must check the major and minor codes to determine the current event and then decide what action is to be performed.
! **
! ** @param initPvxState A reference to an object of class %PvxClass(PvxState)%
function update(initPvxState) update
/*
! ** Convert the specified ProvideX keyed file to XML.
! ** @param aFile$ The name of the ProvideX keyed file to be converted.
*/
function local data2xml(aFile$) data2xml
/*
! ** Convert the specified XML file to a ProvideX keyed file.
! ** @param theSource$ The name of the XML file to be converted.
*/
function local xml2data(theSource$) xml2data
/*
! ** Convert the specified XML file to a ProvideX keyed file.
! ** @param theSource$ The name of the XML file to be converted.
! ** @param theDest$ The name of the XML file to be converted.
*/
function local xml2data(theSource$,theDest$) xml2data
end def
init:
_obj'init(from "AbstractActionListener")
return
do_ActionPerformed:
enter IExtCommand
local resPath$,_TMP,_TMP$
/* define a reference to the java Resource Manager */
def object resManager,"[wdx]com.pvx.ooadide.eventmanager.ResourceManager"
/* Create a local reference to the EventLog */
_eventLog=new("ErrorLogBuilder",_pvxConstants,ViewManager)
_eventLog'bufferInit()
_eventLog'bufferAddText("Contributed action: "+_obj'getDescription$()+$0A$)
/* Get the name of the source resource from the Resource Manager */
resource = resManager'getSelectedResourceInNavigator()
if resource<>0 {
resPath$=resManager'getPathToSelectedResourceInNavigator$()
if resource'getType()<>resource'FOLDER {
_TMP$="", \
_TMP=0;
open input(hfn,isz=1,err=*next)resPath$;
_TMP=lfo;
read record (_TMP,ind=0,siz=8,err=*next)_TMP$
if _TMP>0 \
then close (_TMP)
if pos(_TMP$="[Pvxkey][Pvxky2]",8)>0 {
_obj'data2xml(resPath$)
} else {
if lcs(mid(resPath$,-4))=".xml" {
_obj'xml2data(resPath$)
}
}
/* Force a refresh of Navigation view (DEPTH_ONE, DEPTH_INFINITE, DEPTH_ZERO) */
resource'refreshLocal(resource'DEPTH_ZERO,*-1)
}
}
drop object resManager
drop object _eventLog
return
getDescription:
! Change the value to be the actual description of this observer
local theDescription$="Convert ProvideX keyed files to/from XML"
return theDescription$
! get Event Notification Flag
getEventNotificationFlag:
return _pvxConstants'_idePostProcess
update:
enter aPvxState
/*
* This observer is triggered when an incremental build is initiated on a
* data file.
*
* If the source file ends with the XML extension, it will be converted to
* a PVX keyed file. Otherwise, the file header is read to verify that this
* is in fact a PVX keyed file and then it is converted to XML.
*/
/* Get the major/minor codes for this event. */
psMajor$=aPvxState'getMajor$(), \
psMinor$=aPvxState'getMinor$()
/* Get the parameters that were passed into this event. */
source$=aPvxState'getArgumentValue$(_pvxConstants'SrcFile$), \
dest$=aPvxState'getArgumentValue$(_pvxConstants'Dest$), \
domFile$=aPvxState'getArgumentValue$(_pvxConstants'DomFile$), \
passwd$=aPvxState'getArgumentValue$(_pvxConstants'pkf_Password$), \
passwd_type$=aPvxState'getArgumentValue$(_pvxConstants'_iPasswordType$)
/* Create a local reference to the EventLog */
_eventLog=new("ErrorLogBuilder",_pvxConstants,ViewManager)
_eventLog'bufferInit()
_eventLog'bufferAddText("["+psMajor$+"]"+$0A$+"==>"+psMinor$+"<=="+$0A$)
switch psMajor$
case _pvxConstants'Incremental_Build$
switch psMinor$
/* Convert a ProvideX data file to XML */
case _pvxConstants'BuildType_DataFile$
_obj'data2xml(source$)
break
/* Convert a XML to ProvideX data file */
case _pvxConstants'BuildType_OtherFile$
_obj'xml2data(source$,dest$)
break
end switch
break
end switch
_eventLog'bufferWriteText()
drop object _eventLog
return 0
data2xml:
enter source$,err=*return
/*
* Convert a ProvideX data file to XML
*
* Steps:
* - Check file header to verify source file is a ProvideX keyed file
* - Read the resource properties (password)
* - Convert the file to XML
* - Tell Eclipse that there is a new resource and copy the properties
* of the old resource to the new one
* - delete the old file; this will cause Eclipse to also delete the resource
*/
local _eventlog,aMonitor
_eventLog=new("ErrorLogBuilder",_pvxConstants,ViewManager)
_eventLog'bufferAddText(" Convert ProvideX Keyed file to XML"+$0A$)
_TMP$="", \
_TMP=0;
open input(hfn,isz=1,err=*next)source$;
_TMP=lfo;
read record (_TMP,ind=0,siz=8,err=*next)_TMP$
if _TMP>0 \
then close (_TMP)
/* Must be a ProvideX keyed file - or it is ignored! */
if pos(_TMP$="[Pvxkey][Pvxky2]",8)>0 \
{
/*
* Create a reference to the Java ResourceManager in eclipse
*/
def object resManager,"[wdx]com.pvx.ooadide.eventmanager.ResourceManager"
/* Get the name of the source resource from the Resource Manager */
file_obj=resManager'getFile(source$)
file_name$=FILE_OBJ'getName$()
/* Add an '.xml' extension to the name */
file_dest$=file_name$+".xml", \
new_dest$=source$+".xml"
/*
* Since a new file is to be created, the properties of the original file
* (passed as arguments) must be associated with the new file.
*
* This is accomplished by telling the java ResourceManager to add the new property
* and its value to the list of properties for the new file. Once all processing has
* been completed for this event, the list will be used to assign (or move) the
* properties and values.
*/
resManager'addtoPropertyUpdateList$(new_dest$,_pvxConstants'Output_File_Name$,file_name$)
resManager'addtoPropertyUpdateList$(new_dest$,_pvxConstants'p_Password$,passwd$)
drop object resManager
/*
* Get a handle to a ProgressMonitor...
* - first, check for an existing instance of the class which is possible
* since the class is a singleton (unique)
* - if there is already an instance, it is already showing the process of
* an event, so this task will not update it
* - otherwise, since there is no existing monitor, a new one will be created
* to show the progress of this task.
*/
isActive=0
aMonitor=new("ProgressMonitor",err=*next);
isActive=1
if not(isActive) {
aMonitor=new("ProgressMonitor","Converting "+source$+" to XML",-1)
aMonitor'setTaskDetail("Processing...")
} else {
aMonitor=0
}
/* do the conversion */
call "pvxtoxml.pvx",err=*next,source$,new_dest$,passwd$,passwd_type$,status,aMonitor
/*
* if conversion was sucessful, delete original file
* Otherwise, display failed status and message (reason)
*/
if not(status) \
then \
erase source$,err=*next;
_eventLog'bufferAddText(" ** Success **"+$0A$) \
else \
_eventLog'bufferAddText(" ** Failed **"+$0A$+msg(status)+$0A$)
! Finished this file.
if aMonitor {
aMonitor'done()
drop object aMonitor
}
}
drop object _eventLog
return
xml2data:
enter source$,err=*next
enter *,dest$,err=*next
local aKey,aMonitor,aText$,dE,dM,isActive,xDoc,xKeys,xSchema,xTable, \
_eventlog,_eraseSrc,domFile$
if not(nul(source$)) and lcs(mid(source$,-4))=".xml" \
{
_eventLog=new("ErrorLogBuilder",_pvxConstants,ViewManager)
_eventLog'bufferAddText( \
" Convert XML file to ProvideX Keyed file"+$0A$+ \
source$+" ==> "+dest$+$0A$ \
)
/*
* Get a handle to a ProgressMonitor...
* - first, check for an existing instance of the class which is possible
* since the class is a singleton (unique)
* - if there is already an instance, it is already showing the process of
* an event, so this task will not update it
* - otherwise, since there is no existing monitor, a new one will be created
* to show the progress of this task.
*/
isActive=0
aMonitor=new("ProgressMonitor",err=*next);
isActive=1
if not(isActive) {
aMonitor=new("ProgressMonitor","Convert XML to ProvideX Keyed",-1)
aMonitor'setTaskDetail("Converting "+source$+"...")
} else {
aMonitor=0
}
/*
* Convert a XML file into a ProvideX keyed file
*/
if nul(dest$) {
dest$=mid(source$,1,len(source$)-4), \
_eraseSrc=1
}
call "xmltopvx.pvx",err=*next,source$,dest$,status,aMonitor
/* check to see if conversion was sucessful */
if not(status) \
{
_eventLog'bufferAddText(" ** Success **"+$0A$)
if aMonitor {
aMonitor'setTaskDetail("Build DOM information...")
}
/* Now, create the DOM information for this source file */
_eventLog'bufferAddText(" .. Build DOM information"+$0A$)
/*
* Derive the name of the DOM file from the SOURCE file since the DEST
* does not exist as a resource yet. Must also strip the ".xml" extension
* from the DomFile name.
*/
dE=new("domEntity",source$,_pvxConstants'_iPvxData)
dM=new("domManager",dE)
domFile$=dM'getDOMFile$(), \
domFile$=mid(domFile$,1,len(domFile$)-4)
call %_PluginDir$+"get_FileInfo.pvx",err=*next,dest$,domFile$,0
call %_PluginDir$+"get_DictInfo.pvx",err=*next,dest$,domFile$+".dict",0
drop object dM
drop object dE
if _eraseSrc {
erase source$,err=*next
}
} else {
_eventLog'bufferAddText(" ** Failed **"+$0A$+msg(status)+$0A$)
}
! Finished this file.
if aMonitor {
aMonitor'done()
drop object aMonitor
}
drop object _eventLog
}
return
end