/*----------------------------------------------------------------------- -----------------------------------------------------------------------*/ static char * BM_topicGetTitle (Element topic_item) { ElementType elType; Element el; char *buffer = NULL; int length; Language lang; if (!topic_item) return NULL; /* topic title */ elType = TtaGetElementType (topic_item); elType.ElTypeNum = Topics_EL_Topic_title; el = TtaSearchTypedElement (elType, SearchInTree, topic_item); el = TtaGetFirstChild (el); if (el) { length = TtaGetTextLength (el) + 1; buffer = (char *)TtaGetMemory (length); TtaGiveTextContent (el, (unsigned char *)buffer, &length, &lang); } return buffer; }
/*----------------------------------------------------------------------- LINK_AddAnnotIcon If the annotation is not orphan, adds an annotation icon to a source document, an annotation link pointing to the annotation. Returns TRUE if the annotation could be attached and FALSE if the annotation became orphan. -----------------------------------------------------------------------*/ void LINK_AddAnnotIcon (Document source_doc, Element anchor, AnnotMeta *annot) { Element el; char iconName[MAX_LENGTH]; char previous[MAX_LENGTH]; RDFStatementP iconS = (RDFStatementP) NULL; int len; Language lang; el = TtaGetFirstChild (anchor); if (!PROP_usesIcon) PROP_usesIcon = ANNOT_FindRDFResource (&annot_schema_list, USESICON_PROPNAME, TRUE); if (annot->type) iconS = ANNOT_FindRDFStatement (annot->type->statements, PROP_usesIcon); if (iconS) { char *ptr; char *path; char temp[MAX_LENGTH]; /* @@@ JK? */ strcpy (iconName, iconS->object->name); WWWToLocal (iconName); /* expand $THOTDIR and $APP_HOME */ ptr = strstr (iconName, "$THOTDIR"); if (ptr) { ptr += 8; path = TtaGetEnvString ("THOTDIR"); } else { ptr = strstr (iconName, "$APP_HOME"); if (ptr) { ptr += 9; path = TtaGetEnvString ("APP_HOME"); } } if (ptr) { strcpy (temp, ptr); strcpy (iconName, path); strcat (iconName, temp); } } else sprintf (iconName, "%s%camaya%cannot.png", TtaGetEnvString ("THOTDIR"), DIR_SEP, DIR_SEP); /* only substitute the icon name if it has changed */ len = TtaGetTextLength (el); if (len > 0 && len < (int) (sizeof (previous))) { TtaGiveTextContent (el, (unsigned char *)previous, &len, &lang); previous[len] = EOS; } else previous[0] = EOS; if (previous[0] == EOS || strcasecmp (iconName, previous)) { ThotBool docModified; docModified = TtaIsDocumentModified (source_doc); TtaSetPictureContent (el, (unsigned char *)iconName, SPACE, source_doc, "image/png"); if (!docModified) { TtaSetDocumentUnmodified (source_doc); DocStatusUpdate (source_doc, docModified); } } }
/*---------------------------------------------------------------------- * Dump template element ----------------------------------------------------------------------*/ void DumpTemplateElement (Element el, Document doc) { #ifdef TEMPLATE_DEBUG ElementType elType; AttributeType attType; Attribute att; SSchema schema = TtaGetSSchema ("Template", doc); char* str; char buffer[MAX_LENGTH]; int len; Language lang; if (el && doc) { elType = TtaGetElementType(el); printf("- %p %d ", elType.ElSSchema, elType.ElTypeNum); printf(" %s", TtaGetSSchemaName(elType.ElSSchema)); printf(":%s", TtaGetElementTypeName(elType)); if (elType.ElTypeNum == 1) { len = MAX_LENGTH-1; TtaGiveTextContent(el, (unsigned char*)buffer, &len, &lang); buffer[len] = EOS; printf(" \"%s\"", buffer); } if (elType.ElSSchema == schema) { switch(elType.ElTypeNum) { case Template_EL_head: str = GetAttributeStringValueFromNum(el, Template_ATTR_version, NULL); printf(" version=%s", str); TtaFreeMemory(str); str = GetAttributeStringValueFromNum(el, Template_ATTR_templateVersion, NULL); printf(" templateVersion=%s", str); TtaFreeMemory(str); break; case Template_EL_component: str = GetAttributeStringValueFromNum(el, Template_ATTR_name, NULL); printf(" name=%s", str); TtaFreeMemory(str); break; case Template_EL_union: str = GetAttributeStringValueFromNum(el, Template_ATTR_name, NULL); printf(" name=%s", str); TtaFreeMemory(str); str = GetAttributeStringValueFromNum(el, Template_ATTR_includeAt, NULL); printf(" include=%s", str); TtaFreeMemory(str); str = GetAttributeStringValueFromNum(el, Template_ATTR_exclude, NULL); printf(" exclude=%s", str); TtaFreeMemory(str); break; case Template_EL_import: str = GetAttributeStringValueFromNum(el, Template_ATTR_src, NULL); printf(" src=%s", str); TtaFreeMemory(str); break; case Template_EL_repeat: str = GetAttributeStringValueFromNum(el, Template_ATTR_title, NULL); printf(" label=%s", str); TtaFreeMemory(str); str = GetAttributeStringValueFromNum(el, Template_ATTR_minOccurs, NULL); printf(" minOccurs=%s", str); TtaFreeMemory(str); str = GetAttributeStringValueFromNum(el, Template_ATTR_maxOccurs, NULL); printf(" maxOccurs=%s", str); TtaFreeMemory(str); break; case Template_EL_useSimple: case Template_EL_useEl: str = GetAttributeStringValueFromNum(el, Template_ATTR_title, NULL); printf (" label=%s", str); TtaFreeMemory(str); str = GetAttributeStringValueFromNum(el, Template_ATTR_types, NULL); printf (" types=%s", str); TtaFreeMemory(str); attType.AttrSSchema = elType.ElSSchema; attType.AttrTypeNum = Template_ATTR_option; att = TtaGetAttribute (el, attType); if (att) printf (" option"); break; case Template_EL_bag: str = GetAttributeStringValueFromNum(el, Template_ATTR_title, NULL); printf(" label=%s", str); TtaFreeMemory(str); str = GetAttributeStringValueFromNum(el, Template_ATTR_types, NULL); printf(" types=%s", str); TtaFreeMemory(str); break; case Template_EL_attribute: str = GetAttributeStringValueFromNum(el, Template_ATTR_ref_name, NULL); printf (" name=%s", str); TtaFreeMemory(str); str = GetAttributeStringValueFromNum(el, Template_ATTR_type, NULL); printf (" type=%s", str); TtaFreeMemory(str); str = GetAttributeStringValueFromNum(el, Template_ATTR_useAt, NULL); printf (" use=%s", str); TtaFreeMemory(str); str = GetAttributeStringValueFromNum(el, Template_ATTR_defaultAt, NULL); printf (" default=%s", str); TtaFreeMemory(str); str = GetAttributeStringValueFromNum(el, Template_ATTR_fixed, NULL); printf (" fixed=%s", str); TtaFreeMemory(str); break; } } } #endif /* TEMPLATE_DEBUG */ }
/*---------------------------------------------------------------------- GetStyleContents returns a buffer that contains the whole text of the style element el. It returns NULL if the element is empty. The buffer should be freed by the caller. ----------------------------------------------------------------------*/ char *GetStyleContents (Element el) { ElementType elType; Element text; Attribute attr; AttributeType attrType; CSSmedia media = CSS_ALL; Language lang; char *buffer, *name; int length, i, j; ThotBool loadcss; buffer = NULL; /* check if we have to load CSS */ TtaGetEnvBoolean ("LOAD_CSS", &loadcss); if (loadcss && el) { /* check the media type of the element */ elType = TtaGetElementType (el); attrType.AttrSSchema = elType.ElSSchema; name = TtaGetSSchemaName (attrType.AttrSSchema); if (!strcmp (name, "HTML")) attrType.AttrTypeNum = HTML_ATTR_media; #ifdef _SVG else if (!strcmp (name, "HTML")) attrType.AttrTypeNum = SVG_ATTR_media; #endif /* _SVG */ else attrType.AttrTypeNum = 0; if (attrType.AttrTypeNum) { attr = TtaGetAttribute (el, attrType); if (attr) { length = TtaGetTextAttributeLength (attr); name = (char *)TtaGetMemory (length + 1); TtaGiveTextAttributeValue (attr, name, &length); media = CheckMediaCSS (name); TtaFreeMemory (name); } } /* get enough space to store UTF-8 characters */ length = TtaGetElementVolume (el) * 6 + 1; if ((media == CSS_ALL || media == CSS_SCREEN) && length > 1) { /* get the length of the included text */ buffer = (char *)TtaGetMemory (length); /* fill the buffer */ elType.ElTypeNum = 1 /* 1 = TEXT_UNIT element */; text = TtaSearchTypedElementInTree (elType, SearchForward, el, el); i = 0; while (text != NULL) { j = length - i; TtaGiveTextContent (text, (unsigned char *)&buffer[i], &j, &lang); i += TtaGetTextLength (text); text = TtaSearchTypedElementInTree (elType, SearchForward, el, text); } buffer[i] = EOS; } } return (buffer); }