version 1.150, 2002/09/24 12:39:48
|
version 1.151, 2002/10/07 14:27:45
|
Line 931 char *GetBaseURL (Document doc)
|
Line 931 char *GetBaseURL (Document doc)
|
Attribute attr; |
Attribute attr; |
char *ptr, *basename; |
char *ptr, *basename; |
int length; |
int length; |
|
ThotBool hasDocBase; |
|
|
if (doc == 0 || !DocumentURLs[doc]) |
if (doc == 0 || !DocumentURLs[doc]) |
return NULL; |
return NULL; |
Line 938 char *GetBaseURL (Document doc)
|
Line 939 char *GetBaseURL (Document doc)
|
basename = TtaGetMemory (MAX_LENGTH); |
basename = TtaGetMemory (MAX_LENGTH); |
basename[0] = EOS; |
basename[0] = EOS; |
length = MAX_LENGTH -1; |
length = MAX_LENGTH -1; |
|
hasDocBase = FALSE; |
/* do we have a location header? */ |
|
if (DocumentMeta[doc] && DocumentMeta[doc]->full_content_location |
/* If the document has a base URL, it has a priority over the headers. */ |
&& DocumentMeta[doc]->full_content_location[0] != EOS) |
/* @@ We need to do this too when we support XML:base */ |
{ |
|
strncpy (basename, DocumentMeta[doc]->full_content_location, MAX_LENGTH-1); |
/* is it a HTML document ? */ |
basename[MAX_LENGTH-1] = EOS; |
elType.ElSSchema = TtaGetDocumentSSchema (doc); |
length = strlen (basename); |
if (!strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML")) |
} |
/* it's a HTML document */ |
else |
|
{ |
{ |
/* is it a HTML document ? */ |
/* get the document element */ |
elType.ElSSchema = TtaGetDocumentSSchema (doc); |
el = TtaGetMainRoot (doc); |
if (!strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML")) |
/* search the BASE element */ |
/* it's a HTML document */ |
elType.ElTypeNum = HTML_EL_HEAD; |
|
el = TtaSearchTypedElement (elType, SearchForward, el); |
|
if (el) |
|
/* there is a HEAD element */ |
{ |
{ |
/* get the document element */ |
/* look for a BASE element within the HEAD */ |
el = TtaGetMainRoot (doc); |
elType.ElTypeNum = HTML_EL_BASE; |
/* search the BASE element */ |
el = TtaSearchTypedElement (elType, SearchInTree, el); |
elType.ElTypeNum = HTML_EL_HEAD; |
} |
el = TtaSearchTypedElement (elType, SearchForward, el); |
if (el) |
if (el) |
{ |
/* there is a HEAD element */ |
/* The document has a BASE element. Get the HREF attribute of the |
{ |
BASE element */ |
/* look for a BASE element within the HEAD */ |
hasDocBase = TRUE; |
elType.ElTypeNum = HTML_EL_BASE; |
attrType.AttrSSchema = elType.ElSSchema; |
el = TtaSearchTypedElement (elType, SearchInTree, el); |
attrType.AttrTypeNum = HTML_ATTR_HREF_; |
} |
attr = TtaGetAttribute (el, attrType); |
if (el) |
if (attr) |
{ |
{ |
/* The document has a BASE element. Get the HREF attribute of the |
/* Use the base path of the document */ |
BASE element */ |
TtaGiveTextAttributeValue (attr, basename, &length); |
attrType.AttrSSchema = elType.ElSSchema; |
|
attrType.AttrTypeNum = HTML_ATTR_HREF_; |
|
attr = TtaGetAttribute (el, attrType); |
|
if (attr) |
|
{ |
|
/* Use the base path of the document */ |
|
TtaGiveTextAttributeValue (attr, basename, &length); |
|
} |
|
} |
} |
} |
} |
} |
} |
|
|
|
/* there was no BASE. Do we have a location header? */ |
|
if (!hasDocBase && DocumentMeta[doc] && DocumentMeta[doc]->full_content_location |
|
&& DocumentMeta[doc]->full_content_location[0] != EOS) |
|
{ |
|
strncpy (basename, DocumentMeta[doc]->full_content_location, MAX_LENGTH-1); |
|
basename[MAX_LENGTH-1] = EOS; |
|
length = strlen (basename); |
|
} |
|
|
if (basename[0] != EOS) |
if (basename[0] != EOS) |
{ |
{ |
/* base and orgName have to be separated by a DIR_SEP */ |
/* base and orgName have to be separated by a DIR_SEP */ |