1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package com.sun.star.filter.config.tools.utils;
25 
26 //_______________________________________________
27 
28 import java.lang.*;
29 import java.util.*;
30 import java.io.*;
31 
32 //_______________________________________________
33 
34 /**
35  *  It implements a container for all possible entries which are part of the type
36  *  and filter mechanism of an office - means all items of the configuration file
37  *  "TypeDetection". How these entries will be read or written can be switch
38  *  in different modes. That would make it possible to edit an xml directly or
39  *  to contact a running office instance.
40  *
41  *
42  */
43 public class Cache
44 {
45     //___________________________________________
46     // public const
47 
48     /** identifies a file type item of this cache. */
49     public static final int E_TYPE = 0;
50 
51     /** identifies a filter item of this cache. */
52     public static final int E_FILTER = 1;
53 
54     /** identifies a detect service item of this cache. */
55     public static final int E_DETECTSERVICE = 2;
56 
57     /** identifies a frame loader item of this cache. */
58     public static final int E_FRAMELOADER = 3;
59 
60     /** identifies a content handler item of this cache. */
61     public static final int E_CONTENTHANDLER = 4;
62 
63     /** indicates an unsupported xml format => error! */
64     public static final int FORMAT_UNSUPPORTED = -1;
65 
66     /** identify the configuration format of an office 6.0.
67      *  The own formatted data string is used. */
68     public static final int FORMAT_60 = 0;
69 
70     /** identify the configuration format of an office 6.y.
71      *  Properties are really xml tags again. */
72     public static final int FORMAT_6Y = 1;
73 
74     /** identify the configuration format which is used inside
75      *  this tooling project. */
76     public static final int FORMAT_INTERNAL = 2;
77 
78     /** right value for a command line parameter to define a 6.0 version. */
79     public static final java.lang.String CMDVAL_FORMAT_60 = "6.0";
80 
81     /** right value for a command line parameter to define a 6.Y version. */
82     public static final java.lang.String CMDVAL_FORMAT_6Y = "6.Y";
83 
84     /** right value for a command line parameter to define an internal xml version! */
85     public static final java.lang.String CMDVAL_FORMAT_INTERNAL = "internal";
86 
87     // general
88     public static final java.lang.String PROPNAME_DATA = "Data";
89     public static final java.lang.String PROPNAME_NAME = "Name";
90     public static final java.lang.String PROPNAME_UINAME = "UIName";
91     public static final java.lang.String PROPNAME_UINAMES = "UINames";
92 
93     // type 6.0 ...
94     public static final java.lang.String PROPNAME_MEDIATYPE = "MediaType";
95     public static final java.lang.String PROPNAME_PREFERRED = "Preferred";
96     public static final java.lang.String PROPNAME_CLIPBOARDFORMAT = "ClipboardFormat";
97     public static final java.lang.String PROPNAME_DOCUMENTICONID = "DocumentIconID";
98     public static final java.lang.String PROPNAME_URLPATTERN = "URLPattern";
99     public static final java.lang.String PROPNAME_EXTENSIONS = "Extensions";
100     // ... +6.y
101     public static final java.lang.String PROPNAME_UIORDER = "UIOrder";
102     public static final java.lang.String PROPNAME_PREFERREDFILTER = "PreferredFilter";
103     public static final java.lang.String PROPNAME_DETECTSERVICE = "DetectService";
104     public static final java.lang.String PROPNAME_FRAMELOADER = "FrameLoader";
105     public static final java.lang.String PROPNAME_CONTENTHANDLER = "ContentHandler";
106 
107     // filter
108     public static final java.lang.String PROPNAME_DOCUMENTSERVICE = "DocumentService";
109     public static final java.lang.String PROPNAME_FILEFORMATVERSION = "FileFormatVersion";
110     public static final java.lang.String PROPNAME_FILTERSERVICE = "FilterService";
111     public static final java.lang.String PROPNAME_FLAGS = "Flags";
112     public static final java.lang.String PROPNAME_ORDER = "Order"; // -6.y
113     public static final java.lang.String PROPNAME_TEMPLATENAME = "TemplateName";
114     public static final java.lang.String PROPNAME_TYPE = "Type";
115     public static final java.lang.String PROPNAME_UICOMPONENT = "UIComponent";
116     public static final java.lang.String PROPNAME_USERDATA = "UserData";
117 
118     // frame loader / detect services / content handler
119     public static final java.lang.String PROPNAME_TYPES = "Types";
120 
121     //___________________________________________
122     // private const
123 
124     private static final java.lang.String FILTERSERVICE_NATIVEWARPPER = "com.sun.star.filter.NativeFilterWrapper";
125     private static final java.lang.String GENERIC_DETECTSERVICE = "com.sun.star.comp.office.FrameLoader";
126 
127     /** it's the name of the cfg set, which contains all types. */
128     private static final java.lang.String CFGNODE_TYPES = "Types";
129 
130     /** it's the name of the cfg set, which contains all filters. */
131     private static final java.lang.String CFGNODE_FILTERS = "Filters";
132 
133     /** it's the name of the cfg set, which contains all detect services. */
134     private static final java.lang.String CFGNODE_DETECTSERVICES = "DetectServices";
135 
136     /** it's the name of the cfg set, which contains all frame loaders. */
137     private static final java.lang.String CFGNODE_FRAMELOADERS = "FrameLoaders";
138 
139     /** it's the name of the cfg set, which contains all content handlers. */
140     private static final java.lang.String CFGNODE_CONTENTHANDLERS = "ContentHandlers";
141 
142     // names for filter flags
143     private static final java.lang.String FLAGNAME_3RDPARTYFILTER   = "3RDPARTYFILTER";
144     private static final java.lang.String FLAGNAME_ALIEN            = "ALIEN";
145     private static final java.lang.String FLAGNAME_ASYNCHRON        = "ASYNCHRON";
146     private static final java.lang.String FLAGNAME_BROWSERPREFERRED = "BROWSERPREFERRED";
147     private static final java.lang.String FLAGNAME_CONSULTSERVICE   = "CONSULTSERVICE";
148     private static final java.lang.String FLAGNAME_DEFAULT          = "DEFAULT";
149     private static final java.lang.String FLAGNAME_EXPORT           = "EXPORT";
150     private static final java.lang.String FLAGNAME_IMPORT           = "IMPORT";
151     private static final java.lang.String FLAGNAME_INTERNAL         = "INTERNAL";
152     private static final java.lang.String FLAGNAME_NOTINCHOOSER     = "NOTINCHOOSER";
153     private static final java.lang.String FLAGNAME_NOTINFILEDIALOG  = "NOTINFILEDIALOG";
154     private static final java.lang.String FLAGNAME_NOTINSTALLED     = "NOTINSTALLED";
155     private static final java.lang.String FLAGNAME_OWN              = "OWN";
156     private static final java.lang.String FLAGNAME_PACKED           = "PACKED";
157     private static final java.lang.String FLAGNAME_PREFERRED        = "PREFERRED";
158     private static final java.lang.String FLAGNAME_READONLY         = "READONLY";
159     private static final java.lang.String FLAGNAME_TEMPLATE         = "TEMPLATE";
160     private static final java.lang.String FLAGNAME_TEMPLATEPATH     = "TEMPLATEPATH";
161     private static final java.lang.String FLAGNAME_USESOPTIONS      = "USESOPTIONS";
162 
163     private static final java.lang.String FLAGNAME_COMBINED         = "COMBINED";
164     private static final java.lang.String FLAGNAME_SUPPORTSSELECTION= "SUPPORTSSELECTION";
165 
166     // values for filter flags
167     private static final int FLAGVAL_3RDPARTYFILTER    = 0x00080000; // 524288
168     private static final int FLAGVAL_ALIEN             = 0x00000040; // 64
169     private static final int FLAGVAL_ALL               = 0xffffffff; // 4294967295
170     private static final int FLAGVAL_ASYNCHRON         = 0x00004000; // 16384
171     private static final int FLAGVAL_BROWSERPREFERRED  = 0x00400000; // 4194304
172     private static final int FLAGVAL_CONSULTSERVICE    = 0x00040000; // 262144
173     private static final int FLAGVAL_DEFAULT           = 0x00000100; // 256
174     private static final int FLAGVAL_EXPORT            = 0x00000002; // 2
175     private static final int FLAGVAL_IMPORT            = 0x00000001; // 1
176     private static final int FLAGVAL_INTERNAL          = 0x00000008; // 8
177     private static final int FLAGVAL_NOTINCHOOSER      = 0x00002000; // 8192
178     private static final int FLAGVAL_NOTINFILEDIALOG   = 0x00001000; // 4096
179     private static final int FLAGVAL_NOTINSTALLED      = 0x00020000; // 131072
180     private static final int FLAGVAL_OWN               = 0x00000020; // 32
181     private static final int FLAGVAL_PACKED            = 0x00100000; // 1048576
182     private static final int FLAGVAL_PREFERRED         = 0x10000000; // 268435456
183     private static final int FLAGVAL_READONLY          = 0x00010000; // 65536
184     private static final int FLAGVAL_TEMPLATE          = 0x00000004; // 4
185     private static final int FLAGVAL_TEMPLATEPATH      = 0x00000010; // 16
186     private static final int FLAGVAL_USESOPTIONS       = 0x00000080; // 128
187 
188     private static final int FLAGVAL_COMBINED          = 0x00800000; // ...
189     private static final int FLAGVAL_SUPPORTSSELECTION = 0x00000400; // 1024
190 
191     //___________________________________________
192     // member
193 
194     /** list of all located types.
195      *  Format: [string,HashMap]
196      */
197     private java.util.HashMap m_lTypes;
198 
199     /** list of all located filters.
200      *  Format: [string,HashMap]
201      */
202     private java.util.HashMap m_lFilters;
203 
204     /** list of all located detect services.
205      *  Format: [string,HashMap]
206      */
207     private java.util.HashMap m_lDetectServices;
208 
209     /** list of all located frame loader.
210      *  Format: [string,HashMap]
211      */
212     private java.util.HashMap m_lFrameLoaders;
213 
214     /** list of all located content handler.
215      *  Format: [string,HashMap]
216      */
217     private java.util.HashMap m_lContentHandlers;
218 
219     /** contains all analyzed relations between
220      *  filters and types. The key is an internal
221      *  type name (can be used as reference into the
222      *  list m_lTypes) and the value is a Vector of all
223      *  internal filter names, which are registered for
224      *  this type.
225      *  Format: [string, Vector]
226      */
227     private java.util.HashMap m_lFilterToTypeRegistrations;
228 
229     private int m_nDoubleRegisteredFilters;
230     private int m_nTypesForFilters;
231     private int m_nTypesForDetectServices;
232     private int m_nTypesForFrameLoaders;
233     private int m_nTypesForContentHandlers;
234 
235     /** can be used to log different information. */
236     private Logger m_aDebug;
237 
238     //___________________________________________
239     // interface
240 
241     /** standard ctor.
242      *
243      *  Initialize an empty cache instance. You have to use
244      *  on of the fromXXX() methods to fill it from different
245      *  sources with content.
246      */
Cache(Logger aDebug)247     public Cache(Logger aDebug)
248     {
249         reset();
250         m_aDebug = aDebug;
251     }
252 
253     //___________________________________________
254 
255     /** free memory and set default values on all members.
256      */
reset()257     public synchronized void reset()
258     {
259         m_lTypes                     = new java.util.HashMap();
260         m_lFilters                   = new java.util.HashMap();
261         m_lFrameLoaders              = new java.util.HashMap();
262         m_lDetectServices            = new java.util.HashMap();
263         m_lContentHandlers           = new java.util.HashMap();
264         m_lFilterToTypeRegistrations = new java.util.HashMap();
265         m_aDebug                     = new Logger();
266         m_nDoubleRegisteredFilters   = 0;
267         m_nTypesForFilters           = 0;
268         m_nTypesForDetectServices    = 0;
269         m_nTypesForFrameLoaders      = 0;
270         m_nTypesForContentHandlers   = 0;
271     }
272 
273     //___________________________________________
274 
275     /** converts a string representation of an xml format
276      *  to its int value, which must be used at some interface
277      *  methods of this cache.
278      *
279      *  If the given string does not match to any well known format,
280      *  the return value will be FORMAT_UNSUPPORTED. The calls have to
281      *  check that. Otherwise a called interface method at this cache
282      *  instance will be rejected by an exception!
283      *
284      *  @param  sFormat
285      *          the string representation
286      *          Must be one of our public const values from type CMDVAL_FORMAT_xxx.
287      *
288      *  @return [int]
289      *          the int representation.
290      *          Will be one of our public const values from type FORMAT_xxx.
291      */
mapFormatString2Format(java.lang.String sFormat)292     public static int mapFormatString2Format(java.lang.String sFormat)
293     {
294         int nFormat = FORMAT_UNSUPPORTED;
295         if (sFormat.equalsIgnoreCase(CMDVAL_FORMAT_60))
296             nFormat = FORMAT_60;
297         else
298         if (sFormat.equalsIgnoreCase(CMDVAL_FORMAT_6Y))
299             nFormat = FORMAT_6Y;
300         else
301         if (sFormat.equalsIgnoreCase(CMDVAL_FORMAT_INTERNAL))
302             nFormat = FORMAT_INTERNAL;
303         return nFormat;
304     }
305 
306     //___________________________________________
307 
308     /** return some statistic values.
309      *
310      *  Such values can be: - count of container items,
311      *                      - ...
312      *
313      *  @return [java.lang.String]
314      *          a formatted string, which contains al statistic data.
315      */
getStatistics()316     public synchronized java.lang.String getStatistics()
317     {
318         java.lang.StringBuffer sBuffer = new java.lang.StringBuffer(256);
319 
320         sBuffer.append("types                          = "+m_lTypes.size()           +"\n");
321         sBuffer.append("filters                        = "+m_lFilters.size()         +"\n");
322         sBuffer.append("detect services                = "+m_lDetectServices.size()  +"\n");
323         sBuffer.append("frame loaders                  = "+m_lFrameLoaders.size()    +"\n");
324         sBuffer.append("content handler                = "+m_lContentHandlers.size() +"\n");
325         sBuffer.append("double registered filters      = "+m_nDoubleRegisteredFilters+"\n");
326         sBuffer.append("types used by filters          = "+m_nTypesForFilters        +"\n");
327         sBuffer.append("types used by detect services  = "+m_nTypesForDetectServices +"\n");
328         sBuffer.append("types used by frame loaders    = "+m_nTypesForFrameLoaders   +"\n");
329         sBuffer.append("types used by content handlers = "+m_nTypesForContentHandlers+"\n");
330 
331         return sBuffer.toString();
332     }
333 
334     //___________________________________________
335 
336     /** reset this cache and fill it with new values using the given XML file.
337      *
338      *  @param  aXML
339      *          must be a system file of a suitable XML file, which
340      *          include all necessary type/filter items.
341      *
342      *  @param  nFormat
343      *          identifies the format of the specified xml file,
344      *          which must be interpreted.
345      */
fromXML(java.io.File aXML , int nFormat)346     public synchronized void fromXML(java.io.File aXML   ,
347                                      int          nFormat)
348         throws java.lang.Exception
349     {
350         // clear this cache
351         reset();
352 
353         // parse it
354         javax.xml.parsers.DocumentBuilderFactory aFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
355         /* Attention:
356          *  This call is important. It forces right handling of entities during parsing and(!)
357          *  writing. It let all possible signs for entities or its quoted representations
358          *  untouched. So this class don't change the original signs of the original file.
359          *  Means:
360          *      <ul>
361          *          <li>(') => (')</li>
362          *          <li>(") => (")</li>
363          *          <li>(>) => (&gt;)</li>
364          *          <li>(<) => (&lt;)</li>
365          *          <li>(&gt;) => (&gt;)</li>
366          *          <li>(&amp;) => (&amp;)</li>
367          *          <li>...</li>
368          *      </ul>
369          */
370 
371         System.out.println("TODO: must be adapted to java 1.3 :-(");
372         System.exit(-1);
373 //TODO_JAVA        aFactory.setExpandEntityReferences(false);
374 
375         javax.xml.parsers.DocumentBuilder aBuilder = aFactory.newDocumentBuilder();
376         org.w3c.dom.Document              aDOM     = aBuilder.parse(aXML);
377         org.w3c.dom.Element               aRoot    = aDOM.getDocumentElement();
378 
379         // step over all sets
380         java.util.Vector      lSetNodes = XMLHelper.extractChildNodesByTagName(aRoot, XMLHelper.XMLTAG_NODE);
381         java.util.Enumeration it1       = lSetNodes.elements();
382         while (it1.hasMoreElements())
383         {
384             // try to find out, which set should be read
385             org.w3c.dom.Node aSetNode = (org.w3c.dom.Node)it1.nextElement();
386             java.lang.String sSetName = XMLHelper.extractNodeAttribByName(aSetNode, XMLHelper.XMLATTRIB_OOR_NAME);
387             if (sSetName == null)
388                 throw new java.io.IOException("unsupported format: could not extract set name on node ...\n"+aSetNode);
389 
390             // map some generic interfaces to the right members!
391             int               eType = -1  ;
392             java.util.HashMap rMap  = null;
393 
394             if (sSetName.equals(CFGNODE_TYPES))
395             {
396                 eType = E_TYPE;
397                 rMap  = m_lTypes;
398             }
399             else
400             if (sSetName.equals(CFGNODE_FILTERS))
401             {
402                 eType = E_FILTER;
403                 rMap  = m_lFilters;
404             }
405             else
406             if (sSetName.equals(CFGNODE_FRAMELOADERS))
407             {
408                 eType = E_FRAMELOADER;
409                 rMap  = m_lFrameLoaders;
410             }
411             else
412             if (sSetName.equals(CFGNODE_DETECTSERVICES))
413             {
414                 eType = E_DETECTSERVICE;
415                 rMap  = m_lDetectServices;
416             }
417             else
418             if (sSetName.equals(CFGNODE_CONTENTHANDLERS))
419             {
420                 eType = E_CONTENTHANDLER;
421                 rMap  = m_lContentHandlers;
422             }
423             else
424                 throw new java.io.IOException("unsupported format: unknown set name [\""+sSetName+"\"] detected on node ...\n"+aSetNode);
425 
426             // load all set entries
427             java.util.Vector      lChildNodes = XMLHelper.extractChildNodesByTagName(aSetNode, XMLHelper.XMLTAG_NODE);
428             java.util.Enumeration it2         = lChildNodes.elements();
429             while (it2.hasMoreElements())
430             {
431                 org.w3c.dom.Node aChildNode = (org.w3c.dom.Node)it2.nextElement();
432                 java.lang.String sChildName = XMLHelper.extractNodeAttribByName(aChildNode, XMLHelper.XMLATTRIB_OOR_NAME);
433                 if (sChildName == null)
434                     throw new java.io.IOException("unsupported format: could not extract child node name on node ...\n"+aChildNode);
435                 java.util.HashMap aPropSet = null;
436 
437                 // Note: Our internal format is different from the source format!
438                 java.util.HashMap aTempSet = XMLHelper.convertNodeToPropSet(aChildNode);
439                 switch(eType)
440                 {
441                     case E_TYPE :
442                     {
443                         aPropSet = Cache.convertTypePropsToInternal(aTempSet, nFormat);
444                         m_aDebug.setDetailedInfo("type [\""+sChildName+"\"] converted to internal format");
445                     }
446                     break;
447 
448                     case E_FILTER :
449                     {
450                         aPropSet = Cache.convertFilterPropsToInternal(aTempSet, nFormat);
451                         m_aDebug.setDetailedInfo("filter [\""+sChildName+"\"] converted to internal format");
452                     }
453                     break;
454 
455                     case E_DETECTSERVICE :
456                     {
457                         aPropSet = Cache.convertDetectServicePropsToInternal(aTempSet, nFormat);
458                         m_aDebug.setDetailedInfo("detect service [\""+sChildName+"\"] converted to internal format");
459                     }
460                     break;
461 
462                     case E_FRAMELOADER :
463                     {
464                         aPropSet = Cache.convertFrameLoaderPropsToInternal(aTempSet, nFormat);
465                         m_aDebug.setDetailedInfo("frame loader [\""+sChildName+"\"] converted to internal format");
466                     }
467                     break;
468 
469                     case E_CONTENTHANDLER :
470                     {
471                         aPropSet = Cache.convertContentHandlerPropsToInternal(aTempSet, nFormat);
472                         m_aDebug.setDetailedInfo("content handler [\""+sChildName+"\"] converted to internal format");
473                     }
474                     break;
475                 }
476                 m_aDebug.setDetailedInfo("props = "+aTempSet);
477                 rMap.put(sChildName, aPropSet);
478             }
479         }
480     }
481 
482     //___________________________________________
483 
484     /** create some html views of the current content of this cache.
485      *
486      *  The given directory is used to create different html files
487      *  there. Every of them show another aspect of this cache.
488      *  E.g.: - all type/filter properties
489      *        - relation ships between types/filters/loaders etc.
490      *
491      *  @param  aDirectory
492      *          points to a system directory, which
493      *          can be used completely(!) to generate
494      *          the results there.
495      *
496      *  @param  nFormat
497      *          specify in which context the cache items should be
498      *          interpreted.
499      */
toHTML(java.io.File aDirectory, int nFormat , java.lang.String sEncoding )500     public synchronized void toHTML(java.io.File     aDirectory,
501                                     int              nFormat   ,
502                                     java.lang.String sEncoding )
503         throws java.lang.Exception
504     {
505         if (nFormat != FORMAT_6Y)
506             throw new java.lang.Exception("HTML views are supported for the new 6.y format only yet.");
507 
508         java.lang.StringBuffer sRelationView = new java.lang.StringBuffer(1000);
509         sRelationView.append("<html><header><title>Relation View</title></header><body>");
510         sRelationView.append("<table border=1>");
511         sRelationView.append("<tr><td><b>type</b></td><td><b>detect service</b></td><td><b>preferred filter</b></td><td><b>frame loader</b></td><td><b>content handler</b></td></tr>");
512 
513         java.util.Iterator aIt = m_lTypes.keySet().iterator();
514         while (aIt.hasNext())
515         {
516             java.lang.String  sType = (java.lang.String)aIt.next();
517             java.util.HashMap aType = (java.util.HashMap)m_lTypes.get(sType);
518 
519             sRelationView.append("<tr>");
520             sRelationView.append("<td>"+sType+"</td>");
521 
522             java.lang.String sVal = (java.lang.String)aType.get(PROPNAME_DETECTSERVICE);
523             if (sVal == null || sVal.length()<1)
524                 sRelationView.append("<td> - </td>");
525             else
526                 sRelationView.append("<td>"+sVal+"</td>");
527 
528             sVal = (java.lang.String)aType.get(PROPNAME_PREFERREDFILTER);
529             if (sVal == null || sVal.length()<1)
530                 sRelationView.append("<td> - </td>");
531             else
532                 sRelationView.append("<td>"+sVal+"</td>");
533 
534             sVal = (java.lang.String)aType.get(PROPNAME_FRAMELOADER);
535             if (sVal == null || sVal.length()<1)
536                 sRelationView.append("<td> - </td>");
537             else
538                 sRelationView.append("<td>"+sVal+"</td>");
539 
540             sVal = (java.lang.String)aType.get(PROPNAME_CONTENTHANDLER);
541             if (sVal == null || sVal.length()<1)
542                 sRelationView.append("<td> - </td>");
543             else
544                 sRelationView.append("<td>"+sVal+"</td>");
545 
546             sRelationView.append("</tr>");
547         }
548 
549         sRelationView.append("</table>");
550         sRelationView.append("</body>");
551 
552         FileHelper.writeEncodedBufferToFile(new java.io.File(aDirectory, "relation_view.html"), sEncoding, false, sRelationView);
553 
554         java.util.HashMap lFilters2TypeRegistration = new java.util.HashMap();
555         aIt = m_lFilters.keySet().iterator();
556         while (aIt.hasNext())
557         {
558             java.lang.String  sFilter = (java.lang.String)aIt.next();
559             java.util.HashMap aFilter = (java.util.HashMap)m_lFilters.get(sFilter);
560             java.lang.String  sType   = (java.lang.String)aFilter.get(PROPNAME_TYPE);
561 
562             java.util.Vector lFilters = (java.util.Vector)lFilters2TypeRegistration.get(sType);
563             if (lFilters == null)
564                 lFilters = new java.util.Vector();
565             lFilters.add(sFilter);
566             lFilters2TypeRegistration.put(sType, lFilters);
567         }
568 
569         java.lang.StringBuffer sType2FiltersView = new java.lang.StringBuffer(1000);
570         sType2FiltersView.append("<html><header><title>Type2Filters View</title></header><body>");
571         sType2FiltersView.append("<table border=1>");
572         sType2FiltersView.append("<tr><td><b>type</b></td><td><b>filters</b></td></tr>");
573 
574         aIt = lFilters2TypeRegistration.keySet().iterator();
575         while (aIt.hasNext())
576         {
577             java.lang.String sType    = (java.lang.String)aIt.next();
578             java.util.Vector lFilters = (java.util.Vector)lFilters2TypeRegistration.get(sType);
579 
580             sType2FiltersView.append("<tr><td>"+sType+"</td><td>");
581             java.util.Enumeration aEn = lFilters.elements();
582             while(aEn.hasMoreElements())
583                 sType2FiltersView.append(aEn.nextElement()+"<br>");
584             sType2FiltersView.append("</td></tr>");
585         }
586 
587         sType2FiltersView.append("</table>");
588         sType2FiltersView.append("</body>");
589 
590         FileHelper.writeEncodedBufferToFile(new java.io.File(aDirectory, "type2filters_view.html"), sEncoding, false, sType2FiltersView);
591     }
592 
593     //___________________________________________
594 
595     /** converts all items of this cache to its xml representation
596      *  and write it to the given file.
597      *
598      *  @param  aXML
599      *          the target file for output.
600      *
601      *  @param  nFormat
602      *          the requested xml format.
603      *          see const values FORMAT_xxx too.
604      *
605      *  @param  sEncoding
606      *          specify the file encoding for the generated xml file.
607      *
608      *  @throws [java.lang.Exception]
609      *          if something fail during conversion.
610      */
toXML(java.io.File aXML , int nFormat , java.lang.String sEncoding)611     public synchronized void toXML(java.io.File     aXML     ,
612                                    int              nFormat  ,
613                                    java.lang.String sEncoding)
614         throws java.lang.Exception
615     {
616         java.lang.StringBuffer sXML = new java.lang.StringBuffer(500000);
617 
618         for (int i=0; i<5; ++i)
619         {
620             // define right sub container
621             java.lang.String  sSetName = null;
622             java.util.HashMap rMap     = null;
623             int               eType    = -1;
624 
625             switch(i)
626             {
627                 case 0 :
628                 {
629                     sSetName = CFGNODE_TYPES;
630                     rMap     = m_lTypes;
631                     eType    = E_TYPE;
632                 }
633                 break;
634 
635                 case 1 :
636                 {
637                     sSetName = CFGNODE_FILTERS;
638                     rMap     = m_lFilters;
639                     eType    = E_FILTER;
640                 }
641                 break;
642 
643                 case 2 :
644                 {
645                     sSetName = CFGNODE_DETECTSERVICES;
646                     rMap     = m_lDetectServices;
647                     eType    = E_DETECTSERVICE;
648                 }
649                 break;
650 
651                 case 3 :
652                 {
653                     sSetName = CFGNODE_FRAMELOADERS;
654                     rMap     = m_lFrameLoaders;
655                     eType    = E_FRAMELOADER;
656                 }
657                 break;
658 
659                 case 4 :
660                 {
661                     sSetName = CFGNODE_CONTENTHANDLERS;
662                     rMap     = m_lContentHandlers;
663                     eType    = E_CONTENTHANDLER;
664                 }
665                 break;
666             }
667 
668             // generate set
669             sXML.append("<node oor:name=\""+sSetName+"\" oor:op=\"replace\">\n");
670             java.util.Iterator it = rMap.keySet().iterator();
671             while(it.hasNext())
672             {
673                 java.lang.String sItem = (java.lang.String)it.next();
674                 sXML.append("<node oor:name=\""+sItem+"\" oor:op=\"replace\">\n");
675                 sXML.append(getItemAsXML(eType, sItem, nFormat));
676                 sXML.append("</node>\n");
677             }
678             sXML.append("</node>\n");
679         }
680 
681         java.io.FileOutputStream   aStream = new java.io.FileOutputStream(aXML.getAbsolutePath(), false);
682         java.io.OutputStreamWriter aWriter = new java.io.OutputStreamWriter(aStream, sEncoding);
683         java.lang.String           sOut    = sXML.toString();
684         aWriter.write(sOut, 0, sOut.length());
685         aWriter.flush();
686         aWriter.close();
687     }
688 
689     //___________________________________________
690 
691     /** converts a type property set from internal format
692      *  to an external one.
693      *
694      *  @param  aMap
695      *          points to the item, which should be converted.
696      *
697      *  @param  nFormat
698      *          specify the requested output format.
699      *
700      *  @return [java.util.HashMap]
701      *          contains the properties in the requested format.
702      *
703      *  @throws [java.lang.Exception
704      *          if something fail during conversion.
705      */
convertTypePropsToExternal(java.util.HashMap aMap , int nFormat)706     private static java.util.HashMap convertTypePropsToExternal(java.util.HashMap aMap   ,
707                                                                 int               nFormat)
708         throws java.lang.Exception
709     {
710         java.util.HashMap aResultMap = new java.util.HashMap();
711         // copy Name property ... if it exists!
712         if (aMap.containsKey(PROPNAME_NAME))
713             aResultMap.put(PROPNAME_NAME, aMap.get(PROPNAME_NAME));
714         switch(nFormat)
715         {
716             //-----------------------------------
717             case FORMAT_60 :
718             {
719                 // copy UIName property unchanged
720                 aResultMap.put(PROPNAME_UINAME, aMap.get(PROPNAME_UINAME));
721 
722                 // ignore properties "UIOrder", "PreferredFilter", "DetectService"
723                 // They are not supported for 6.0 types.
724 
725                 // pack all other properties to one "Data" string value
726                 java.lang.StringBuffer sData = new java.lang.StringBuffer(256);
727 
728                 sData.append(aMap.get(PROPNAME_PREFERRED));
729                 sData.append(",");
730                 sData.append(aMap.get(PROPNAME_MEDIATYPE));
731                 sData.append(",");
732                 sData.append(aMap.get(PROPNAME_CLIPBOARDFORMAT));
733                 sData.append(",");
734 
735                 java.util.Vector lList = (java.util.Vector)aMap.get(PROPNAME_URLPATTERN);
736                 int              c     = lList.size();
737                 int              i     = 0;
738                 for (i=0; i<c; ++i)
739                 {
740                     sData.append(lList.elementAt(i));
741                     if (i<(c-1))
742                         sData.append(";");
743                 }
744 
745                 lList = (java.util.Vector)aMap.get(PROPNAME_EXTENSIONS);
746                 c     = lList.size();
747                 for (i=0; i<c; ++i)
748                 {
749                     sData.append(lList.elementAt(i));
750                     if (i<(c-1))
751                         sData.append(";");
752                 }
753 
754                 sData.append(",");
755                 sData.append(aMap.get(PROPNAME_DOCUMENTICONID));
756                 sData.append(",");
757 
758                 aResultMap.put(PROPNAME_DATA, sData.toString());
759             }
760             break;
761 
762             //-----------------------------------
763             case FORMAT_6Y :
764             {
765                 // copy all supported properties directly
766                 aResultMap.put(PROPNAME_PREFERRED      , aMap.get(PROPNAME_PREFERRED      ));
767                 aResultMap.put(PROPNAME_MEDIATYPE      , aMap.get(PROPNAME_MEDIATYPE      ));
768                 aResultMap.put(PROPNAME_URLPATTERN     , aMap.get(PROPNAME_URLPATTERN     ));
769                 aResultMap.put(PROPNAME_EXTENSIONS     , aMap.get(PROPNAME_EXTENSIONS     ));
770                 aResultMap.put(PROPNAME_UINAME         , aMap.get(PROPNAME_UINAME         ));
771                 aResultMap.put(PROPNAME_PREFERREDFILTER, aMap.get(PROPNAME_PREFERREDFILTER));
772                 aResultMap.put(PROPNAME_DETECTSERVICE  , aMap.get(PROPNAME_DETECTSERVICE  ));
773                 aResultMap.put(PROPNAME_CLIPBOARDFORMAT, aMap.get(PROPNAME_CLIPBOARDFORMAT));
774                 aResultMap.put(PROPNAME_UIORDER        , aMap.get(PROPNAME_UIORDER        ));
775                 /* REMOVED!
776                 aResultMap.put(PROPNAME_DOCUMENTICONID , aMap.get(PROPNAME_DOCUMENTICONID ));
777                  */
778             }
779             break;
780 
781             //-----------------------------------
782             default :
783                 throw new java.lang.Exception("unknown format");
784         }
785 
786         return aResultMap;
787     }
788 
789     //___________________________________________
790 
791     /** converts a filter property set from internal format
792      *  to an external one.
793      *
794      *  @param  aMap
795      *          points to the item, which should be converted.
796      *
797      *  @param  nFormat
798      *          specify the requested output format.
799      *
800      *  @return [java.util.HashMap]
801      *          contains the properties in the requested format.
802      *
803      *  @throws [java.lang.Exception
804      *          if something fail during conversion.
805      */
convertFilterPropsToExternal(java.util.HashMap aMap , int nFormat)806     private static java.util.HashMap convertFilterPropsToExternal(java.util.HashMap aMap   ,
807                                                                   int               nFormat)
808         throws java.lang.Exception
809     {
810         java.util.HashMap aResultMap = new java.util.HashMap();
811         // copy Name property ... if it exists!
812         if (aMap.containsKey(PROPNAME_NAME))
813             aResultMap.put(PROPNAME_NAME, aMap.get(PROPNAME_NAME));
814         switch(nFormat)
815         {
816             //-----------------------------------
817             case FORMAT_60 :
818             {
819                 // copy UIName property unchanged!
820                 aResultMap.put(PROPNAME_UINAME, aMap.get(PROPNAME_UINAME));
821 
822                 // but pack all other properties
823                 java.lang.StringBuffer sData = new java.lang.StringBuffer(256);
824 
825                 sData.append(aMap.get(PROPNAME_ORDER));
826                 sData.append(",");
827                 sData.append(aMap.get(PROPNAME_TYPE));
828                 sData.append(",");
829                 sData.append(aMap.get(PROPNAME_DOCUMENTSERVICE));
830                 sData.append(",");
831                 sData.append(aMap.get(PROPNAME_FILTERSERVICE));
832                 sData.append(",");
833                 sData.append(aMap.get(PROPNAME_FLAGS));
834                 sData.append(",");
835                 java.util.Vector lList = (java.util.Vector)aMap.get(PROPNAME_USERDATA);
836                 int              c     = lList.size();
837                 int              i     = 0;
838                 for (i=0; i<c; ++i)
839                 {
840                     sData.append(lList.elementAt(i));
841                     if (i<(c-1))
842                         sData.append(";");
843                 }
844                 sData.append(",");
845                 sData.append(aMap.get(PROPNAME_FILEFORMATVERSION));
846                 sData.append(",");
847                 sData.append(aMap.get(PROPNAME_TEMPLATENAME));
848                 sData.append(",");
849                 sData.append(aMap.get(PROPNAME_UICOMPONENT));
850                 sData.append(",");
851 
852                 aResultMap.put(PROPNAME_DATA, sData.toString());
853             }
854             break;
855 
856             //-----------------------------------
857             case FORMAT_6Y :
858             {
859                 // suppress "Order" property.
860                 // Will be moved to type entries in 6.y version!
861 
862                 // suppress "UIName" property.
863                 // Only type entries will be localized in 6.y version!
864                 /* TODO make it configurable :-) */
865                 aResultMap.put(PROPNAME_UINAME           , aMap.get(PROPNAME_UINAME           ));
866 
867                 // copy all supported properties directly
868                 aResultMap.put(PROPNAME_TYPE             , aMap.get(PROPNAME_TYPE             ));
869                 aResultMap.put(PROPNAME_DOCUMENTSERVICE  , aMap.get(PROPNAME_DOCUMENTSERVICE  ));
870                 aResultMap.put(PROPNAME_FILTERSERVICE    , aMap.get(PROPNAME_FILTERSERVICE    ));
871                 aResultMap.put(PROPNAME_USERDATA         , aMap.get(PROPNAME_USERDATA         ));
872                 aResultMap.put(PROPNAME_FILEFORMATVERSION, aMap.get(PROPNAME_FILEFORMATVERSION));
873                 aResultMap.put(PROPNAME_TEMPLATENAME     , aMap.get(PROPNAME_TEMPLATENAME     ));
874                 aResultMap.put(PROPNAME_UICOMPONENT      , aMap.get(PROPNAME_UICOMPONENT      ));
875 
876                 // "Flags" will be converted from internal format [int] to
877                 // the 6.y format [string-list]!
878                 java.lang.Integer nFlags = (java.lang.Integer)aMap.get(PROPNAME_FLAGS);
879                 java.util.Vector  lFlags = Cache.convertFilterFlagValues2Names(nFlags);
880                 aResultMap.put(PROPNAME_FLAGS, lFlags);
881             }
882             break;
883 
884             //-----------------------------------
885             default :
886                 throw new java.lang.Exception("unknown format");
887         }
888 
889         return aResultMap;
890     }
891 
892     //___________________________________________
893 
894     /** converts a detect service property set from internal format
895      *  to an external one.
896      *
897      *  @param  aMap
898      *          points to the item, which should be converted.
899      *
900      *  @param  nFormat
901      *          specify the requested output format.
902      *
903      *  @return [java.util.HashMap]
904      *          contains the properties in the requested format.
905      *
906      *  @throws [java.lang.Exception
907      *          if something fail during conversion.
908      */
convertDetectServicePropsToExternal(java.util.HashMap aMap , int nFormat)909     private static java.util.HashMap convertDetectServicePropsToExternal(java.util.HashMap aMap   ,
910                                                                          int               nFormat)
911         throws java.lang.Exception
912     {
913         java.util.HashMap aResultMap = null;
914 
915         switch(nFormat)
916         {
917             //-----------------------------------
918             case FORMAT_60 :
919             {
920                 // no changes!
921                 aResultMap = aMap;
922             }
923             break;
924 
925             //-----------------------------------
926             case FORMAT_6Y :
927             {
928                 // remove localized name
929                 aResultMap = aMap;
930                 aResultMap.remove(PROPNAME_UINAME);
931             }
932             break;
933 
934             //-----------------------------------
935             default :
936                 throw new java.lang.Exception("unknown format");
937         }
938 
939         return aResultMap;
940     }
941 
convertFrameLoaderPropsToExternal(java.util.HashMap aMap , int nFormat)942     private static java.util.HashMap convertFrameLoaderPropsToExternal(java.util.HashMap aMap   ,
943                                                                        int               nFormat)
944         throws java.lang.Exception
945     {
946         java.util.HashMap aResultMap = null;
947 
948         switch(nFormat)
949         {
950             //-----------------------------------
951             case FORMAT_60 :
952             {
953                 // no changes!
954                 aResultMap = aMap;
955             }
956             break;
957 
958             //-----------------------------------
959             case FORMAT_6Y :
960             {
961                 // remove localized name
962                 aResultMap = aMap;
963                 aResultMap.remove(PROPNAME_UINAME);
964             }
965             break;
966 
967             //-----------------------------------
968             default :
969                 throw new java.lang.Exception("unknown format");
970         }
971 
972         return aResultMap;
973     }
974 
convertContentHandlerPropsToExternal(java.util.HashMap aMap , int nFormat)975     private static java.util.HashMap convertContentHandlerPropsToExternal(java.util.HashMap aMap   ,
976                                                                           int               nFormat)
977         throws java.lang.Exception
978     {
979         java.util.HashMap aResultMap = null;
980 
981         switch(nFormat)
982         {
983             //-----------------------------------
984             case FORMAT_60 :
985             {
986                 // no changes!
987                 aResultMap = aMap;
988             }
989             break;
990 
991             //-----------------------------------
992             case FORMAT_6Y :
993             {
994                 // remove localized name
995                 aResultMap = aMap;
996                 aResultMap.remove(PROPNAME_UINAME);
997             }
998             break;
999 
1000             //-----------------------------------
1001             default :
1002                 throw new java.lang.Exception("unknown format");
1003         }
1004 
1005         return aResultMap;
1006     }
1007 
1008     //___________________________________________
1009 
1010     /** converts a type property set (using an external format) to
1011      *  our internal cache format.
1012      *
1013      *  Especially the data format string will be expanded
1014      *  to its real properties.
1015      *
1016      *  Schema:
1017      *      aMap["UIName"] => aExpandedMap["UIName"]
1018      *      aMap["Data"  ] => aExpandedMap["Preferred" ], aExpandedMap["MediaType"] etc. ...
1019      *
1020      *  @param  aMap
1021      *          points to the item, which should be converted.
1022 
1023      *  @param  nFormat
1024      *          specify the external format.
1025      *
1026      *  @return [java.util.HashMap]
1027      *          The new map in internal format.
1028      */
convertTypePropsToInternal(java.util.HashMap aMap , int nFormat)1029     private static java.util.HashMap convertTypePropsToInternal(java.util.HashMap aMap   ,
1030                                                                 int               nFormat)
1031         throws java.lang.Exception
1032     {
1033         java.util.HashMap aResultMap = new java.util.HashMap();
1034         // copy Name property ... if it exists!
1035         if (aMap.containsKey(PROPNAME_NAME))
1036             aResultMap.put(PROPNAME_NAME, aMap.get(PROPNAME_NAME));
1037         switch(nFormat)
1038         {
1039             //-----------------------------------
1040             case FORMAT_60 :
1041             {
1042                 // copy UIName property unchanged!
1043                 aResultMap.put(PROPNAME_UINAME, aMap.get(PROPNAME_UINAME));
1044 
1045                 // generate new property "UIOrder"
1046                 // It's the moved property "Order" of filters for versions >= 6.y!
1047                 aResultMap.put(PROPNAME_UIORDER, new java.lang.Integer(0));
1048 
1049                 // generate new property "PreferredFilter"
1050                 // It's a the moved filter flag "Preferred" for versions >= 6.y!
1051                 aResultMap.put(PROPNAME_PREFERREDFILTER, new java.lang.String());
1052 
1053                 // generate new property "DetectService"
1054                 // Every type knows its detector directly from now. No search
1055                 // will be necessary any longer.
1056                 aResultMap.put(PROPNAME_DETECTSERVICE, new java.lang.String());
1057 
1058                 // analyze the Data property of the original map
1059                 // and copy its results (means all expanded properties)
1060                 // to the result map.
1061                 java.lang.String sDataVal = (java.lang.String)aMap.get(PROPNAME_DATA);
1062                 java.util.Vector lTokens  = Cache.splitTokenString(sDataVal, ",");
1063 
1064                 int t = 0;
1065                 java.util.Enumeration it = lTokens.elements();
1066                 while (it.hasMoreElements())
1067                 {
1068                     java.lang.String sToken = (java.lang.String)it.nextElement();
1069                     switch(t)
1070                     {
1071                         case 0 :
1072                             aResultMap.put(PROPNAME_PREFERRED, new java.lang.Boolean(sToken));
1073                             break;
1074                         case 1 :
1075                             aResultMap.put(PROPNAME_MEDIATYPE, sToken);
1076                             break;
1077                         case 2 :
1078                         {
1079                             /*HACK replace %20 with " " ...*/
1080                             int ni = sToken.indexOf("%20");
1081                             if (ni!=-1)
1082                             {
1083                                 java.lang.String sPatch = sToken.substring(0,ni) + " " + sToken.substring(ni+3);
1084                                 sToken = sPatch;
1085                             }
1086                             aResultMap.put(PROPNAME_CLIPBOARDFORMAT, sToken);
1087                         }
1088                             break;
1089                         case 3 :
1090                             aResultMap.put(PROPNAME_URLPATTERN, Cache.splitTokenString(sToken, ";"));
1091                             break;
1092                         case 4 :
1093                             aResultMap.put(PROPNAME_EXTENSIONS, Cache.splitTokenString(sToken, ";"));
1094                             break;
1095                         case 5 :
1096                             aResultMap.put(PROPNAME_DOCUMENTICONID, new java.lang.Integer(sToken));
1097                             break;
1098                         default :
1099                             throw new java.lang.Exception("unsupported format for data value of a type \""+aMap.get(PROPNAME_NAME)+"\" detected.");
1100                     }
1101                     ++t;
1102                 }
1103             }
1104             break;
1105 
1106             //-----------------------------------
1107             case FORMAT_6Y :
1108             {
1109                 // copy all supported properties directly
1110                 aResultMap.put(PROPNAME_PREFERRED      , aMap.get(PROPNAME_PREFERRED      ));
1111                 aResultMap.put(PROPNAME_MEDIATYPE      , aMap.get(PROPNAME_MEDIATYPE      ));
1112                 aResultMap.put(PROPNAME_CLIPBOARDFORMAT, aMap.get(PROPNAME_CLIPBOARDFORMAT));
1113                 aResultMap.put(PROPNAME_URLPATTERN     , aMap.get(PROPNAME_URLPATTERN     ));
1114                 aResultMap.put(PROPNAME_EXTENSIONS     , aMap.get(PROPNAME_EXTENSIONS     ));
1115                 aResultMap.put(PROPNAME_DOCUMENTICONID , aMap.get(PROPNAME_DOCUMENTICONID ));
1116                 aResultMap.put(PROPNAME_UINAME         , aMap.get(PROPNAME_UINAME         ));
1117                 aResultMap.put(PROPNAME_UIORDER        , aMap.get(PROPNAME_UIORDER        ));
1118                 aResultMap.put(PROPNAME_PREFERREDFILTER, aMap.get(PROPNAME_PREFERREDFILTER));
1119                 aResultMap.put(PROPNAME_DETECTSERVICE  , aMap.get(PROPNAME_DETECTSERVICE  ));
1120             }
1121             break;
1122 
1123             //-----------------------------------
1124             default :
1125                 throw new java.lang.Exception("unknown format");
1126         }
1127 
1128         return aResultMap;
1129     }
1130 
1131     //___________________________________________
1132 
1133     /** converts a filter property set (using an external format) to
1134      *  our internal cache format.
1135      *
1136      *  Especially the data format string will be expanded
1137      *  to its real properties.
1138      *
1139      *  Schema:
1140      *      aMap["UIName"] => aExpandedMap["UIName"]
1141      *      aMap["Data"  ] => aExpandedMap["Order" ], aExpandedMap["Flags"] etc. ...
1142      *
1143      *  @param  aMap
1144      *          points to the item, which should be converted.
1145      *
1146      *  @param  nFormat
1147      *          specify the external format.
1148      *
1149      *  @return [java.util.HashMap]
1150      *          The new map in internal format.
1151      */
convertFilterPropsToInternal(java.util.HashMap aMap , int nFormat)1152     private static java.util.HashMap convertFilterPropsToInternal(java.util.HashMap aMap   ,
1153                                                                   int               nFormat)
1154         throws java.lang.Exception
1155     {
1156         java.util.HashMap aResultMap = new java.util.HashMap();
1157         // copy Name property ... if it exists!
1158         if (aMap.containsKey(PROPNAME_NAME))
1159             aResultMap.put(PROPNAME_NAME, aMap.get(PROPNAME_NAME));
1160         switch(nFormat)
1161         {
1162             //-----------------------------------
1163             case FORMAT_60 :
1164             {
1165                 // copy UIName property
1166                 aResultMap.put(PROPNAME_UINAME, aMap.get(PROPNAME_UINAME));
1167 
1168                 // analyze the Data property of the original map
1169                 // and copy its results (means all expanded properties)
1170                 // to the result map.
1171                 java.lang.String sDataVal = (java.lang.String)aMap.get(PROPNAME_DATA);
1172                 java.util.Vector lTokens  = Cache.splitTokenString(sDataVal, ",");
1173 
1174                 int t = 0;
1175                 java.util.Enumeration it = lTokens.elements();
1176                 while (it.hasMoreElements())
1177                 {
1178                     java.lang.String sToken = (java.lang.String)it.nextElement();
1179                     switch(t)
1180                     {
1181                         case 0 :
1182                             aResultMap.put(PROPNAME_ORDER, new java.lang.Integer(sToken));
1183                             break;
1184                         case 1 :
1185                             aResultMap.put(PROPNAME_TYPE, sToken);
1186                             break;
1187                         case 2 :
1188                             aResultMap.put(PROPNAME_DOCUMENTSERVICE, sToken);
1189                             break;
1190                         case 3 :
1191                             aResultMap.put(PROPNAME_FILTERSERVICE, sToken);
1192                             break;
1193                         case 4 :
1194                             aResultMap.put(PROPNAME_FLAGS, new java.lang.Integer(sToken));
1195                             break;
1196                         case 5 :
1197                             aResultMap.put(PROPNAME_USERDATA, Cache.splitTokenString(sToken, ";"));
1198                             break;
1199                         case 6 :
1200                             aResultMap.put(PROPNAME_FILEFORMATVERSION, new java.lang.Integer(sToken));
1201                             break;
1202                         case 7 :
1203                             aResultMap.put(PROPNAME_TEMPLATENAME, sToken);
1204                             break;
1205                         case 8 :
1206                             aResultMap.put(PROPNAME_UICOMPONENT, sToken);
1207                             break;
1208                         default :
1209                             throw new java.lang.Exception("unsupported format for data value of a filter detected.");
1210                     }
1211                     ++t;
1212                 }
1213 
1214                 // it's an optional property :-)
1215                 if (!aResultMap.containsKey(PROPNAME_TEMPLATENAME))
1216                     aResultMap.put(PROPNAME_TEMPLATENAME, new java.lang.String(""));
1217 
1218                 // it's an optional property :-)
1219                 if (!aResultMap.containsKey(PROPNAME_UICOMPONENT))
1220                     aResultMap.put(PROPNAME_UICOMPONENT, new java.lang.String(""));
1221             }
1222             break;
1223 
1224             //-----------------------------------
1225             case FORMAT_6Y :
1226             {
1227                 // "Order" does not exist for 6.y versions! Use default.
1228                 aResultMap.put(PROPNAME_ORDER, new java.lang.Integer(0));
1229 
1230                 // "UIName" property does not exist for 6.y versions! use default.
1231                 /* TODO make it configurable :-) */
1232                 aResultMap.put(PROPNAME_UINAME, aMap.get(PROPNAME_UINAME));
1233                 //aResultMap.put(PROPNAME_UINAME, new java.util.HashMap());
1234 
1235                 // "Flags" must be converted from names to its values
1236                 java.util.Vector  lFlags = (java.util.Vector)aMap.get(PROPNAME_FLAGS);
1237                 java.lang.Integer nFlags = Cache.convertFilterFlagNames2Values(lFlags);
1238                 aResultMap.put(PROPNAME_FLAGS, nFlags);
1239 
1240                 // copy all direct supported properties
1241                 aResultMap.put(PROPNAME_TYPE             , aMap.get(PROPNAME_TYPE             ));
1242                 aResultMap.put(PROPNAME_DOCUMENTSERVICE  , aMap.get(PROPNAME_DOCUMENTSERVICE  ));
1243                 aResultMap.put(PROPNAME_FILTERSERVICE    , aMap.get(PROPNAME_ORDER            ));
1244                 aResultMap.put(PROPNAME_USERDATA         , aMap.get(PROPNAME_USERDATA         ));
1245                 aResultMap.put(PROPNAME_FILEFORMATVERSION, aMap.get(PROPNAME_FILEFORMATVERSION));
1246                 aResultMap.put(PROPNAME_TEMPLATENAME     , aMap.get(PROPNAME_TEMPLATENAME     ));
1247                 aResultMap.put(PROPNAME_UICOMPONENT      , aMap.get(PROPNAME_UICOMPONENT      ));
1248             }
1249             break;
1250 
1251             //-----------------------------------
1252             default :
1253                 throw new java.lang.Exception("unknown format");
1254         }
1255 
1256         return aResultMap;
1257     }
1258 
convertDetectServicePropsToInternal(java.util.HashMap aMap , int nFormat)1259     private static java.util.HashMap convertDetectServicePropsToInternal(java.util.HashMap aMap   ,
1260                                                                          int               nFormat)
1261         throws java.lang.Exception
1262     {
1263         /*FIXME*/
1264         java.util.HashMap aResultMap = aMap;
1265         return aResultMap;
1266     }
1267 
convertFrameLoaderPropsToInternal(java.util.HashMap aMap , int nFormat)1268     private static java.util.HashMap convertFrameLoaderPropsToInternal(java.util.HashMap aMap   ,
1269                                                                        int               nFormat)
1270         throws java.lang.Exception
1271     {
1272         /*FIXME*/
1273         java.util.HashMap aResultMap = aMap;
1274         return aResultMap;
1275     }
1276 
convertContentHandlerPropsToInternal(java.util.HashMap aMap , int nFormat)1277     private static java.util.HashMap convertContentHandlerPropsToInternal(java.util.HashMap aMap   ,
1278                                                                           int               nFormat)
1279         throws java.lang.Exception
1280     {
1281         /*FIXME*/
1282         java.util.HashMap aResultMap = aMap;
1283         return aResultMap;
1284     }
1285 
1286     //___________________________________________
1287 
1288     /** converts filter flag names to its int representation.
1289      *
1290      *  @param  lFlags
1291      *          a list of flag names.
1292      *
1293      *  @return [java.lang.Integer]
1294      *          an integer field of all set flags.
1295      *
1296      *  @throws [java.lang.Exception]
1297      *          for unsupported flags or empty flag fields!
1298      */
convertFilterFlagNames2Values(java.util.Vector lFlags)1299     private static java.lang.Integer convertFilterFlagNames2Values(java.util.Vector lFlags)
1300         throws java.lang.Exception
1301     {
1302         int                   nFlags = 0;
1303         java.util.Enumeration it     = lFlags.elements();
1304         while(it.hasMoreElements())
1305         {
1306             java.lang.String sFlagName = (java.lang.String)it.nextElement();
1307 
1308             if (sFlagName.equals(FLAGNAME_3RDPARTYFILTER))
1309                 nFlags |= FLAGVAL_3RDPARTYFILTER;
1310             else
1311             if (sFlagName.equals(FLAGNAME_ALIEN))
1312                 nFlags |= FLAGVAL_ALIEN;
1313             else
1314             if (sFlagName.equals(FLAGNAME_ASYNCHRON))
1315                 nFlags |= FLAGVAL_ASYNCHRON;
1316             else
1317             if (sFlagName.equals(FLAGNAME_BROWSERPREFERRED))
1318                 nFlags |= FLAGVAL_BROWSERPREFERRED;
1319             else
1320             if (sFlagName.equals(FLAGNAME_CONSULTSERVICE))
1321                 nFlags |= FLAGVAL_CONSULTSERVICE;
1322             else
1323             if (sFlagName.equals(FLAGNAME_DEFAULT))
1324                 nFlags |= FLAGVAL_DEFAULT;
1325             else
1326             if (sFlagName.equals(FLAGNAME_EXPORT))
1327                 nFlags |= FLAGVAL_EXPORT;
1328             else
1329             if (sFlagName.equals(FLAGNAME_IMPORT))
1330                 nFlags |= FLAGVAL_IMPORT;
1331             else
1332             if (sFlagName.equals(FLAGNAME_INTERNAL))
1333                 nFlags |= FLAGVAL_INTERNAL;
1334             else
1335             if (sFlagName.equals(FLAGNAME_NOTINCHOOSER))
1336                 nFlags |= FLAGVAL_NOTINCHOOSER;
1337             else
1338             if (sFlagName.equals(FLAGNAME_NOTINFILEDIALOG))
1339                 nFlags |= FLAGVAL_NOTINFILEDIALOG;
1340             else
1341             if (sFlagName.equals(FLAGNAME_NOTINSTALLED))
1342                 nFlags |= FLAGVAL_NOTINSTALLED;
1343             else
1344             if (sFlagName.equals(FLAGNAME_OWN))
1345                 nFlags |= FLAGVAL_OWN;
1346             else
1347             if (sFlagName.equals(FLAGNAME_PACKED))
1348                 nFlags |= FLAGVAL_PACKED;
1349             else
1350             if (sFlagName.equals(FLAGNAME_PREFERRED))
1351                 nFlags |= FLAGVAL_PREFERRED;
1352             else
1353             if (sFlagName.equals(FLAGNAME_READONLY))
1354                 nFlags |= FLAGVAL_READONLY;
1355             else
1356             if (sFlagName.equals(FLAGNAME_TEMPLATE))
1357                 nFlags |= FLAGVAL_TEMPLATE;
1358             else
1359             if (sFlagName.equals(FLAGNAME_TEMPLATEPATH))
1360                 nFlags |= FLAGVAL_TEMPLATEPATH;
1361             else
1362             if (sFlagName.equals(FLAGNAME_USESOPTIONS))
1363                 nFlags |= FLAGVAL_USESOPTIONS;
1364             else
1365             if (sFlagName.equals(FLAGNAME_COMBINED))
1366                 nFlags |= FLAGVAL_COMBINED;
1367             else
1368                 throw new java.lang.Exception("unsupported filter flag detected: \""+sFlagName+"\"");
1369         }
1370 
1371         if (nFlags == 0)
1372             throw new java.lang.Exception("no filter flags?");
1373 
1374         return new java.lang.Integer(nFlags);
1375     }
1376 
1377     //___________________________________________
1378 
1379     /** converts filter flag values to its string representation.
1380      *
1381      *  @param  nFlags
1382      *          the flag field as int value.
1383      *
1384      *  @return [java.util.Vector]
1385      *          a list of flag names.
1386      *
1387      *  @throws [java.lang.Exception]
1388      *          for unsupported flags or empty flag fields!
1389      */
convertFilterFlagValues2Names(java.lang.Integer nFlags)1390     private static java.util.Vector convertFilterFlagValues2Names(java.lang.Integer nFlags)
1391         throws java.lang.Exception
1392     {
1393         java.util.Vector lFlags = new java.util.Vector();
1394         int              field  = nFlags.intValue();
1395 
1396         if (field == 0)
1397             throw new java.lang.Exception("no filter flags?");
1398 
1399         if((field & FLAGVAL_IMPORT) == FLAGVAL_IMPORT)
1400             lFlags.add(FLAGNAME_IMPORT);
1401 
1402         if((field & FLAGVAL_EXPORT) == FLAGVAL_EXPORT)
1403             lFlags.add(FLAGNAME_EXPORT);
1404 
1405         if((field & FLAGVAL_TEMPLATE) == FLAGVAL_TEMPLATE)
1406             lFlags.add(FLAGNAME_TEMPLATE);
1407 
1408         if((field & FLAGVAL_INTERNAL) == FLAGVAL_INTERNAL)
1409             lFlags.add(FLAGNAME_INTERNAL);
1410 
1411         if((field & FLAGVAL_TEMPLATEPATH) == FLAGVAL_TEMPLATEPATH)
1412             lFlags.add(FLAGNAME_TEMPLATEPATH);
1413 
1414         if((field & FLAGVAL_OWN) == FLAGVAL_OWN)
1415             lFlags.add(FLAGNAME_OWN);
1416 
1417         if((field & FLAGVAL_ALIEN) == FLAGVAL_ALIEN)
1418             lFlags.add(FLAGNAME_ALIEN);
1419 
1420         if((field & FLAGVAL_USESOPTIONS) == FLAGVAL_USESOPTIONS)
1421             lFlags.add(FLAGNAME_USESOPTIONS);
1422 
1423         if((field & FLAGVAL_DEFAULT) == FLAGVAL_DEFAULT)
1424             lFlags.add(FLAGNAME_DEFAULT);
1425 
1426         if((field & FLAGVAL_NOTINFILEDIALOG) == FLAGVAL_NOTINFILEDIALOG)
1427             lFlags.add(FLAGNAME_NOTINFILEDIALOG);
1428 
1429         if((field & FLAGVAL_NOTINCHOOSER) == FLAGVAL_NOTINCHOOSER)
1430             lFlags.add(FLAGNAME_NOTINCHOOSER);
1431 
1432         if((field & FLAGVAL_ASYNCHRON) == FLAGVAL_ASYNCHRON)
1433             lFlags.add(FLAGNAME_ASYNCHRON);
1434 
1435         if((field & FLAGVAL_READONLY) == FLAGVAL_READONLY)
1436             lFlags.add(FLAGNAME_READONLY);
1437 
1438         if((field & FLAGVAL_NOTINSTALLED) == FLAGVAL_NOTINSTALLED)
1439             lFlags.add(FLAGNAME_NOTINSTALLED);
1440 
1441         if((field & FLAGVAL_CONSULTSERVICE) == FLAGVAL_CONSULTSERVICE)
1442             lFlags.add(FLAGNAME_CONSULTSERVICE);
1443 
1444         if((field & FLAGVAL_3RDPARTYFILTER) == FLAGVAL_3RDPARTYFILTER)
1445             lFlags.add(FLAGNAME_3RDPARTYFILTER);
1446 
1447         if((field & FLAGVAL_PACKED) == FLAGVAL_PACKED)
1448             lFlags.add(FLAGNAME_PACKED);
1449 
1450         if((field & FLAGVAL_BROWSERPREFERRED) == FLAGVAL_BROWSERPREFERRED)
1451             lFlags.add(FLAGNAME_BROWSERPREFERRED);
1452 
1453         if((field & FLAGVAL_PREFERRED) == FLAGVAL_PREFERRED)
1454             lFlags.add(FLAGNAME_PREFERRED);
1455 
1456         if((field & FLAGVAL_COMBINED) == FLAGVAL_COMBINED)
1457             lFlags.add(FLAGNAME_COMBINED);
1458 
1459         if((field & FLAGVAL_COMBINED) == FLAGVAL_SUPPORTSSELECTION)
1460             lFlags.add(FLAGNAME_SUPPORTSSELECTION);
1461 
1462         return lFlags;
1463     }
1464 
1465     //___________________________________________
1466 
1467     /** return a reference to one of our member
1468      *  lists for types/filters etc ...
1469      *
1470      *  @param  eItemType
1471      *          specify, which item map is required.
1472      *
1473      *  @return [java.util.HashMap]
1474      *          a reference(!) to the right member.
1475      *
1476      *  @throws [java.lang.Exception]
1477      *          if the specified map does not exist.
1478      */
getItemMap(int eItemType)1479     private java.util.HashMap getItemMap(int eItemType)
1480         throws java.lang.Exception
1481     {
1482         java.util.HashMap rMap = null;
1483         switch(eItemType)
1484         {
1485             case E_TYPE :
1486                 rMap = m_lTypes;
1487                 break;
1488 
1489             case E_FILTER :
1490                 rMap = m_lFilters;
1491                 break;
1492 
1493             case E_DETECTSERVICE :
1494                 rMap = m_lDetectServices;
1495                 break;
1496 
1497             case E_FRAMELOADER :
1498                 rMap = m_lFrameLoaders;
1499                 break;
1500 
1501             case E_CONTENTHANDLER :
1502                 rMap = m_lContentHandlers;
1503                 break;
1504 
1505             default:
1506                 throw new java.lang.Exception("Invalid item map specified.");
1507         }
1508         return rMap;
1509     }
1510 
1511     //___________________________________________
1512 
1513     /** return the count of items inside a sub container
1514      *  of this cache.
1515      *
1516      *  @param  eItemType
1517      *          specify, which item map is required.
1518      *
1519      *  @throws [java.lang.Exception]
1520      *          if the specified map does not exist.
1521      */
getItemCount(int eItemType)1522     public synchronized int getItemCount(int eItemType)
1523         throws java.lang.Exception
1524     {
1525         java.util.HashMap rMap = getItemMap(eItemType);
1526         return rMap.size();
1527     }
1528 
1529     //___________________________________________
1530 
1531     /** get a list of all item names of the specified
1532      *  sub container.
1533      *
1534      *  @param  eItemType
1535      *          specify, which item map is required.
1536      *
1537      *  @throws [java.lang.Exception]
1538      *          if the specified map does not exist.
1539      */
getItemNames(int eItemType)1540     public synchronized java.util.Vector getItemNames(int eItemType)
1541         throws java.lang.Exception
1542     {
1543         java.util.Vector   lNames = new java.util.Vector();
1544         java.util.HashMap  rMap   = getItemMap(eItemType);
1545         java.util.Iterator it     = rMap.keySet().iterator();
1546         while(it.hasNext())
1547             lNames.add(it.next());
1548         return lNames;
1549     }
1550 
1551     //___________________________________________
1552 
1553     /** get a list of all item names of the specified
1554      *  sub container, where items match to given property set.
1555      *
1556      *  Note: The given property set must exist at all
1557      *  returned items as minimum and every checked property
1558      *  value must be equals! Using of reg expressions or
1559      *  similar mechanism will not be supported here.
1560      *
1561      *  @param  eItemType
1562      *          specify, which item map is required.
1563      *
1564      *  @param  aPropSet
1565      *          the set of properties, which must
1566      *          exist at the returned item as minimum.
1567      *
1568      *  @throws [java.lang.Exception]
1569      *          if the specified map does not exist.
1570      */
getMatchedItemNames(int eItemType, java.util.HashMap aPropSet )1571     public synchronized java.util.Vector getMatchedItemNames(int               eItemType,
1572                                                              java.util.HashMap aPropSet )
1573         throws java.lang.Exception
1574     {
1575         java.util.Vector   lNames = new java.util.Vector();
1576         java.util.HashMap  rMap   = getItemMap(eItemType);
1577         java.util.Iterator it     = rMap.keySet().iterator();
1578         while(it.hasNext())
1579         {
1580             java.lang.String  sItemName  = (java.lang.String)it.next();
1581             java.util.HashMap rItemProps = (java.util.HashMap)rMap.get(sItemName);
1582 
1583             boolean bMatch = Cache.matchPropSet(rItemProps, aPropSet);
1584             if (bMatch)
1585                 lNames.add(sItemName);
1586             else
1587             {
1588                 java.lang.StringBuffer sBuffer = new java.lang.StringBuffer(1000);
1589                 sBuffer.append("entry ["+eItemType+"] \""+sItemName+"\" does not match.\n");
1590                 sBuffer.append("\torg items = {"+rItemProps+"}\n");
1591                 sBuffer.append("\treq items = {"+aPropSet+"}\n");
1592 
1593                 m_aDebug.setDetailedInfo(sBuffer.toString());
1594             }
1595         }
1596         return lNames;
1597     }
1598 
1599     //___________________________________________
1600 
1601     /** check if two property sets are equals in its
1602      *  shared properties.
1603      *
1604      *  Note: Only set properties of the match set will be searched
1605      *  inside the original set. And its values must be equals.
1606      *  Using of reg expressions or similar mechanism will not
1607      *  be supported here.
1608      *
1609      *  @param  rOrgProps
1610      *          the original property set, which should be checked.
1611      *
1612      *  @param  rMatchProps
1613      *          contains the properties, which must be searched
1614      *          inside rOrgProps.
1615      *
1616      *  @return TRUE if all properties of rMatchProps could be located
1617      *          inside rOrgProps.
1618      */
matchPropSet(java.util.HashMap rOrgProps , java.util.HashMap rMatchProps)1619     private static boolean matchPropSet(java.util.HashMap rOrgProps  ,
1620                                         java.util.HashMap rMatchProps)
1621     {
1622         java.util.Iterator it = rMatchProps.keySet().iterator();
1623         while(it.hasNext())
1624         {
1625             java.lang.String sMatchName  = (java.lang.String)it.next();
1626             java.lang.Object aMatchValue = rMatchProps.get(sMatchName);
1627 
1628             if (
1629                 (!rOrgProps.containsKey(sMatchName)            ) ||
1630                 (!rOrgProps.get(sMatchName).equals(aMatchValue))
1631                )
1632             {
1633                 return false;
1634             }
1635         }
1636         return true;
1637     }
1638 
1639     //___________________________________________
1640 
1641     /** return a property set for the queried container item.
1642      *
1643      *  @param  eItemType
1644      *          specify, which item map is required.
1645      *
1646      *  @param  sItemName
1647      *          must be a valid item name of the specified item map.
1648      *
1649      *  @return [java.util.HashMap]
1650      *          the property set of the queried item.
1651      *          Always different from null!
1652      *
1653      *  @throws [java.lang.Exception]
1654      *          if the specified item does not exists or
1655      *          seems to be invalid in general (means null!).
1656      */
getItem(int eItemType, java.lang.String sItemName)1657     public synchronized java.util.HashMap getItem(int              eItemType,
1658                                                   java.lang.String sItemName)
1659         throws java.lang.Exception
1660     {
1661         java.util.HashMap rMap  = getItemMap(eItemType);
1662         java.util.HashMap rItem = (java.util.HashMap)rMap.get(sItemName);
1663         if (rItem == null)
1664             throw new java.lang.Exception("Queried item \""+sItemName+"\" does not exist inside this cache.");
1665         return rItem;
1666     }
1667 
1668     //___________________________________________
1669 
1670     /** return a requested item in XML format.
1671      *
1672      *  @param  eItemType
1673      *          identify the right sub set of this cache
1674      *          inside which the requested item should exist.
1675      *          e.g. E_TYPE, E_FILTER, ...
1676      *
1677      *  @param  sItemName
1678      *          the name of the request item
1679      *
1680      *  @param  nXMLFormat
1681      *          means the format of the generated xml source.
1682      *
1683      *  @return [java.lang.String]
1684      *          a xml formatted string, which contains all properties
1685      *          for this container item.
1686      */
getItemAsXML(int eItemType , java.lang.String sItemName , int nXMLFormat)1687     public synchronized java.lang.String getItemAsXML(int              eItemType ,
1688                                                       java.lang.String sItemName ,
1689                                                       int              nXMLFormat)
1690         throws java.lang.Exception
1691     {
1692         // Note: Our internal format must be converted to the target format!
1693         java.util.HashMap rItem         = getItem(eItemType, sItemName);
1694         java.util.HashMap rFormatedItem = null;
1695         switch(eItemType)
1696         {
1697             case E_TYPE :
1698                 {
1699                     rFormatedItem = Cache.convertTypePropsToExternal(rItem, nXMLFormat);
1700                     m_aDebug.setGlobalInfo("type to external \""+sItemName+"\"");
1701                 }
1702                 break;
1703 
1704             case E_FILTER :
1705                 {
1706                     rFormatedItem = Cache.convertFilterPropsToExternal(rItem, nXMLFormat);
1707                     m_aDebug.setGlobalInfo("filter to external \""+sItemName+"\"");
1708                 }
1709                 break;
1710 
1711             case E_DETECTSERVICE :
1712                 {
1713                     rFormatedItem = Cache.convertDetectServicePropsToExternal(rItem, nXMLFormat);
1714                     m_aDebug.setGlobalInfo("detect service to external \""+sItemName+"\"");
1715                 }
1716                 break;
1717 
1718             case E_FRAMELOADER :
1719                 {
1720                     rFormatedItem = Cache.convertFrameLoaderPropsToExternal(rItem, nXMLFormat);
1721                     m_aDebug.setGlobalInfo("frame loader to external \""+sItemName+"\"");
1722                 }
1723                 break;
1724 
1725             case E_CONTENTHANDLER :
1726                 {
1727                     rFormatedItem = Cache.convertContentHandlerPropsToExternal(rItem, nXMLFormat);
1728                     m_aDebug.setGlobalInfo("content handler to external \""+sItemName+"\"");
1729                 }
1730                 break;
1731         }
1732 
1733         java.lang.StringBuffer sXML        = new java.lang.StringBuffer(1000);
1734         int                    nPrettyTabs = 1;
1735         for (int t=0; t<nPrettyTabs; ++t)
1736             sXML.append("\t");
1737         sXML.append("<"+XMLHelper.XMLTAG_NODE+" "+XMLHelper.XMLATTRIB_OOR_NAME+"=\""+XMLHelper.encodeHTMLSigns(sItemName)+"\" "+XMLHelper.XMLATTRIB_OOR_OP+"=\""+XMLHelper.XMLATTRIB_OP_REPLACE+"\">\n");
1738         sXML.append(XMLHelper.convertPropSetToXML(rFormatedItem, nPrettyTabs+1));
1739         for (int t=0; t<nPrettyTabs; ++t)
1740             sXML.append("\t");
1741         sXML.append("</"+XMLHelper.XMLTAG_NODE+">\n");
1742 
1743         return sXML.toString();
1744     }
1745 
1746     //___________________________________________
1747 
1748     /** split the given string (using the specified delimiter)
1749      *  and return alist of found string tokens.
1750      *
1751      *  Note: Against the normal behavior of the StringTokenizer class
1752      *  this method returns empty tokens too.
1753      *  E.g: "0,,1" will return "0" - "" - "1"
1754      *
1755      *  @param  sTokenString
1756      *          the string value, which should be analyzed.
1757      *
1758      *  @param  sDelim
1759      *          the delimiter, which will be used to differ between tokens.
1760      *
1761      *  @return [java.util.Vector]
1762      *          a list of string tokens. Can be empty - but not null!
1763      */
splitTokenString(java.lang.String sTokenString, java.lang.String sDelim )1764     private static java.util.Vector splitTokenString(java.lang.String sTokenString,
1765                                                      java.lang.String sDelim      )
1766     {
1767         java.util.Vector          lTokens       = new java.util.Vector();
1768         java.util.StringTokenizer aTokenizer    = new java.util.StringTokenizer(sTokenString, sDelim, true);
1769         boolean                   bLastWasDelim = false;
1770 
1771         while (aTokenizer.hasMoreTokens())
1772         {
1773             java.lang.String sToken = aTokenizer.nextToken();
1774             if (sToken.equals(sDelim))
1775             {
1776                 if (bLastWasDelim)
1777                 {
1778                     // last token was a delimiter - new one too
1779                     // => an empty token must be placed between these
1780                     //    two delimiters! Add this empty value to the return list.
1781                     lTokens.add("");
1782                 }
1783                 else
1784                 {
1785                     // last token was not a delimiter - new one is such delim
1786                     // => ignore this delimiter - but save the information, that
1787                     //    it occurred
1788                     bLastWasDelim = true;
1789                 }
1790             }
1791             else
1792             {
1793                 // new token is no delim
1794                 // => Add it to the return list.
1795                 lTokens.add(sToken);
1796                 // Dont forget to reset this information - so next loop
1797                 // will do the right things!
1798                 bLastWasDelim = false;
1799             }
1800         }
1801 
1802         return lTokens;
1803     }
1804 
1805     //___________________________________________
1806 
1807     /**
1808      */
analyze()1809     public synchronized void analyze()
1810     {
1811         m_nDoubleRegisteredFilters = 0;
1812         m_nTypesForFilters         = 0;
1813         m_nTypesForDetectServices  = 0;
1814         m_nTypesForFrameLoaders    = 0;
1815         m_nTypesForContentHandlers = 0;
1816 
1817         // create table of types and all registered filters for such types
1818         // By the way: count all double registrations, where a filter
1819         // uses the same type then another filter.
1820         m_lFilterToTypeRegistrations = new java.util.HashMap();
1821         java.util.Iterator aIt1 = m_lFilters.keySet().iterator();
1822         while (aIt1.hasNext())
1823         {
1824             java.lang.String  sFilter = (java.lang.String)aIt1.next();
1825             java.util.HashMap aFilter = (java.util.HashMap)m_lFilters.get(sFilter);
1826             java.lang.String  sType   = (java.lang.String)aFilter.get(PROPNAME_TYPE);
1827 
1828             java.util.Vector lFilters = (java.util.Vector)m_lFilterToTypeRegistrations.get(sType);
1829             if (lFilters == null)
1830                 lFilters = new java.util.Vector();
1831             else
1832                 ++m_nDoubleRegisteredFilters;
1833             lFilters.add(sFilter);
1834             m_lFilterToTypeRegistrations.put(sType, lFilters);
1835         }
1836 
1837         // count, how many types are used by filters, frame loaders or content handlers
1838         aIt1 = m_lTypes.keySet().iterator();
1839         while (aIt1.hasNext())
1840         {
1841             java.lang.String sType = (java.lang.String)aIt1.next();
1842 
1843             java.util.Iterator aIt2 = m_lFilters.keySet().iterator();
1844             while (aIt2.hasNext())
1845             {
1846                 java.lang.String  sItem    = (java.lang.String)aIt2.next();
1847                 java.util.HashMap aItem    = (java.util.HashMap)m_lFilters.get(sItem);
1848                 java.lang.String  sTypeReg = (java.lang.String)aItem.get(PROPNAME_TYPE);
1849 
1850                 if (sTypeReg.equals(sType))
1851                 {
1852                     ++m_nTypesForFilters;
1853                     break;
1854                 }
1855             }
1856 
1857             aIt2 = m_lDetectServices.keySet().iterator();
1858             while (aIt2.hasNext())
1859             {
1860                 java.lang.String  sItem    = (java.lang.String)aIt2.next();
1861                 java.util.HashMap aItem    = (java.util.HashMap)m_lDetectServices.get(sItem);
1862                 java.util.Vector  lTypeReg = (java.util.Vector)aItem.get(PROPNAME_TYPES);
1863 
1864                 if (lTypeReg.contains(sType))
1865                 {
1866                     ++m_nTypesForDetectServices;
1867                     break;
1868                 }
1869             }
1870 
1871             aIt2 = m_lFrameLoaders.keySet().iterator();
1872             while (aIt2.hasNext())
1873             {
1874                 java.lang.String  sItem    = (java.lang.String)aIt2.next();
1875                 java.util.HashMap aItem    = (java.util.HashMap)m_lFrameLoaders.get(sItem);
1876                 java.util.Vector  lTypeReg = (java.util.Vector)aItem.get(PROPNAME_TYPES);
1877 
1878                 if (lTypeReg.contains(sType))
1879                 {
1880                     ++m_nTypesForFrameLoaders;
1881                     break;
1882                 }
1883             }
1884 
1885             aIt2 = m_lContentHandlers.keySet().iterator();
1886             while (aIt2.hasNext())
1887             {
1888                 java.lang.String  sItem    = (java.lang.String)aIt2.next();
1889                 java.util.HashMap aItem    = (java.util.HashMap)m_lContentHandlers.get(sItem);
1890                 java.util.Vector  lTypeReg = (java.util.Vector)aItem.get(PROPNAME_TYPES);
1891 
1892                 if (lTypeReg.contains(sType))
1893                 {
1894                     ++m_nTypesForContentHandlers;
1895                     break;
1896                 }
1897             }
1898         }
1899     }
1900 
1901     //___________________________________________
1902 
1903     /** validate all cache entries.
1904      *
1905      *  It checks if all made registrations are valid;
1906      *  try to repair some simple problems;
1907      *  create missing information on demand ...
1908      *
1909      *  @param  nFormat
1910      *          specify, which configuration format
1911      *          must be checked.
1912      *
1913      *  @throws [java.lang.Exception]
1914      *          if an unrecoverable problem occurs.
1915      */
validate(int nFormat)1916     public synchronized void validate(int nFormat)
1917         throws java.lang.Exception
1918     {
1919         validateTypes(nFormat);
1920         validateFilters(nFormat);
1921     }
1922 
1923     //___________________________________________
1924 
1925     /** validate all type entries of this cache.
1926      *
1927      *  @param  nFormat
1928      *          specify, which configuration format
1929      *          must be checked.
1930      *
1931      *  @throws [java.lang.Exception]
1932      *          if an unrecoverable problem occurs.
1933      */
validateTypes(int nFormat)1934     private void validateTypes(int nFormat)
1935         throws java.lang.Exception
1936     {
1937         java.util.Iterator aIt1 = m_lTypes.keySet().iterator();
1938         while(aIt1.hasNext())
1939         {
1940             java.lang.String  sType = (java.lang.String)aIt1.next();
1941             java.util.HashMap aType = (java.util.HashMap)m_lTypes.get(sType);
1942             if (aType == null)
1943                 throw new java.lang.Exception("type ["+sType+"] dos not exist really?!");
1944 
1945             if (
1946                 (!aType.containsKey(PROPNAME_MEDIATYPE      )) ||
1947                 (!aType.containsKey(PROPNAME_PREFERRED      )) ||
1948                 (!aType.containsKey(PROPNAME_CLIPBOARDFORMAT)) ||
1949                 (!aType.containsKey(PROPNAME_DOCUMENTICONID )) ||
1950                 (!aType.containsKey(PROPNAME_URLPATTERN     )) ||
1951                 (!aType.containsKey(PROPNAME_EXTENSIONS     )) ||
1952                 (!aType.containsKey(PROPNAME_UINAME         ))
1953                )
1954             {
1955                 throw new java.lang.Exception("Type \""+sType+"\" does not contain all necessary properties for a 6.0/6.Y format.");
1956             }
1957 
1958             if (
1959                 (((java.util.Vector)aType.get(PROPNAME_EXTENSIONS)).isEmpty()) &&
1960                 (((java.util.Vector)aType.get(PROPNAME_URLPATTERN)).isEmpty())
1961                )
1962             {
1963                 throw new java.lang.Exception("Type \""+sType+"\" does not contain any extension nor an url pattern.");
1964             }
1965 
1966             if (((java.util.HashMap)aType.get(PROPNAME_UINAME)).isEmpty())
1967                 throw new java.lang.Exception("Type \""+sType+"\" is not localized.");
1968 
1969             if (nFormat == FORMAT_6Y)
1970             {
1971                 if (
1972                     (!aType.containsKey(PROPNAME_UIORDER        )) ||
1973                     (!aType.containsKey(PROPNAME_PREFERREDFILTER)) ||
1974                     (!aType.containsKey(PROPNAME_DETECTSERVICE  ))
1975                    )
1976                 {
1977                     throw new java.lang.Exception("Type \""+sType+"\" does not contain all necessary properties for a 6.Y format.");
1978                 }
1979 
1980                 if (((java.lang.Integer)aType.get(PROPNAME_UIORDER)).intValue() < 0)
1981                     throw new java.lang.Exception("Type \""+sType+"\" has invalid value for prop UIOrder.");
1982 
1983                 if (((java.lang.String)aType.get(PROPNAME_DETECTSERVICE)).length() < 1)
1984                     m_aDebug.setWarning("Type \""+sType+"\" has no detect service registered.");
1985 
1986                 java.lang.String sPreferredReg = (java.lang.String)aType.get(PROPNAME_PREFERREDFILTER);
1987                 if (
1988                     (sPreferredReg          == null) ||
1989                     (sPreferredReg.length() <  1   )
1990                    )
1991                 {
1992                     m_aDebug.setWarning("Type \""+sType+"\" has no preferred filter ...");
1993                     /*FIXME
1994                      *  OK - not every type has a filter registered .. but the
1995                      *  a frame loader MUST(!) exist! Check it.
1996                      */
1997                 }
1998                 else
1999                 {
2000                     if (!m_lFilters.containsKey(sPreferredReg))
2001                         throw new java.lang.Exception("Type \""+sType+"\" has no valid preferred filter registration [\""+sPreferredReg+"\"].");
2002                 }
2003             }
2004         }
2005     }
2006 
2007     //___________________________________________
2008 
2009     /** validate all filter entries of this cache.
2010      *
2011      *  @param  nFormat
2012      *          specify, which configuration format
2013      *          must be checked.
2014      *
2015      *  @throws [java.lang.Exception]
2016      *          if an unrecoverable problem occurs.
2017      */
validateFilters(int nFormat)2018     public synchronized void validateFilters(int nFormat)
2019         throws java.lang.Exception
2020     {
2021         java.util.Iterator aIt1 = m_lFilters.keySet().iterator();
2022         while(aIt1.hasNext())
2023         {
2024             java.lang.String  sFilter = (java.lang.String)aIt1.next();
2025             java.util.HashMap aFilter = (java.util.HashMap)m_lFilters.get(sFilter);
2026             if (aFilter == null)
2027                 throw new java.lang.Exception("filter ["+sFilter+"] dos not exist really?!");
2028 
2029             if (
2030                 (!aFilter.containsKey(PROPNAME_DOCUMENTSERVICE  )) ||
2031                 (!aFilter.containsKey(PROPNAME_FILEFORMATVERSION)) ||
2032                 (!aFilter.containsKey(PROPNAME_FILTERSERVICE    )) ||
2033                 (!aFilter.containsKey(PROPNAME_FLAGS            )) ||
2034                 (!aFilter.containsKey(PROPNAME_TEMPLATENAME     )) ||
2035                 (!aFilter.containsKey(PROPNAME_TYPE             )) ||
2036                 (!aFilter.containsKey(PROPNAME_UICOMPONENT      )) ||
2037                 (!aFilter.containsKey(PROPNAME_USERDATA         ))
2038                )
2039             {
2040                 throw new java.lang.Exception("Filter \""+sFilter+"\" does not contain all necessary properties for a 6.0/6.Y format.");
2041             }
2042 
2043             if (((java.lang.Integer)aFilter.get(PROPNAME_FLAGS)).intValue() < 1)
2044                 throw new java.lang.Exception("Filter \""+sFilter+"\" does not have a valid flag field.");
2045 
2046             if (!m_lTypes.containsKey(aFilter.get(PROPNAME_TYPE)))
2047                 throw new java.lang.Exception("Filter \""+sFilter+"\" is not registered for a well known type.");
2048 
2049             if (nFormat == FORMAT_60)
2050             {
2051                 if (
2052                     (!aFilter.containsKey(PROPNAME_ORDER )) ||
2053                     (!aFilter.containsKey(PROPNAME_UINAME))
2054                    )
2055                 {
2056                     throw new java.lang.Exception("Filter \""+sFilter+"\" does not contain all necessary properties for a 6.0 format.");
2057                 }
2058 
2059                 if (((java.lang.Integer)aFilter.get(PROPNAME_ORDER)).intValue() < 0)
2060                     throw new java.lang.Exception("Filter \""+sFilter+"\" does not have a valid Order value.");
2061 
2062                 if (((java.util.HashMap)aFilter.get(PROPNAME_UINAME)).isEmpty())
2063                     throw new java.lang.Exception("Filter \""+sFilter+"\" is not localized.");
2064             }
2065 /*TODO
2066     depends from the configuration item "remove_filter_flag_preferred" ...
2067 
2068             if (nFormat == FORMAT_6Y)
2069             {
2070                 int flags = ((java.lang.Integer)aFilter.get(PROPNAME_FLAGS)).intValue();
2071                 if ((flags & FLAGVAL_PREFERRED) == FLAGVAL_PREFERRED)
2072                     throw new java.lang.Exception("Filter \""+sFilter+"\" has superflous Preferred flag set. Please remove this flag. ["+flags+"]");
2073             }
2074 */
2075         }
2076     }
2077 
2078     /*TODO
2079      * - remove graphic filters!
2080      * - move detect services to types
2081      */
2082 
transform60to6Y(boolean bCreateCombineFilterFlag , boolean bRemoveFilterFlagBrowserPreferred, boolean bRemoveFilterFlagPreferred , boolean bRemoveFilterFlag3rdparty , boolean bRemoveFilterUINames , boolean bRemoveGraphicFilters , boolean bSetDefaultDetector )2083     public synchronized void transform60to6Y(boolean bCreateCombineFilterFlag         ,
2084                                              boolean bRemoveFilterFlagBrowserPreferred,
2085                                              boolean bRemoveFilterFlagPreferred       ,
2086                                              boolean bRemoveFilterFlag3rdparty        ,
2087                                              boolean bRemoveFilterUINames             ,
2088                                              boolean bRemoveGraphicFilters            ,
2089                                              boolean bSetDefaultDetector              )
2090         throws java.lang.Exception
2091     {
2092         // remove some superfluous cache entries ...
2093         // everything related to "load macros"
2094         // Macros should be dispatched instead of loaded!
2095         if (m_lTypes.containsKey("macro"))
2096         {
2097             m_lTypes.remove("macro");
2098             m_aDebug.setDetailedInfo("superflous type \"macro\" was removed");
2099         }
2100         if (m_lFrameLoaders.containsKey("com.sun.star.comp.sfx2.SfxMacroLoader"))
2101         {
2102             m_lFrameLoaders.remove("com.sun.star.comp.sfx2.SfxMacroLoader");
2103             m_aDebug.setDetailedInfo("superflous frame loader \"com.sun.star.comp.sfx2.SfxMacroLoader\" was removed");
2104         }
2105 
2106         // step over all filters and check her properties and references
2107         java.util.Vector   lPreferredFilters = new java.util.Vector();
2108         java.util.Vector   lNoRealFilters    = new java.util.Vector();
2109         java.util.Iterator aIt1              = m_lFilters.keySet().iterator();
2110         while(aIt1.hasNext())
2111         {
2112             java.lang.String  sFilter  = (java.lang.String)aIt1.next();
2113             java.util.HashMap aFilter  = (java.util.HashMap)m_lFilters.get(sFilter);
2114 
2115             // remove the "graphic helper filters" used by draw and impress
2116             // They don't have any valid document service name set and can't be handled
2117             // by our generic FrameLoader!
2118             // They must be moved to her own configuration ...
2119 
2120             if (
2121                 (bRemoveGraphicFilters                                                 ) &&
2122                 (((java.lang.String)aFilter.get(PROPNAME_DOCUMENTSERVICE)).length() < 1)
2123                )
2124             {
2125                 lNoRealFilters.add(sFilter);
2126                 continue;
2127             }
2128 
2129             java.lang.String  sTypeReg = (java.lang.String)aFilter.get(PROPNAME_TYPE);
2130             java.util.HashMap aType    = (java.util.HashMap)m_lTypes.get(sTypeReg);
2131 
2132             // move UINames of filters to types
2133             java.util.HashMap  lFilterUINames = (java.util.HashMap)aFilter.get(PROPNAME_UINAME);
2134             java.util.HashMap  lTypeUINames   = (java.util.HashMap)aType.get(PROPNAME_UINAME);
2135             java.util.HashMap  lPatchUINames  = new java.util.HashMap();
2136 
2137             java.util.Iterator pUINames = lTypeUINames.keySet().iterator();
2138             while(pUINames.hasNext())
2139             {
2140                 java.lang.String sLocale = (java.lang.String)pUINames.next();
2141                 java.lang.String sValue  = (java.lang.String)lTypeUINames.get(sLocale);
2142                 lPatchUINames.put(sLocale, sValue);
2143             }
2144 
2145             pUINames = lFilterUINames.keySet().iterator();
2146             while(pUINames.hasNext())
2147             {
2148                 java.lang.String sLocale = (java.lang.String)pUINames.next();
2149                 java.lang.String sValue  = (java.lang.String)lFilterUINames.get(sLocale);
2150                 lPatchUINames.put(sFilter+":"+sLocale, sValue);
2151             }
2152             aType.put(PROPNAME_UINAME, lPatchUINames);
2153 
2154             // set generic filter service wrapper for our own native filters!
2155             // By the way: The format types of such filters can be detected by our
2156             // generic detector too.
2157             if (
2158                 (bSetDefaultDetector                                                 ) &&
2159                 (((java.lang.String)aFilter.get(PROPNAME_FILTERSERVICE)).length() < 1)
2160                )
2161             {
2162  /*ME_THINKING               aFilter.put(PROPNAME_FILTERSERVICE, FILTERSERVICE_NATIVEWARPPER);*/
2163                 aType.put(PROPNAME_DETECTSERVICE, GENERIC_DETECTSERVICE);
2164             }
2165 
2166             // move the preferred filter information to any type
2167             // Set the filter name to the type for which the filter is registered.
2168             // If this type already have a set PreferredFilter value, check if the current filter
2169             // has the preferred flag set. If not ignore it - otherwise overwrite the
2170             // current information at the type. But look for multiple preferred filter relations ...
2171             // means: look if more than one filter has set the preferred flag for the same type!
2172 
2173             /* Attention!
2174              *
2175              * Don't remove the preferred flag from any filter! ... not here.
2176              * Otherwise next loop can't detect ambiguous preferred registrations!
2177              * Add filter to a temp. list, which can be used later to remove the preferred
2178              * flag ...
2179              */
2180 
2181             int     flags1     = ((java.lang.Integer)aFilter.get(PROPNAME_FLAGS)).intValue();
2182             java.lang.String sDocSrv = (java.lang.String)aFilter.get(PROPNAME_DOCUMENTSERVICE);
2183             if (sDocSrv.length()>0)// without a doc service it's not a real filter - it's a graphic filter!
2184             {
2185                 boolean preferred1 = ((flags1 & FLAGVAL_PREFERRED) == FLAGVAL_PREFERRED);
2186                 if (preferred1)
2187                     lPreferredFilters.add(aFilter);
2188 
2189                 java.lang.String sAlreadyRegisteredFilter = (java.lang.String)aType.get(PROPNAME_PREFERREDFILTER);
2190                 // no registration => set this filter as "any possible one"!
2191                 if (sAlreadyRegisteredFilter.length() < 1)
2192                     aType.put(PROPNAME_PREFERREDFILTER, sFilter);
2193                 else
2194                 {
2195                     java.util.HashMap aAlreadyRegisteredFilter = (java.util.HashMap)m_lFilters.get(sAlreadyRegisteredFilter);
2196                     int               flags2                   = ((java.lang.Integer)aAlreadyRegisteredFilter.get(PROPNAME_FLAGS)).intValue();
2197                     boolean           preferred2               = ((flags2 & FLAGVAL_PREFERRED) == FLAGVAL_PREFERRED);
2198 
2199                     // two preferred filters for the same type! => error
2200                     if (preferred1 && preferred2)
2201                     {
2202                         java.lang.StringBuffer sMsg = new java.lang.StringBuffer(256);
2203                         sMsg.append("More the one preferred filter detected for the same type.\n");
2204                         sMsg.append("\ttype      = \""+sTypeReg+"\"\n");
2205                         sMsg.append("\tfilter[1] = \""+sAlreadyRegisteredFilter+"\"\n");
2206                         sMsg.append("\tfilter[2] = \""+sFilter+"\"\n");
2207                         throw new java.lang.Exception(sMsg.toString());
2208                     }
2209                     else
2210                     // overwrite the "any possible" filter with a real preferred one
2211                     if (preferred1 && !preferred2)
2212                         aType.put(PROPNAME_PREFERREDFILTER, sFilter);
2213                 }
2214             }
2215 
2216             // create the new combined filter flag if required
2217             if (bCreateCombineFilterFlag)
2218             {
2219                 if (
2220                     ((flags1 & FLAGVAL_IMPORT) == FLAGVAL_IMPORT) &&
2221                     ((flags1 & FLAGVAL_EXPORT) == FLAGVAL_EXPORT)
2222                    )
2223                 {
2224                     flags1 |=  FLAGVAL_COMBINED;
2225                     flags1 &= ~FLAGVAL_IMPORT  ;
2226                     flags1 &= ~FLAGVAL_EXPORT  ;
2227                     aFilter.put(PROPNAME_FLAGS, new java.lang.Integer(flags1));
2228                 }
2229             }
2230 
2231             // remove some obsolete filter flags
2232             if (bRemoveFilterFlagBrowserPreferred)
2233             {
2234                 flags1 &= ~FLAGVAL_BROWSERPREFERRED;
2235                 aFilter.put(PROPNAME_FLAGS, new java.lang.Integer(flags1));
2236             }
2237 
2238             if (bRemoveFilterFlag3rdparty)
2239             {
2240                 flags1 &= ~FLAGVAL_3RDPARTYFILTER;
2241                 aFilter.put(PROPNAME_FLAGS, new java.lang.Integer(flags1));
2242             }
2243 
2244             // if it's a filter with an UI order ...
2245             // move this information to the registered type.
2246             // Note: Because more then one filter can be registered for the same type.
2247             // Handle it as an error ... till we find a better transformation!
2248             java.lang.Integer nOrder   = (java.lang.Integer)aFilter.get(PROPNAME_ORDER);
2249             java.lang.Integer nUIOrder = (java.lang.Integer)aType.get(PROPNAME_UIORDER);
2250             int               order    = nOrder.intValue();
2251             int               uiorder  = nUIOrder.intValue();
2252 
2253             if (order > 0)
2254             {
2255                 if (
2256                     (uiorder < 1    ) ||
2257                     (uiorder > order)
2258                    )
2259                 {
2260                     aType.put(PROPNAME_UIORDER, nOrder);
2261                     m_aDebug.setDetailedInfo("moved order value "+nOrder+" from filter \""+sFilter+"\" to type \""+sTypeReg+"\"");
2262                 }
2263                 else
2264                     m_aDebug.setDetailedInfo("ignore order value [order="+nOrder+",uiorder="+nUIOrder+"] for filter \""+sFilter+"\" and type \""+sTypeReg+"\"");
2265             }
2266         }
2267 
2268         // NOW ... remove the preferred flags from every filter, which it has set.
2269         java.util.Enumeration aIt2 = null;
2270         if (bRemoveFilterFlagPreferred)
2271         {
2272             aIt2 = lPreferredFilters.elements();
2273             while (aIt2.hasMoreElements())
2274             {
2275                 java.util.HashMap aFilter = (java.util.HashMap)aIt2.nextElement();
2276                 int               flags   = ((java.lang.Integer)aFilter.get(PROPNAME_FLAGS)).intValue();
2277                 flags &= ~FLAGVAL_PREFERRED;
2278                 aFilter.put(PROPNAME_FLAGS, new java.lang.Integer(flags));
2279             }
2280         }
2281 
2282         // NOW ... remove all "no real filters" like the graphic helper filters of
2283         // Draw and Impress!
2284         aIt2 = lNoRealFilters.elements();
2285         while (aIt2.hasMoreElements())
2286             m_lFilters.remove(aIt2.nextElement());
2287 
2288         // step over all detect services and move this information directly to
2289         // the corresponding types
2290         // Overwrite possible default registrations with a real existing one!
2291         aIt1 = m_lDetectServices.keySet().iterator();
2292         while(aIt1.hasNext())
2293         {
2294             java.lang.String      sDetector = (java.lang.String)aIt1.next();
2295             java.util.HashMap     aDetector = (java.util.HashMap)m_lDetectServices.get(sDetector);
2296             java.util.Vector      lTypeReg  = (java.util.Vector)aDetector.get(PROPNAME_TYPES);
2297             aIt2 = lTypeReg.elements();
2298             while(aIt2.hasMoreElements())
2299             {
2300                 java.lang.String  sTypeReg                   = (java.lang.String)aIt2.nextElement();
2301                 java.util.HashMap aType                      = (java.util.HashMap)m_lTypes.get(sTypeReg);
2302 
2303                 if (aType == null)
2304                 {
2305                     m_aDebug.setWarning("Detector \""+sDetector+"\" seem to be registered for unknown type \""+sTypeReg+"\"");
2306                     continue;
2307                 }
2308 
2309                 java.lang.Object  aAlreadyRegisteredDetector = aType.get(PROPNAME_DETECTSERVICE);
2310                 if (aAlreadyRegisteredDetector != null && ((java.lang.String)aAlreadyRegisteredDetector).length() > 0)
2311                 {
2312                     java.lang.StringBuffer sMsg = new java.lang.StringBuffer(256);
2313                     sMsg.append("type \""+sTypeReg+"\" has ambiguous registrations of a detect service\n");
2314                     sMsg.append("\tdetect service[1] = \""+(java.lang.String)aAlreadyRegisteredDetector+"\"\n");
2315                     sMsg.append("\tdetect service[2] = \""+sDetector+"\"\n");
2316                     m_aDebug.setWarning(sMsg.toString());
2317                 }
2318                 aType.put(PROPNAME_DETECTSERVICE, sDetector);
2319                 m_aDebug.setGlobalInfo("move detector \""+sDetector+"\" to type \""+sTypeReg+"\"");
2320             }
2321         }
2322 
2323         // because all detect service was registered as type properties directly ...
2324         // remove all detect service objects of this cache!
2325         m_lDetectServices.clear();
2326 
2327         // step over all frame loader and move this information directly to
2328         // the corresponding types
2329         // Overwrite possible default registrations with a real existing one!
2330         aIt1 = m_lFrameLoaders.keySet().iterator();
2331         while(aIt1.hasNext())
2332         {
2333             java.lang.String      sLoader  = (java.lang.String)aIt1.next();
2334             java.util.HashMap     aLoader  = (java.util.HashMap)m_lFrameLoaders.get(sLoader);
2335             java.util.Vector      lTypeReg = (java.util.Vector)aLoader.get(PROPNAME_TYPES);
2336             aIt2 = lTypeReg.elements();
2337             while(aIt2.hasMoreElements())
2338             {
2339                 java.lang.String  sTypeReg                 = (java.lang.String)aIt2.nextElement();
2340                 java.util.HashMap aType                    = (java.util.HashMap)m_lTypes.get(sTypeReg);
2341                 java.lang.String  sAlreadyRegisteredLoader = (java.lang.String)aType.get(PROPNAME_FRAMELOADER);
2342                 if (sAlreadyRegisteredLoader != null && sAlreadyRegisteredLoader.length() > 0)
2343                 {
2344                     java.lang.StringBuffer sMsg = new java.lang.StringBuffer(256);
2345                     sMsg.append("type \""+sTypeReg+"\" has ambiguous registrations of a frame loader\n");
2346                     sMsg.append("\tframe loader[1] = \""+sAlreadyRegisteredLoader+"\"\n");
2347                     sMsg.append("\tframe loader[2] = \""+sLoader+"\"\n");
2348                     m_aDebug.setWarning(sMsg.toString());
2349                 }
2350                 aType.put(PROPNAME_FRAMELOADER, sLoader);
2351                 System.out.println("move loader \""+sLoader+"\" to type \""+sTypeReg+"\"");
2352             }
2353         }
2354 
2355         m_lFrameLoaders.clear();
2356 
2357         // step over all content handler and move this information directly to
2358         // the corresponding types
2359         // Overwrite possible default registrations with a real existing one!
2360         aIt1 = m_lContentHandlers.keySet().iterator();
2361         while(aIt1.hasNext())
2362         {
2363             java.lang.String      sHandler = (java.lang.String)aIt1.next();
2364             java.util.HashMap     aHandler = (java.util.HashMap)m_lContentHandlers.get(sHandler);
2365             java.util.Vector      lTypeReg = (java.util.Vector)aHandler.get(PROPNAME_TYPES);
2366             aIt2 = lTypeReg.elements();
2367             while(aIt2.hasMoreElements())
2368             {
2369                 java.lang.String  sTypeReg                  = (java.lang.String)aIt2.nextElement();
2370                 java.util.HashMap aType                     = (java.util.HashMap)m_lTypes.get(sTypeReg);
2371                 java.lang.String  sAlreadyRegisteredHandler = (java.lang.String)aType.get(PROPNAME_CONTENTHANDLER);
2372                 if (sAlreadyRegisteredHandler != null && sAlreadyRegisteredHandler.length() > 0)
2373                 {
2374                     java.lang.StringBuffer sMsg = new java.lang.StringBuffer(256);
2375                     sMsg.append("type \""+sTypeReg+"\" has ambiguous registrations of a content handler\n");
2376                     sMsg.append("\tcontent handler[1] = \""+sAlreadyRegisteredHandler+"\"\n");
2377                     sMsg.append("\tcontent handler[2] = \""+sHandler+"\"\n");
2378                     m_aDebug.setWarning(sMsg.toString());
2379                 }
2380                 aType.put(PROPNAME_CONTENTHANDLER, sHandler);
2381                 System.out.println("move handler \""+sHandler+"\" to type \""+sTypeReg+"\"");
2382             }
2383         }
2384 
2385         m_lContentHandlers.clear();
2386 
2387 /*
2388         int c = m_lTypes.size();
2389         java.lang.String[] lT1 = new java.lang.String[c];
2390         java.lang.String[] lT2 = new java.lang.String[c];
2391         long nUPS = 0;
2392 
2393         int i = 0;
2394         aIt1 = m_lTypes.keySet().iterator();
2395         while(aIt1.hasNext())
2396         {
2397             lT1[i] = (java.lang.String)aIt1.next();
2398             lT2[i] = lT1[i];
2399             ++i;
2400         }
2401 
2402         for (int i1=0; i1<c; ++i1)
2403         {
2404             java.lang.String  sT1 = lT1[i1];
2405             java.util.HashMap aT1 = (java.util.HashMap)m_lTypes.get(sT1);
2406 
2407             for (int i2=i1; i2<c; ++i2)
2408             {
2409                 java.lang.String  sT2 = lT1[i2];
2410                 java.util.HashMap aT2 = (java.util.HashMap)m_lTypes.get(sT2);
2411 
2412                 if (!sT1.equals(sT2))
2413                 {
2414                     if (
2415                         aT1.get(PROPNAME_MEDIATYPE).equals(aT2.get(PROPNAME_MEDIATYPE)) &&
2416                         aT1.get(PROPNAME_CLIPBOARDFORMAT).equals(aT2.get(PROPNAME_CLIPBOARDFORMAT)) &&
2417                         aT1.get(PROPNAME_URLPATTERN).equals(aT2.get(PROPNAME_URLPATTERN)) &&
2418                         aT1.get(PROPNAME_EXTENSIONS).equals(aT2.get(PROPNAME_EXTENSIONS))
2419                        )
2420                     {
2421                         System.err.println("UUPPSS----------------------------------------------------------------------------");
2422                         System.err.println("[1]\""+sT1+"\" equals [2]\""+sT2+"\"");
2423                         System.err.println("\tprops 1: "+aT1);
2424                         System.err.println("\tprops 2: "+aT2);
2425                         System.err.println("----------------------------------------------------------------------------------\n");
2426                         ++nUPS;
2427 //                        throw new java.lang.Exception("UUPPS :-)");
2428                     }
2429                 }
2430             }
2431         }
2432         System.err.println("count of UPS = "+nUPS);
2433 */
2434     }
2435 }
2436