001package org.javasimon.console.html;
002
003import org.javasimon.console.json.ArrayJS;
004import org.javasimon.console.json.ObjectJS;
005import org.javasimon.console.text.StringifierFactory;
006
007/**
008 * JavaScript or CSS resource used by a plugin.
009 *
010 * @author gquintana
011 */
012public final class HtmlResource {
013
014        /** Path/location of the resource. */
015        private final String path;
016        /** Resource type: either JavaScript or CSS. */
017        private final HtmlResourceType type;
018
019        public HtmlResource(String path, HtmlResourceType type) {
020                this.path = path;
021                this.type = type;
022        }
023
024        public String getPath() {
025                return path;
026        }
027
028        public HtmlResourceType getType() {
029                return type;
030        }
031
032        public ObjectJS toJson(StringifierFactory jsonStringifierFactory) {
033                return ObjectJS.create(this, jsonStringifierFactory);
034        }
035
036        public static ArrayJS toJson(Iterable<HtmlResource> resources, StringifierFactory jsonStringifierFactory) {
037                ArrayJS resourcesJS = new ArrayJS();
038                for (HtmlResource resource : resources) {
039                        resourcesJS.addElement(resource.toJson(jsonStringifierFactory));
040                }
041                return resourcesJS;
042        }
043}