diff --git a/src/main/java/org/harctoolbox/girr/Command.java b/src/main/java/org/harctoolbox/girr/Command.java index aecd94c..0ffe14c 100644 --- a/src/main/java/org/harctoolbox/girr/Command.java +++ b/src/main/java/org/harctoolbox/girr/Command.java @@ -29,6 +29,7 @@ import static org.harctoolbox.girr.XmlStatic.COMMAND_ELEMENT_NAME; import static org.harctoolbox.girr.XmlStatic.COMMENT_ATTRIBUTE_NAME; import static org.harctoolbox.girr.XmlStatic.DISPLAYNAME_ATTRIBUTE_NAME; +import static org.harctoolbox.girr.XmlStatic.DISPLAYNAME_ELEMENT_NAME; import static org.harctoolbox.girr.XmlStatic.DUTYCYCLE_ATTRIBUTE_NAME; import static org.harctoolbox.girr.XmlStatic.ENDING_ELEMENT_NAME; import static org.harctoolbox.girr.XmlStatic.FLASH_ELEMENT_NAME; @@ -245,7 +246,7 @@ public static ModulatedIrSequence concatenateAsSequence(Collection comm private MasterType masterType; private Map notes; private String name; - private String displayName; + private Map displayName = new HashMap<>(1); private String protocolName; // should always be lowercase private Map parameters; private Integer frequency; @@ -271,7 +272,11 @@ public Command(Element element, String inheritProtocol, Map inheri if (inheritParameters != null) parameters.putAll(inheritParameters); otherFormats = new HashMap<>(0); - displayName = element.getAttribute(DISPLAYNAME_ATTRIBUTE_NAME); + String displayNameAttribute = element.getAttribute(DISPLAYNAME_ATTRIBUTE_NAME); + displayName = XmlStatic.parseElementsByLanguage(element.getElementsByTagName(DISPLAYNAME_ELEMENT_NAME)); + if (! displayNameAttribute.isEmpty() && ! displayName.containsKey(ENGLISH)) + displayName.put(ENGLISH, displayNameAttribute); + notes = XmlStatic.parseElementsByLanguage(element.getElementsByTagName(NOTES_ELEMENT_NAME)); try { @@ -700,12 +705,20 @@ public String getFormat(String name) { return otherFormats != null ? otherFormats.get(name) : null; } + public String getDisplayName(String lang) { + return displayName.get(lang); + } + public String getDisplayName() { - return displayName; + return getDisplayName(ENGLISH); + } + + public void setDisplayName(String lang, String dispName) { + displayName.put(lang, dispName); } public void setDisplayName(String dispName) { - displayName = dispName; + setDisplayName(ENGLISH, dispName); } /** @@ -1052,8 +1065,13 @@ Element toElement(Document doc, String title, boolean fatRaw, boolean createSche element.setAttribute(MASTER_ATTRIBUTE_NAME, actualMasterType.name()); if (comment != null && !comment.isEmpty()) element.setAttribute(COMMENT_ATTRIBUTE_NAME, comment); - if (displayName != null && !displayName.isEmpty()) - element.setAttribute(DISPLAYNAME_ATTRIBUTE_NAME, this.displayName); + + for (Map.Entry kvp : displayName.entrySet()) { + Element dispName = doc.createElementNS(GIRR_NAMESPACE, DISPLAYNAME_ELEMENT_NAME); + dispName.setAttribute(XML_LANG_ATTRIBUTE_NAME, kvp.getKey()); + dispName.setTextContent(kvp.getValue()); + element.appendChild(dispName); + } notes.entrySet().stream().map((note) -> { Element notesEl = doc.createElementNS(GIRR_NAMESPACE, NOTES_ELEMENT_NAME); diff --git a/src/main/java/org/harctoolbox/girr/XmlStatic.java b/src/main/java/org/harctoolbox/girr/XmlStatic.java index 49eb437..cc2f200 100644 --- a/src/main/java/org/harctoolbox/girr/XmlStatic.java +++ b/src/main/java/org/harctoolbox/girr/XmlStatic.java @@ -41,7 +41,7 @@ public abstract class XmlStatic { * (not to be confused with the version of an implementation). * Should be the same as the attribute girrVersion in girr_ns.xsd. */ - public static final String GIRR_VERSION = "1.2"; + public static final String GIRR_VERSION = "1.3"; /** * Namespace URI @@ -56,7 +56,7 @@ public abstract class XmlStatic { /** * URL for schema file supporting name spaces. */ - public static final String GIRR_SCHEMA_LOCATION_URI = "http://www.harctoolbox.org/schemas/girr_ns-" + GIRR_VERSION + ".xsd"; + public static final String GIRR_SCHEMA_LOCATION_URI = "file:///home/bengt/harctoolbox/Girr/src/main/schemas/girr_ns-" + GIRR_VERSION + ".xsd"; /** * URL for schema file, namespace-less version. @@ -115,6 +115,7 @@ public abstract class XmlStatic { static final String ADMINDATA_ELEMENT_NAME = "adminData"; static final String CREATIONDATA_ELEMENT_NAME = "creationData"; static final String REMOTES_ELEMENT_NAME = "remotes"; + static final String DISPLAYNAME_ELEMENT_NAME = "displayName"; static final String SPACE = " "; diff --git a/src/main/schemas/girr_ns-1.3.xsd b/src/main/schemas/girr_ns-1.3.xsd new file mode 100644 index 0000000..7cfc8ce --- /dev/null +++ b/src/main/schemas/girr_ns-1.3.xsd @@ -0,0 +1,481 @@ + + + + + + + + The Girr format + is documented at www.harctoolbox.org/Girr.html + + + + + + + + + + + + Determines whether the raw representation, the ccf, or the protocol with parameters is the master of the data. + + + + + + + + + + + A parameter value, either a decimal, nonnegative number, or a hexadecimal number preceeded by 0x. + + + + + + + + + Data type describing a four-digit hexadecimal number. + + + + + + + + + Data type describing a Pronto Hex CCF string. + + + + + + + Number between 0 and 1. + + + + + + + + + + + This element models a set of remotes. It may act as a data base for a program or device. + + + + + + + + + + + + + + + + + + + + + + + Textual title of the document. + + + + + + + + Version of the Girr specification the document claims to follow. + + + + + + + + Name that is used to identify the element. + Should therefore be unique in the context. + Even though arbitrary strings are allowed, C-syntax type strings, + in the English language, are recommended. + + + + + + Name of the command as being displayed to the user. + Special characters and non-English languages are here appropriate. + The attribute is deprecated; please use the element with the same name instead. + + + + + + Textual comment. + + + + + + + + + + + + + + + + + + + + + Describes how, from what, and by whom the document was created. + + + + + Name of creating user + + + + + Source of the information, for example, another document that was converted to the present one. + + + + + Date of creation, or last modification. + + + + + Name of creating tool. + + + + + Version of creating tool. + + + + + Name of secondary creating tool, if applicable. + + + + + Version of creating tool. + + + + + + + + Versioning data; semanics is still to be determined. + + + + + + + + + + + Textual notes, possibly using formatting in HTML. + + + + + + + + + + + + The element models an abstract remote, which is basically a collection of commands. + + + + + + + + + + + + + + + + + + + + + + + Name of captured remote control as a component. Normally different from the name. + + + + + + + + + + + + + + + + + + + + + + Data, only relevant for a particular application or domain, can be embedded here. + + + + + + + + + Name of application or domain the application data is intended for. + + + + + + + + + + + + + + Numerical value for a parameter. Nonnegative integer with base 10. + + + + + + + + + String value for a parameter. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Protocol name as known to e.g. IrpMaster. + + + + + + + + + + + + + + + + A command is essentially an IR signal with a name. + + + + + + + + + + + + + + Value of the F parameter for the current command in the current protocol (if applicable). + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the command as being displayed to the user. + Special characters and non-English languages are here appropriate. + + + + + + + + + + + + + Models a raw IR signal, with into, repeat, and ending sequence (any of these may be empty). + + + + + + + + + + + + Carrier frequency in Hz. + + + + + Duty cycle of modulation signal, between 0 and 1. + + + + + + + + + + Toggle value, the "T" parameter in many protocols. + + + + + + + Models a raw IR sequence, defined by its durations. + This should be either a sequence of numbers, or alternating flash and gap elements. + Unfortunately, this cannot be described in XML Schemas :-(. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/girr/topping-command.girr b/src/test/girr/topping-command.girr index 126f68b..2c36202 100644 --- a/src/test/girr/topping-command.girr +++ b/src/test/girr/topping-command.girr @@ -9,6 +9,10 @@ girrVersion="1.2" title="IrScrutinizer parametric export" xsi:schemaLocation="http://www.harctoolbox.org/Girr ../../main/schemas/girr_ns-1.2.xsd"> + + Strom Ein/Aus + Ström På/Av +