Search in sources :

Example 76 with NodeList

use of org.w3c.dom.NodeList in project cogtool by cogtool.

the class BalsamiqButtonAPIConverter method checkWidgetGroupType.

//TODO: check if the widgets align best horizontally or vertically
//align the widgets to average coord, first, left or rightmost
//prohibit the dimensions at the api level
/** Helper function used by parseWidget
	 * This method is used to verify that all widgets in a group are of the same type
     * 
     * @param  groupXMLNode the node that represents a group
     */
public WidgetType checkWidgetGroupType(Node groupXMLNode) {
    NodeList children = groupXMLNode.getChildNodes();
    String balsamiqGroupControlType = null;
    for (int j = 0; j < children.getLength(); j++) {
        Node child = children.item(j);
        String nodeName = child.getNodeName();
        String balsamiqControlType = getAttributeValue(child, CONTROL_TYPE_ATTR);
        /*double x =
				Double.parseDouble(getAttributeValue(child, X_ATTR));
			double y =
				Double.parseDouble(getAttributeValue(child, Y_ATTR));*/
        System.out.println("713 - WidgetGroupType- nodeName " + nodeName + " " + balsamiqControlType);
        if (balsamiqGroupControlType != null && balsamiqControlType != null && !balsamiqGroupControlType.equals(balsamiqControlType)) {
            return null;
        } else if (balsamiqControlType != null) {
            balsamiqGroupControlType = balsamiqControlType;
        }
    /*if(j==0){
				initialX = x;
				initialY = y;
			}
			else
			{
				if(x != initialX){
					xCoordAlign = false;
				}
				if(y != initialY){
					yCoordAlign = false;
				}
			}*/
    }
    String widgetTypeString = (balsamiqGroupControlType == null) ? null : getBMMLWidgetType(balsamiqGroupControlType);
    System.out.println("724 " + widgetTypeString);
    /*if(xCoordAlign || yCoordAlign)
		{*/
    return getWidgetType(widgetTypeString);
/*}
		else
		{
			return null;
		}*/
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node)

Example 77 with NodeList

use of org.w3c.dom.NodeList in project cogtool by cogtool.

the class BalsamiqButtonAPIConverter method parseBMMLGroup.

// parseBMMLWidget
//TODO: probably need to give the group dimensions
/** Helper function used by parseFrame
	 * This method is used to parse the tags of each control tag in Balsamiq XML. A control tag
	 * represents a Balsamiq Group.
     * 
     * @param  node a node of the tree that represents a Balsamiq widget
     * @frame  frame that the widget is being added to
     * @group  parent group
     * @groupX x coordinate of parent group
     * @groupY y coordinate of parent group
     * @return      new group containing widgets
     */
public void parseBMMLGroup(Node groupXMLtag, Frame frame, SimpleWidgetGroup parentGroup, double initX, double initY) {
    SimpleWidgetGroup widgetGrp = null;
    NodeList groupSubtags = groupXMLtag.getChildNodes();
    String grpName = getAttributeValue(groupXMLtag, CONTROL_ID_ATTR);
    double x = Double.parseDouble(getAttributeValue(groupXMLtag, X_ATTR));
    double y = Double.parseDouble(getAttributeValue(groupXMLtag, Y_ATTR));
    x += initX;
    y += initY;
    if (grpName == null) {
    //TODO: report to the user
    }
    System.out.println("587-GROUP " + grpName);
    if ((grpName != null) && !"".equals(grpName)) {
        widgetGrp = groupRegistry.get(grpName);
        for (int i = 0; i < groupSubtags.getLength(); i++) {
            Node groupSubtag = groupSubtags.item(i);
            String groupSubtagName = groupSubtag.getNodeName();
            System.out.println("598-nodeName1 " + groupSubtagName);
            /*Whitespace in the DOM tree is represented as #text. Ignore these nodes*/
            if (!groupSubtagName.equals("#text")) {
                if (groupSubtagName.equalsIgnoreCase("groupChildrenDescriptors")) {
                    System.out.println("605-groupchildrendescriptors");
                    WidgetType groupType = checkWidgetGroupType(groupSubtag);
                    if (groupType != null) {
                        System.out.println("630-groupwidgetType " + groupType.getName());
                    } else {
                        System.out.println("groupwidgetType is null");
                    }
                    NodeList children2 = groupSubtag.getChildNodes();
                    for (int j = 0; j < children2.getLength(); j++) {
                        Node child3 = children2.item(j);
                        String nodeName3 = child3.getNodeName();
                        System.out.println("657- nodeName3 " + nodeName3 + " j is " + j + " length " + children2.getLength());
                        if (nodeName3.equalsIgnoreCase(CONTROL_ELT)) {
                            System.out.println("660-This is a control!");
                            Widget widget2 = null;
                            if (widgetGrp == null) {
                                if (groupType == WidgetType.Radio) {
                                    widgetGrp = new RadioButtonGroup();
                                } else if (groupType == WidgetType.Check) {
                                    System.out.println("654-grouptype is a check");
                                    widgetGrp = new GridButtonGroup();
                                } else {
                                    widgetGrp = new SimpleWidgetGroup(1);
                                }
                                widgetGrp.setName(grpName);
                                groupRegistry.put(grpName, widgetGrp);
                            }
                            try {
                                String balsamiqControlType = getAttributeValue(child3, CONTROL_TYPE_ATTR);
                                String widgetTypeString = (balsamiqControlType == null) ? null : getBMMLWidgetType(balsamiqControlType);
                                System.out.println("663-widgetTypeString " + widgetTypeString);
                                if (widgetTypeString.equals("group")) {
                                    System.out.println("682-calling bmmlgroup");
                                    parseBMMLGroup(child3, frame, widgetGrp, x, y);
                                }
                                widget2 = parseBMMLWidget(child3, frame, widgetGrp, x, y);
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            int widgetCount = widgetGrp.elementCount();
                            System.out.println("692- WIDGET COUNT for " + grpName + ": " + widgetCount + " " + widget2.getName());
                            if (widget2 != null) {
                                //TODO: check widget does not need to be added here
                                //widgetGrp.addElement(widget2);
                                widget2.setParentGroup(widgetGrp);
                                //frame.addEltGroup(gridWidgetGrp);
                                frame.addWidget(widget2);
                                widgetLoader.set(widget2, Widget.widgetTypeVAR, widget2.getWidgetType());
                            //AShape widgetShape = widget2.getShapeType();
                            //if (widgetShape != null) {
                            // widgetLoader.set(widget2, Widget.shapeVAR, widgetShape);
                            // }
                            }
                            System.out.println("696-widget2 added");
                        }
                    }
                }
            }
        }
    }
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Widget(edu.cmu.cs.hcii.cogtool.model.Widget) RadioButtonGroup(edu.cmu.cs.hcii.cogtool.model.RadioButtonGroup) IOException(java.io.IOException) WidgetType(edu.cmu.cs.hcii.cogtool.model.WidgetType) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 78 with NodeList

use of org.w3c.dom.NodeList in project cogtool by cogtool.

the class BalsamiqButtonAPIConverter method parseFrame.

/** Helper function used by importDesign.
	 * This method is used to parse the tags of each .bmml file and assign the
	 * attributes of the frame to the frame object
     * 
     * @param  document the root of the XML tree
     * @param  fileName the specified directory or file
     * @return              the newly created frame
     */
protected Frame parseFrame(Node document, String fileName) throws IOException {
    // This adds the created frame to the design
    Frame frame = getFrame(fileName);
    if (frame == null) {
        throw new RcvrImportException("Null Frame.");
    }
    //addAttributes(frame, node);
    Frame.setFrameDevices(frame, design.getDeviceTypes());
    NodeList children = document.getChildNodes();
    double frameWidth = 0;
    double frameHeight = 0;
    if (children != null) {
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeName().equalsIgnoreCase(MOCKUP_ELT)) {
                frameWidth = Integer.parseInt(getAttributeValue(child, MEASURED_WIDTH_ATTR));
                frameHeight = Integer.parseInt(getAttributeValue(child, MEASURED_HEIGHT_ATTR));
            }
        }
    }
    //TODO: if it doesnt import anything, a new frame window should still be imported?
    parseWidgets(document, frame);
    return frame;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) RcvrImportException(edu.cmu.cs.hcii.cogtool.util.RcvrImportException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node)

Example 79 with NodeList

use of org.w3c.dom.NodeList in project cw-omnibus by commonsguy.

the class WeatherFragment method buildForecasts.

private ArrayList<Forecast> buildForecasts(String raw) throws Exception {
    ArrayList<Forecast> forecasts = new ArrayList<Forecast>();
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.parse(new InputSource(new StringReader(raw)));
    NodeList times = doc.getElementsByTagName("start-valid-time");
    for (int i = 0; i < times.getLength(); i++) {
        Element time = (Element) times.item(i);
        Forecast forecast = new Forecast();
        forecasts.add(forecast);
        forecast.setTime(time.getFirstChild().getNodeValue());
    }
    NodeList temps = doc.getElementsByTagName("value");
    for (int i = 0; i < temps.getLength(); i++) {
        Element temp = (Element) temps.item(i);
        Forecast forecast = forecasts.get(i);
        forecast.setTemp(Integer.valueOf(temp.getFirstChild().getNodeValue()));
    }
    NodeList icons = doc.getElementsByTagName("icon-link");
    for (int i = 0; i < icons.getLength(); i++) {
        Element icon = (Element) icons.item(i);
        Forecast forecast = forecasts.get(i);
        forecast.setIcon(icon.getFirstChild().getNodeValue());
    }
    return (forecasts);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) Document(org.w3c.dom.Document)

Example 80 with NodeList

use of org.w3c.dom.NodeList in project cw-android by commonsguy.

the class StaticFileDemo method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    selection = (TextView) findViewById(R.id.selection);
    try {
        InputStream in = getResources().openRawResource(R.raw.words);
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(in, null);
        NodeList words = doc.getElementsByTagName("word");
        for (int i = 0; i < words.getLength(); i++) {
            items.add(((Element) words.item(i)).getAttribute("value"));
        }
        in.close();
    } catch (Throwable t) {
        Toast.makeText(this, "Exception: " + t.toString(), Toast.LENGTH_LONG).show();
    }
    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items));
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Aggregations

NodeList (org.w3c.dom.NodeList)1806 Node (org.w3c.dom.Node)1059 Element (org.w3c.dom.Element)902 Document (org.w3c.dom.Document)636 ArrayList (java.util.ArrayList)314 DocumentBuilder (javax.xml.parsers.DocumentBuilder)268 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)208 IOException (java.io.IOException)183 NamedNodeMap (org.w3c.dom.NamedNodeMap)144 InputSource (org.xml.sax.InputSource)131 HashMap (java.util.HashMap)121 Test (org.junit.Test)117 SAXException (org.xml.sax.SAXException)117 StringReader (java.io.StringReader)106 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)100 XPath (javax.xml.xpath.XPath)99 Attr (org.w3c.dom.Attr)80 XPathExpressionException (javax.xml.xpath.XPathExpressionException)76 File (java.io.File)64 HashSet (java.util.HashSet)59