Project

General

Profile

« Previous | Next » 

Revision 30622

[maven-release-plugin] copy for tag unibi-data-collective-transformation-common-1.0.0

View differences:

modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-1.0.0/src/main/java/eu/dnetlib/data/collective/transformation/core/xsl/AbstractXslElement.java
1
package eu.dnetlib.data.collective.transformation.core.xsl;
2

  
3
import java.util.LinkedList;
4
import java.util.List;
5

  
6
/**
7
 * @author jochen
8
 *
9
 */
10
public abstract class AbstractXslElement {
11

  
12
	private String functionName;
13
	protected List<String> attrList = new LinkedList<String>();
14
	protected StringBuilder enclosedElements = new StringBuilder();
15
	protected List<String> nsList = new LinkedList<String>();
16

  
17

  
18
	public AbstractXslElement(String aFunctioName) {
19
		this.functionName = aFunctioName;
20
	}
21
	
22
	public String asXml(boolean isEmpty){
23
		StringBuilder builder = new StringBuilder();
24
		builder.append("<");
25
		builder.append(functionName + " ");
26
		for (String ns: nsList){
27
			builder.append(ns + " ");			
28
		}
29
		
30
		for (String attr: attrList){
31
			builder.append(attr);
32
		}
33
		if (isEmpty){
34
			builder.append("/>");
35
		}else{
36
			builder.append(">");
37
			builder.append(enclosedElements.toString());
38
			builder.append("</");
39
			builder.append(functionName + ">");			
40
		}
41
		return builder.toString();		
42
	}
43
	
44
	public String asXml() {
45
		return asXml(false);
46
	}
47

  
48
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-1.0.0/src/main/java/eu/dnetlib/data/collective/transformation/core/schema/SchemaElement.java
1
package eu.dnetlib.data.collective.transformation.core.schema;
2

  
3
import java.util.LinkedList;
4
import java.util.List;
5

  
6
/**
7
 * @author jochen
8
 *
9
 */
10
public class SchemaElement {
11

  
12
	private String targetNamespace;
13
	private String name;
14
	private boolean isRepeatable;
15
	private boolean isRoot;
16
	private boolean containsSimpleType;
17
	private int minOccurs;
18
	private int maxOccurs;
19
	private List<SchemaElement> childList = new LinkedList<SchemaElement>();
20
	private List<SchemaAttribute> attributeList = new LinkedList<SchemaAttribute>();
21
	private Namespace namespace;
22

  
23
	/**
24
	 * @return the targetNamespace
25
	 */
26
	public String getTargetNamespace() {
27
		return targetNamespace;
28
	}
29
	/**
30
	 * @param targetNamespace the targetNamespace to set
31
	 */
32
	public void setTargetNamespace(String targetNamespace) {
33
		this.targetNamespace = targetNamespace;
34
	}
35
	/**
36
	 * @return the isRepeatable
37
	 */
38
	public boolean isRepeatable() {
39
		return isRepeatable;
40
	}
41
	/**
42
	 * @param isRepeatable the isRepeatable to set
43
	 */
44
	public void setRepeatable(boolean isRepeatable) {
45
		this.isRepeatable = isRepeatable;
46
	}
47
	/**
48
	 * @return the isMandatory
49
	 */
50
	public boolean isMandatory() {
51
		if (minOccurs > 0) return true;
52
		return false;
53
	}
54
	
55
	/**
56
	 * @return the minOccurs
57
	 */
58
	public int getMinOccurs() {
59
		return minOccurs;
60
	}
61
	/**
62
	 * @param minOccurs the minOccurs to set
63
	 */
64
	public void setMinOccurs(int minOccurs) {
65
		this.minOccurs = minOccurs;
66
	}
67
	/**
68
	 * @return the maxOccurs
69
	 */
70
	public int getMaxOccurs() {
71
		return maxOccurs;
72
	}
73
	/**
74
	 * @param maxOccurs the maxOccurs to set
75
	 */
76
	public void setMaxOccurs(int maxOccurs) {
77
		this.maxOccurs = maxOccurs;
78
	}
79
	/**
80
	 * @return the childList
81
	 */
82
	public List<SchemaElement> getChildList() {
83
		return childList;
84
	}
85
	/**
86
	 * @param childList the childList to set
87
	 */
88
	public void setChildList(List<SchemaElement> childList) {
89
		this.childList = childList;
90
	}
91
	
92
	/**
93
	 * @param name the name of the element to set
94
	 */
95
	public void setName(String name) {
96
		this.name = name;
97
	}
98
	
99
	/**
100
	 * @return the name of this element
101
	 */
102
	public String getName() {
103
		return name;
104
	}
105
	
106
	/**
107
	 * sets true if this element contains a simpleType, false else
108
	 * @param containsSimpleType
109
	 */
110
	public void setContainsSimpleType(boolean containsSimpleType) {
111
		this.containsSimpleType = containsSimpleType;
112
	}
113
	
114
	/**
115
	 * @return the containsSimpleType
116
	 */
117
	public boolean containsSimpleType() {
118
		return containsSimpleType;
119
	}
120
	
121
	/**
122
	 * @param isRoot the isRoot to set
123
	 */
124
	public void setRoot(boolean isRoot) {
125
		this.isRoot = isRoot;
126
	}
127
	
128
	/**
129
	 * @return the isRoot
130
	 */
131
	public boolean isRoot() {
132
		return isRoot;
133
	}
134
	/**
135
	 * @param namespace the namespace to set
136
	 */
137
	public void setNamespace(Namespace namespace) {
138
		this.namespace = namespace;
139
	}
140
	/**
141
	 * @return the namespace
142
	 */
143
	public Namespace getNamespace() {
144
		return namespace;
145
	}
146
	/**
147
	 * @return the attributeList
148
	 */
149
	public List<SchemaAttribute> getAttributeList() {
150
		return attributeList;
151
	}
152
	/**
153
	 * @param attributeList the attributeList to set
154
	 */
155
	public void addAttribute(SchemaAttribute aAttribute) {
156
		this.attributeList.add(aAttribute);
157
	}
158
	
159
	
160
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-1.0.0/src/main/java/eu/dnetlib/data/collective/transformation/core/xsl/ext/TransformationFunctionProxy.java
1
package eu.dnetlib.data.collective.transformation.core.xsl.ext;
2

  
3
import java.io.StringReader;
4
import java.io.StringWriter;
5
import java.util.Collection;
6
import java.util.HashMap;
7
import java.util.Iterator;
8
import java.util.LinkedList;
9
import java.util.List;
10
import java.util.Map;
11

  
12
import javax.xml.XMLConstants;
13
import javax.xml.namespace.NamespaceContext;
14
import javax.xml.parsers.DocumentBuilder;
15
import javax.xml.parsers.DocumentBuilderFactory;
16
import javax.xml.transform.Result;
17
import javax.xml.transform.Transformer;
18
import javax.xml.transform.TransformerFactory;
19
import javax.xml.transform.dom.DOMSource;
20
import javax.xml.transform.stream.StreamResult;
21
import javax.xml.xpath.XPath;
22
import javax.xml.xpath.XPathFactory;
23

  
24
import net.sf.saxon.om.NodeInfo;
25
import net.sf.saxon.value.AtomicValue;
26

  
27
import org.apache.commons.lang.StringEscapeUtils;
28
import org.apache.commons.logging.Log;
29
import org.apache.commons.logging.LogFactory;
30
import org.svenson.JSONParser;
31
import org.w3c.dom.Document;
32
import org.w3c.dom.Node;
33
import org.w3c.dom.NodeList;
34
import org.w3c.dom.Text;
35
import org.xml.sax.InputSource;
36

  
37
import eu.dnetlib.data.collective.transformation.engine.FunctionResults;
38
import eu.dnetlib.data.collective.transformation.engine.functions.Convert;
39
import eu.dnetlib.data.collective.transformation.engine.functions.IdentifierExtract;
40
import eu.dnetlib.data.collective.transformation.engine.functions.LookupRecord;
41
import eu.dnetlib.data.collective.transformation.engine.functions.ProcessingException;
42
import eu.dnetlib.data.collective.transformation.engine.functions.RegularExpression;
43
import eu.dnetlib.data.collective.transformation.engine.functions.Split;
44

  
45
/**
46
 * The class implements external XSLT functions
47
 * @author jochen
48
 *
49
 */
50
public class TransformationFunctionProxy {
51

  
52
	@SuppressWarnings("unused")
53
	private static final Log log = LogFactory.getLog(TransformationFunctionProxy.class);
54
	private static TransformationFunctionProxy tf;
55
	private RegularExpression regExprFunction = new RegularExpression();
56
	private Convert convertFunction;
57
	private IdentifierExtract identifierExtractFunction = new IdentifierExtract();
58
	private static DocumentBuilder docBuilder;
59
	private static Transformer transformer;
60
	private Split split = new Split();
61
	private List<String> ignoreRecordList;
62
	private Map<String, FunctionResults> mapOfResults = new HashMap<String, FunctionResults>();
63
	private LookupRecord lookupRecord;
64
	private static XPath xpath = XPathFactory.newInstance().newXPath();
65
	
66
	/**
67
	 * @return the transformationFunctionProxy instance
68
	 */
69
	public static TransformationFunctionProxy getInstance(){
70
		if ( tf == null ){
71
			tf = new TransformationFunctionProxy();
72
			try {
73
				DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
74
				dbf.setNamespaceAware(true);
75
				docBuilder = dbf.newDocumentBuilder();
76
				transformer  = TransformerFactory.newInstance().newTransformer();
77
				xpath.setNamespaceContext(new NamespaceContext() {
78
					
79
					@Override
80
					public Iterator getPrefixes(String namespaceURI) {
81
						// TODO Auto-generated method stub
82
						return null;
83
					}
84
					
85
					@Override
86
					public String getPrefix(String namespaceURI) {
87
						// TODO Auto-generated method stub
88
						return null;
89
					}
90
					
91
					@Override
92
					public String getNamespaceURI(String aPrefix) {
93
						if (aPrefix == null){
94
							throw new IllegalArgumentException("No prefix provided!");
95
						}else if (aPrefix.equals(XMLConstants.DEFAULT_NS_PREFIX)){
96
							return "http://namespace.openaire.eu";
97
						}else if (aPrefix.equals("dc")){
98
							return "http://purl.org/dc/elements/1.1/";
99
						}else{
100
							return XMLConstants.NULL_NS_URI;
101
						}
102
					}
103
				});
104

  
105
			} catch (Exception e) {
106
				log.fatal("error while instantiating DocumentBuilderFactory, Transfomer, Xpath.namespacecontext", e);
107
				throw new IllegalStateException(e);
108
			}
109
		}
110
		return tf;
111
	}
112
	
113
	/**
114
	 * @param uniqueKey
115
	 * @param i
116
	 * @return
117
	 */
118
	public String getValue(String uniqueKey, int i){
119
		if ( !mapOfResults.containsKey(uniqueKey)){
120
			throw new IllegalStateException("unknown key: " + uniqueKey);
121
		}
122
		return mapOfResults.get(uniqueKey).get(i);
123
	}
124
	
125
	/**
126
	 * @param uniqueKey
127
	 * @param i
128
	 * @return
129
	 * @deprecated
130
	 */
131
//	public String convert(String uniqueKey, int i){
132
//		if (mapOfResults == null){
133
//			return "transformationFunctionProxy_convert not initialized";
134
//		}else{
135
//			if (!mapOfResults.containsKey(uniqueKey)){
136
//				throw new IllegalStateException("unknown key: " + uniqueKey);
137
//			}
138
//			return mapOfResults.get(uniqueKey).get(i);			
139
//		}
140
//	}
141
	
142
	/**
143
	 * @param uniqueKey
144
	 * @param i
145
	 * @param aPos
146
	 * @return
147
	 * @deprecated
148
	 */
149
//	public String convert(String uniqueKey, int i, int aPos){
150
//		if (mapOfResults == null){
151
//			return "transformationFunctionProxy_convert not initialized";
152
//		}else{
153
//			if (!mapOfResults.containsKey(uniqueKey)){
154
//				throw new IllegalStateException("unknown key: " + uniqueKey);
155
//			}
156
//			return mapOfResults.get(uniqueKey).get(i, aPos);
157
//		}
158
//	}
159
	
160
	/**
161
	 * @param uniqueKey
162
	 * @param i
163
	 * @return
164
	 */
165
	public String extract(String uniqueKey, int i){
166
		if (mapOfResults == null){
167
			return "transformationFunctionProxy_extract not initialized";
168
		}else{
169
			if (!mapOfResults.containsKey(uniqueKey)){
170
				throw new IllegalStateException("unknown key: " + uniqueKey);
171
			}
172
			return mapOfResults.get(uniqueKey).get(i);			
173
		}		
174
	}
175
	
176
	/**
177
 	 * normalize values given as an input value by using a vocabulary 
178
	 * @param aInput - the value as a String
179
	 * @param aVocabularyName - the name of the vocabulary, which must be known for the vocabulary registry
180
	 * @return
181
	 */
182
	public synchronized String convertString(String aInput, String aVocabularyName){
183
		List<String> values = new LinkedList<String>();
184
		values.add(aInput);
185
		try {
186
			log.debug("conversion input: " + aInput);
187
			String conversionResult = convertFunction.executeSingleValue(aVocabularyName, values);
188
			log.debug("conversion result: " + conversionResult);
189
			return conversionResult;
190
		} catch (ProcessingException e) {
191
			log.fatal("convert failed for args 'input': " + aInput + " , 'vocabularyName': " + aVocabularyName, e);
192
			throw new IllegalStateException(e);
193
		}
194
	}
195

  
196
	/**
197
	 * normalize values given as a NodeList by using a vocabulary 
198
	 * @param aInput - the input values as NodeList
199
	 * @param aVocabularyName - the name of the vocabulary, which must be known for the vocabulary registry
200
	 * @return
201
	 */
202
	public synchronized String convert(NodeList aInput, String aVocabularyName){
203
		List<String> values = new LinkedList<String>();
204
		getTextFromNodeList(aInput, values);
205
		try {
206
			return convertFunction.executeSingleValue(aVocabularyName, values);
207
		} catch (ProcessingException e) {
208
			throw new IllegalStateException(e);
209
		}
210
	}
211
	
212
	public synchronized String convert(NodeList aInput, String aVocabularyName, String aDefaultPattern, String aFunction){
213
		List<String> values = new LinkedList<String>();
214
		getTextFromNodeList(aInput, values);
215
		try {
216
			List<String> results = convertFunction.executeFilterByParams(aVocabularyName, values, aDefaultPattern, aFunction);
217
			if (results.size() > 0)
218
				return results.get(0);
219
			else
220
				return "";
221
		} catch (ProcessingException e) {
222
			throw new IllegalStateException(e);
223
		}
224
	}
225
	
226
	private void getTextFromNodeList(NodeList aNodeList, List<String> aTextvalues){
227
		for (int i = 0; i < aNodeList.getLength(); i++){
228
			Node n = aNodeList.item(i);
229
			if (n.getNodeType() == Node.ELEMENT_NODE)
230
				getTextFromNodeList(n.getChildNodes(), aTextvalues);
231
			else if (n instanceof Text)
232
				aTextvalues.add(n.getNodeValue());
233
		}
234
	}
235

  
236
	/**
237
	 * substitutes using regular expression
238
	 * @param aInput
239
	 * @param aReplacement
240
	 * @param aRegularExpression
241
	 * @return
242
	 */
243
	public synchronized String regExpr(String aInput, String aReplacement, String aRegularExpression){
244
		try {
245
			int lastSlash = aRegularExpression.lastIndexOf("/");
246
			String trailingOptions = aRegularExpression.substring(lastSlash);
247
//			log.debug("trailingOptions: " + trailingOptions);
248
			int replacementSlash = aRegularExpression.substring(0, lastSlash).lastIndexOf("/");
249
			String replacementFromExpression = aRegularExpression.substring(replacementSlash + 1, lastSlash);
250
//			log.debug("replacementFromExpr lengt: " + replacementFromExpression.length() + ", value: " + replacementFromExpression);
251
			String newRegExpr = aRegularExpression.substring(0, replacementSlash + 1) + aReplacement + replacementFromExpression + trailingOptions;
252
//			log.debug("newRegExpr: " + newRegExpr);
253
			return regExprFunction.executeSingleValue(newRegExpr, aInput, aReplacement);
254
		} catch (ProcessingException e) {
255
			throw new IllegalStateException(e);
256
		}
257
	}
258
	
259
	public String lookup(String aIdentifier, String aPropertyKey){
260
		log.debug("functionProxy.lookup: param identifier: " + aIdentifier + " , key: " + aPropertyKey);
261
		return this.lookupRecord.getPropertyValue(aIdentifier, aPropertyKey);
262
	}
263

  
264
	public synchronized Collection<String> split(NodeList aInput, String aRegularExpression, String aCallId){
265
		try {
266
			List<String> textValues = new LinkedList<String>();
267
			getTextFromNodeList(aInput, textValues);
268
			return split.executeAllValues(textValues, aRegularExpression);
269
			//return split.executeSingleValue(textValues, aRegularExpression, aCallId);
270
		}catch (ProcessingException e){
271
			throw new IllegalStateException(e);
272
		}
273
	}
274
	
275
	public synchronized String split(String aCallId){
276
		try {
277
			return split.executeSingleValue(aCallId);
278
		}catch (ProcessingException e){
279
			throw new IllegalStateException(e);
280
		}		
281
	}
282
	
283
	/**
284
	 * extract content that match pattern given by a regular expression from a given node
285
	 * @param xpathExprJson
286
	 * @param aInput
287
	 * @param aRegExpression
288
	 * @return nodeList
289
	 */
290
	public synchronized NodeList identifierExtract(String aXpathExprJson, Node aInput, String aRegExpression){
291
		String xpathExprJson = StringEscapeUtils.unescapeXml(aXpathExprJson);
292
		log.debug("unescape xpathExprJson: " + xpathExprJson);
293
		String regExpression = StringEscapeUtils.unescapeXml(aRegExpression);
294
		log.debug("unescape regExpr" + regExpression);
295

  
296
		try{
297
			List<String> xpathExprList = JSONParser.defaultJSONParser().parse(List.class, xpathExprJson);
298
			
299
			// workaround: rewrap, why ?
300
			DOMSource s = new DOMSource(aInput);
301
			StringWriter w = new StringWriter();
302
			Result r = new StreamResult(w);
303
			transformer.transform(s, r);
304
			Document doc = docBuilder.parse(new InputSource(new StringReader(w.toString())));
305
			
306
			return identifierExtractFunction.extract(xpathExprList, doc, regExpression, docBuilder.newDocument(), xpath);
307
		}catch(Exception e){
308
			log.fatal("identifierExtract failed for node value: " + aInput.getNodeValue(), e);
309
			throw new IllegalStateException(e.getMessage());
310
		}
311
	}
312
	
313
//	public String regExpr(String uniqueKey, int i){
314
//		if ( !mapOfResults.containsKey(uniqueKey)){
315
//			throw new IllegalStateException("unknown key: " + uniqueKey);			
316
//		}
317
//		return mapOfResults.get(uniqueKey).get(i);
318
//	}
319
	
320
	/**
321
	 * add record identified by 'aIndex' to the list of records to be skipped
322
	 * @param aIndex the index of the record in the object record list
323
	 * @return
324
	 */
325
	public String skipRecord(int aIndex){
326
		this.ignoreRecordList.add("" + aIndex);
327
		return "";
328
	}
329
	
330
	/**
331
	 * @param key
332
	 * @param resultsFunction_getvalue
333
	 */
334
	public void setResults(String key, FunctionResults resultsFunction_getvalue) {
335
		mapOfResults.put(key, resultsFunction_getvalue);
336
	}
337

  
338
	/**
339
	 * @param ignoreRecordList the ignoreRecordList to set
340
	 */
341
	public void setIgnoreRecordList(List<String> ignoreRecordList) {
342
		this.ignoreRecordList = ignoreRecordList;
343
	}
344

  
345
	/**
346
	 * @return the ignoreRecordList
347
	 */
348
	public List<String> getIgnoreRecordList() {
349
		return ignoreRecordList;
350
	}
351

  
352
	/**
353
	 * @param convertFunction the convertFunction to set
354
	 */
355
	public void setConvertFunction(Convert convertFunction) {
356
		this.convertFunction = convertFunction;
357
	}
358

  
359
	/**
360
	 * @return the convertFunction
361
	 */
362
	public Convert getConvertFunction() {
363
		return convertFunction;
364
	}
365

  
366
	/**
367
	 * @return the lookupRecord
368
	 */
369
	public LookupRecord getLookupRecord() {
370
		return lookupRecord;
371
	}
372

  
373
	/**
374
	 * @param lookupRecord the lookupRecord to set
375
	 */
376
	public void setLookupRecord(LookupRecord lookupRecord) {
377
		this.lookupRecord = lookupRecord;
378
	}
379

  
380
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-1.0.0/src/main/java/eu/dnetlib/data/collective/transformation/rulelanguage/visitor/AbstractVisitor.java
1
package eu.dnetlib.data.collective.transformation.rulelanguage.visitor;
2

  
3
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyAssign;
4
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyAttribute;
5
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyOp;
6
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTStart;
7
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.FtScriptVisitor;
8
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.SimpleNode;
9

  
10
public abstract class AbstractVisitor implements FtScriptVisitor {
11

  
12
	/* (non-Javadoc)
13
	 * @see examples.jjtree.FtScriptVisitor#visit(examples.jjtree.ASTMyAssign, java.lang.Object)
14
	 */
15
	@Override
16
	public Object visit(ASTMyAssign node, Object data) {
17
		// TODO Auto-generated method stub
18
		return null;
19
	}
20

  
21
	/* (non-Javadoc)
22
	 * @see examples.jjtree.FtScriptVisitor#visit(examples.jjtree.ASTMyAttribute, java.lang.Object)
23
	 */
24
	@Override
25
	public Object visit(ASTMyAttribute node, Object data) {
26
		// TODO Auto-generated method stub
27
		return null;
28
	}
29

  
30

  
31
	/* (non-Javadoc)
32
	 * @see examples.jjtree.FtScriptVisitor#visit(examples.jjtree.ASTMyOp, java.lang.Object)
33
	 */
34
	@Override
35
	public Object visit(ASTMyOp node, Object data) {
36
		// TODO Auto-generated method stub
37
		return null;
38
	}
39

  
40
	/* (non-Javadoc)
41
	 * @see examples.jjtree.FtScriptVisitor#visit(examples.jjtree.ASTStart, java.lang.Object)
42
	 */
43
	@Override
44
	public Object visit(ASTStart node, Object data) {
45
		// TODO Auto-generated method stub
46
		return null;
47
	}
48

  
49
	/* (non-Javadoc)
50
	 * @see examples.jjtree.FtScriptVisitor#visit(examples.jjtree.SimpleNode, java.lang.Object)
51
	 */
52
	@Override
53
	public Object visit(SimpleNode node, Object data) {
54
		// TODO Auto-generated method stub
55
		return null;
56
	}
57

  
58
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-1.0.0/src/main/java/eu/dnetlib/data/collective/transformation/rulelanguage/parser/ASTMySet.java
1
/* Generated By:JJTree: Do not edit this line. ASTMySet.java Version 4.3 */
2
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=false,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
3
package eu.dnetlib.data.collective.transformation.rulelanguage.parser;
4

  
5
import java.util.LinkedList;
6
import java.util.List;
7

  
8
import org.apache.commons.logging.Log;
9
import org.apache.commons.logging.LogFactory;
10

  
11
import eu.dnetlib.data.collective.transformation.rulelanguage.Rules;
12

  
13
/**
14
 * This class is primarily designed to assign values to the element and attributes of the element
15
 * @author jochen
16
 *
17
 */
18
public class ASTMySet extends AbstractNode {
19
	
20
	private static final Log log = LogFactory.getLog(ASTMySet.class);
21
	private List<Rules> rulesList = new LinkedList<Rules>();
22
	private String expressionValue;
23
	private String constValue;
24
	private boolean isExpressionValue = false;
25
	
26
	
27
  public ASTMySet(int id) {
28
    super(id);
29
  }
30

  
31
  public ASTMySet(FtScript p, int id) {
32
    super(p, id);
33
  }
34

  
35
  /** Accept the visitor. **/
36
  public Object jjtAccept(FtScriptVisitor visitor, Object data) {
37
    return visitor.visit(this, data);
38
  }
39
  
40
  public void addAttributeRule(Rules aRule){
41
	  log.debug("called method:  ASTMySet.addRule " + aRule.getUniqueName()+
42
			  " attribute: " + aRule.getAttribute() + " defines variable?: " + aRule.definesVariable());
43
	  rulesList.add(aRule);
44
  }
45
  
46
  public List<Rules> getRules(){
47
	  return this.rulesList;
48
  }
49

  
50
  public void setValueExpression(String aExpression) {
51
	  log.debug("expression: " + aExpression);
52
	this.expressionValue = aExpression;
53
	this.isExpressionValue = true;
54
  }
55
  
56
  public String getValueExpression(){
57
	  return this.expressionValue;
58
  }
59
  
60
  public boolean isValueExpression(){
61
	  return this.isExpressionValue;
62
  }
63

  
64
  public void setAttribute(String aValue) {
65
	  this.constValue = aValue;
66
  }
67
}
68
/* JavaCC - OriginalChecksum=1a796456845c74ed0ee62389483ce5a7 (do not edit this line) */
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-1.0.0/src/main/java/eu/dnetlib/data/collective/transformation/core/schema/visitor/Visitor.java
1
package eu.dnetlib.data.collective.transformation.core.schema.visitor;
2

  
3

  
4
import java.util.LinkedList;
5
import java.util.List;
6

  
7
import org.apache.commons.lang.NotImplementedException;
8
//import org.apache.commons.logging.Log;
9
//import org.apache.commons.logging.LogFactory;
10

  
11
import com.sun.xml.xsom.XSAnnotation;
12
import com.sun.xml.xsom.XSAttGroupDecl;
13
import com.sun.xml.xsom.XSAttributeDecl;
14
import com.sun.xml.xsom.XSAttributeUse;
15
import com.sun.xml.xsom.XSComplexType;
16
import com.sun.xml.xsom.XSContentType;
17
import com.sun.xml.xsom.XSElementDecl;
18
import com.sun.xml.xsom.XSFacet;
19
import com.sun.xml.xsom.XSIdentityConstraint;
20
import com.sun.xml.xsom.XSModelGroup;
21
import com.sun.xml.xsom.XSModelGroupDecl;
22
import com.sun.xml.xsom.XSNotation;
23
import com.sun.xml.xsom.XSParticle;
24
import com.sun.xml.xsom.XSSchema;
25
import com.sun.xml.xsom.XSSimpleType;
26
import com.sun.xml.xsom.XSType;
27
import com.sun.xml.xsom.XSWildcard;
28
import com.sun.xml.xsom.XSXPath;
29
import com.sun.xml.xsom.visitor.XSVisitor;
30

  
31
import eu.dnetlib.data.collective.transformation.core.schema.SchemaAttribute;
32
import eu.dnetlib.data.collective.transformation.core.schema.SchemaElement;
33

  
34
/**
35
 * @author jochen
36
 *
37
 */
38
public class Visitor implements XSVisitor {
39
	
40
	//private static Log log = LogFactory.getLog(Visitor.class);
41
	List<SchemaElement> schemaElements = new LinkedList<SchemaElement>();
42
	SchemaElement currentElement;
43
	SchemaAttribute currentAttribute;
44
	
45
	@Override
46
	public void annotation(XSAnnotation arg0) {
47
		throw new NotImplementedException();
48
	}
49

  
50
	@Override
51
	public void attGroupDecl(XSAttGroupDecl arg0) {
52
		throw new NotImplementedException();
53
	}
54

  
55
	@Override
56
	public void attributeDecl(XSAttributeDecl aAttributeDecl) {
57
		currentAttribute.setName(aAttributeDecl.getName());
58
		//log.debug("visit attribute name: " + aAttributeDecl.getName());
59
		//log.debug("visit attribute type: " + aAttributeDecl.getType());
60
		throw new NotImplementedException();
61
	}
62

  
63
	@Override
64
	public void attributeUse(XSAttributeUse aAttributeUse) {
65
		throw new NotImplementedException();
66
	}
67

  
68
	@Override
69
	public void complexType(XSComplexType aType) {
70
		if (aType.getDerivationMethod()== XSType.RESTRICTION){
71
			XSContentTypeVisitorImpl contentTypeVisitor = new XSContentTypeVisitorImpl();
72
			contentTypeVisitor.setVisitor(this);
73
			aType.getContentType().visit(contentTypeVisitor);				
74
		}else{
75
			// aType.getExplicitContent().visit(this);
76
			throw new NotImplementedException("visiting types other then 'RESTRICTION are not implemented'");
77
		}
78
	}
79

  
80
	@Override
81
	public void facet(XSFacet arg0) {
82
		throw new NotImplementedException();
83
	}
84

  
85
	@Override
86
	public void identityConstraint(XSIdentityConstraint arg0) {
87
		throw new NotImplementedException();
88
	}
89

  
90
	@Override
91
	public void notation(XSNotation arg0) {
92
		throw new NotImplementedException();
93
	}
94

  
95
	@Override
96
	public void schema(XSSchema arg0) {
97
		throw new NotImplementedException();
98
	}
99

  
100
	@Override
101
	public void xpath(XSXPath arg0) {
102
		throw new NotImplementedException();
103
	}
104

  
105
	@Override
106
	public void elementDecl(XSElementDecl aElementDecl) {
107
		XSType type = aElementDecl.getType();
108
		if (type.isLocal()){
109
			// complete infos about the current element
110
			// log.debug("visitor element name: " + aElementDecl.getName());
111
			currentElement.setName(aElementDecl.getName());
112
			currentElement.setTargetNamespace(aElementDecl.getTargetNamespace());
113
			type.visit(this);
114
		}
115
	}
116

  
117
	@Override
118
	public void modelGroup(XSModelGroup aGroup) {
119
		// a group of elements as childs of the root element
120
		for (XSParticle p: aGroup.getChildren()){
121
			particle(p);
122
		}
123
	}
124

  
125
	@Override
126
	public void modelGroupDecl(XSModelGroupDecl arg0) {
127
		throw new NotImplementedException();
128
	}
129

  
130
	@Override
131
	public void wildcard(XSWildcard arg0) {
132
		throw new NotImplementedException();
133
	}
134

  
135
	@Override
136
	public void empty(XSContentType arg0) {
137
		throw new NotImplementedException();
138
	}
139

  
140
	@Override
141
	public void particle(XSParticle aParticle) {
142
		// create a new schema element, add to the list of schema elements, set this element as current element
143
		SchemaElement element = new SchemaElement();
144
		element.setMinOccurs(aParticle.getMinOccurs().intValue());
145
		element.setMaxOccurs(aParticle.getMaxOccurs().intValue());
146
		element.setRepeatable(aParticle.isRepeated());
147
		schemaElements.add(element);
148
		currentElement = element;
149
		XSTermVisitorImpl termVisitor = new XSTermVisitorImpl();
150
		termVisitor.setVisitor(this);
151
		aParticle.getTerm().visit(termVisitor);
152
	}
153
 	
154
	
155
	@Override
156
	public void simpleType(XSSimpleType arg0) {
157
		throw new NotImplementedException();
158
	}
159
	
160
	public List<SchemaElement> getElements(){
161
		return this.schemaElements;
162
	}
163

  
164
	protected SchemaElement getCurrentElement(){
165
		return currentElement;
166
	}
167

  
168
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-1.0.0/src/main/java/eu/dnetlib/data/collective/transformation/core/schema/visitor/XSTermVisitorImpl.java
1
package eu.dnetlib.data.collective.transformation.core.schema.visitor;
2

  
3
import org.apache.commons.lang.NotImplementedException;
4

  
5
import com.sun.xml.xsom.XSElementDecl;
6
import com.sun.xml.xsom.XSModelGroup;
7
import com.sun.xml.xsom.XSModelGroupDecl;
8
import com.sun.xml.xsom.XSParticle;
9
import com.sun.xml.xsom.XSWildcard;
10
import com.sun.xml.xsom.visitor.XSTermVisitor;
11

  
12
/**
13
 * @author jochen
14
 *
15
 */
16
public class XSTermVisitorImpl implements XSTermVisitor {
17

  
18
	private Visitor visitor;
19
	
20
	@Override
21
	public void elementDecl(XSElementDecl aElementDecl) {
22
		if (aElementDecl.isLocal()){
23
			  this.visitor.elementDecl(aElementDecl);
24
		}else{
25
			// ignore non local element declarations
26
		}
27
	}
28

  
29
	@Override
30
	public void modelGroup(XSModelGroup aModelGroup) {
31
		XSContentTypeVisitorImpl contentTypeVisitor = new XSContentTypeVisitorImpl();
32
		contentTypeVisitor.setVisitor(this.visitor);
33
		for (XSParticle p: aModelGroup.getChildren()){
34
			contentTypeVisitor.particle(p);
35
		}										
36
	}
37

  
38
	@Override
39
	public void modelGroupDecl(XSModelGroupDecl arg0) {
40
		throw new NotImplementedException();
41
	}
42

  
43
	@Override
44
	public void wildcard(XSWildcard arg0) {
45
		throw new NotImplementedException();
46
	}
47

  
48
	public void setVisitor(Visitor visitor) {
49
		this.visitor = visitor;
50
	}
51

  
52
	public Visitor getVisitor() {
53
		return visitor;
54
	}
55

  
56
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-1.0.0/pom.xml
1
<?xml version="1.0" ?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet-parent</artifactId>
6
		<version>1.0.0</version>
7
	</parent>
8
	<modelVersion>4.0.0</modelVersion>
9
	<groupId>eu.dnetlib</groupId>
10
	<artifactId>unibi-data-collective-transformation-common</artifactId>
11
	<packaging>jar</packaging>
12
	<version>1.0.0</version>
13
	<scm>
14
	  <developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-1.0.0</developerConnection>
15
	</scm>
16
	<dependencies>
17
		<dependency>
18
			<groupId>commons-beanutils</groupId>
19
			<artifactId>commons-beanutils</artifactId>
20
			<version>1.8.3</version>
21
		</dependency>
22
		<dependency>
23
			<groupId>junit</groupId>
24
			<artifactId>junit</artifactId>
25
			<version>${junit.version}</version>
26
			<scope>test</scope>
27
		</dependency>
28
		<dependency>
29
			<groupId>org.mockito</groupId>
30
			<artifactId>mockito-core</artifactId>
31
			<version>1.6</version>
32
			<scope>test</scope>
33
		</dependency>
34
		<dependency>
35
			<groupId>org.svenson</groupId>
36
			<artifactId>svenson-json</artifactId>
37
			<version>[1.4.0,1.5.0)</version>
38
		</dependency>
39
		<dependency>
40
			<groupId>org.slf4j</groupId>
41
			<artifactId>slf4j-api</artifactId>
42
			<version>1.6.4</version>
43
			<scope>compile</scope>
44
		</dependency>
45
		<dependency>
46
			<groupId>org.slf4j</groupId>
47
			<artifactId>slf4j-log4j12</artifactId>
48
			<version>1.6.4</version>
49
			<scope>runtime</scope>
50
		</dependency>
51
		<dependency>
52
			<groupId>com.google.guava</groupId>
53
			<artifactId>guava</artifactId>
54
			<version>${google.guava.version}</version>
55
		</dependency>
56
		<dependency>
57
			<groupId>eu.dnetlib</groupId>
58
			<artifactId>cnr-service-common</artifactId>
59
			<version>[1.0.0,2.0.0)</version>
60
		</dependency>
61
		<dependency>
62
			<groupId>com.sun.xsom</groupId>
63
			<artifactId>xsom</artifactId>
64
			<version>20110809</version>
65
		</dependency>		
66
	</dependencies>
67
</project>
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-1.0.0/src/main/java/eu/dnetlib/data/collective/transformation/core/schema/SchemaAttribute.java
1
/**
2
 * 
3
 */
4
package eu.dnetlib.data.collective.transformation.core.schema;
5

  
6
/**
7
 * @author jochen
8
 *
9
 */
10
public class SchemaAttribute {
11

  
12
	private String name;
13
	private boolean required;
14

  
15
	/**
16
	 * @return the name
17
	 */
18
	public String getName() {
19
		return name;
20
	}
21

  
22
	/**
23
	 * @param name the name to set
24
	 */
25
	public void setName(String name) {
26
		this.name = name;
27
	}
28

  
29
	/**
30
	 * @return the required
31
	 */
32
	public boolean isRequired() {
33
		return required;
34
	}
35

  
36
	/**
37
	 * @param required the required to set
38
	 */
39
	public void setRequired(boolean required) {
40
		this.required = required;
41
	}
42
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-1.0.0/src/main/java/eu/dnetlib/data/collective/transformation/rulelanguage/visitor/RuleLanguageVisitor.java
1
package eu.dnetlib.data.collective.transformation.rulelanguage.visitor;
2

  
3
import java.util.HashMap;
4
import java.util.LinkedHashMap;
5
import java.util.LinkedHashSet;
6
import java.util.LinkedList;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.Set;
10

  
11
import org.apache.commons.logging.Log;
12
import org.apache.commons.logging.LogFactory;
13

  
14
import eu.dnetlib.data.collective.transformation.rulelanguage.Argument;
15
import eu.dnetlib.data.collective.transformation.rulelanguage.Condition;
16
import eu.dnetlib.data.collective.transformation.rulelanguage.IRule;
17
import eu.dnetlib.data.collective.transformation.rulelanguage.Rules;
18
import eu.dnetlib.data.collective.transformation.rulelanguage.RulesSet;
19
import eu.dnetlib.data.collective.transformation.rulelanguage.Argument.Type;
20
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyAssign;
21
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyAttribute;
22
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyCondition;
23
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyCopy;
24
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyEmpty;
25
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyImport;
26
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyNs;
27
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyOp;
28
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyPreprocess;
29
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyScript;
30
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyScript.SCRIPTTYPE;
31
import eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMySet;
32
import eu.dnetlib.data.collective.transformation.rulelanguage.util.Converter;
33
import eu.dnetlib.data.collective.transformation.rulelanguage.util.FunctionCall;
34

  
35
/**
36
 * Implementation of the visitor pattern; maps production rules into Java data structures
37
 * @author jochen
38
 *
39
 */
40
public class RuleLanguageVisitor extends AbstractVisitor{
41

  
42
	private static final Log log = LogFactory.getLog(RuleLanguageVisitor.class);
43
	
44
	private String scriptName = "";
45
	private ASTMyScript.SCRIPTTYPE scriptType;
46
	private Map<String, Set<IRule>> elementMappingRules = new LinkedHashMap<String, Set<IRule>>();
47
	private Map<String, IRule> variableMappingRules = new LinkedHashMap<String, IRule>();
48
	private Map<String, IRule> templateMappingRules = new LinkedHashMap<String, IRule>();
49
	private List<String> importedScriptList = new LinkedList<String>();
50
	private List<FunctionCall> functionCallList = new LinkedList<FunctionCall>();
51
	private Map<String, String> namespaceDeclMap = new HashMap<String, String>();
52
	private List<Map<String, String>> preprocessingMap = new LinkedList<Map<String,String>>();
53
	
54
	
55
	/**
56
	 * @return the name of the rule script
57
	 */
58
	public String getScriptName(){
59
		return this.scriptName;
60
	}
61
	
62
	/**
63
	 * @return the type of the script
64
	 */
65
	public SCRIPTTYPE getScriptType(){
66
		return this.scriptType;
67
	}
68
	
69
	/**
70
	 * @return the mapping of all rules
71
	 */
72
	public Map<String, Set<IRule>> getElementMappingRules(){
73
		return this.elementMappingRules;
74
	}
75
	
76
	public Map<String, IRule> getVariableMappingRules(){
77
		return this.variableMappingRules;
78
	}
79
	
80
	public Map<String, IRule> getTemplateMappingRules(){
81
		return this.templateMappingRules;
82
	}
83
	
84
	/**
85
	 * @return the list of function calls - this is a subset of the rule mapping
86
	 */
87
	public List<FunctionCall> getFunctionCalls(){
88
		return this.functionCallList;
89
	}
90
	
91
	/**
92
	 * @return the list of scripts that are declared as import
93
	 */
94
	public List<String> getImportedScripts(){
95
		return this.importedScriptList;
96
	}
97
	
98
	/**
99
	 * @return the map of name-space declarations made in the script
100
	 */
101
	public Map<String, String> getNamespaceDeclarations(){
102
		return this.namespaceDeclMap;
103
	}
104
	
105
	/**
106
	 * @return the map of preprocessings (functions, parameters)
107
	 */
108
	public List<Map<String, String>> getPreprocessings(){
109
		return this.preprocessingMap;
110
	}
111
	
112
	public Object visit(ASTMyAssign node, Object data) {
113
		String attrValue = "";
114
		String fieldExprValue = "";
115
		Rules r = node.getRule();
116
		
117
		if (node.isFieldExpression()){
118
			// todo e.g. convert field-expression into a xpath-expression
119
			fieldExprValue = node.getFieldExpression();
120
			if (fieldExprValue.startsWith("xpath:")){
121
				fieldExprValue = Converter.getXpathFromXpathExpr(fieldExprValue);				
122
				r.setXpath(fieldExprValue);
123
			}else if (fieldExprValue.startsWith("$") && !fieldExprValue.startsWith("$job.")){
124
				// variable
125
				log.debug("ruleLangVisitor: assign variable:" + fieldExprValue);
126
				r.setAssignmentVariable(fieldExprValue);
127
			}
128
		}else if (node.isAttribute()){
129
			attrValue = node.getValue();
130
		}else {
131
			// shouldn't happen
132
			attrValue = "value not defined: " + node.getValue();
133
		}
134
		r.setConstant(attrValue);
135
		if (r.getUniqueName().trim().length() > 0){
136
			addRule(r, r.getUniqueName());			
137
		}
138
		return null;
139
	}
140
	
141
	@Override
142
	public Object visit(ASTMyCopy node, Object data) {
143
		Rules r = node.getRule();
144
		r.setTemplateMatch(node.getTemplateMatchName());
145
		r.getProperties().setProperty("applyTemplateSelectExpression", node.getApplyTemplateSelectExpression());
146
		r.getProperties().setProperty("copySelectExpression", node.getCopySelectExpression());
147
		addRule(r, r.getUniqueName());
148
		return null;
149
	}
150

  
151
	@Override
152
	public Object visit(ASTMySet aNode, Object aData) {
153
		log.debug("called method: RuleLanguageVisitor.visit(ASTMySet)");
154
		// check if the outputfield is the same in rules of this production
155
		Rules myRule = aNode.getRule();
156

  
157
		if (aNode.isValueExpression()){
158
			// todo e.g. convert field-expression into a xpath-expression
159
			String exprValue = aNode.getValueExpression();
160
			if (exprValue.startsWith("xpath:")){
161
				exprValue = Converter.getXpathFromXpathExpr(exprValue);				
162
				myRule.setXpath(exprValue);
163
			}else if (exprValue.startsWith("$") && !exprValue.startsWith("$job.")){
164
				// variable
165
				log.debug("ruleLangVisitor: assign variable:" + exprValue);
166
				myRule.setAssignmentVariable(exprValue);
167
			}
168
		}
169

  
170
		List<Rules> rules = aNode.getRules();
171
		RulesSet set = new RulesSet();
172
		//set.setPrimaryRule(rules.get(0));
173
		myRule.setRulesSet(set);
174
		log.debug("rulelangvisitor rule name: " + myRule.getUniqueName() + " , hasSet : " + myRule.hasSet());
175
		set.getPendingRules().addAll(rules);
176
		addRule(myRule, myRule.getUniqueName());
177
		return null;
178
	}
179

  
180
	@Override
181
	public Object visit(ASTMyEmpty node, Object data) {
182
		Rules r = node.getRule();
183
		r.setEmpty(node.isEmpty());
184
		addRule(r, r.getUniqueName());
185
		return null;
186
	}
187

  
188

  
189
	/**
190
	 * vist a production rule that is defined as an operation or external function call 
191
	 * @see eu.dnetlib.data.collective.transformation.rulelanguage.visitor.AbstractVisitor#visit(eu.dnetlib.data.collective.transformation.rulelanguage.parser.ASTMyOp, java.lang.Object)
192
	 */
193
	public Object visit(ASTMyOp node, Object data) {
194
		Rules r = node.getRule();
195
		r.setFunctionCall(node.createFunctionCall(r.isStatic()));
196
		functionCallList.add(r.getFunctionCall());
197
		log.debug("fc name: " + r.getFunctionCall().getExternalFunctionName());
198
		for(int i =0; i < node.jjtGetNumChildren(); i++) {
199
            ASTMyAttribute sn = (ASTMyAttribute)node.jjtGetChild(i);
200
            Argument arg = null;
201
            if (sn.getAttributeValue() != null){
202
            	arg = new Argument(Type.VALUE, sn.getAttributeValue());
203
            }else if (sn.getAttributeInputField() != null){
204
            	if (sn.getAttributeInputField().startsWith("xpath:")){
205
                	arg = new Argument(Type.INPUTFIELD, Converter.getXpathFromXpathExpr(sn.getAttributeInputField()));            		
206
            	}else if (sn.getAttributeInputField().startsWith("$job.")){
207
            		// job constant
208
                	arg = new Argument(Type.JOBCONST, sn.getAttributeInputField());
209
            	}else{
210
            		// variable
211
            		arg = new Argument(Type.VAR, sn.getAttributeInputField());
212
            	}
213
            }else{
214
            	throw new IllegalStateException("Argument with neither value nor inputfield is not allowed.");
215
            }
216
            log.debug("argument: " + arg.getArgument());
217
            r.getFunctionCall().addArgument(arg);
218
		}
219
		if (r.getFunctionCall().getParameters() != null){
220
			Set<String> keys = r.getFunctionCall().getParameters().keySet();
221
			for (String key: keys){
222
				log.debug("key: " + key + " , value: " + r.getFunctionCall().getParameters().get(key));
223
			}			
224
		}
225
		log.debug("add rule with declaration: " + r.getRuleDeclaration());
226
		addRule(r, r.getUniqueName());			
227

  
228
		return null;
229
	}
230

  
231
	@Override
232
	public Object visit(ASTMyImport node, Object data) {
233
		importedScriptList.add(node.getScriptName());
234
		return null;
235
	}
236

  
237
	@Override
238
	public Object visit(ASTMyNs node, Object data) {
239
		namespaceDeclMap.put(node.getNsPrefix(), node.getNsUri());
240
		return null;
241
	}
242

  
243
	@Override
244
	public Object visit(ASTMyScript node, Object data) {
245
		this.scriptName = node.getScript();
246
		this.scriptType = node.getScriptType();
247
		return null;
248
	}
249

  
250
	@Override
251
	public Object visit(ASTMyCondition node, Object data) {
252
		Condition condition = new Condition();
253
		if (node.getApplyExpression().length() > 0){
254
			String applyExpr = Converter.getXpathFromXpathExpr(node.getApplyExpression());
255
			condition.setApplyExpression(applyExpr);
256
		}
257
		
258
		String conditionalExpr = Converter.getXpathFromXpathExpr(node.getConditionalExpression());
259
		condition.setConditionExpression(conditionalExpr);
260
		condition.setPrimaryRule(node.getPrimaryRule());
261
		node.getPrimaryRule().setCondition(condition);
262
		condition.setSecondaryRule(node.getSecondaryRule());
263
		node.getSecondaryRule().setCondition(condition);
264
		return null;
265
	}
266
	
267
	@Override
268
	public Object visit(ASTMyPreprocess node, Object data) {
269
		Map<String, String> functionMap = new HashMap<String, String>();
270
		functionMap.put(node.getFunctionName(), node.getParameter());
271
		preprocessingMap.add(functionMap);
272
		return null;
273
	}	
274

  
275
	
276

  
277

  
278
	private void addRule(IRule rule, String key){
279
		log.debug("add rule with key: " + key);
280
		Set<IRule> ruleSet = null;
281
		if (rule.definesVariable()){
282
			variableMappingRules.put(key, rule);
283
		}else if (rule.definesTemplate()){
284
			templateMappingRules.put(key, rule);
285
		}else{
286
			if (elementMappingRules.containsKey(key)){
287
				ruleSet = elementMappingRules.get(key);
288
			}else{
289
				ruleSet = new LinkedHashSet<IRule>();
290
				elementMappingRules.put(key, ruleSet);
291
			}			
292
			ruleSet.add(rule);		
293
		}
294
	}
295

  
296

  
297
}
modules/unibi-data-collective-transformation-common/tags/unibi-data-collective-transformation-common-1.0.0/src/main/java/eu/dnetlib/data/collective/transformation/rulelanguage/Rules.java
1
package eu.dnetlib.data.collective.transformation.rulelanguage;
2

  
3
import java.util.Properties;
4

  
5
import eu.dnetlib.data.collective.transformation.core.schema.SchemaElement;
6
import eu.dnetlib.data.collective.transformation.rulelanguage.util.FunctionCall;
7

  
8
/**
9
 * @author jochen
10
 *
11
 */
12
public class Rules implements Comparable<Rules>, IRule{
13

  
14
	public static final String staticRule = "static";
15
	private String attribute = "";
16
	private String targetField = "";
17
	private String ruleDeclaration = "";
18
	private String xpath = "";
19
	private String constant = "";
20
	private String namespace = "";
21
	private String variable = "";
22
	private String template = "";
23
	private String templateMatch = "";
24
	private FunctionCall funcCall;
25
	private Condition condition;
26
	private boolean isEmpty = false;
27
	private SchemaElement targetSchemaElement;
28
	private String assignmentVariable = "";
29
	private RulesSet rulesSet;
30
	private Properties properties = new Properties();
31
	
32
	public Rules() {
33
	}
34
				
35
	/**
36
	 * indicates if the rule is declared as static
37
	 * @return true if static, false otherwise
38
	 */
39
	public boolean isStatic(){
40
		if (ruleDeclaration.equals(staticRule)){
41
			return true;
42
		}
43
		return false;
44
	}
45
	
46
	/**
47
	 * indicates if the rule defines a variable
48
	 * @return true if variable is defined, false otherwise
49
	 * @see eu.dnetlib.data.collective.transformation.rulelanguage.IRule#definesVariable()
50
	 */
51
	public boolean definesVariable(){
52
		if (variable.length() > 0) return true;
53
		return false;
54
	}
55
	
56
	public boolean definesTargetField(){
57
		if (targetField.length() > 0) return true;
58
		return false;
59
	}
60
	
61
	/**
62
	 * checks if this rule defines an attribute
63
	 * @return true if defines attribute else false
64
	 */
65
	public boolean definesAttribute(){
66
		if (attribute.length() > 0) return true;
67
		return false;
68
	}
69
	
70
	public boolean definesTemplate(){
71
		if (template.length() > 0) return true;
72
		return false;
73
	}
74
	
75
	@Override
76
	public boolean definesTemplateMatch() {
77
		if (templateMatch.length() > 0) return true;
78
		return false;
79
	}
80
	
81
	public void setXpath(String xpath) {
82
		this.xpath = xpath;
83
	}
84
	public String getXpath() {
85
		return xpath;
86
	}
87
	
88
	/**
89
	 * sets the argument aVariable as the value of the rule
90
	 * @param aVariable the variable as a reference to the value
91
	 */
92
	public void setAssignmentVariable(String aVariable){
93
		this.assignmentVariable = aVariable;
94
	}
95
	
96
	public String getAssignmentVariable(){
97
		return this.assignmentVariable;
98
	}
99

  
100
	public void setNamespace(String namespace) {
101
		this.namespace = namespace;
102
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff