diff --git a/src/main/java/org/gedcom4j/parser/FamilyChildParser.java b/src/main/java/org/gedcom4j/parser/FamilyChildParser.java new file mode 100644 index 00000000..b0702380 --- /dev/null +++ b/src/main/java/org/gedcom4j/parser/FamilyChildParser.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2009-2016 Matthew R. Harrah + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.gedcom4j.parser; + +import java.util.List; + +import org.gedcom4j.model.*; + +/** + * Parser for {@link FamilyChild} objects + * + * @author frizbog + */ +class FamilyChildParser extends AbstractParser { + + /** + * Constructor + * + * @param gedcomParser + * a reference to the root {@link GedcomParser} + * @param stringTree + * {@link StringTree} to be parsed + * @param loadInto + * the object we are loading data into + */ + FamilyChildParser(GedcomParser gedcomParser, StringTree stringTree, FamilyChild loadInto) { + super(gedcomParser, stringTree, loadInto); + } + + @Override + void parse() { + Family f = getFamily(stringTree.getValue()); + loadInto.setFamily(f); + if (stringTree.getChildren() != null) { + for (StringTree ch : stringTree.getChildren()) { + if (Tag.NOTE.equalsText(ch.getTag())) { + List notes = loadInto.getNotes(true); + new NoteListParser(gedcomParser, ch, notes).parse(); + } else if (Tag.PEDIGREE.equalsText(ch.getTag())) { + loadInto.setPedigree(new StringWithCustomTags(ch)); + } else if (Tag.ADOPTION.equalsText(ch.getTag())) { + loadInto.setAdoptedBy(AdoptedByWhichParent.valueOf(ch.getValue())); + } else if (Tag.STATUS.equalsText(ch.getTag())) { + loadInto.setStatus(new StringWithCustomTags(ch)); + if (g55()) { + addWarning("GEDCOM version is 5.5 but status was specified for child-to-family link on line " + ch.getLineNum() + + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); + } + } else { + unknownTag(ch, loadInto); + } + } + } + } + +} diff --git a/src/main/java/org/gedcom4j/parser/GedcomParser.java b/src/main/java/org/gedcom4j/parser/GedcomParser.java index 4ea709a7..fd2ef6aa 100644 --- a/src/main/java/org/gedcom4j/parser/GedcomParser.java +++ b/src/main/java/org/gedcom4j/parser/GedcomParser.java @@ -583,8 +583,9 @@ private void loadFamilyEvent(StringTree st, List events) { } else if (Tag.DATE.equalsText(ch.getTag())) { e.setDate(new StringWithCustomTags(ch)); } else if (Tag.PLACE.equalsText(ch.getTag())) { - e.setPlace(new Place()); - loadPlace(ch, e.getPlace()); + Place place = new Place(); + e.setPlace(place); + new PlaceParser(gedcomParser, ch, place).parse(); } else if (Tag.OBJECT_MULTIMEDIA.equalsText(ch.getTag())) { List multimedia = e.getMultimedia(true); new MultimediaLinkParser(gedcomParser, ch, multimedia).parse(); @@ -659,41 +660,6 @@ private void loadFamilyEvent(StringTree st, List events) { } - /** - * Load a reference to a family where this individual was a child, from a string tree node - * - * @param st - * the string tree node - * @param familiesWhereChild - * the list of families where the individual was a child - */ - private void loadFamilyWhereChild(StringTree st, List familiesWhereChild) { - Family f = getFamily(st.getValue()); - FamilyChild fc = new FamilyChild(); - familiesWhereChild.add(fc); - fc.setFamily(f); - if (st.getChildren() != null) { - for (StringTree ch : st.getChildren()) { - if (Tag.NOTE.equalsText(ch.getTag())) { - loadNote(ch, fc.getNotes(true)); - } else if (Tag.PEDIGREE.equalsText(ch.getTag())) { - fc.setPedigree(new StringWithCustomTags(ch)); - } else if (Tag.ADOPTION.equalsText(ch.getTag())) { - fc.setAdoptedBy(AdoptedByWhichParent.valueOf(ch.getValue())); - } else if (Tag.STATUS.equalsText(ch.getTag())) { - fc.setStatus(new StringWithCustomTags(ch)); - if (g55()) { - addWarning("GEDCOM version is 5.5 but status was specified for child-to-family link on line " + ch.getLineNum() - + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); - } - } else { - unknownTag(ch, fc); - } - } - } - - } - /** * Load a reference to a family where this individual was a spouse, from a string tree node * @@ -761,7 +727,9 @@ private void loadIndividual(StringTree st) { + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); } } else if (IndividualEventType.isValidTag(ch.getTag())) { - loadIndividualEvent(ch, i.getEvents(true)); + IndividualEvent event = new IndividualEvent(); + i.getEvents(true).add(event); + new IndividualEventParser(gedcomParser, ch, event).parse(); } else if (IndividualAttributeType.isValidTag(ch.getTag())) { loadIndividualAttribute(ch, i.getAttributes(true)); } else if (LdsIndividualOrdinanceType.isValidTag(ch.getTag())) { @@ -789,7 +757,9 @@ private void loadIndividual(StringTree st) { } else if (Tag.FAMILY_WHERE_SPOUSE.equalsText(ch.getTag())) { loadFamilyWhereSpouse(ch, i.getFamiliesWhereSpouse(true)); } else if (Tag.FAMILY_WHERE_CHILD.equalsText(ch.getTag())) { - loadFamilyWhereChild(ch, i.getFamiliesWhereChild(true)); + FamilyChild fc = new FamilyChild(); + i.getFamiliesWhereChild(true).add(fc); + new FamilyChildParser(gedcomParser, ch, fc).parse(); } else if (Tag.ASSOCIATION.equalsText(ch.getTag())) { Association a = new Association(); i.getAssociations(true).add(a); @@ -838,8 +808,9 @@ private void loadIndividualAttribute(StringTree st, List at } else if (Tag.DATE.equalsText(ch.getTag())) { a.setDate(new StringWithCustomTags(ch)); } else if (Tag.PLACE.equalsText(ch.getTag())) { - a.setPlace(new Place()); - loadPlace(ch, a.getPlace()); + Place place = new Place(); + a.setPlace(place); + new PlaceParser(gedcomParser, ch, place).parse(); } else if (Tag.AGE.equalsText(ch.getTag())) { a.setAge(new StringWithCustomTags(ch)); } else if (Tag.CAUSE.equalsText(ch.getTag())) { @@ -891,114 +862,6 @@ private void loadIndividualAttribute(StringTree st, List at } } - /** - * Load an event about an individual from a string tree node - * - * @param st - * the node - * @param events - * the list of events about an individual - */ - private void loadIndividualEvent(StringTree st, List events) { - IndividualEvent e = new IndividualEvent(); - events.add(e); - e.setType(IndividualEventType.getFromTag(st.getTag())); - if ("Y".equals(st.getValue())) { - e.setyNull(st.getValue()); - e.setDescription(null); - } else if (st.getValue() == null || st.getValue().trim().length() == 0) { - e.setyNull(null); - e.setDescription(null); - } else { - e.setyNull(null); - e.setDescription(new StringWithCustomTags(st.getValue())); - addWarning(st.getTag() + " tag had description rather than [Y|] - violates standard"); - } - if (st.getChildren() != null) { - for (StringTree ch : st.getChildren()) { - if (Tag.TYPE.equalsText(ch.getTag())) { - e.setSubType(new StringWithCustomTags(ch)); - } else if (Tag.DATE.equalsText(ch.getTag())) { - e.setDate(new StringWithCustomTags(ch)); - } else if (Tag.PLACE.equalsText(ch.getTag())) { - e.setPlace(new Place()); - loadPlace(ch, e.getPlace()); - } else if (Tag.OBJECT_MULTIMEDIA.equalsText(ch.getTag())) { - List multimedia = e.getMultimedia(true); - new MultimediaLinkParser(gedcomParser, ch, multimedia).parse(); - } else if (Tag.NOTE.equalsText(ch.getTag())) { - loadNote(ch, e.getNotes(true)); - } else if (Tag.SOURCE.equalsText(ch.getTag())) { - List citations = e.getCitations(true); - new CitationListParser(gedcomParser, ch, citations).parse(); - } else if (Tag.AGE.equalsText(ch.getTag())) { - e.setAge(new StringWithCustomTags(ch)); - } else if (Tag.CAUSE.equalsText(ch.getTag())) { - e.setCause(new StringWithCustomTags(ch)); - } else if (Tag.ADDRESS.equalsText(ch.getTag())) { - Address address = new Address(); - e.setAddress(address); - new AddressParser(gedcomParser, ch, address).parse(); - } else if (Tag.AGENCY.equalsText(ch.getTag())) { - e.setRespAgency(new StringWithCustomTags(ch)); - } else if (Tag.RESTRICTION.equalsText(ch.getTag())) { - e.setRestrictionNotice(new StringWithCustomTags(ch)); - if (g55()) { - addWarning("GEDCOM version is 5.5 but restriction notice was specified for individual event on line " + ch.getLineNum() - + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); - } - } else if (Tag.RELIGION.equalsText(ch.getTag())) { - e.setReligiousAffiliation(new StringWithCustomTags(ch)); - if (g55()) { - addWarning("GEDCOM version is 5.5 but religious affiliation was specified for individual event on line " + ch.getLineNum() - + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); - } - } else if (Tag.PHONE.equalsText(ch.getTag())) { - e.getPhoneNumbers(true).add(new StringWithCustomTags(ch)); - } else if (Tag.WEB_ADDRESS.equalsText(ch.getTag())) { - e.getWwwUrls(true).add(new StringWithCustomTags(ch)); - if (g55()) { - addWarning("GEDCOM version is 5.5 but WWW URL was specified on " + e.getType() + " event on line " + ch.getLineNum() - + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); - } - } else if (Tag.FAX.equalsText(ch.getTag())) { - e.getFaxNumbers(true).add(new StringWithCustomTags(ch)); - if (g55()) { - addWarning("GEDCOM version is 5.5 but fax was specified on " + e.getType() + " event on line " + ch.getLineNum() - + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); - } - } else if (Tag.EMAIL.equalsText(ch.getTag())) { - e.getEmails(true).add(new StringWithCustomTags(ch)); - if (g55()) { - addWarning("GEDCOM version is 5.5 but email was specified on " + e.getType() + " event on line " + ch.getLineNum() - + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); - } - } else if (Tag.CONCATENATION.equalsText(ch.getTag())) { - if (e.getDescription() == null) { - e.setDescription(new StringWithCustomTags(ch)); - } else { - e.getDescription().setValue(e.getDescription().getValue() + ch.getValue()); - } - } else if (Tag.CONTINUATION.equalsText(ch.getTag())) { - if (e.getDescription() == null) { - e.setDescription(new StringWithCustomTags(ch.getValue() == null ? "" : ch.getValue())); - } else { - e.getDescription().setValue(e.getDescription().getValue() + "\n" + ch.getValue()); - } - } else if (Tag.FAMILY_WHERE_CHILD.equalsText(ch.getTag())) { - List families = new ArrayList(); - loadFamilyWhereChild(ch, families); - if (!families.isEmpty()) { - e.setFamily(families.get(0)); - } - } else { - unknownTag(ch, e); - } - } - } - - } - /** * Load an LDS individual ordinance from a string tree node * @@ -1028,11 +891,9 @@ private void loadLdsIndividualOrdinance(StringTree st, List families = new ArrayList(); - loadFamilyWhereChild(ch, families); - if (!families.isEmpty()) { - o.setFamilyWhereChild(families.get(0)); - } + FamilyChild fc = new FamilyChild(); + o.setFamilyWhereChild(fc); + new FamilyChildParser(gedcomParser, ch, fc).parse(); } else { unknownTag(ch, o); } @@ -1135,87 +996,6 @@ private void loadNote(StringTree st, List notes) { } } - /** - * Load a place structure from a string tree node - * - * @param st - * the node - * @param place - * the place structure to fill in - */ - private void loadPlace(StringTree st, Place place) { - place.setPlaceName(st.getValue()); - if (st.getChildren() != null) { - for (StringTree ch : st.getChildren()) { - if (Tag.FORM.equalsText(ch.getTag())) { - place.setPlaceFormat(new StringWithCustomTags(ch)); - } else if (Tag.SOURCE.equalsText(ch.getTag())) { - List citations = place.getCitations(true); - new CitationListParser(gedcomParser, ch, citations).parse(); - } else if (Tag.NOTE.equalsText(ch.getTag())) { - loadNote(ch, place.getNotes(true)); - } else if (Tag.CONCATENATION.equalsText(ch.getTag())) { - place.setPlaceName(place.getPlaceName() + (ch.getValue() == null ? "" : ch.getValue())); - } else if (Tag.CONTINUATION.equalsText(ch.getTag())) { - place.setPlaceName(place.getPlaceName() + "\n" + (ch.getValue() == null ? "" : ch.getValue())); - } else if (Tag.ROMANIZED.equalsText(ch.getTag())) { - if (g55()) { - addWarning("GEDCOM version is 5.5 but a romanized variation was specified on a place on line " + ch.getLineNum() - + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); - } - NameVariation nv = new NameVariation(); - place.getRomanized(true).add(nv); - nv.setVariation(ch.getValue()); - if (ch.getChildren() != null) { - for (StringTree gch : ch.getChildren()) { - if (Tag.TYPE.equalsText(gch.getTag())) { - nv.setVariationType(new StringWithCustomTags(gch)); - } else { - unknownTag(gch, nv); - } - } - } - } else if (Tag.PHONETIC.equalsText(ch.getTag())) { - if (g55()) { - addWarning("GEDCOM version is 5.5 but a phonetic variation was specified on a place on line " + ch.getLineNum() - + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); - } - NameVariation nv = new NameVariation(); - place.getPhonetic(true).add(nv); - nv.setVariation(ch.getValue()); - if (ch.getChildren() != null) { - for (StringTree gch : ch.getChildren()) { - if (Tag.TYPE.equalsText(gch.getTag())) { - nv.setVariationType(new StringWithCustomTags(gch)); - } else { - unknownTag(gch, nv); - } - } - } - } else if (Tag.MAP.equalsText(ch.getTag())) { - if (g55()) { - addWarning("GEDCOM version is 5.5 but a map coordinate was specified on a place on line " + ch.getLineNum() - + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); - } - if (ch.getChildren() != null) { - for (StringTree gch : ch.getChildren()) { - if (Tag.LATITUDE.equalsText(gch.getTag())) { - place.setLatitude(new StringWithCustomTags(gch)); - } else if (Tag.LONGITUDE.equalsText(gch.getTag())) { - place.setLongitude(new StringWithCustomTags(gch)); - } else { - unknownTag(gch, place); - } - } - } - } else { - unknownTag(ch, place); - } - } - } - - } - /** * Load a repository for sources from a string tree node, and put it in the gedcom collection of repositories * diff --git a/src/main/java/org/gedcom4j/parser/IndividualEventParser.java b/src/main/java/org/gedcom4j/parser/IndividualEventParser.java new file mode 100644 index 00000000..c6dbaa7d --- /dev/null +++ b/src/main/java/org/gedcom4j/parser/IndividualEventParser.java @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2009-2016 Matthew R. Harrah + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.gedcom4j.parser; + +import java.util.List; + +import org.gedcom4j.model.*; + +/** + * Parser for {@link IndividualEvent} object nodes + * + * @author frizbog + */ +class IndividualEventParser extends AbstractParser { + + /** + * Constructor + * + * @param gedcomParser + * a reference to the root {@link GedcomParser} + * @param stringTree + * {@link StringTree} to be parsed + * @param loadInto + * the object we are loading data into + */ + IndividualEventParser(GedcomParser gedcomParser, StringTree stringTree, IndividualEvent loadInto) { + super(gedcomParser, stringTree, loadInto); + } + + @Override + void parse() { + loadInto.setType(IndividualEventType.getFromTag(stringTree.getTag())); + if ("Y".equals(stringTree.getValue())) { + loadInto.setyNull(stringTree.getValue()); + loadInto.setDescription(null); + } else if (stringTree.getValue() == null || stringTree.getValue().trim().length() == 0) { + loadInto.setyNull(null); + loadInto.setDescription(null); + } else { + loadInto.setyNull(null); + loadInto.setDescription(new StringWithCustomTags(stringTree.getValue())); + addWarning(stringTree.getTag() + " tag had description rather than [Y|] - violates standard"); + } + if (stringTree.getChildren() != null) { + for (StringTree ch : stringTree.getChildren()) { + if (Tag.TYPE.equalsText(ch.getTag())) { + loadInto.setSubType(new StringWithCustomTags(ch)); + } else if (Tag.DATE.equalsText(ch.getTag())) { + loadInto.setDate(new StringWithCustomTags(ch)); + } else if (Tag.PLACE.equalsText(ch.getTag())) { + Place place = new Place(); + loadInto.setPlace(place); + new PlaceParser(gedcomParser, ch, place).parse(); + } else if (Tag.OBJECT_MULTIMEDIA.equalsText(ch.getTag())) { + List multimedia = loadInto.getMultimedia(true); + new MultimediaLinkParser(gedcomParser, ch, multimedia).parse(); + } else if (Tag.NOTE.equalsText(ch.getTag())) { + List notes = loadInto.getNotes(true); + new NoteListParser(gedcomParser, ch, notes).parse(); + } else if (Tag.SOURCE.equalsText(ch.getTag())) { + List citations = loadInto.getCitations(true); + new CitationListParser(gedcomParser, ch, citations).parse(); + } else if (Tag.AGE.equalsText(ch.getTag())) { + loadInto.setAge(new StringWithCustomTags(ch)); + } else if (Tag.CAUSE.equalsText(ch.getTag())) { + loadInto.setCause(new StringWithCustomTags(ch)); + } else if (Tag.ADDRESS.equalsText(ch.getTag())) { + Address address = new Address(); + loadInto.setAddress(address); + new AddressParser(gedcomParser, ch, address).parse(); + } else if (Tag.AGENCY.equalsText(ch.getTag())) { + loadInto.setRespAgency(new StringWithCustomTags(ch)); + } else if (Tag.RESTRICTION.equalsText(ch.getTag())) { + loadInto.setRestrictionNotice(new StringWithCustomTags(ch)); + if (g55()) { + addWarning("GEDCOM version is 5.5 but restriction notice was specified for individual event on line " + ch.getLineNum() + + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); + } + } else if (Tag.RELIGION.equalsText(ch.getTag())) { + loadInto.setReligiousAffiliation(new StringWithCustomTags(ch)); + if (g55()) { + addWarning("GEDCOM version is 5.5 but religious affiliation was specified for individual event on line " + ch.getLineNum() + + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); + } + } else if (Tag.PHONE.equalsText(ch.getTag())) { + loadInto.getPhoneNumbers(true).add(new StringWithCustomTags(ch)); + } else if (Tag.WEB_ADDRESS.equalsText(ch.getTag())) { + loadInto.getWwwUrls(true).add(new StringWithCustomTags(ch)); + if (g55()) { + addWarning("GEDCOM version is 5.5 but WWW URL was specified on " + loadInto.getType() + " event on line " + ch.getLineNum() + + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); + } + } else if (Tag.FAX.equalsText(ch.getTag())) { + loadInto.getFaxNumbers(true).add(new StringWithCustomTags(ch)); + if (g55()) { + addWarning("GEDCOM version is 5.5 but fax was specified on " + loadInto.getType() + " event on line " + ch.getLineNum() + + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); + } + } else if (Tag.EMAIL.equalsText(ch.getTag())) { + loadInto.getEmails(true).add(new StringWithCustomTags(ch)); + if (g55()) { + addWarning("GEDCOM version is 5.5 but email was specified on " + loadInto.getType() + " event on line " + ch.getLineNum() + + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); + } + } else if (Tag.CONCATENATION.equalsText(ch.getTag())) { + if (loadInto.getDescription() == null) { + loadInto.setDescription(new StringWithCustomTags(ch)); + } else { + loadInto.getDescription().setValue(loadInto.getDescription().getValue() + ch.getValue()); + } + } else if (Tag.CONTINUATION.equalsText(ch.getTag())) { + if (loadInto.getDescription() == null) { + loadInto.setDescription(new StringWithCustomTags(ch.getValue() == null ? "" : ch.getValue())); + } else { + loadInto.getDescription().setValue(loadInto.getDescription().getValue() + "\n" + ch.getValue()); + } + } else if (Tag.FAMILY_WHERE_CHILD.equalsText(ch.getTag())) { + FamilyChild fc = new FamilyChild(); + loadInto.setFamily(fc); + new FamilyChildParser(gedcomParser, ch, fc).parse(); + } else { + unknownTag(ch, loadInto); + } + } + } + + } + +} diff --git a/src/main/java/org/gedcom4j/parser/PlaceParser.java b/src/main/java/org/gedcom4j/parser/PlaceParser.java new file mode 100644 index 00000000..d586244c --- /dev/null +++ b/src/main/java/org/gedcom4j/parser/PlaceParser.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2009-2016 Matthew R. Harrah + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.gedcom4j.parser; + +import java.util.List; + +import org.gedcom4j.model.*; + +/** + * Parser for {@link Place} objects + * + * @author frizbog + */ +class PlaceParser extends AbstractParser { + + /** + * Constructor + * + * @param gedcomParser + * a reference to the root {@link GedcomParser} + * @param stringTree + * {@link StringTree} to be parsed + * @param loadInto + * the object we are loading data into + */ + PlaceParser(GedcomParser gedcomParser, StringTree stringTree, Place loadInto) { + super(gedcomParser, stringTree, loadInto); + } + + @Override + void parse() { + loadInto.setPlaceName(stringTree.getValue()); + if (stringTree.getChildren() != null) { + for (StringTree ch : stringTree.getChildren()) { + if (Tag.FORM.equalsText(ch.getTag())) { + loadInto.setPlaceFormat(new StringWithCustomTags(ch)); + } else if (Tag.SOURCE.equalsText(ch.getTag())) { + List citations = loadInto.getCitations(true); + new CitationListParser(gedcomParser, ch, citations).parse(); + } else if (Tag.NOTE.equalsText(ch.getTag())) { + List notes = loadInto.getNotes(true); + new NoteListParser(gedcomParser, ch, notes).parse(); + } else if (Tag.CONCATENATION.equalsText(ch.getTag())) { + loadInto.setPlaceName(loadInto.getPlaceName() + (ch.getValue() == null ? "" : ch.getValue())); + } else if (Tag.CONTINUATION.equalsText(ch.getTag())) { + loadInto.setPlaceName(loadInto.getPlaceName() + "\n" + (ch.getValue() == null ? "" : ch.getValue())); + } else if (Tag.ROMANIZED.equalsText(ch.getTag())) { + if (g55()) { + addWarning("GEDCOM version is 5.5 but a romanized variation was specified on a place on line " + ch.getLineNum() + + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); + } + NameVariation nv = new NameVariation(); + loadInto.getRomanized(true).add(nv); + nv.setVariation(ch.getValue()); + if (ch.getChildren() != null) { + for (StringTree gch : ch.getChildren()) { + if (Tag.TYPE.equalsText(gch.getTag())) { + nv.setVariationType(new StringWithCustomTags(gch)); + } else { + unknownTag(gch, nv); + } + } + } + } else if (Tag.PHONETIC.equalsText(ch.getTag())) { + if (g55()) { + addWarning("GEDCOM version is 5.5 but a phonetic variation was specified on a place on line " + ch.getLineNum() + + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); + } + NameVariation nv = new NameVariation(); + loadInto.getPhonetic(true).add(nv); + nv.setVariation(ch.getValue()); + if (ch.getChildren() != null) { + for (StringTree gch : ch.getChildren()) { + if (Tag.TYPE.equalsText(gch.getTag())) { + nv.setVariationType(new StringWithCustomTags(gch)); + } else { + unknownTag(gch, nv); + } + } + } + } else if (Tag.MAP.equalsText(ch.getTag())) { + if (g55()) { + addWarning("GEDCOM version is 5.5 but a map coordinate was specified on a place on line " + ch.getLineNum() + + ", which is a GEDCOM 5.5.1 feature." + " Data loaded but cannot be re-written unless GEDCOM version changes."); + } + if (ch.getChildren() != null) { + for (StringTree gch : ch.getChildren()) { + if (Tag.LATITUDE.equalsText(gch.getTag())) { + loadInto.setLatitude(new StringWithCustomTags(gch)); + } else if (Tag.LONGITUDE.equalsText(gch.getTag())) { + loadInto.setLongitude(new StringWithCustomTags(gch)); + } else { + unknownTag(gch, loadInto); + } + } + } + } else { + unknownTag(ch, loadInto); + } + } + } + + } + +}