Project

General

Profile

« Previous | Next » 

Revision 42184

oai import

View differences:

OAIConfigurationParser.java
6 6
import java.util.HashMap;
7 7
import java.util.List;
8 8
import java.util.Map;
9

  
9 10
import javax.xml.stream.XMLInputFactory;
10 11
import javax.xml.stream.XMLStreamConstants;
11 12
import javax.xml.stream.XMLStreamException;
12 13
import javax.xml.stream.XMLStreamReader;
13 14
import javax.xml.transform.stream.StreamSource;
14 15

  
16
import org.apache.commons.logging.Log;
17
import org.apache.commons.logging.LogFactory;
18

  
15 19
import com.google.common.collect.ArrayListMultimap;
16 20
import com.google.common.collect.Multimap;
21

  
17 22
import eu.dnetlib.oai.PublisherField;
18 23
import eu.dnetlib.oai.info.SetInfo;
19
import eu.dnetlib.oai.publisher.OaiPublisherRuntimeException;
20 24
import eu.dnetlib.rmi.provision.MDFInfo;
21
import org.apache.commons.logging.Log;
22
import org.apache.commons.logging.LogFactory;
25
import eu.dnetlib.rmi.provision.OaiPublisherRuntimeException;
23 26

  
24 27
/**
25 28
 * Parses an XML document representing the OAI configuration profile and creates the corresponding OAIConfiguration object.
......
40 43

  
41 44
	public OAIConfiguration getConfiguration(final String configurationProfile) throws IOException {
42 45
		log.debug(configurationProfile);
43
		OAIConfiguration config = new OAIConfiguration();
44
		Map<String, SetInfo> setsMap = new HashMap<>();
45
		Map<String, MDFInfo> mdFormatsMap = new HashMap<>();
46
		List<String> indexNames = new ArrayList<>();
47
		List<PublisherField> fields = new ArrayList<>();
46
		final OAIConfiguration config = new OAIConfiguration();
47
		final Map<String, SetInfo> setsMap = new HashMap<>();
48
		final Map<String, MDFInfo> mdFormatsMap = new HashMap<>();
49
		final List<String> indexNames = new ArrayList<>();
50
		final List<PublisherField> fields = new ArrayList<>();
48 51
		try {
49
			final XMLStreamReader parser = factory.get().createXMLStreamReader(new StreamSource(new StringReader(configurationProfile)));
52
			final XMLStreamReader parser = this.factory.get().createXMLStreamReader(new StreamSource(new StringReader(configurationProfile)));
50 53
			while (parser.hasNext()) {
51 54
				int event = parser.next();
52 55
				if (event == XMLStreamConstants.START_ELEMENT) {
......
57 60
						config.setIdNamespace(parser.getElementText());
58 61
					} else if (localName.equals("OAISET")) {
59 62
						boolean inSet = true;
60
						SetInfo setInfo = new SetInfo();
61
						String enabled = parser.getAttributeValue(null, "enabled");
63
						final SetInfo setInfo = new SetInfo();
64
						final String enabled = parser.getAttributeValue(null, "enabled");
62 65
						setInfo.setEnabled(Boolean.parseBoolean(enabled));
63 66
						while (parser.hasNext() && inSet) {
64 67
							event = parser.next();
65 68
							if (event == XMLStreamConstants.START_ELEMENT) {
66
								String setElementName = parser.getLocalName();
67
								String setElementValue = parser.getElementText();
69
								final String setElementName = parser.getLocalName();
70
								final String setElementValue = parser.getElementText();
68 71
								this.handleSetInfo(setInfo, setElementName, setElementValue);
69 72
							}
70 73
							if ((event == XMLStreamConstants.END_ELEMENT) && parser.getLocalName().equals("OAISET")) {
......
75 78
					} else {
76 79
						if (localName.equals("METADATAFORMAT")) {
77 80
							boolean inMetadata = true;
78
							MDFInfo mdfInfo = new MDFInfo();
79
							String exportable = parser.getAttributeValue(null, "exportable");
81
							final MDFInfo mdfInfo = new MDFInfo();
82
							final String exportable = parser.getAttributeValue(null, "exportable");
80 83
							mdfInfo.setEnabled(Boolean.parseBoolean(exportable));
81
							String mdPrefix = parser.getAttributeValue(null, "metadataPrefix");
84
							final String mdPrefix = parser.getAttributeValue(null, "metadataPrefix");
82 85
							mdfInfo.setPrefix(mdPrefix);
83 86
							while (parser.hasNext() && inMetadata) {
84 87
								event = parser.next();
85 88
								if (event == XMLStreamConstants.START_ELEMENT) {
86
									String mdfElementName = parser.getLocalName();
89
									final String mdfElementName = parser.getLocalName();
87 90
									if (mdfElementName.equals("SOURCE_METADATA_FORMAT")) {
88 91
										this.handleSourceMDF(mdfInfo, parser);
89 92
										config.getSourcesMDF().add(mdfInfo);
90 93
									} else {
91
										String mdfElementValue = parser.getElementText();
94
										final String mdfElementValue = parser.getElementText();
92 95
										this.handleMDFInfo(mdfInfo, mdfElementName, mdfElementValue);
93 96
									}
94 97
								}
......
101 104
							// INDICES
102 105
							if (localName.equals("INDEX")) {
103 106
								boolean inIndex = true;
104
								PublisherField publisherField = new PublisherField();
105
								String indexName = parser.getAttributeValue(null, "name");
106
								String repeatable = parser.getAttributeValue(null, "repeatable");
107
								boolean isRepeatable = Boolean.valueOf(repeatable);
107
								final PublisherField publisherField = new PublisherField();
108
								final String indexName = parser.getAttributeValue(null, "name");
109
								final String repeatable = parser.getAttributeValue(null, "repeatable");
110
								final boolean isRepeatable = Boolean.valueOf(repeatable);
108 111
								indexNames.add(indexName);
109 112
								publisherField.setFieldName(indexName);
110 113
								publisherField.setRepeatable(isRepeatable);
111 114
								// now let's set the SOURCES
112
								Multimap<String, String> fieldSources = ArrayListMultimap.create();
115
								final Multimap<String, String> fieldSources = ArrayListMultimap.create();
113 116
								while (parser.hasNext() && inIndex) {
114 117
									event = parser.next();
115 118
									if (event == XMLStreamConstants.START_ELEMENT) {
116
										String currentElementName = parser.getLocalName();
119
										final String currentElementName = parser.getLocalName();
117 120
										this.handleIndex(fieldSources, indexName, parser, currentElementName);
118 121
									}
119 122
									if ((event == XMLStreamConstants.END_ELEMENT) && parser.getLocalName().equals("INDEX")) {
......
149 152
	 */
150 153
	private void handleIndex(final Multimap<String, String> fieldSources, final String indexName, final XMLStreamReader parser, final String currentLocalName) {
151 154
		if (currentLocalName.equals("SOURCE")) {
152
			MDFInfo indexSource = new MDFInfo();
155
			final MDFInfo indexSource = new MDFInfo();
153 156
			this.handleSourceMDF(indexSource, parser);
154
			String key = indexSource.getSourceFormatName() + "-" + indexSource.getSourceFormatLayout() + "-" + indexSource.getSourceFormatInterpretation();
157
			final String key =
158
					indexSource.getSourceFormatName() + "-" + indexSource.getSourceFormatLayout() + "-" + indexSource.getSourceFormatInterpretation();
155 159
			fieldSources.put(key, parser.getAttributeValue(null, "path"));
156 160
		} else {
157 161
			log.warn("I do not know how to handle INDEX element with name " + currentLocalName);
......
165 169
	 * @param parser
166 170
	 */
167 171
	private void handleSourceMDF(final MDFInfo mdfInfo, final XMLStreamReader parser) {
168
		String interpretation = parser.getAttributeValue(null, "interpretation");
169
		String layout = parser.getAttributeValue(null, "layout");
170
		String name = parser.getAttributeValue(null, "name");
172
		final String interpretation = parser.getAttributeValue(null, "interpretation");
173
		final String layout = parser.getAttributeValue(null, "layout");
174
		final String name = parser.getAttributeValue(null, "name");
171 175
		mdfInfo.setSourceFormatInterpretation(interpretation);
172 176
		mdfInfo.setSourceFormatLayout(layout);
173 177
		mdfInfo.setSourceFormatName(name);

Also available in: Unified diff