Java Code Examples for org.dom4j.Element.attributes()

The following are Jave code examples for showing how to use attributes() of the org.dom4j.Element class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: iBase4J-Common   File: XmlUtil.java   View Source Code Vote up 6 votes
/**
 * Element to map
 * @param e
 * @param map
 */
public static void element2Map(Element e, Map<String, Object> map) {
    List<Object> list = e.elements();
    if (e.attributeCount() > 0) {
        for (Object attri : e.attributes()) {
            Attribute at = (Attribute)attri;
            map.put(at.getName(), at.getValue());
        }
    }
    if (list.size() < 1 && DataUtil.isEmpty(e.getText())) {
        return;
    } else if (list.size() < 1 && !DataUtil.isEmpty(e.getText())) {
        map.put("text", e.getText());
    }
    for (Object aList : list) {
        Element iter = (Element)aList;
        Map<String, Object> cMap = new HashMap<String, Object>();
        element2Map(iter, cMap);
        map.put(iter.getName(), cMap);
    }
}
 
Example 2
Project: automat   File: XmlUtil.java   View Source Code Vote up 6 votes
/**
 * Element to map
 * 
 * @param e
 * @return
 */
public static void element2Map(Element e, Map<String, Object> map) {
	List<Object> list = e.elements();
	if (e.attributeCount() > 0) {
		for (Object attri : e.attributes()) {
			Attribute at = (Attribute) attri;
			map.put(at.getName(), at.getValue());
		}
	}
	if (list.size() < 1 && DataUtil.isEmpty(e.getText())) {
		return;
	} else if (list.size() < 1 && !DataUtil.isEmpty(e.getText())) {
		map.put("text", e.getText());
	}
	for (Object aList : list) {
		Element iter = (Element) aList;
		Map<String, Object> cMap = new HashMap<String, Object>();
		element2Map(iter, cMap);
		map.put(iter.getName(), cMap);
	}
}
 
Example 3
Project: atlas   File: ManifestFileUtils.java   View Source Code Vote up 6 votes
/**
 * Update the plug-in's minSdkVersion and targetSdkVersion
 *
 * @param androidManifestFile
 * @throws IOException
 * @throws DocumentException
 */
public static String getVersionName(File androidManifestFile) throws IOException, DocumentException {
    SAXReader reader = new SAXReader();
    String versionName = "";
    if (androidManifestFile.exists()) {
        Document document = reader.read(androidManifestFile);// Read the XML file
        Element root = document.getRootElement();// Get the root node
        if ("manifest".equalsIgnoreCase(root.getName())) {
            List<Attribute> attributes = root.attributes();
            for (Attribute attr : attributes) {
                if (StringUtils.equalsIgnoreCase(attr.getName(), "versionName")) {
                    versionName = attr.getValue();
                }
            }
        }
    }
    return versionName;
}
 
Example 4
Project: atlas   File: ManifestFileUtils.java   View Source Code Vote up 6 votes
public static String getVersionCode(File androidManifestFile) throws IOException, DocumentException {
    SAXReader reader = new SAXReader();
    String versionCode = "";
    if (androidManifestFile.exists()) {
        Document document = reader.read(androidManifestFile);// Read the XML file
        Element root = document.getRootElement();// Get the root node
        if ("manifest".equalsIgnoreCase(root.getName())) {
            List<Attribute> attributes = root.attributes();
            for (Attribute attr : attributes) {
                if (StringUtils.equalsIgnoreCase(attr.getName(), "versionCode")) {
                    versionCode = attr.getValue();
                }
            }
        }
    }
    return versionCode;
}
 
Example 5
Project: iBase4J   File: XmlUtil.java   View Source Code Vote up 6 votes
/**
 * Element to map
 * 
 * @param e
 * @return
 */
public static void element2Map(Element e, Map<String, Object> map) {
	List<Object> list = e.elements();
	if (e.attributeCount() > 0) {
		for (Object attri : e.attributes()) {
			Attribute at = (Attribute) attri;
			map.put(at.getName(), at.getValue());
		}
	}
	if (list.size() < 1 && DataUtil.isEmpty(e.getText())) {
		return;
	} else if (list.size() < 1 && !DataUtil.isEmpty(e.getText())) {
		map.put("text", e.getText());
	}
	for (Object aList : list) {
		Element iter = (Element) aList;
		Map<String, Object> cMap = new HashMap<String, Object>();
		element2Map(iter, cMap);
		map.put(iter.getName(), cMap);
	}
}
 
Example 6
Project: JAVA-   File: XmlUtil.java   View Source Code Vote up 6 votes
/**
 * Element to map
 * 
 * @param e
 * @return
 */
public static void element2Map(Element e, Map<String, Object> map) {
	List<Object> list = e.elements();
	if (e.attributeCount() > 0) {
		for (Object attri : e.attributes()) {
			Attribute at = (Attribute) attri;
			map.put(at.getName(), at.getValue());
		}
	}
	if (list.size() < 1 && DataUtil.isEmpty(e.getText())) {
		return;
	} else if (list.size() < 1 && !DataUtil.isEmpty(e.getText())) {
		map.put("text", e.getText());
	}
	for (Object aList : list) {
		Element iter = (Element) aList;
		Map<String, Object> cMap = new HashMap<String, Object>();
		element2Map(iter, cMap);
		map.put(iter.getName(), cMap);
	}
}
 
Example 7
Project: gen_code   File: ConfigParser.java   View Source Code Vote up 5 votes
/**
 * 将指定节点的属性设置到对象里面
 * @param obj 对象
 * @param element 节点
 * @param tempflag 模板化标识
 * @return 返回结果
 */
public static <T> T fillObj(T obj, Element element,boolean tempflag){
    if(element!=null){
        List<Attribute> attributes = element.attributes();
        for(Attribute a:attributes){
            AnalysisObject.invokeSetter(obj,a.getName(),
                    tempflag?FreeMarkerUtil.render(a.getValue()):a.getValue());
        }
    }
    return obj;
}
 
Example 8
Project: gitplex-mit   File: JpaConverter.java   View Source Code Vote up 5 votes
private void marshallElement(HierarchicalStreamWriter writer, Element element) {
	writer.startNode(element.getName());
	for (Attribute attribute: (List<Attribute>)element.attributes())
		writer.addAttribute(attribute.getName(), attribute.getValue());
	if (element.getText().trim().length() != 0)
		writer.setValue(element.getText().trim());
	for (Element child: (List<Element>)element.elements())
		marshallElement(writer, child);
	writer.endNode();
}
 
Example 9
Project: GraphicsViewJambi   File: ImportSumoNetwork.java   View Source Code Vote up 5 votes
/**
 * Manage all Attribute in a Node
 * 
 * @param node
 * 		Node to Manage
 * @param subNode   
 *      Sub Node or not
 */
@SuppressWarnings("unchecked")
private void manageAttributeInfo(final Element node, final boolean subNode)
{
	final String startVorString =  (subNode == false) ? "! Start Node --  ": "! Start SubNode --  "; 
	final String startHinString =  (subNode == false) ? "  -- Start Node ! ": "  -- Start SubNode !"; 
	final String endVorString =  (subNode == false) ? "! End Node --  ": "! End SubNode --  "; 
	final String endHinString =  (subNode == false) ? "  -- End Node !": "  -- End SubNode !"; 
	
	System.out.println("! ----------------------------------------------- !");
	System.out.println(startVorString + node.getName() + startHinString);
	final List<Attribute> list = node.attributes();
	for (final Attribute attr : list)
	{
		//System.out.println(attr.getText() + "\n" );
		System.out.println("  = > " + attr.getName() + " = " + attr.getValue() + ";" );
		//Do something to match related information in Node
		
	}
 
	if (!(node.getTextTrim().equals("")))
	{
		System.out.println("Text: " + node.getText());
	}
	System.out.println(endVorString + node.getName() + endHinString);
	System.out.println("! ----------------------------------------------- !\n");
}
 
Example 10
Project: GraphicsViewJambi   File: ImportNetworkFromSUMO.java   View Source Code Vote up 5 votes
/**
 * Manage all Attribute in a Node
 * 
 * @param node
 * 		Node to Manage
 * @param subNode   
 *      Sub Node or not
 */
@SuppressWarnings("unchecked")
private void manageAttributeInfo(final Element node, final boolean subNode)
{
	final String startVorString =  (subNode == false) ? "! Start Node --  ": "! Start SubNode --  "; 
	final String startHinString =  (subNode == false) ? "  -- Start Node ! ": "  -- Start SubNode !"; 
	final String endVorString =  (subNode == false) ? "! End Node --  ": "! End SubNode --  "; 
	final String endHinString =  (subNode == false) ? "  -- End Node !": "  -- End SubNode !"; 
	
	System.out.println("! ----------------------------------------------- !");
	System.out.println(startVorString + node.getName() + startHinString);
	final List<Attribute> list = node.attributes();
	for (final Attribute attr : list)
	{
		//System.out.println(attr.getText() + "\n" );
		System.out.println("  = > " + attr.getName() + " = " + attr.getValue() + ";" );
		//Do something to match related information in Node
		
	}
 
	if (!(node.getTextTrim().equals("")))
	{
		System.out.println("Text: " + node.getText());
	}
	System.out.println(endVorString + node.getName() + endHinString);
	System.out.println("! ----------------------------------------------- !\n");
}
 
Example 11
Project: bdf2   File: AbstractConverter.java   View Source Code Vote up 5 votes
protected void buildCommonGraphCellElement(Element element,Element targetElement){
	for(Object obj:element.attributes()){
		Attribute attr=(Attribute)obj;
		String name=attr.getName();
		if(name.equals("name") || name.equals("g")){
			continue;
		}
		targetElement.addAttribute(attr.getName(),attr.getValue());
	}
}
 
Example 12
Project: GraphicsViewJambi   File: ImportLocalNetImplement.java   View Source Code Vote up 4 votes
/**
 * 添加外部连接到路网
 * @param extLinkList
 */
@SuppressWarnings("unchecked")
private void addExtLinkToNetwork(List<Element> extLinkList)
{
	final int extLinkListSize = extLinkList.size();
	System.out.println("ExtLink's count: " + extLinkListSize); 
	for(int i = 0; i<extLinkListSize; i++)
	{
		//Get a node from the node list
		Element element = extLinkList.get(i);
		
		List<Attribute> listExtLinkAttribute = element.attributes();
		String id = listExtLinkAttribute.get(0).getValue();
		//String fromJunction = listExtLinkAttribute.get(1).getValue();
		//String toJunction = listExtLinkAttribute.get(2).getValue();
		String numLanes = listExtLinkAttribute.get(3).getValue();
		String speed = listExtLinkAttribute.get(4).getValue();
		String length = listExtLinkAttribute.get(5).getValue();

		Vertex linkStartNodeVertex = null;	//连接的起点
		Vertex linkEndNodeVertex = null;  	//连接的终点
		
		List<Element> extConnectionList = element.selectNodes(LocalXmlAttributeMatch.EXTCONNECTION);
		//int numExtConnection = extConnectionList.size();	
		
		List<Attribute> listExtConnectionAttribute = extConnectionList.get(0).attributes();
		String fromNode = listExtConnectionAttribute.get(0).getValue();		//外部连接内部起点
		String from_x = listExtConnectionAttribute.get(1).getValue();  			//起点X坐标
		String from_y = listExtConnectionAttribute.get(2).getValue();  			//起点Y坐标
		String toNode = listExtConnectionAttribute.get(3).getValue();  		//外部连接内部终点
		String to_x = listExtConnectionAttribute.get(4).getValue();	   			//终点X坐标
		String to_y = listExtConnectionAttribute.get(5).getValue();    			//终点Y坐标
		String dir = listExtConnectionAttribute.get(6).getValue();	   				//转向信息

		linkStartNodeVertex = new Vertex(fromNode,"Internal",
				Double.parseDouble(from_x),
				Double.parseDouble(from_y));
		linkEndNodeVertex = new Vertex(toNode,"Internal",
				Double.parseDouble(to_x),
				Double.parseDouble(to_y));
		
		//添加外部连接到路网
		//-----------------------------------------------------------
		Link link = new Link(linkStartNodeVertex, linkEndNodeVertex);
		link.setDirection(dir);
		link.setName(id);
		link.setLaneCount(Integer.parseInt(numLanes));
		link.setLinkType("External");
		link.setSpeed(Double.parseDouble(speed));
		link.setLength(Double.parseDouble(length));
		
		network.addLink(link);
	}
}
 
Example 13
Project: GraphicsViewJambi   File: ImportNetworkFromLocal.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
private void addJunctionToNetwork(List<Element> junctionList)
{
	final int junctionListSize = junctionList.size();
	System.out.println("Junction's count: " + junctionListSize); 
	for(int i = 0; i<junctionListSize; i++)
	{
		Junction junction = null;
		//Get a Junction from the Junction List
		Element element = junctionList.get(i);
		
		List<Attribute> listJunctionAttribute = element.attributes();
		String id = listJunctionAttribute.get(0).getValue();
		String type = listJunctionAttribute.get(1).getValue();
		String x = listJunctionAttribute.get(2).getValue();
		String y = listJunctionAttribute.get(3).getValue();
		String intNode = listJunctionAttribute.get(4).getValue();
		
		junction = new Junction(id);//设置路口名
		junction.setType(type);     //设置路口类型
		junction.setX_Coordinate(Double.parseDouble(x));//设置路口X坐标
		junction.setY_Coordinate(Double.parseDouble(y));//设置路口Y坐标
		
		//添加内部节点到路口
		//---------------------------------------------------
		intNode = intNode.replace("[", "");
		intNode = intNode.replace("]", "");
		String[]intNodes = intNode.split(", ");
		for(int p=0; p<intNodes.length; p++)
		{
			String[] node = intNodes[p].split(" ");
			
			Vertex interNode = null;//内部连接的点
			interNode = new Vertex(node[0],"Internal",
									Double.parseDouble(node[1]),
									Double.parseDouble(node[2]));
			junction.addInternalNode(interNode);
		}

		//添加内部连接到路口
		//-----------------------------------------------------
		List<Element> intLinkList = element.selectNodes(LocalXmlAttributeMatch.INTCONNECTION);
		int numIntLink = intLinkList.size();	
		for(int j = 0; j<numIntLink; j++)
		{
			List<Attribute> listIntLinkAttribute = intLinkList.get(j).attributes();
			String intLinkID = listIntLinkAttribute.get(0).getValue();		//内部连接名
			String intLinkNumLanes = listIntLinkAttribute.get(1).getValue();//车道数
			String intLinkFrom = listIntLinkAttribute.get(2).getValue();	//起点
			String intLinkFromX = listIntLinkAttribute.get(3).getValue();	//起点X坐标
			String intLinkFromY = listIntLinkAttribute.get(4).getValue();	//起点Y坐标
			String intLinkTo = listIntLinkAttribute.get(5).getValue();		//终点
			String intLinkToX = listIntLinkAttribute.get(6).getValue();		//终点X坐标
			String intLinkToY = listIntLinkAttribute.get(7).getValue();		//终点Y坐标
			String dir = listIntLinkAttribute.get(8).getValue();			//转向信息
			
			Vertex interFromNode = null;//内部连接的点
			interFromNode = new Vertex(intLinkFrom,"Internal",
										Double.parseDouble(intLinkFromX),
										Double.parseDouble(intLinkFromY));
			Vertex interToNode = null;//内部连接的点
			interToNode = new Vertex(intLinkTo,"Internal",
									  Double.parseDouble(intLinkToX),
									  Double.parseDouble(intLinkToY));
			
			junction.addInternalEdge(interFromNode, interToNode);
			//添加内部连接到路口
			//---------------------------------------------------
			Link link = new Link(interFromNode,interToNode);
			link.setName(intLinkID);
			link.setLinkType("Internal");
			link.setLaneCount(Integer.parseInt(intLinkNumLanes));
			link.setDirection(dir);
			
			network.addLink(link);
		}	
		//添加路口到网络
		network.addJunction(junction);
	}
}
 
Example 14
Project: GraphicsViewJambi   File: ImportNetworkFromLocal.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
private void addExtLinkToNetwork(List<Element> extLinkList)
{
	final int extLinkListSize = extLinkList.size();
	System.out.println("ExtLink's count: " + extLinkListSize); 
	for(int i = 0; i<extLinkListSize; i++)
	{
		//Get a node from the node list
		Element element = extLinkList.get(i);
		
		List<Attribute> listExtLinkAttribute = element.attributes();
		String id = listExtLinkAttribute.get(0).getValue();
		//String fromJunction = listExtLinkAttribute.get(1).getValue();
		//String toJunction = listExtLinkAttribute.get(2).getValue();
		String numLanes = listExtLinkAttribute.get(3).getValue();
		String speed = listExtLinkAttribute.get(4).getValue();
		String length = listExtLinkAttribute.get(5).getValue();

		Vertex linkStartNodeVertex = null;//连接的起点
		Vertex linkEndNodeVertex = null;  //连接的终点
		
		List<Element> extConnectionList = element.selectNodes(LocalXmlAttributeMatch.EXTCONNECTION);
		//int numExtConnection = extConnectionList.size();	
		
		List<Attribute> listExtConnectionAttribute = extConnectionList.get(0).attributes();
		String fromNode = listExtConnectionAttribute.get(0).getValue();//外部连接内部起点
		String from_x = listExtConnectionAttribute.get(1).getValue();  //起点X坐标
		String from_y = listExtConnectionAttribute.get(2).getValue();  //起点Y坐标
		String toNode = listExtConnectionAttribute.get(3).getValue();  //外部连接内部终点
		String to_x = listExtConnectionAttribute.get(4).getValue();	   //终点X坐标
		String to_y = listExtConnectionAttribute.get(5).getValue();    //终点Y坐标
		String dir = listExtConnectionAttribute.get(6).getValue();	   //转向信息

		linkStartNodeVertex = new Vertex(fromNode,"Internal",
				Double.parseDouble(from_x),
				Double.parseDouble(from_y));
		linkEndNodeVertex = new Vertex(toNode,"Internal",
				Double.parseDouble(to_x),
				Double.parseDouble(to_y));
		
		//添加外部连接到路网
		//-----------------------------------------------------------
		Link link = new Link(linkStartNodeVertex, linkEndNodeVertex);
		link.setDirection(dir);
		link.setName(id);
		link.setLaneCount(Integer.parseInt(numLanes));
		link.setLinkType("External");
		link.setSpeed(Double.parseDouble(speed));
		link.setLength(Double.parseDouble(length));
		
		network.addLink(link);
	}
}
 
Example 15
Project: GraphicsViewJambi   File: ImportSumoNetwork.java   View Source Code Vote up 4 votes
/**
 * Analysis Information in a Node
 * 
 * @param matrix
 * 		Information will be stored in the Matrix
 * @param nodeToAnalysis
 * 		Node To Analysis
 * @param nodeList
 * 		Node List
 * @param matchAttributeList
 */
@SuppressWarnings("unchecked")
public void saveJunctionAttributeValues(Matrix matrix, 
										  final String nodeToAnalysis, 
										  final List<Element> nodeList, 
										  final List<String> matchAttributeList)
{
	final int nodeListSize = nodeList.size();
	
	System.out.println(nodeToAnalysis +" \'s count: " + nodeListSize); 
	for(int i = 0; i<nodeListSize; i++)
	{
		//Get a node from the node list
		final Element element = nodeList.get(i);
		
		//match attribute information
		//System.out.println("! ----------------------------------------------- !");
		//System.out.println("! Start Node --  " + element.getName() + "  -- Start Node !");
		
		final List<Attribute> listAttribute = element.attributes();
		Map<String, String> mapCurrently = new HashMap<String, String>();
		for (final Attribute attr : listAttribute)
		{
			//Save all Attribute and it's Value in a Key-Value Map
			mapCurrently.put(attr.getName(),attr.getValue());
		}
		
		if(nodeToAnalysis.equals(SumoXmlAttributeMatch.JUNCTION))
		{
			String matchAttribute = "";
			//Match all demanded Attributes		
			for(int j = 0; j<matchAttributeList.size(); j++)
			{
				matchAttribute = matchAttributeList.get(j);
				if(mapCurrently.containsKey(matchAttribute))
				{
					final String attributeValue = mapCurrently.get(matchAttribute);
					//System.out.println("  = > " + matchAttribute + " = " + attributeValue + ";" );
					matrix.setAsObject(attributeValue, i,j);
				}
			}
		}
		//System.out.println("! End Node --  " + element.getName() + "  -- End Node !");
		//System.out.println("! ----------------------------------------------- !\n");		
	}
}
 
Example 16
Project: GraphicsViewJambi   File: ImportSumoNetwork.java   View Source Code Vote up 4 votes
/**
 * Analysis Information in a Node
 * 
 * @param matrix
 * 		Information will be stored in the Matrix
 * @param nodeToAnalysis
 * 		Node To Analysis
 * @param nodeList
 * 		Node List
 * @param matchAttributeList
 */
@SuppressWarnings("unchecked")
public void saveEdgeAttributeValues(Matrix matrix, 
									  final String nodeToAnalysis, 
									  final List<Element> nodeList, 
									  final List<String> matchAttributeList)
{
	final int nodeListSize = nodeList.size();
	
	System.out.println(nodeToAnalysis +" \'s count: " + nodeListSize); 
	for(int i = 0; i<nodeListSize; i++)
	{
		//Get a node from the node list
		final Element element = nodeList.get(i);
		
		//match attribute information
		//System.out.println("! ----------------------------------------------- !");
		//System.out.println("! Start Node --  " + element.getName() + "  -- Start Node !");
		
		final List<Attribute> listAttribute = element.attributes();
		Map<String, String> mapCurrently = new HashMap<String, String>();
		for (final Attribute attr : listAttribute)
		{
			//Save all Attribute and it's Value in a Key-Value Map
			mapCurrently.put(attr.getName(),attr.getValue());
		}
		
		if(nodeToAnalysis.equals(SumoXmlAttributeMatch.EDGE))
		{
			//Sub Node
			String start_node = mapCurrently.get("from") + "@" + mapCurrently.get("id");
			String end_node = mapCurrently.get("to") + "@" + mapCurrently.get("id");
			double speed = 0, length = 0, start_x = 0, start_y = 0, end_x = 0, end_y = 0;

			final List<Element> subNodeList = element.selectNodes("lane");
			int numLanes = subNodeList.size();	
			for(int p = 0; p<numLanes; p++)
			{
				speed += Double.parseDouble(subNodeList.get(p).attribute("speed").getValue());
				length += Double.parseDouble(subNodeList.get(p).attribute("length").getValue());

				final String[] shape = subNodeList.get(p).attribute("shape").getValue().split(",| ");
				start_x += Double.parseDouble(shape[0]);
				start_y += Double.parseDouble(shape[1]);
				end_x += Double.parseDouble(shape[shape.length-2]);
				end_y += Double.parseDouble(shape[shape.length-1]);
			}
			speed /= numLanes;
			length /= numLanes;
			start_x /= numLanes;
			start_y /= numLanes;
			end_x /= numLanes;
			end_y /= numLanes;

			matrix.setAsObject(mapCurrently.get("id"), i,0);
			matrix.setAsObject(mapCurrently.get("from"), i,1);
			matrix.setAsObject(mapCurrently.get("to"), i,2);
			matrix.setAsObject(Integer.toString(numLanes), i,3);
			matrix.setAsObject(Double.toString(speed), i,4);
			matrix.setAsObject(Double.toString(length), i,5);
			matrix.setAsObject(start_node, i,6);
			matrix.setAsObject(Double.toString(start_x), i,7);
			matrix.setAsObject(Double.toString(start_y), i,8);
			matrix.setAsObject(end_node, i,9);
			matrix.setAsObject(Double.toString(end_x), i,10);
			matrix.setAsObject(Double.toString(end_y), i,11);
		}
		//System.out.println("! End Node --  " + element.getName() + "  -- End Node !");
		//System.out.println("! ----------------------------------------------- !\n");		
	}
}
 
Example 17
Project: GraphicsViewJambi   File: ImportSumoNetwork.java   View Source Code Vote up 4 votes
/**
 * Analysis Information in a Node
 * 
 * @param matrix
 * 		Information will be stored in the Matrix
 * @param nodeToAnalysis
 * 		Node To Analysis
 * @param nodeList
 * 		Node List
 * @param matchAttributeList
 */
@SuppressWarnings("unchecked")
public void saveConnectionAttributeValues(Matrix matrix, 
										  final String nodeToAnalysis, 
										  final List<Element> nodeList, 
										  final List<String> matchAttributeList)
{
	final int nodeListSize = nodeList.size();
	
	System.out.println(nodeToAnalysis +" \'s count: " + nodeListSize); 
	for(int i = 0; i<nodeListSize; i++)
	{
		//Get a node from the node list
		final Element element = nodeList.get(i);
		
		//match attribute information
		//System.out.println("! ----------------------------------------------- !");
		//System.out.println("! Start Node --  " + element.getName() + "  -- Start Node !");
		
		final List<Attribute> listAttribute = element.attributes();
		Map<String, String> mapCurrently = new HashMap<String, String>();
		for (final Attribute attr : listAttribute)
		{
			//Save all Attribute and it's Value in a Key-Value Map
			mapCurrently.put(attr.getName(),attr.getValue());
		}
		
		if(nodeToAnalysis.equals(SumoXmlAttributeMatch.CONNECTION))
		{
			String matchAttribute = "";
			//Match all demanded Attributes		
			for(int j = 0; j<matchAttributeList.size(); j++)
			{
				matchAttribute = matchAttributeList.get(j);
				if(mapCurrently.containsKey(matchAttribute))
				{
					final String attributeValue = mapCurrently.get(matchAttribute);
					//System.out.println("  = > " + matchAttribute + " = " + attributeValue + ";" );
					matrix.setAsObject(attributeValue, i,j);
				}
			}
		}
		//System.out.println("! End Node --  " + element.getName() + "  -- End Node !");
		//System.out.println("! ----------------------------------------------- !\n");		
	}
}
 
Example 18
Project: GraphicsViewJambi   File: ImportNetworkFromSUMO.java   View Source Code Vote up 4 votes
/**
 * Analysis Information in a Node
 * 
 * @param matrix
 * 		Information will be stored in the Matrix
 * @param nodeToAnalysis
 * 		Node To Analysis
 * @param nodeList
 * 		Node List
 * @param matchAttributeList
 */
@SuppressWarnings("unchecked")
public void saveJunctionAttributeValues(Matrix matrix, 
										  final String nodeToAnalysis, 
										  final List<Element> nodeList, 
										  final List<String> matchAttributeList)
{
	final int nodeListSize = nodeList.size();
	
	System.out.println(nodeToAnalysis +" \'s count: " + nodeListSize); 
	for(int i = 0; i<nodeListSize; i++)
	{
		//Get a node from the node list
		final Element element = nodeList.get(i);
		
		//match attribute information
		//System.out.println("! ----------------------------------------------- !");
		//System.out.println("! Start Node --  " + element.getName() + "  -- Start Node !");
		
		final List<Attribute> listAttribute = element.attributes();
		Map<String, String> mapCurrently = new HashMap<String, String>();
		for (final Attribute attr : listAttribute)
		{
			//Save all Attribute and it's Value in a Key-Value Map
			mapCurrently.put(attr.getName(),attr.getValue());
		}
		
		if(nodeToAnalysis.equals(SumoXmlAttributeMatch.JUNCTION))
		{
			String matchAttribute = "";
			//Match all demanded Attributes		
			for(int j = 0; j<matchAttributeList.size(); j++)
			{
				matchAttribute = matchAttributeList.get(j);
				if(mapCurrently.containsKey(matchAttribute))
				{
					final String attributeValue = mapCurrently.get(matchAttribute);
					//System.out.println("  = > " + matchAttribute + " = " + attributeValue + ";" );
					matrix.setAsObject(attributeValue, i,j);
				}
			}
		}
		//System.out.println("! End Node --  " + element.getName() + "  -- End Node !");
		//System.out.println("! ----------------------------------------------- !\n");		
	}
}
 
Example 19
Project: GraphicsViewJambi   File: ImportNetworkFromSUMO.java   View Source Code Vote up 4 votes
/**
 * Analysis Information in a Node
 * 
 * @param matrix
 * 		Information will be stored in the Matrix
 * @param nodeToAnalysis
 * 		Node To Analysis
 * @param nodeList
 * 		Node List
 * @param matchAttributeList
 */
@SuppressWarnings("unchecked")
public void saveEdgeAttributeValues(Matrix matrix, 
									  final String nodeToAnalysis, 
									  final List<Element> nodeList, 
									  final List<String> matchAttributeList)
{
	final int nodeListSize = nodeList.size();
	
	System.out.println(nodeToAnalysis +" \'s count: " + nodeListSize); 
	for(int i = 0; i<nodeListSize; i++)
	{
		//Get a node from the node list
		final Element element = nodeList.get(i);
		
		//match attribute information
		//System.out.println("! ----------------------------------------------- !");
		//System.out.println("! Start Node --  " + element.getName() + "  -- Start Node !");
		
		final List<Attribute> listAttribute = element.attributes();
		Map<String, String> mapCurrently = new HashMap<String, String>();
		for (final Attribute attr : listAttribute)
		{
			//Save all Attribute and it's Value in a Key-Value Map
			mapCurrently.put(attr.getName(),attr.getValue());
		}
		
		if(nodeToAnalysis.equals(SumoXmlAttributeMatch.EDGE))
		{
			//Sub Node
			String start_node = mapCurrently.get("from") + "@" + mapCurrently.get("id");
			String end_node = mapCurrently.get("to") + "@" + mapCurrently.get("id");
			double speed = 0, length = 0, start_x = 0, start_y = 0, end_x = 0, end_y = 0;

			final List<Element> subNodeList = element.selectNodes("lane");
			int numLanes = subNodeList.size();	
			for(int p = 0; p<numLanes; p++)
			{
				speed += Double.parseDouble(subNodeList.get(p).attribute("speed").getValue());
				length += Double.parseDouble(subNodeList.get(p).attribute("length").getValue());

				final String[] shape = subNodeList.get(p).attribute("shape").getValue().split(",| ");
				start_x += Double.parseDouble(shape[0]);
				start_y += Double.parseDouble(shape[1]);
				end_x += Double.parseDouble(shape[shape.length-2]);
				end_y += Double.parseDouble(shape[shape.length-1]);
			}
			speed /= numLanes;
			length /= numLanes;
			start_x /= numLanes;
			start_y /= numLanes;
			end_x /= numLanes;
			end_y /= numLanes;

			matrix.setAsObject(mapCurrently.get("id"), i,0);
			matrix.setAsObject(mapCurrently.get("from"), i,1);
			matrix.setAsObject(mapCurrently.get("to"), i,2);
			matrix.setAsObject(Integer.toString(numLanes), i,3);
			matrix.setAsObject(Double.toString(speed), i,4);
			matrix.setAsObject(Double.toString(length), i,5);
			matrix.setAsObject(start_node, i,6);
			matrix.setAsObject(Double.toString(start_x), i,7);
			matrix.setAsObject(Double.toString(start_y), i,8);
			matrix.setAsObject(end_node, i,9);
			matrix.setAsObject(Double.toString(end_x), i,10);
			matrix.setAsObject(Double.toString(end_y), i,11);
		}
		//System.out.println("! End Node --  " + element.getName() + "  -- End Node !");
		//System.out.println("! ----------------------------------------------- !\n");		
	}
}
 
Example 20
Project: GraphicsViewJambi   File: ImportNetworkFromSUMO.java   View Source Code Vote up 4 votes
/**
 * Analysis Information in a Node
 * 
 * @param matrix
 * 		Information will be stored in the Matrix
 * @param nodeToAnalysis
 * 		Node To Analysis
 * @param nodeList
 * 		Node List
 * @param matchAttributeList
 */
@SuppressWarnings("unchecked")
public void saveConnectionAttributeValues(Matrix matrix, 
										  final String nodeToAnalysis, 
										  final List<Element> nodeList, 
										  final List<String> matchAttributeList)
{
	final int nodeListSize = nodeList.size();
	
	System.out.println(nodeToAnalysis +" \'s count: " + nodeListSize); 
	for(int i = 0; i<nodeListSize; i++)
	{
		//Get a node from the node list
		final Element element = nodeList.get(i);
		
		//match attribute information
		//System.out.println("! ----------------------------------------------- !");
		//System.out.println("! Start Node --  " + element.getName() + "  -- Start Node !");
		
		final List<Attribute> listAttribute = element.attributes();
		Map<String, String> mapCurrently = new HashMap<String, String>();
		for (final Attribute attr : listAttribute)
		{
			//Save all Attribute and it's Value in a Key-Value Map
			mapCurrently.put(attr.getName(),attr.getValue());
		}
		
		if(nodeToAnalysis.equals(SumoXmlAttributeMatch.CONNECTION))
		{
			String matchAttribute = "";
			//Match all demanded Attributes		
			for(int j = 0; j<matchAttributeList.size(); j++)
			{
				matchAttribute = matchAttributeList.get(j);
				if(mapCurrently.containsKey(matchAttribute))
				{
					final String attributeValue = mapCurrently.get(matchAttribute);
					//System.out.println("  = > " + matchAttribute + " = " + attributeValue + ";" );
					matrix.setAsObject(attributeValue, i,j);
				}
			}
		}
		//System.out.println("! End Node --  " + element.getName() + "  -- End Node !");
		//System.out.println("! ----------------------------------------------- !\n");		
	}
}