Project

General

Profile

« Previous | Next » 

Revision 2f53c10a

Added by Andreas Müller 8 months ago

cleanup

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/markup/MarkupFeatureImport.java
6 6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
 * See LICENSE.TXT at the top of this package for the full license terms.
8 8
 */
9

  
10 9
package eu.etaxonomy.cdm.io.markup;
11 10

  
12 11
import java.util.ArrayList;
......
22 21
import javax.xml.stream.events.XMLEvent;
23 22

  
24 23
import org.apache.commons.lang.StringUtils;
25
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
24
import org.apache.logging.log4j.LogManager;
25
import org.apache.logging.log4j.Logger;
26 26

  
27 27
import eu.etaxonomy.cdm.common.CdmUtils;
28 28
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
29 29
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
30 30
import eu.etaxonomy.cdm.model.common.Annotation;
31 31
import eu.etaxonomy.cdm.model.common.AnnotationType;
32
import eu.etaxonomy.cdm.model.common.CdmBase;
32 33
import eu.etaxonomy.cdm.model.common.IntextReference;
33 34
import eu.etaxonomy.cdm.model.common.Language;
34 35
import eu.etaxonomy.cdm.model.common.LanguageString;
......
48 49
/**
49 50
 * @author a.mueller
50 51
 * @since 30.05.2012
51
 *
52 52
 */
53 53
public class MarkupFeatureImport extends MarkupImportBase {
54
	@SuppressWarnings("unused")
54

  
55
    @SuppressWarnings("unused")
55 56
	private static final Logger logger = LogManager.getLogger(MarkupFeatureImport.class);
56 57

  
57 58
	protected static final String MODS_TITLEINFO = "titleInfo";
......
186 187

  
187 188
	/**
188 189
     * Creates a full description text from the mark
189
     * @param cachedEvents
190
     * @return
191 190
     */
192 191
    private String makeFullDescriptionText(List<XMLEvent> events) {
193 192
        String result = "";
......
198 197
        return result;
199 198
    }
200 199

  
201
    /**
202
	 * @param state
203
	 * @param reader
204
	 * @param taxonDescription
205
	 * @param isDescription
206
	 * @param lastDescriptionElement
207
	 * @param next
208
	 * @return
209
	 * @throws XMLStreamException
210
	 */
211 200
	public DescriptionElementBase makeFeatureFigureRef(MarkupImportState state, XMLEventReader reader,TaxonDescription taxonDescription,
212 201
					boolean isDescription, DescriptionElementBase lastDescriptionElement, Reference sourceReference, XMLEvent next) throws XMLStreamException {
213 202
		FigureDataHolder figureHolder = handleFigureRef(state, reader, next);
......
247 236
		return lastDescriptionElement;
248 237
	}
249 238

  
250
	/**
251
	 * @param state
252
	 * @param reader
253
	 * @param feature
254
	 * @param taxonDescription
255
	 * @param lastDescriptionElement
256
	 * @param distributionList
257
	 * @param next
258
	 * @return
259
	 * @throws XMLStreamException
260
	 * @throws
261
	 */
262 239
	private DescriptionElementBase makeFeatureString(MarkupImportState state,XMLEventReader reader, Feature feature,
263 240
				TaxonDescription taxonDescription, DescriptionElementBase lastDescriptionElement, XMLEvent next, Boolean isFreetext) throws XMLStreamException {
264 241

  
......
327 304
		}
328 305
	}
329 306

  
330
	/**
331
	 * @param classValue
332
	 * @param state
333
	 * @param parentEvent
334
	 * @param parentFeature
335
	 * @return
336
	 * @throws UndefinedTransformerMethodException
337
	 */
338 307
	private Feature makeFeature(String classValue, MarkupImportState state, XMLEvent parentEvent, Feature parentFeature) {
339 308
		UUID uuid;
340 309
		try {
......
346 315
				classValue = String.format(classValue, parentFeature.getTitleCache());
347 316
			}
348 317

  
349

  
350 318
			//get existing feature
351 319
			if (classValue.endsWith(".")){
352 320
			    classValue = classValue.substring(0, classValue.length() - 1);
......
527 495
		throw new IllegalStateException("RefPart has no closing tag");
528 496
	}
529 497

  
530

  
531
	/**
532
	 * @param state
533
	 * @param reader
534
	 * @param classValue
535
	 * @param feature
536
	 * @param next
537
	 * @throws XMLStreamException
538
	 */
539 498
	private void makeFeatureHeading(MarkupImportState state, XMLEventReader reader, String classValue, Feature feature, XMLEvent next) throws XMLStreamException {
540 499
		String heading = handleHeading(state, reader, next);
541 500
		if (StringUtils.isNotBlank(heading)) {
......
558 517
		}
559 518
	}
560 519

  
561

  
562
	/**
563
	 * @param state
564
	 * @param reader
565
	 * @param feature
566
	 * @param taxon
567
	 * @param next
568
	 * @throws XMLStreamException
569
	 */
570 520
	private void makeFeatureWriter(MarkupImportState state,XMLEventReader reader, Feature feature, Taxon taxon, XMLEvent next) throws XMLStreamException {
571 521
		WriterDataHolder writer = handleWriter(state, reader, next);
572 522
		if (isNotBlank(writer.writer)) {
......
647 597
     * @see #handleHabitat(MarkupImportState, XMLEventReader, XMLEvent)
648 598
	 */
649 599
	private String handleAltitude(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException {
650
	        checkNoAttributes(parentEvent);
651
	        Taxon taxon = state.getCurrentTaxon();
652
	        // TODO which ref to take?
653
	        Reference sourceReference = state.getConfig().getSourceReference();
654

  
655
	        boolean isTextMode = true;
656
	        String text = "";
657
	        while (reader.hasNext()) {
658
	            XMLEvent next = readNoWhitespace(reader);
659
	            if (isMyEndingElement(next, parentEvent)) {
660
	                Feature feature = getFeature(
661
	                        state,
662
	                        MarkupTransformer.uuidExtractedAltitude,
663
	                        "Extracted Altitude",
664
	                        "An altitude that was extracted from a habitat text",
665
	                        "extr. alt.", null);
666
	                //TODO try to make quantitative data
667
	                TextData altitude = TextData.NewInstance(feature);
668
	                altitude.putText(getDefaultLanguage(state), text);
669
	                altitude.addPrimaryTaxonomicSource(sourceReference);
670
	                TaxonDescription description = getExtractedMarkupMarkedDescription(state, taxon, sourceReference);
671

  
672
	                description.addElement(altitude);
673

  
674
	                return text;
675
	            } else if (next.isCharacters()) {
676
	                if (! isTextMode) {
677
	                    String message = "String is not in text mode";
678
	                    fireWarningEvent(message, next, 6);
679
	                } else {
680
	                    text += next.asCharacters().getData();
681
	                }
682
	            } else if (isStartingElement(next, BR)) {
683
	                    text += "<br/>";
684
	                    isTextMode = false;
685
	            } else if (isEndingElement(next, BR)) {
686
	                    isTextMode = true;
687
	            } else {
688
	                String type = next.toString();
689
	                String location = String.valueOf(next.getLocation().getLineNumber());
690
	                System.out.println("MarkupFeatureImport.handleAltitude: Unexpected element in habitat: " + type + ":  " + location);
691
	                handleUnexpectedElement(next);
692
	            }
693
	        }
694
	        throw new IllegalStateException("<Habitat> has no closing tag");
695
	    }
696

  
697

  
698

  
600
        checkNoAttributes(parentEvent);
601
        Taxon taxon = state.getCurrentTaxon();
602
        // TODO which ref to take?
603
        Reference sourceReference = state.getConfig().getSourceReference();
604

  
605
        boolean isTextMode = true;
606
        String text = "";
607
        while (reader.hasNext()) {
608
            XMLEvent next = readNoWhitespace(reader);
609
            if (isMyEndingElement(next, parentEvent)) {
610
                Feature feature = getFeature(
611
                        state,
612
                        MarkupTransformer.uuidExtractedAltitude,
613
                        "Extracted Altitude",
614
                        "An altitude that was extracted from a habitat text",
615
                        "extr. alt.", null);
616
                //TODO try to make quantitative data
617
                TextData altitude = TextData.NewInstance(feature);
618
                altitude.putText(getDefaultLanguage(state), text);
619
                altitude.addPrimaryTaxonomicSource(sourceReference);
620
                TaxonDescription description = getExtractedMarkupMarkedDescription(state, taxon, sourceReference);
621

  
622
                description.addElement(altitude);
623

  
624
                return text;
625
            } else if (next.isCharacters()) {
626
                if (! isTextMode) {
627
                    String message = "String is not in text mode";
628
                    fireWarningEvent(message, next, 6);
629
                } else {
630
                    text += next.asCharacters().getData();
631
                }
632
            } else if (isStartingElement(next, BR)) {
633
                    text += "<br/>";
634
                    isTextMode = false;
635
            } else if (isEndingElement(next, BR)) {
636
                    isTextMode = true;
637
            } else {
638
                String type = next.toString();
639
                String location = String.valueOf(next.getLocation().getLineNumber());
640
                System.out.println("MarkupFeatureImport.handleAltitude: Unexpected element in habitat: " + type + ":  " + location);
641
                handleUnexpectedElement(next);
642
            }
643
        }
644
        throw new IllegalStateException("<Habitat> has no closing tag");
645
    }
699 646

  
700 647
	private FigureDataHolder handleFigureRef(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent)
701 648
			throws XMLStreamException {
......
741 688

  
742 689
	private List<DescriptionElementBase> makeCommonNameString(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException{
743 690

  
744
		List<DescriptionElementBase> result = new ArrayList<DescriptionElementBase>();
691
		List<DescriptionElementBase> result = new ArrayList<>();
745 692

  
746 693
		checkNoAttributes(parentEvent);
747 694

  
......
773 720
			}
774 721
		}
775 722
		throw new IllegalStateException("closing tag is missing");
776

  
777

  
778 723
	}
779 724

  
780 725
	private List<DescriptionElementBase> makeVernacularNames(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException{
781
		List<DescriptionElementBase> result = new ArrayList<DescriptionElementBase>();
726

  
727
	    List<DescriptionElementBase> result = new ArrayList<>();
782 728
		checkNoAttributes(parentEvent);
783 729

  
784 730
		while (reader.hasNext()) {
......
796 742
			}
797 743
		}
798 744
		throw new IllegalStateException("closing tag is missing");
799

  
800 745
	}
801 746

  
802 747
	private void makeVernacularNamesSubHeading(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException {
......
824 769
			}
825 770
		}
826 771
		throw new IllegalStateException("closing tag is missing");
827

  
828 772
	}
829 773

  
830 774
	private NamedArea getCommonNameArea(String text) {
......
844 788
	}
845 789

  
846 790
	private List<CommonTaxonName> makeSingleVernacularName(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException{
847
		checkNoAttributes(parentEvent);
848
		List<CommonTaxonName> result = new ArrayList<CommonTaxonName>();
791

  
792
	    checkNoAttributes(parentEvent);
793
		List<CommonTaxonName> result = new ArrayList<>();
849 794

  
850 795
		Language language = state.getDefaultLanguage();
851 796
		while (reader.hasNext()) {
......
994 939
		}
995 940
	}
996 941

  
997

  
998
	private String handleHeading(MarkupImportState state,XMLEventReader reader, XMLEvent parentEvent)throws XMLStreamException {
942
	private String handleHeading(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent)throws XMLStreamException {
999 943
		checkNoAttributes(parentEvent);
1000 944

  
1001 945
		String text = "";
......
1016 960
			}
1017 961
		}
1018 962
		throw new IllegalStateException("<String> has no closing tag");
1019

  
1020 963
	}
1021 964

  
1022

  
1023 965
	private List<Reference> handleReferences(MarkupImportState state, XMLEventReader reader, XMLEvent parentEvent) throws XMLStreamException {
1024 966
		// attributes
1025 967
		Map<String, Attribute> attributes = getAttributes(parentEvent);
......
1117 1059
		}
1118 1060
		throw new IllegalStateException("Some tag has no closing tag");
1119 1061
	}
1120
}
1062
}

Also available in: Unified diff