Skip to content

Commit

Permalink
trim name value in <param> tag
Browse files Browse the repository at this point in the history
  • Loading branch information
yoikawa committed May 30, 2023
1 parent ba9b788 commit c4624ef
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public Noun createNoun(String name, String pluralAlias, NounType type, String en
public Noun createNoun(String tableEnumOrId, NounType type, ResultSet rs, Uniquefy uniquefy) throws SQLException {
LanguageStartsWith starts = LanguageStartsWith.fromDbValue(rs.getString("STARTS_WITH"));
LanguageGender gen = LanguageGender.fromDbValue(rs.getString("GENDER"));
String name = uniquefy.unique(rs.getString("NAME"));
String name = rs.getString("NAME");
return createNoun(name, null, type, tableEnumOrId, starts, gen, null, false, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ protected void setString(String value, NounForm form) {
protected boolean validateValues(String name, LanguageCase _case) {
///CLOVER:OFF
if (this.value == null) {
logger.info("###\tError: The noun " + name + " has no value");
// this is wrong. the noun should have singular form
logger.severe("###\tError: The noun " + name + " has no value");
return false;
}
///CLOVER:ON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package com.force.i18n.grammar.parser;

import static com.force.i18n.commons.util.settings.IniFileUtil.intern;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
Expand Down Expand Up @@ -174,10 +176,11 @@ abstract class BaseTag {
this.parent = parent;
this.attributes = atts;
if (atts != null) {
this.name = getParser().uniquefy(atts.getValue(NAME));
String n = atts.getValue(NAME);
this.name = (n != null) ? intern(n.trim()) : null;
///CLOVER:OFF
if (this.name == null && isNameRequired())
throw new SAXParseException("Missing required attribuite:" + NAME, getLocator());
if (this.name == null && isNameRequired())
throw new SAXParseException("Missing required attribuite:" + NAME, getLocator());
///CLOVER:ON
}
}
Expand Down Expand Up @@ -364,17 +367,16 @@ String getTagName() {
currentParam = this;
}


@Override
boolean isNameRequired() {
return true;
}

@Override
void endElement() {
super.endElement();
void endElement() {
super.endElement();
currentParam = null;
}
}

@Override
void addLabelDataToParent(Object data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package com.force.i18n.grammar.parser;

import static com.force.i18n.commons.util.settings.IniFileUtil.intern;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
Expand Down Expand Up @@ -62,8 +64,8 @@ public class GrammaticalLabelFileParser implements BasePropertyFile.Parser {
*/
public GrammaticalLabelFileParser(LanguageDictionary dictionary, LabelSetDescriptor labelDesc, GrammaticalLabelSetProvider parentProvider) throws IOException {
this(dictionary, labelDesc, parentProvider,
dictionary.getLanguage() == LanguageProviderFactory.get().getBaseLanguage()
&& isDupeLabelTrackingEnabled());
dictionary.getLanguage() == LanguageProviderFactory.get().getBaseLanguage()
&& isDupeLabelTrackingEnabled());
}

public GrammaticalLabelFileParser(LanguageDictionary dictionary, LabelSetDescriptor labelDesc, GrammaticalLabelSetProvider parentProvider, boolean trackDupes) {
Expand All @@ -90,12 +92,12 @@ public void load(PropertyFileData data, Map<String, Map<String, MetaDataInfo>> m
}
}
} else {
if(this.desc.hasModularizedFiles()) {
for(URL modularizedFile : this.desc.getModularizedFiles()) {
found = true;
parseLabels(data, modularizedFile);
}
} else if (TrackingHandler.exists(this.desc.getRootFile())) {
if(this.desc.hasModularizedFiles()) {
for(URL modularizedFile : this.desc.getModularizedFiles()) {
found = true;
parseLabels(data, modularizedFile);
}
} else if (TrackingHandler.exists(this.desc.getRootFile())) {
// Parse english labels
found = true;
parseLabels(data, this.desc.getRootFile());
Expand Down Expand Up @@ -178,11 +180,11 @@ boolean trackDupes() {
}

static boolean isDupeLabelTrackingEnabled() {
return false;
return false;
}

String uniquefy(String label) {
return this.uniquefy.unique(label);
return uniquefy.unique(label);
}

void trackLabel(String label, String location) {
Expand Down Expand Up @@ -302,7 +304,8 @@ private Object validateDst(LabelSet label) {
}

LabelRef makeLabelRef(String section, String param) {
return aliasUniquefy.unique(new LabelRef(uniquefy(section), uniquefy(param)));
// use inern(String) for section/param name as these are always reused
return aliasUniquefy.unique(new LabelRef(intern(section), intern(param)));
}

@Override
Expand Down Expand Up @@ -357,11 +360,11 @@ void addAlias(String srcSection, String srcParam, String dstSection, String dstP
}

void removeAlias(String srcSection, String srcParam) {
if (this.aliasMap != null) {
String k = getKey(srcSection, srcParam);
if (this.aliasMap.containsKey(k)) {
this.aliasMap.remove(k);
}
assert this.aliasMap != null;

String k = getKey(srcSection, srcParam);
if (this.aliasMap.containsKey(k)) {
this.aliasMap.remove(k);
}
}

Expand Down Expand Up @@ -396,7 +399,6 @@ void resolveAliases(GrammaticalLabelSet labelSet, GrammaticalLabelSetImpl writeS
}
}
assert this.aliasMap.isEmpty() : "Unresolved aliases: " + this.aliasMap;
this.uniquefy = null;
this.aliasUniquefy = null;
}

Expand Down Expand Up @@ -434,7 +436,7 @@ private Object resolveAlias(GrammaticalLabelSet labelSet, GrammaticalLabelSetImp
Set<String> localRefSet = refSet;
if (refSet == null) {
// means this is the top level (or maybe middle) of alias chain
localRefSet = new HashSet<String>();
localRefSet = new HashSet<>();
} else {
// recursively called from alias chain. add to the chain list
refSet.add(ap.getKey());
Expand All @@ -460,7 +462,7 @@ private Object resolveAlias(GrammaticalLabelSet labelSet, GrammaticalLabelSetImp
return retValue;
}

public static enum ErrorType {
public enum ErrorType {
// noun does not exist
UnknownEntity("Unknown entity <{0}>"),
// bad alias -- circular reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void startElement(String uri, String localName, String qName, Attributes attribu
@Override
void endElement() {
assert getParent() != null;
getParent().setString(uniquefy.unique(this.sb.toString()), attribute);
getParent().setString(intern(this.sb.toString()), attribute);
}
}

Expand All @@ -242,12 +242,12 @@ class NounTag extends BaseTag {
super(parent, atts);

// always store as lower case
this.name = uniquefy.unique(atts.getValue(NAME).toLowerCase());
this.name = intern(atts.getValue(NAME).toLowerCase());
NounType type = NounType.getByApiValue(atts.getValue(TYPE));

String tableEnum = uniquefy.unique(atts.getValue(ENTITY));
String tableEnum = intern(atts.getValue(ENTITY));
String access = atts.getValue(ACCESS);
String alias = uniquefy.unique(atts.getValue(ALIAS));
String alias = uniquefy.unique(atts.getValue(ALIAS)); // use local uniquefy 'cause it's temporally
LanguageStartsWith starts = LanguageStartsWith.fromDbValue(atts.getValue(ENDS) != null ? atts.getValue(ENDS) : atts.getValue(STARTS));
LanguageGender gen = LanguageGender.fromLabelValue(atts.getValue(GENDER));
boolean isStandardField = (atts.getValue(STANDARDFIELD) == null ? true : atts
Expand All @@ -259,7 +259,7 @@ class NounTag extends BaseTag {
if (parser.hasParentDictionarySameLang() && this.n == parser.getParentDictionary().getNoun(name, false)) {
this.n = this.n.clone(gen, starts);
}
String classifier = uniquefy.unique(atts.getValue(COUNTER));
String classifier = intern(atts.getValue(COUNTER));
if (classifier != null) {
if (n instanceof Noun.WithClassifier) {
((Noun.WithClassifier)n).setClassifier(classifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private void _testComplexGrammaticalFormInvariant(List<?> list) throws Exception
* Chances are you should run this again in the production environment, that's why there's
* a test version so you don't have tests that run forever
*/
@Test
public void testDeclensionInvariants() throws Exception {
declensionInvariantTester(LanguageProviderFactory.get().getAll());
}
Expand Down

0 comments on commit c4624ef

Please sign in to comment.