cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Segment violation (signal 11)...Again. Integration with CMS.

Highlighted
Newbie

Segment violation (signal 11)...Again. Integration with CMS.


Adepters,

We are integrating Epic Editor 5.1 with a Web-based Content Management
System. This is the following scenario:

1) An XML file on the CMS with a content type of application/epic is
tied to a "Document Object". This content type is linked to Epic Editor
at the OS level. The Document Oject also contains the actual XML file
our user would really care about.

2) The XML file has a root node of "ContentMetaData" and contains
information about the actual XML document, including its location in the
CMS, Authorization Header, Authentication Token, etc...

3) User clicks on the ContentMetaData link in the CMS.

4) ContentMetaData is downloaded and Epic opens it.

5) Our editinit script examines the ContentMetaData document:

if (doc_type() == "ContentMetaData") {

$fileName = com_call(vb_handle, "initCMSIntegration")

if (window_count("edit") <= 1)
{
doc_show(doc_open($fileName,0x002),1)
}
else
{
doc_close(current_doc())
file_close(current_window())

window_show(window_create('edit',0xF9FB,doc_open($fileName,0x002)),1)
}
}

The com_call to initCMSIntegration parses the ContentMetaData and
downloads the actual XML file to a temporary directory on the user's
workstation, it also returns the location of the content downloaded.

Notice that when an instance of Epic does not exist, there is no need to
close the ContentMetaData document. I'm not sure why, but if I do close
the ContentMetaData document, I receive a segment violation error.

On subsequent loads, I am able to load the document, but if I close the
ContentMetaData as shown above I receive a segment violation error when
I interact with application as user, such as inserting new elements,
adding text, etc...

I tried everything I could think of. For some reason Epic just gags when
a document is closed in ACL via file_close, doc_close, window_destroy,
etc.

If I remove the doc_close, file_close commands and manually close the
ContentMetaData documents, I do not receive the segment violation
errors.

Any one here have any suggestions. I'm just completely out of ideas and
I'm thinking of quitting this job.

Aloha.
Tags (2)
2 REPLIES 2

Re: Segment violation (signal 11)...Again. Integration with CMS.

That sounds like an idea. How do you implement the editbeforehook? I
rarely use ACL and will do it only if its necessary. Also, the help in
Epic is not helping. Is there sample code somewhere? Where do I add the
add_hook call? What about the hook function? Where should I implement
it?

-Gerald.
Highlighted

Re: Segment violation (signal 11)...Again. Integration with CMS.

Gerald,

I briefly reviewed some old code, written against Epic 4.2.3. Ah, the
memories. There were some hurdles with this approach. The following
may be a bit painful, but given a deadline, I've got to paste & run.

Admittedly, there is a lot of fat in this code; if you go this route, it's
likely yours wouldn't have to implement this much.

And, yes, there is likely a better way to accomplish this in a later
version of Epic; e.g., AOM. I do encourage you to look for alternatives.

Basically, it starts by setting the editbeforehook (config::initPacakge).
Next time there's a request to edit the file, that hook gets called.
Within, if the requested file was our equivalent of your ContentMetadata,
we ran off and requested the user-file from the server. By the end of it,
we either displayed the initially requested file or one from the server.

Please note not all dependent functions and constants are present.

package config;

#
# All existing files are opened through this function.
#
# Within this function, the menuloadhook should be removed temporarily; it is
# added back in elsewhere (initDoc()).
#
function editBeforeHook( name, flags = constants::DEFAULT_DOC_OPEN_FLAGS, \
win = uWindow::WIN_ID_INVALID )
{
local rtn = 0; # default to allow epic to open the file.
# Require a name
if ( name != " )
{
# Require successful application initialization
if ( init::SUCCESSFULLY_INITIALIZED )
{
# Remove the menuloadhook; it will be reset in initDoc.
remove_hook( "menuloadhook", "menus::menuLoadHook" );

# Each time an existing file is opened, Epic open's a "new" associated
# FOSI and a "new" file of the doctype matching the file that is to be
# opened. To prevent configuration abnormalities, remove the doc create
# callback. Add the callback once back from HECommand::openFile()
# and after the edit command.
doc_remove_callback( 0, "create", "config::docCreateCallback" );

# Have HECommand::openFile open the file.
rtn = -1; # we're opening the file and do not need epic to do it too.
local doc = HECommand::openFile( name, constants::TRUE, flags, win );

# Perform document initialization
if ( uDoc::isDocValid( doc ) )
{
initDoc( doc );
}

# Give back the doc create callback
doc_add_callback( 0, "create", "config::docCreateCallback" );
}
# Else, remove the editbeforehook
else
{
remove_hook( "editbeforehook", "config::editBeforeHook" );
}
}
return rtn;
}

#
# Initialize this package. Package must be initialized before the first
# file is opened. Initialization is to include:
#
function initPackage()
{
#
# Increasing default line break length upon saves.
#
set outputrecordlength=256;

# Add our editbeforehook
add_hook( "editbeforehook", "config::editBeforeHook" );

# Add our create new doc callback
doc_add_callback( 0, "create", "config::docCreateCallback" );

# Add window quit callback
window_add_callback( 0, "quit", "config::winQuitCallback" );

# Add session quit callback
session_add_callback( "quit", "config::sessionQuitCallback" );

# Add window create callback and invoke.
window_add_callback( 0, "create", "config::windowCreateCallback" );
windowCreateCallback();

global INITIALIZED = 1;
}

#
# Initialize this package
#
initPackage();

package HECommand;

#
# Open the given filename. If the file is an HECommand
# file, attempt to process its command. Else, place the
# opened file in an edit window for the user. This
# function is responsible for all files being opened.
#
# Params:
# filename: File to open
# giveErrorIfFail: When true and doc open fails, error posted to user.
# flags: doc open flags
# win: Desired window to open doc within. Submit uWindow::WIN_ID_INVALID
# (default) if leaving up to the application to decide which window.
#
# Return doc id (could be valid or invalid doc id)
#
function openFile( filename, giveErrorIfFail = constants::FALSE, \
flags = constants::DEFAULT_DOC_OPEN_FLAGS, win = uWindow::WIN_ID_INVALID )
{
local msg;

# Open the given file
local doc = doc_open( filename, flags );

if ( uDoc::isDocValid( doc ) )
{
local doctypeName = uDoc::doctype( doc );
local editFile = constants::TRUE;
local readOnly = constants::FALSE;

# EVERYTHING HEREIN WAS OUR EQUIVALENT OR YOUR CONTENTMETADATA.
# GUT AND PERFORM YOUR COM CALL.
if ( doctypeName == init::ENV[ "COMMAND_DOCTYPE_NAME" ] )
{
# Create data array for processCommand
local cmdInfo[];
cmdInfo[ constants::DATA_INDEX_FIRST_DOC_ID ] = doc;
cmdInfo[ constants::DATA_INDEX_FIRST_FILENAME ] = filename;
cmdInfo[ constants::DATA_INDEX_DOC_OPEN_FLAGS ] = flags;

# Retrieve EI from Editing Service. If this function returns true, a
# new doc is loaded into memory but needs to be loaded into a window.
if ( processCommand( cmdInfo ) && \
uDoc::isDocValid( cmdInfo[ constants::DATA_INDEX_SECOND_DOC_ID ] ) )
{
# Update local vars based on modified cmdInfo[] array
editFile = constants::TRUE;
doc = cmdInfo[ constants::DATA_INDEX_SECOND_DOC_ID ];
filename = cmdInfo[ constants::DATA_INDEX_SECOND_FILENAME ];
readOnly = cmdInfo[ constants::DATA_INDEX_READ_ONLY ];
}
else
{
editFile = constants::FALSE;
}
delete( cmdInfo );
}
else
{
# do nothing
}

if ( editFile == constants::TRUE )
{
# If xml file requested, verify Epic sees this file as XML.
if ( uMath::isBitInNum( constants::DOC_OPEN_FLAG_XML, flags ) \
&& doc_type_xml( doc ) \
&& ( doc_kind( doc ) != "xml" ) )
{
msg = "Opened \"$filename\"; however, $main::progname is not " . \
"treating this instance as XML.\n\nFuture use of this file " . \
"may be hindered.\n\nDoctype = \" . uDoc::doctype( doc ) . \
"\"\nXML Doctype ?= " . doc_type_xml( doc ) . \
"\nDoc Kind = \" . doc_kind( doc ) . "\";
if ( giveErrorIfFail )
{
java::displayMessage( msg, constants::MESSAGE_TYPE_WARNING, \
constants::EMPTY_ARRAY );
}
else
{
init::debug( msg );
}
}

# Display doc in window
local cmd = "edit -nocc";
local docmapWin = uWindow::getOppositeEditWin( current_window() );
#TODO - If epic.exe is given a file param, a new window is ALWAYS created.
# If we want a user preference dictate if we create a new window or
# not, we will need control whether Epic creates a new window or not.
# Window is already created at this point and is done before
# editBeforeHook is called.

local needNewWindow;
local oppWin;
if ( uWindow::isWinValid( win ) )
{
needNewWindow = 0;
oppWin = uWindow::getOppositeEditWin( win );
}
else
{
win = current_window();
needNewWindow = !uWindow::isWinEmpty( win );
oppWin = uWindow::getOppositeEditWin( win );
if ( !needNewWindow )
{
if ( uWindow::isWinValid( oppWin ) )
{
needNewWindow = !uWindow::isWinEmpty( oppWin );
}
}
}

if ( needNewWindow )
{
cmd .= " -newwindow";
}
if ( readOnly == constants::TRUE )
{
cmd .= " -readonly";
}
cmd .= " \"$filename\";
set contextwarning=off;
java::flushEpicErrors();
execute( cmd );
if ( main::ERROR == " )
{
# Update doc and win vars.
doc = current_doc();
win = doc_window( doc );

# If oppWin is valid and we did not need a new window, load the
# new doc in the opposite window.
if ( uWindow::isWinValid( oppWin ) && !needNewWindow )
{
doc_show( doc, oppWin );

# If we have two windows, assume larger window is on left and
# make it have the docmap view. This code would override a users
# potential preference to have the docmap on the right side,
# top, bottom or not at all.
local docMapWin = max( win, oppWin );
local editWin = min( win, oppWin );
if ( window_get( docMapWin, uWindow::WIN_OPT_DOCMAP ) != 1 )
{
window_set( docMapWin, uWindow::WIN_OPT_DOCMAP, 1 );
}
if ( window_get( editWin, uWindow::WIN_OPT_DOCMAP ) != 0 )
{
window_set( editWin, uWindow::WIN_OPT_DOCMAP, 0 );
}
}

# Give focus to main edit win.
current_window( win );

# Attempt to turn context rules on if not already on.
if ( option("context") != "on" )
{
execute( "set context=on" );
}

# If context rules are on, finish up.
if ( option("context") == "on" )
{
# Invoke doc_read_only(), as appropriate
if ( readOnly == constants::TRUE )
{
doc_read_only( doc, 1 );
set modified=off;
}
}
# Else, perform completeness check
else
{
# Perform completeness check
check_completeness;
}
}
else
{
init::debug( "Error caught from edit command, \"$main::ERROR\" );
}
}
}
else
{
msg = "Unable to open \"$filename\";
if ( giveErrorIfFail )
{
java::displayErrorMessage( msg );
}
else
{
init::debug( msg );
}
}

return doc;
}
Announcements