categories of additional tags for roads
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / Feature.as
index 6e3e724..e24c827 100644 (file)
@@ -9,10 +9,16 @@ package net.systemeD.potlatch2.mapfeatures {
         private var _xml:XML;
         private static var variablesPattern:RegExp = /[$][{]([^}]+)[}]/g;
         private var _tags:Array;
+        private var _editors:Array;
 
         public function Feature(mapFeatures:MapFeatures, _xml:XML) {
             this.mapFeatures = mapFeatures;
             this._xml = _xml;
+            parseTags();
+            parseEditors();
+        }
+        
+        private function parseTags():void {
             _tags = new Array();
             
             for each(var tag:XML in definition.tag) {
@@ -21,7 +27,44 @@ package net.systemeD.potlatch2.mapfeatures {
                 tagObj["v"] = tag.@v;
                 _tags.push(tagObj);
             }
-
+        }
+        
+        private function parseEditors():void {
+            _editors = new Array();
+            
+            addEditors(definition);
+            
+            _editors.sortOn(["sortOrder", "name"], [Array.DESCENDING | Array.NUMERIC, Array.CASEINSENSITIVE]);
+        }
+        
+        private function addEditors(xml:XML):void {
+            var inputXML:XML;
+            
+            for each(var inputSetRef:XML in xml.inputSet) {
+                var setName:String = String(inputSetRef.@ref);
+                for each (inputXML in mapFeatures.definition.inputSet.(@id==setName)) {
+                    addEditors(inputXML);
+                }
+            }
+            
+            for each(inputXML in xml.input) {
+                addEditor(inputXML);
+            }
+        }
+        
+        private function addEditor(inputXML:XML):void {
+            var inputType:String = inputXML.@type;
+            var presenceStr:String = inputXML.@presence;
+            var sortOrderStr:String = inputXML.@priority;
+            var editor:EditorFactory = EditorFactory.createFactory(inputType, inputXML);
+            if ( editor != null ) {
+                editor.presence = Presence.getPresence(presenceStr);
+                editor.sortOrder = EditorFactory.getPriority(sortOrderStr);
+                _editors.push(editor);
+            }
+        }
+        public function get editors():Array {
+            return _editors;
         }
         
         public function get definition():XML {
@@ -51,12 +94,22 @@ package net.systemeD.potlatch2.mapfeatures {
             var txt:String = icon.children().toXMLString();
             var replaceTag:Function = function():String {
                 var value:String = entity.getTag(arguments[1]);
-                return value == null ? "" : value;
+                return value == null ? "" : htmlEscape(value);
             };
             txt = txt.replace(variablesPattern, replaceTag);
             return txt;
         }
         
+        public static function htmlEscape(str:String):String {
+            var newStr:String = str.replace(/&/g, "&");
+            newStr = newStr.replace(/</g, "&lt;");
+            newStr = newStr.replace(/>/g, "&gt;");
+            newStr = newStr.replace(/"/g, "&quot;");
+            newStr = newStr.replace(/'/g, "&apos;");
+            return newStr;
+        }
+      
+
         public function isInCategory(category:String):Boolean {
             var cats:XMLList = _xml.category;
             if ( cats.length() == 0 )