version 1.89, 2008/10/09 14:59:36
|
version 1.90, 2008/10/14 10:37:19
|
Line 237 static void ParseTemplate (XTigerTemplat
|
Line 237 static void ParseTemplate (XTigerTemplat
|
#ifdef TEMPLATES |
#ifdef TEMPLATES |
AttributeType attType; |
AttributeType attType; |
Attribute att; |
Attribute att; |
Element aux, child, ancestor; //Needed when deleting trees |
Element aux, child; //Needed when deleting trees |
char *name; |
char *name; |
ElementType elType = TtaGetElementType (el); |
ElementType elType = TtaGetElementType (el); |
|
|
Line 496 void CreateInstance(char *templatePath,
|
Line 496 void CreateInstance(char *templatePath,
|
{ |
{ |
#ifdef TEMPLATES |
#ifdef TEMPLATES |
Document doc = 0, newdoc = 0; |
Document doc = 0, newdoc = 0; |
ElementType elType; |
|
Element root, title, text; |
Element root, title, text; |
CHARSET charset; |
ElementType elType; |
char *s, *charsetname; |
CHARSET charset, ocharset; |
ThotBool changes = FALSE; |
char *s, *charsetname, *ocharsetname, *localFile; |
|
|
XTigerTemplate t = GetXTigerTemplate(templatePath); |
XTigerTemplate t = GetXTigerTemplate(templatePath); |
if (t == NULL) |
if (t == NULL) |
Line 516 void CreateInstance(char *templatePath,
|
Line 515 void CreateInstance(char *templatePath,
|
newdoc = TtaGetNextDocumentIndex (); |
newdoc = TtaGetNextDocumentIndex (); |
else |
else |
newdoc = basedoc; |
newdoc = basedoc; |
|
|
|
// close current undo sepquence in the template document |
|
if (TtaHasUndoSequence (doc)) |
|
TtaCloseUndoSequence (doc); |
|
|
|
// update the charset if needed |
|
charsetname = TtaGetEnvString ("DOCUMENT_CHARSET"); |
|
charset = TtaGetCharset (charsetname); |
|
ocharsetname = DocumentMeta[doc]->charset; |
|
ocharset = TtaGetCharset (ocharsetname); |
|
if (charset != UNDEFINED_CHARSET && |
|
DocumentMeta[doc]->charset && |
|
strcmp (charsetname, DocumentMeta[doc]->charset)) |
|
{ |
|
TtaSetDocumentCharset (doc, charset, FALSE); |
|
DocumentMeta[doc]->charset = TtaStrdup (charsetname); |
|
SetNamespacesAndDTD (doc, FALSE); |
|
} |
|
|
// register the document type to open the right page model |
// register the document type to open the right page model |
DocumentTypes[newdoc] = docType; |
DocumentTypes[newdoc] = docType; |
if (!TtaHasUndoSequence (doc)) |
// Generate the instance content as a copy of the template |
|
localFile = SaveDocumentToNewDoc(doc, newdoc, instancePath); |
|
Template_PrepareInstance (instancePath, newdoc, t->version, templatePath); |
|
Template_AddReference (t); |
|
|
|
// Revert template changes |
|
TtaSetDocumentCharset (doc, ocharset, FALSE); |
|
DocumentMeta[doc]->charset = ocharsetname; |
|
// Now parse the instance |
|
// The xtiger PI will be added and components will be removed |
|
GetAmayaDoc (instancePath, NULL, basedoc, basedoc, CE_INSTANCE, |
|
!DontReplaceOldDoc, NULL, NULL); |
|
if (DocumentMeta[newdoc]) |
|
DocumentMeta[newdoc]->method = CE_ABSOLUTE; |
|
// Generate the HTML document title |
|
root = TtaGetRootElement(newdoc); |
|
elType = TtaGetElementType (root); |
|
// get the target document type |
|
s = TtaGetSSchemaName (elType.ElSSchema); |
|
if (strcmp (s, "HTML") == 0) |
{ |
{ |
TtaOpenUndoSequence (doc, NULL, NULL, 0, 0); |
// Initialize the document title |
root = TtaGetRootElement(doc); |
elType.ElTypeNum = HTML_EL_TITLE; |
elType = TtaGetElementType (root); |
title = TtaSearchTypedElement (elType, SearchInTree, root); |
// get the target document type |
text = TtaGetFirstChild (title); |
s = TtaGetSSchemaName (elType.ElSSchema); |
while (text) |
// Do special stuff for HTML documents |
{ |
if (strcmp (s, "HTML") == 0) |
elType = TtaGetElementType (text); |
{ |
if (elType.ElTypeNum == HTML_EL_TEXT_UNIT && Answer_text[0] != EOS) |
// Initialize the document title |
|
elType.ElTypeNum = HTML_EL_TITLE; |
|
title = TtaSearchTypedElement (elType, SearchInTree, root); |
|
text = TtaGetFirstChild (title); |
|
while (text) |
|
{ |
{ |
elType = TtaGetElementType (text); |
TtaSetTextContent (text, (unsigned char*)Answer_text, |
if (elType.ElTypeNum == HTML_EL_TEXT_UNIT && Answer_text[0] != EOS) |
TtaGetDefaultLanguage (), newdoc); |
{ |
text = NULL; |
TtaSetTextContent (text, (unsigned char*)Answer_text, |
SetNewTitle (newdoc); |
TtaGetDefaultLanguage (), doc); |
|
text = NULL; |
|
} |
|
else if ((elType.ElTypeNum == Template_EL_useEl || |
|
elType.ElTypeNum == Template_EL_useSimple) && |
|
!strcmp (TtaGetSSchemaName (elType.ElSSchema), "Template")) |
|
// Ignore the template use element |
|
text = TtaGetFirstChild (text); |
|
else |
|
// Look for the first text child |
|
TtaNextSibling (&text); |
|
} |
} |
|
else if ((elType.ElTypeNum == Template_EL_useEl || |
|
elType.ElTypeNum == Template_EL_useSimple) && |
|
!strcmp (TtaGetSSchemaName (elType.ElSSchema), "Template")) |
|
// Ignore the template use element |
|
text = TtaGetFirstChild (text); |
|
else |
|
// Look for the first text child |
|
TtaNextSibling (&text); |
} |
} |
|
|
// update the charset if needed |
|
charsetname = TtaGetEnvString ("DOCUMENT_CHARSET"); |
|
charset = TtaGetCharset (charsetname); |
|
if (charset != UNDEFINED_CHARSET && |
|
DocumentMeta[doc]->charset && |
|
strcmp (charsetname, DocumentMeta[doc]->charset)) |
|
{ |
|
TtaSetDocumentCharset (doc, charset, FALSE); |
|
DocumentMeta[doc]->charset = TtaStrdup (charsetname); |
|
SetNamespacesAndDTD (doc, FALSE); |
|
} |
|
|
|
// Parse template to fill structure and remove extra data |
|
ParseTemplate (t, root, doc, FALSE); |
|
|
|
// Insert XTiger PI |
|
Template_InsertXTigerPI(doc, t); |
|
|
|
// Save HTML special changes |
|
TtaCloseUndoSequence (doc); |
|
changes = TRUE; |
|
|
|
// Save document |
|
SaveDocumentToNewDoc(doc, newdoc, instancePath); |
|
|
|
// Revert HTML special changes |
|
if (changes) |
|
TtaUndoNoRedo (doc); |
|
|
|
TtaClearUndoHistory (doc); |
|
RemoveParsingErrors (doc); |
|
// now load the document as an instance |
|
GetAmayaDoc (instancePath, NULL, basedoc, basedoc, CE_INSTANCE, |
|
!DontReplaceOldDoc, NULL, NULL); |
|
TtaSetDocumentModified (newdoc); |
|
UpdateTemplateMenus(newdoc); |
|
} |
} |
|
|
|
// Insert XTiger PI |
|
Template_InsertXTigerPI(newdoc, t); |
|
// Parse template to fill structure and remove extra data |
|
ParseTemplate (t, root, newdoc, FALSE); |
|
TtaFreeMemory (localFile); |
|
TtaClearUndoHistory (newdoc); |
|
RemoveParsingErrors (newdoc); |
|
TtaSetDocumentModified (newdoc); |
|
UpdateTemplateMenus(newdoc); |
#endif /* TEMPLATES */ |
#endif /* TEMPLATES */ |
} |
} |
|
|
Line 1117 void Template_InsertXTigerPI(Document do
|
Line 1118 void Template_InsertXTigerPI(Document do
|
return; |
return; |
|
|
root = TtaGetMainRoot (doc); |
root = TtaGetMainRoot (doc); |
|
if (root == NULL) |
|
return; |
//Look for PIs |
//Look for PIs |
/* check if the document has a DOCTYPE declaration */ |
/* check if the document has a DOCTYPE declaration */ |
#ifdef ANNOTATIONS |
#ifdef ANNOTATIONS |
Line 1170 void Template_InsertXTigerPI(Document do
|
Line 1172 void Template_InsertXTigerPI(Document do
|
strcat (buffer, "\""); |
strcat (buffer, "\""); |
TtaSetTextContent (text, (unsigned char*)buffer, Latin_Script, doc); |
TtaSetTextContent (text, (unsigned char*)buffer, Latin_Script, doc); |
TtaSetStructureChecking (TRUE, doc); |
TtaSetStructureChecking (TRUE, doc); |
TtaFreeMemory(charsetname); |
TtaFreeMemory (charsetname); |
|
TtaRegisterElementCreate (piElem, doc); |
} |
} |
} |
} |
|
|
Line 1200 void Template_InsertXTigerPI(Document do
|
Line 1203 void Template_InsertXTigerPI(Document do
|
strcat (buffer, "\""); |
strcat (buffer, "\""); |
} |
} |
TtaSetTextContent (text, (unsigned char*)buffer, Latin_Script, doc); |
TtaSetTextContent (text, (unsigned char*)buffer, Latin_Script, doc); |
|
TtaRegisterElementCreate (elNew, doc); |
TtaSetStructureChecking (TRUE, doc); |
TtaSetStructureChecking (TRUE, doc); |
|
|
// update the document title |
// update the document title |
Line 1207 void Template_InsertXTigerPI(Document do
|
Line 1211 void Template_InsertXTigerPI(Document do
|
{ |
{ |
elType.ElTypeNum = HTML_EL_TITLE; |
elType.ElTypeNum = HTML_EL_TITLE; |
elFound = TtaSearchTypedElement (elType, SearchInTree, root); |
elFound = TtaSearchTypedElement (elType, SearchInTree, root); |
if (elFound) |
text = TtaGetFirstChild (elFound); |
|
while (text) |
{ |
{ |
elFound = TtaGetFirstChild (elFound); |
elType = TtaGetElementType (text); |
TtaSetTextContent (elFound, (unsigned char *)Answer_text, |
if (elType.ElTypeNum == HTML_EL_TEXT_UNIT && Answer_text[0] != EOS) |
TtaGetDefaultLanguage (), doc); |
{ |
|
TtaRegisterElementReplace (text, doc); |
|
TtaSetTextContent (text, (unsigned char*)Answer_text, |
|
TtaGetDefaultLanguage (), doc); |
|
text = NULL; |
|
} |
|
else if ((elType.ElTypeNum == Template_EL_useEl || |
|
elType.ElTypeNum == Template_EL_useSimple) && |
|
!strcmp (TtaGetSSchemaName (elType.ElSSchema), "Template")) |
|
// Ignore the template use element |
|
text = TtaGetFirstChild (text); |
|
else |
|
// Look for the first text child |
|
TtaNextSibling (&text); |
} |
} |
} |
} |
#endif /* TEMPLATES */ |
#endif /* TEMPLATES */ |
Line 1225 void Template_InsertXTigerPI(Document do
|
Line 1243 void Template_InsertXTigerPI(Document do
|
void Template_PreInstantiateComponents (XTigerTemplate t) |
void Template_PreInstantiateComponents (XTigerTemplate t) |
{ |
{ |
#ifdef TEMPLATES |
#ifdef TEMPLATES |
|
ForwardIterator iter; |
|
Declaration dec; |
|
SearchSetNode node; |
|
|
if (!t) |
if (!t) |
return; |
return; |
|
|
|
if (Template_IsInstance (t)) |
|
{ |
#ifdef AMAYA_DEBUG |
#ifdef AMAYA_DEBUG |
DumpAllDeclarations(); |
DumpAllDeclarations(); |
#endif /* AMAYA_DEBUG */ |
#endif /* AMAYA_DEBUG */ |
ForwardIterator iter = SearchSet_GetForwardIterator(GetComponents(t)); |
iter = SearchSet_GetForwardIterator(GetComponents(t)); |
Declaration dec; |
|
SearchSetNode node; |
|
|
|
#ifdef AMAYA_DEBUG |
#ifdef AMAYA_DEBUG |
printf("Template_PreInstantiateComponents %s\n", t->uri); |
printf("Template_PreInstantiateComponents %s\n", t->uri); |
#endif /* AMAYA_DEBUG */ |
#endif /* AMAYA_DEBUG */ |
ITERATOR_FOREACH(iter, SearchSetNode, node) |
ITERATOR_FOREACH(iter, SearchSetNode, node) |
{ |
{ |
dec = (Declaration) node->elem; |
dec = (Declaration) node->elem; |
ParseTemplate(t, GetComponentContent(dec), GetTemplateDocument(t), TRUE); |
ParseTemplate(t, GetComponentContent(dec), GetTemplateDocument(t), TRUE); |
|
} |
|
TtaFreeMemory(iter); |
} |
} |
TtaFreeMemory(iter); |
|
#endif /* TEMPLATES */ |
#endif /* TEMPLATES */ |
} |
} |
|
|