Skip to content

Commit

Permalink
displayName now element in Command, as per #4.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengtmartensson committed Apr 17, 2021
1 parent ba968b1 commit 6520cc0
Show file tree
Hide file tree
Showing 4 changed files with 512 additions and 8 deletions.
30 changes: 24 additions & 6 deletions src/main/java/org/harctoolbox/girr/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -245,7 +246,7 @@ public static ModulatedIrSequence concatenateAsSequence(Collection<Command> comm
private MasterType masterType;
private Map<String, String> notes;
private String name;
private String displayName;
private Map<String, String> displayName = new HashMap<>(1);
private String protocolName; // should always be lowercase
private Map<String, Long> parameters;
private Integer frequency;
Expand All @@ -271,7 +272,11 @@ public Command(Element element, String inheritProtocol, Map<String, Long> 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 {
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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<String, String> 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);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/harctoolbox/girr/XmlStatic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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 = " ";

Expand Down
Loading

0 comments on commit 6520cc0

Please sign in to comment.