initial relation editing
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / Feature.as
index 425768ce8772988857afc3abb5ea4b2829396b1c..714d9c34f6333e0ca18e04972a252a7d20bcb658 100644 (file)
@@ -32,19 +32,36 @@ package net.systemeD.potlatch2.mapfeatures {
         private function parseEditors():void {
             _editors = new Array();
             
-            for each(var inputXML:XML in definition.input) {
-                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);
+            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);
                 }
             }
             
-            _editors.sortOn(["sortOrder", "name"], [Array.DESCENDING | Array.NUMERIC, Array.CASEINSENSITIVE]);
+            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 {
@@ -72,18 +89,32 @@ package net.systemeD.potlatch2.mapfeatures {
         
         public function htmlDetails(entity:Entity):String {
             var icon:XMLList = _xml.icon;
+            return makeHTMLIcon(icon, entity);
+        }   
+
+        public static function makeHTMLIcon(icon:XMLList, entity:Entity):String {
             if ( icon == null )
                 return "";
-
+            
             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 )