Index: modules/cnr-mongo-mdstore/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/mongodb/MongoMDStore.java
===================================================================
--- modules/cnr-mongo-mdstore/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/mongodb/MongoMDStore.java	(revision 34592)
+++ modules/cnr-mongo-mdstore/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/mongodb/MongoMDStore.java	(revision 34593)
@@ -21,6 +21,7 @@
 import com.mongodb.QueryBuilder;
 
 import eu.dnetlib.data.mdstore.DocumentNotFoundException;
+import eu.dnetlib.data.mdstore.modular.MDFormatDescription;
 import eu.dnetlib.data.mdstore.modular.RecordParser;
 import eu.dnetlib.data.mdstore.modular.connector.MDStore;
 import eu.dnetlib.data.mdstore.modular.mongodb.utils.MDStoreUtils;
@@ -264,4 +265,10 @@
 		this.discardedCollection = discardedCollection;
 	}
 
+	@Override
+	public void feed(final Iterable<String> records, final boolean incremental, final List<MDFormatDescription> mdformats) {
+		// TODO Auto-generated method stub
+
+	}
+
 }
Index: modules/cnr-modular-mdstore-service/branches/indexFields/src/test/java/eu/dnetlib/enabling/tools/blackboard/MDStoreUtilTest.java
===================================================================
--- modules/cnr-modular-mdstore-service/branches/indexFields/src/test/java/eu/dnetlib/enabling/tools/blackboard/MDStoreUtilTest.java	(nonexistent)
+++ modules/cnr-modular-mdstore-service/branches/indexFields/src/test/java/eu/dnetlib/enabling/tools/blackboard/MDStoreUtilTest.java	(revision 34593)
@@ -0,0 +1,50 @@
+package eu.dnetlib.enabling.tools.blackboard;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathFactory;
+
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class MDStoreUtilTest {
+
+	@Test
+	public void test() throws Exception {
+
+		String result = "<FIELDS> <FIELD indexable=\"false\" name=\"doi\" result=\"false\" stat=\"true\" xpath=\"//*[local-name()='resource']/*[local-name()='identifier' and ./@identifierType='DOI']\"/> </FIELDS>";
+		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+		DocumentBuilder builder;
+		builder = factory.newDocumentBuilder();
+		Document doc = builder.parse(new ByteArrayInputStream(result.getBytes()));
+		XPathFactory xPathFactory = XPathFactory.newInstance();
+		XPath myXpath = xPathFactory.newXPath();
+		XPathExpression expression = myXpath.compile("//FIELD");
+		Object values = expression.evaluate(doc, XPathConstants.NODESET);
+		NodeList v = (NodeList) values;
+		for (int i = 0; i < v.getLength(); i++) {
+			Node currentItem = v.item(i);
+			NamedNodeMap attributes = currentItem.getAttributes();
+			String name = null;
+			String xpath = null;
+			if (attributes.getNamedItem("name") != null) {
+				name = attributes.getNamedItem("name").getNodeValue();
+			}
+			if (attributes.getNamedItem("xpath") != null) {
+				xpath = attributes.getNamedItem("xpath").getNodeValue();
+			}
+			if (attributes.getNamedItem("value") != null) {
+				xpath = attributes.getNamedItem("value").getNodeValue();
+			}
+		}
+
+	}
+}
Index: modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/FeedAction.java
===================================================================
--- modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/FeedAction.java	(revision 34592)
+++ modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/FeedAction.java	(revision 34593)
@@ -1,7 +1,10 @@
 package eu.dnetlib.data.mdstore.modular;
 
+import java.util.List;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Required;
 
 import eu.dnetlib.data.mdstore.MDStoreServiceException;
@@ -14,6 +17,9 @@
 
 	private MDStoreFeeder feeder;
 
+	@Autowired
+	private MDStoreUtils mdstoreUtils;
+
 	@Override
 	public void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws MDStoreServiceException {
 
@@ -28,8 +34,19 @@
 			storingType = "REFRESH";
 		}
 
-		feeder.feed(mdId, epr, storingType, true, new FeedDoneCallback() {
+		final String layoutIndex = job.getParameters().get("layoutIndex");
+		String format = feeder.getDao().getMDStore(mdId).getFormat();
 
+		List<MDFormatDescription> mdformats = mdstoreUtils.getField(format, layoutIndex);
+		if (mdformats != null) {
+			for (MDFormatDescription desc : mdformats) {
+				log.info("name: " + desc.getName());
+				log.info("xpath: " + desc.getXpath());
+			}
+		}
+
+		feeder.feed(mdId, epr, storingType, true, mdformats, new FeedDoneCallback() {
+
 			@Override
 			public void call(final int size) {
 				job.getParameters().put("total", "" + size);
Index: modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/FieldsExtractor.java
===================================================================
--- modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/FieldsExtractor.java	(nonexistent)
+++ modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/FieldsExtractor.java	(revision 34593)
@@ -0,0 +1,67 @@
+package eu.dnetlib.data.mdstore.modular;
+
+import java.io.ByteArrayInputStream;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class FieldsExtractor {
+
+	private final DocumentBuilderFactory factory;
+	private DocumentBuilder builder;
+	private XPath xpath;
+
+	public FieldsExtractor() throws ParserConfigurationException {
+		factory = DocumentBuilderFactory.newInstance();
+		this.builder = factory.newDocumentBuilder();
+		XPathFactory xPathFactory = XPathFactory.newInstance();
+		this.xpath = xPathFactory.newXPath();
+	}
+
+	public Map<String, List<String>> getData(final String xml, final List<MDFormatDescription> mdref) {
+
+		try {
+			Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
+
+			Map<String, List<String>> result = Maps.newHashMap();
+			for (MDFormatDescription info : mdref) {
+				XPathExpression expression = xpath.compile(info.getXpath());
+				NodeList values = (NodeList) expression.evaluate(doc, XPathConstants.NODESET);
+				for (int i = 0; i < values.getLength(); i++) {
+					Node currentItem = values.item(i);
+					NodeList fields = currentItem.getChildNodes();
+					if (fields != null) {
+						List<String> currentValues = Lists.newArrayList();
+						for (int k = 0; k < fields.getLength(); k++) {
+							Node field = fields.item(k);
+							while (field.hasChildNodes()) {
+								field = field.getFirstChild();
+							}
+							currentValues.add(field.getNodeValue());
+
+						}
+						result.put(info.getName(), currentValues);
+					}
+				}
+			}
+			return result;
+		} catch (Exception e) {
+			return Maps.newHashMap();
+		}
+	}
+
+}
Index: modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/StreamingRecordParser.java
===================================================================
--- modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/StreamingRecordParser.java	(revision 34592)
+++ modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/StreamingRecordParser.java	(revision 34593)
@@ -11,16 +11,15 @@
 import javax.xml.stream.XMLStreamReader;
 
 /**
- * This method outperforms SimpleRecordParser by a vast amount, especially since we are just getting stuff in the
- * header.
- * 
+ * This method outperforms SimpleRecordParser by a vast amount, especially since we are just getting stuff in the header.
+ *
  * @author marko
- * 
+ *
  */
 public class StreamingRecordParser implements RecordParser {
 
 	@Override
-	public Map<String, String> parseRecord(String record) {
+	public Map<String, String> parseRecord(final String record) {
 
 		try {
 			XMLInputFactory factory = XMLInputFactory.newInstance();
@@ -33,7 +32,6 @@
 
 			while (parser.hasNext()) {
 				int event = parser.next();
-
 				if (event == XMLStreamConstants.END_ELEMENT) {
 					elementStack.pop();
 				} else if (event == XMLStreamConstants.START_ELEMENT) {
@@ -48,7 +46,7 @@
 					} else if ("identifier".equals(localName) && "efgEntity".equals(grandParent(elementStack))) {
 						if (!res.containsKey("originalId")) {
 							parser.next();
-//							log.info("ZZZZZZ OK: found identifier at right depth " + elementStack);
+							// log.info("ZZZZZZ OK: found identifier at right depth " + elementStack);
 							res.put("originalId", parser.getText().trim());
 						}
 					}
@@ -55,11 +53,11 @@
 
 					else if ("identifier".equals(localName)) {
 
-//						log.info("ZZZZZZ: found identifier not at right depth " + elementStack + " grand parent " + grandParent(elementStack));
+						// log.info("ZZZZZZ: found identifier not at right depth " + elementStack + " grand parent " +
+						// grandParent(elementStack));
 					}
 
-					if (res.containsKey("id") && res.containsKey("originalId"))
-						return res;
+					if (res.containsKey("id") && res.containsKey("originalId")) { return res; }
 				}
 			}
 			return res;
@@ -69,9 +67,8 @@
 
 	}
 
-	private String grandParent(Stack<String> elementStack) {
-		if (elementStack.size() <= 3)
-			return "";
+	private String grandParent(final Stack<String> elementStack) {
+		if (elementStack.size() <= 3) { return ""; }
 		return elementStack.get(elementStack.size() - 3);
 	}
 
Index: modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStore.java
===================================================================
--- modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStore.java	(revision 34592)
+++ modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/connector/MDStore.java	(revision 34593)
@@ -1,6 +1,9 @@
 package eu.dnetlib.data.mdstore.modular.connector;
 
+import java.util.List;
+
 import eu.dnetlib.data.mdstore.DocumentNotFoundException;
+import eu.dnetlib.data.mdstore.modular.MDFormatDescription;
 import eu.dnetlib.enabling.resultset.ResultSetListener;
 
 public interface MDStore {
@@ -17,6 +20,8 @@
 
 	void feed(Iterable<String> records, boolean incremental);
 
+	void feed(Iterable<String> records, boolean incremental, List<MDFormatDescription> mdformats);
+
 	ResultSetListener deliver(String from, String until, String recordFilter);
 
 	ResultSetListener deliverIds(String from, String until, String recordFilter);
Index: modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/MDFormatDescription.java
===================================================================
--- modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/MDFormatDescription.java	(nonexistent)
+++ modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/MDFormatDescription.java	(revision 34593)
@@ -0,0 +1,53 @@
+package eu.dnetlib.data.mdstore.modular;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class MDFormatDescription.
+ */
+public class MDFormatDescription {
+
+	/** The name. */
+	private String name;
+
+	/** The xpath. */
+	private String xpath;
+
+	/**
+	 * Gets the name.
+	 *
+	 * @return the name
+	 */
+	public String getName() {
+		return name;
+	}
+
+	/**
+	 * Sets the name.
+	 *
+	 * @param name
+	 *            the name to set
+	 */
+	public void setName(final String name) {
+		this.name = name;
+	}
+
+	/**
+	 * Gets the xpath.
+	 *
+	 * @return the xpath
+	 */
+	public String getXpath() {
+		return xpath;
+	}
+
+	/**
+	 * Sets the xpath.
+	 *
+	 * @param xpath
+	 *            the xpath to set
+	 */
+	public void setXpath(final String xpath) {
+		this.xpath = xpath;
+	}
+
+}
Index: modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreFeeder.java
===================================================================
--- modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreFeeder.java	(revision 34592)
+++ modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreFeeder.java	(revision 34593)
@@ -1,5 +1,7 @@
 package eu.dnetlib.data.mdstore.modular;
 
+import java.util.List;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.factory.annotation.Required;
@@ -28,6 +30,7 @@
 			final String rsEpr,
 			final String storingType,
 			final boolean sync,
+			final List<MDFormatDescription> mdformats,
 			final FeedDoneCallback doneCallback,
 			final FeedFailedCallback failCallback) throws MDStoreServiceException {
 		log.info("Start feeding mdstore " + mdId + " with epr " + rsEpr);
@@ -43,7 +46,11 @@
 				mdstore.truncate();
 			}
 
-			mdstore.feed(records, refresh);
+			if (mdformats == null) {
+				mdstore.feed(records, refresh);
+			} else {
+				mdstore.feed(records, refresh, mdformats);
+			}
 
 			dao.commit(mdstore.getId(), mdId);
 
@@ -69,9 +76,8 @@
 		try {
 			final String now = DateUtils.now_ISO8601();
 
-			final String mdstoreXUpdate =
-					"for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + mdId + "']" + "return update value $x//LAST_STORAGE_DATE with '" + now
-					+ "'";
+			final String mdstoreXUpdate = "for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + mdId + "']"
+					+ "return update value $x//LAST_STORAGE_DATE with '" + now + "'";
 
 			serviceLocator.getService(ISRegistryService.class).executeXUpdate(mdstoreXUpdate);
 
@@ -83,9 +89,8 @@
 
 	public void touchSize(final String mdId, final int size) {
 		try {
-			final String mdstoreNumberXUpdate =
-					"for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + mdId + "']" + "return update value $x//NUMBER_OF_RECORDS with '" + size
-					+ "'";
+			final String mdstoreNumberXUpdate = "for $x in //RESOURCE_PROFILE[.//RESOURCE_IDENTIFIER/@value = '" + mdId + "']"
+					+ "return update value $x//NUMBER_OF_RECORDS with '" + size + "'";
 
 			serviceLocator.getService(ISRegistryService.class).executeXUpdate(mdstoreNumberXUpdate);
 		} catch (final Exception e) {
@@ -122,9 +127,9 @@
 	public UniqueServiceLocator getServiceLocator() {
 		return serviceLocator;
 	}
-	
+
 	@Required
-	public void setServiceLocator(UniqueServiceLocator serviceLocator) {
+	public void setServiceLocator(final UniqueServiceLocator serviceLocator) {
 		this.serviceLocator = serviceLocator;
 	}
 
Index: modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreUtils.java
===================================================================
--- modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreUtils.java	(nonexistent)
+++ modules/cnr-modular-mdstore-service/branches/indexFields/src/main/java/eu/dnetlib/data/mdstore/modular/MDStoreUtils.java	(revision 34593)
@@ -0,0 +1,83 @@
+package eu.dnetlib.data.mdstore.modular;
+
+import java.io.ByteArrayInputStream;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathFactory;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import com.google.common.collect.Lists;
+
+import eu.dnetlib.data.mdstore.MDStoreServiceException;
+import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException;
+import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
+import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
+import eu.dnetlib.enabling.locators.UniqueServiceLocator;
+
+public class MDStoreUtils {
+
+	/**
+	 * service locator.
+	 */
+	@Autowired
+	private UniqueServiceLocator serviceLocator;
+
+	public List<MDFormatDescription> getField(final String format, final String layout) throws MDStoreServiceException {
+
+		String xquery = "for $x in collection('')/RESOURCE_PROFILE/BODY[CONFIGURATION/NAME='" + format + "'] return $x/STATUS/LAYOUTS/LAYOUT[@name='" + layout
+				+ "']/FIELDS";
+
+		try {
+			String result = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xquery);
+			final List<MDFormatDescription> mdformat = Lists.newArrayList();
+			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+			DocumentBuilder builder;
+			builder = factory.newDocumentBuilder();
+			Document doc = builder.parse(new ByteArrayInputStream(result.getBytes()));
+			XPathFactory xPathFactory = XPathFactory.newInstance();
+			XPath myXpath = xPathFactory.newXPath();
+			XPathExpression expression = myXpath.compile("//FIELD");
+			Object values = expression.evaluate(doc, XPathConstants.NODESET);
+			NodeList v = (NodeList) values;
+			for (int i = 0; i < v.getLength(); i++) {
+				Node currentItem = v.item(i);
+				NamedNodeMap attributes = currentItem.getAttributes();
+				String name = null;
+				String xpath = null;
+				if (attributes.getNamedItem("name") != null) {
+					name = attributes.getNamedItem("name").getNodeValue();
+				}
+				if (attributes.getNamedItem("xpath") != null) {
+					xpath = attributes.getNamedItem("xpath").getNodeValue();
+				}
+				if (attributes.getNamedItem("value") != null) {
+					xpath = attributes.getNamedItem("value").getNodeValue();
+				}
+
+				MDFormatDescription currentMdFormat = new MDFormatDescription();
+				currentMdFormat.setName(name);
+				currentMdFormat.setXpath(xpath);
+				mdformat.add(currentMdFormat);
+			}
+			return mdformat;
+
+		} catch (ISLookUpDocumentNotFoundException e1) {
+			return null;
+		} catch (ISLookUpException e1) {
+			return null;
+		} catch (Exception e) {
+			throw new MDStoreServiceException("Error on retrieving field from mdformat", e);
+		}
+
+	}
+}
Index: modules/cnr-modular-mdstore-service/branches/indexFields/src/main/resources/eu/dnetlib/data/mdstore/modular/applicationContext-modular-mdstore.properties
===================================================================
--- modules/cnr-modular-mdstore-service/branches/indexFields/src/main/resources/eu/dnetlib/data/mdstore/modular/applicationContext-modular-mdstore.properties	(revision 34592)
+++ modules/cnr-modular-mdstore-service/branches/indexFields/src/main/resources/eu/dnetlib/data/mdstore/modular/applicationContext-modular-mdstore.properties	(revision 34593)
@@ -4,4 +4,4 @@
 services.mdstore.recordParser=eu.dnetlib.data.mdstore.modular.StreamingRecordParser
 services.mdstore.rsfactory.pagesize=20
 services.mdstore.discardrecords=true
-services.mdstore.transaction=mongoMdStoreTransaction
\ No newline at end of file
+services.mdstore.transaction=mongoMdStoreTransaction
Index: modules/cnr-modular-mdstore-service/branches/indexFields/src/main/resources/eu/dnetlib/data/mdstore/modular/applicationContext-modular-mdstore.xml
===================================================================
--- modules/cnr-modular-mdstore-service/branches/indexFields/src/main/resources/eu/dnetlib/data/mdstore/modular/applicationContext-modular-mdstore.xml	(revision 34592)
+++ modules/cnr-modular-mdstore-service/branches/indexFields/src/main/resources/eu/dnetlib/data/mdstore/modular/applicationContext-modular-mdstore.xml	(revision 34593)
@@ -16,6 +16,8 @@
 		init-method="start" destroy-method="stop" p:notificationHandler-ref="mdstoreNotificationHandler"
 		p:iterableResultSetFactory-ref="iterableResultSetFactory"
 		p:feeder-ref="mdstoreFeeder" p:retriever-ref="mdstoreRetriever" />
+		
+	<bean id="mdStoreUtils" class="eu.dnetlib.data.mdstore.modular.MDStoreUtils"/>
 
 	<bean id="mdstoreNotificationHandler"
 		class="eu.dnetlib.enabling.tools.blackboard.BlackboardServerExecutorNotificationHandler"
@@ -70,6 +72,8 @@
 		/> -->
 	<bean id="mdstoreRecordParser" 
 		factory-bean="recordParserFactory" factory-method="newInstance"/>
+		
+	<bean id="fieldExtractor" class="eu.dnetlib.data.mdstore.modular.FieldsExtractor"/>
 	
 	<bean id="recordParserFactory" class="eu.dnetlib.data.mdstore.modular.RecordParserFactory"
 		p:parserType="${services.mdstore.recordParser}" />
