Annotation of Amaya/amaya/insertelem.c, revision 1.2
1.1 kia 1: /*
2: *
3: * COPYRIGHT INRIA and W3C, 1996-2005
4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
7:
8: /*
9: * Authors: Emilien Kia
10: *
11: */
12:
13: #define THOT_EXPORT extern
14: #include "amaya.h"
15: #include "document.h"
16:
17: #include "containers.h"
18: #include "Elemlist.h"
19:
20: #ifdef TEMPLATES
21: #include "Template.h"
22: #include "templates.h"
23: #include "templates_f.h"
24: #include "templateDeclarations.h"
25:
26: #include "mydictionary_f.h"
27: #include "templateLoad_f.h"
28: #include "templateDeclarations_f.h"
29: #include "templateInstantiate_f.h"
30: #include "appdialogue_wx.h"
31: #include "init_f.h"
32: #include "wxdialogapi_f.h"
33: #include "AHTURLTools_f.h"
34:
35: #endif /* TEMPLATES */
36:
37:
38: #include "fetchXMLname_f.h"
39: #include "MENUconf.h"
40: #include "parser.h"
41: #include "fetchXMLname_f.h"
42:
1.2 ! cvs 43: typedef struct _sInsertableElementList *InsertableElementList;
! 44: typedef struct _sInsertableElementList
1.1 kia 45: {
46: /** Current selected element.*/
47: Element elem;
48: /** Insertable element list.*/
49: DLList list;
1.2 ! cvs 50: } sInsertableElementList;
1.1 kia 51:
52:
53: static HashMap InsertableElementMap = NULL;
54:
55:
56: static InsertableElementList InsertableElementList_Create(Element elem, DLList list)
57: {
58: InsertableElementList lst = (InsertableElementList)TtaGetMemory(sizeof(sInsertableElementList));
59: lst->elem = elem;
60: lst->list = list;
61: return lst;
62: }
63:
64: static void InsertableElementList_Destroy(InsertableElementList list)
65: {
66: if(list->list)
67: DLList_Destroy(list->list);
68: TtaFreeMemory(list);
69: }
70:
71: /*----------------------------------------------------------------------
72: InsertableElement_Init
73: Initialize the module.
74: ----------------------------------------------------------------------*/
75:
76: void InsertableElement_Init()
77: {
78: if(!InsertableElementMap)
79: InsertableElementMap = PointerHashMap_Create((Container_DestroyElementFunction)InsertableElementList_Destroy, 32);
80: }
81:
82: /*----------------------------------------------------------------------
83: InsertableElement_Final
84: Finalize the module.
85: ----------------------------------------------------------------------*/
86:
87: void InsertableElement_Final()
88: {
89: if(InsertableElementMap)
90: {
91: HashMap_Destroy(InsertableElementMap);
92: InsertableElementMap = NULL;
93: }
94: }
95:
96:
97:
98:
99: #ifdef TEMPLATES
100:
101: /*----------------------------------------------------------------------
102: FillUnionResolvedPossibleElement
103: Fill an element list with all possible element, resolving them if union.
104: @param name Element name
105: @param elem Document element to attach
106: @param resolvedPath Path of different succesive union name.
107: @param list List to fill.
108: ----------------------------------------------------------------------*/
109: static void FillUnionResolvedPossibleElement(XTigerTemplate t, const char* name, Element elem, const char* resolvedPath, DLList list, int level)
110: {
111: Declaration dec = GetDeclaration (t, name);
112: if(dec->declaredIn->isPredefined)
113: {
114: DLList_Append(list, ElemListElement_CreateComponent(level, dec->name, (void*)dec, resolvedPath, elem));
115: }
116: else if(dec->nature==ComponentNat)
117: {
118: DLList_Append(list, ElemListElement_CreateComponent(level, dec->name, (void*)dec, resolvedPath, elem));
119: }
120: else if(dec->nature==UnionNat)
121: {
122: DLList tempList = ElemList_Create();
123:
124: Record first = dec->unionType.include->first;
125: Record rec = first;
126:
127: int len1 = 0 , len2 = strlen(dec->name);
128: if(resolvedPath!=NULL)
129: len1 = strlen(resolvedPath);
130: char* newPath = (char*)TtaGetMemory(len1+len2+2);
131: if(len1>0)
132: {
133: strcpy(newPath, resolvedPath);
134: newPath[len1] = '/';
135: strcpy(newPath+len1+1, dec->name);
136: }
137: else
138: {
139: strcpy(newPath, dec->name);
140: }
141:
142: while(rec)
143: {
144: FillUnionResolvedPossibleElement(t, rec->key, elem, newPath, tempList, level);
145: rec = rec->next;
146: }
147:
148: ForwardIterator iter = DLList_GetForwardIterator(tempList);
149: DLListNode node = (DLListNode) ForwardIterator_GetFirst(iter);
150: while(node)
151: {
152: DLList_Append(list, node->elem);
153: node = (DLListNode) ForwardIterator_GetNext(iter);
154: }
155: tempList->destroyElement = NULL;
156: DLList_Destroy(tempList);
157:
158: TtaFreeMemory(newPath);
159:
160: /** todo Remove excluded elements.*/
161: }
162: else if(dec->nature==SimpleTypeNat)
163: {
164: DLList_Append(list, ElemListElement_CreateBaseType(level, dec->name, resolvedPath, elem));
165: /* Do nothing. */
166: }
167: else
168: {
169: /* Search in tgt std elements. */
170: int xmlType; /* See parser.h */
171: for(xmlType=XHTML_TYPE; xmlType<Template_TYPE; xmlType++)
172: {
173: ElementType elType = {0,0};
174: char* mappedName;
1.2 ! cvs 175: char content;
1.1 kia 176: ThotBool checkProfile;
1.2 ! cvs 177: MapXMLElementType(xmlType, dec->name, &elType, &mappedName, &content, &checkProfile, TtaGetDocument(elem));
1.1 kia 178: if(elType.ElTypeNum!=0)
179: {
180: DLList_Append(list, ElemListElement_CreateLanguageElement(level, elType, resolvedPath, elem));
181: break;
182: }
183: }
184: }
185: }
186:
187: /*----------------------------------------------------------------------
188: FillInsertableTemplateElementFromStringList
189: Fill an element list with all possible elements extracted from a stringlist.
190: ----------------------------------------------------------------------*/
191: static void FillInsertableTemplateElementFromStringList(XTigerTemplate t, Element refelem, const char* strlist, DLList list, int level)
192: {
193: int pos = 0,
194: offset = 0;
195: int size = strlen(strlist);
196: char* types = strdup(strlist);
197: while(pos<size)
198: {
199: if(isEOSorWhiteSpace(types[pos]))
200: {
201: if(pos>offset)
202: {
203: types[pos] = 0;
204: FillUnionResolvedPossibleElement(t, types+offset, refelem, NULL, list, level);
205: }
206: offset = pos+1;
207: }
208: pos++;
209: }
210: if(pos>offset)
211: {
212: types[pos] = 0;
213: FillUnionResolvedPossibleElement(t, types+offset, refelem, NULL, list, level);
214: }
215: TtaFreeMemory(types);
216: }
217:
218:
219: /*----------------------------------------------------------------------
220: FillInsertableElementFromElemAttribute
221: Fill an element list with all possible elements from an attribute list.
222: ----------------------------------------------------------------------*/
223: static void FillInsertableElementFromElemAttribute(XTigerTemplate t, Element elem, int attrib, DLList list, int level)
224: {
225: ElementType type = TtaGetElementType(elem);
226: AttributeType attributeType = {type.ElSSchema, attrib};
227: Attribute att = TtaGetAttribute (elem, attributeType);
228: int size = TtaGetTextAttributeLength (att);
229: char* types = (char *) TtaGetMemory (size+1);
230: TtaGiveTextAttributeValue (att, types, &size);
231: FillInsertableTemplateElementFromStringList(t, elem, types, list, level);
232: }
233: #endif/* TEMPLATES */
234:
235: /*----------------------------------------------------------------------
236: FillInsertableElemList
237: Fill an element list with all insertable elements (base element or
238: XTiger comonent).
239: ----------------------------------------------------------------------*/
240: static void FillInsertableElemList(Document doc, Element elem, DLList list)
241: {
1.2 ! cvs 242: int level;
! 243: ThotBool cont;
! 244:
1.1 kia 245: if(elem){
246: if(doc==0)
247: doc = TtaGetDocument(elem);
248:
249: #ifdef TEMPLATES
250: XTigerTemplate t = (XTigerTemplate) Dictionary_Get (Templates_Dic, DocumentMeta[doc]->template_url);
251: #endif/* TEMPLATES */
252:
1.2 ! cvs 253: level = 0;
! 254: cont = TRUE;
1.1 kia 255:
256: while(elem!=NULL && cont)
257: {
258: ElementType type = TtaGetElementType(elem);
259: Element child;
260: ElementType childType;
261: switch(type.ElTypeNum)
262: {
263: #ifdef TEMPLATES
264: case Template_EL_repeat:
265: child = TtaGetFirstChild(elem);
266: childType = TtaGetElementType(child);
267: switch(childType.ElTypeNum)
268: {
269: case Template_EL_useEl:
270: case Template_EL_useSimple:
271: FillInsertableElementFromElemAttribute(t, child, Template_ATTR_types, list, level);
272: break;
273: case Template_EL_bag:
274: FillInsertableElementFromElemAttribute(t, child, Template_ATTR_types, list, level);
275: break;
276: default:
277: break;
278: }
279: cont = FALSE;
280: break;
281: case Template_EL_useEl:
282: // Fill for xt:use only if have no child.
283: if(TtaGetFirstChild(elem)==NULL){
284: FillInsertableElementFromElemAttribute(t, elem, Template_ATTR_types, list, level);
285: cont = FALSE;
286: }
287: break;
288: case Template_EL_bag:
289: FillInsertableElementFromElemAttribute(t, elem, Template_ATTR_types, list, level);
290: cont = FALSE;
291: break;
292: #endif /*TEMPLATES */
293: default:
294: break;
295: }
296:
297: elem = TtaGetParent(elem);
298: level ++;
299: }
300: }
301: }
302:
303: /*----------------------------------------------------------------------
304: InsertableElement_GetList
305: Get the insertable element list for a document.
306: @param doc Document
307: @return The insertable element list or NULL.
308: ----------------------------------------------------------------------*/
309: DLList InsertableElement_GetList(Document doc)
310: {
311: InsertableElementList list = (InsertableElementList) HashMap_Get(InsertableElementMap, (void*)doc);
312: if(list!=NULL)
313: return list->list;
314: else
315: return NULL;
316: }
317:
318: /*----------------------------------------------------------------------
319: InsertableElement_Update
320: Update the insertable element list for a document.
321: @param el Selected element, cant be NULL.
322: @param document Document, can be NULL.
323: @param force No dont force the refresh of the list if the element is already selected.
324: @return List of insertable elements.
325: ----------------------------------------------------------------------*/
326: DLList InsertableElement_Update(Document doc, Element el, ThotBool force)
327: {
1.2 ! cvs 328: InsertableElementList list;
1.1 kia 329: if(doc==0)
330: doc= TtaGetDocument(el);
1.2 ! cvs 331: list = (InsertableElementList) HashMap_Get(InsertableElementMap, (void*)doc);
1.1 kia 332: if(list==NULL)
333: {
334: list = InsertableElementList_Create(0, DLList_Create());
335: HashMap_Set(InsertableElementMap, (void*)doc, list);
336: }
337: if(force || list->elem!=el){
338: DLList_Empty(list->list);
339: FillInsertableElemList(doc, el, list->list);
340: list->elem = el;
341: }
342: return list->list;
343: }
344:
345:
Webmaster