View Javadoc

1   /***
2    * Created on Aug 5, 2005, Copyright UC Regents
3    */
4   package wise2.converter.converters;
5   
6   import java.net.MalformedURLException;
7   import java.net.URL;
8   import java.util.HashMap;
9   import java.util.List;
10  import java.util.Map;
11  
12  import org.dom4j.Node;
13  import org.telscenter.pas.beans.PasStep;
14  import org.telscenter.pas.steps.WobbleModule;
15  
16  import wise2.converter.AbstractStepConverter;
17  
18  /***
19   * @author turadg
20   */
21  public class UnsupportedConverter extends AbstractStepConverter {
22  
23  	/***
24  	 * @param list
25  	 * @return
26  	 */
27  	private static Map<String, String> nodeListToMap(List<Node> list) {
28  		Map<String, String> map = new HashMap<String, String>();
29  		for (Node entryNode : list) {
30  			String key = entryNode.getName();
31  			String value = entryNode.getText();
32  			map.put(key, value);
33  		}
34  		return map;
35  	}
36  
37  	@SuppressWarnings("unchecked")
38  	@Override
39  	public PasStep getTypedPasStep() {
40  		WobbleModule step = new WobbleModule();
41  
42  		Node urlNode = stepNode.selectSingleNode("./url");
43  		if (urlNode != null) {
44  			try {
45  				String relativeUrl = urlNode.getText();
46  				// FIXME set this to that of the server we're converting from
47  				String absoluteUrl = "http://wise.berkeley.edu" + relativeUrl;
48  				URL studentUrl = new URL(absoluteUrl);
49  				step.setUrl(studentUrl);
50  			} catch (MalformedURLException e) {
51  				// TODO Auto-generated catch block
52  				e.printStackTrace();
53  			}
54  		}
55  
56  		Node otherDataNode = stepNode.selectSingleNode("./otherData");
57  		if (otherDataNode != null) {
58  			String otherData = otherDataNode.getText();
59  			step.setModuleOtherData(otherData);
60  		}
61  
62  		Node otherNumberNode = stepNode.selectSingleNode("./otherNumber");
63  		if (otherNumberNode != null) {
64  			String otherNumberStr = otherNumberNode.getText();
65  			int otherNumber = Integer.parseInt(otherNumberStr);
66  			step.setModuleOtherNumber(otherNumber);
67  		}
68  
69  		return step;
70  	}
71  
72  	// FIXME hack, I'm making all UnsupportedConverions return the legacy
73  	// WobbleModule
74  	// TODO think more about how this should be done
75  	/*
76  	 * @SuppressWarnings("unchecked") @Override public PasStep getTypedPasStep() {
77  	 * UnsupportedConversion step = new UnsupportedConversion();
78  	 * 
79  	 * List<Node> list = stepNode.selectNodes("./*");
80  	 * step.setStepSettings(nodeListToMap(list));
81  	 * 
82  	 * list = stepNode.selectNodes("parameters/*");
83  	 * step.setStepParameters(nodeListToMap(list));
84  	 * 
85  	 * return step; }
86  	 * 
87  	 */
88  }