private Lineprops getLineProps(Element shape) { return new Lineprops( shape.hasAttribute(ATR_STROKE) ? Float.parseFloat(shape.getAttribute(ATR_STROKE)) : IMPLIED_STROKE, shape.hasAttribute(ATR_LINETYPE) ? Float.parseFloat(shape.getAttribute(ATR_LINETYPE)) : IMPLIED_LINE); }
public ServiceMap parse(Document document) { Map<String, String> map = new HashMap<String, String>(); Map<String, String> publicMap = new HashMap<String, String>(); NodeList servicesNodes = document.getElementsByTagName("service"); for (int i = 0; i < servicesNodes.getLength(); i++) { Element node = (Element) servicesNodes.item(i); if (node.hasAttribute("class") && node.hasAttribute("id")) { map.put(node.getAttribute("id"), "\\" + node.getAttribute("class")); } if (!(node.hasAttribute("public") && node.getAttribute("public").equals("false"))) { publicMap.put(node.getAttribute("id"), "\\" + node.getAttribute("class")); } } // Support services whose class isn't specified populateMapWithDefaultServices(map); populateMapWithDefaultServices(publicMap); return new ServiceMap(map, publicMap); }
private Color getColor(Element shape) { Color color; if (shape.hasAttribute(ATR_COLOUR)) { String s = shape.getAttribute(ATR_COLOUR); if (s.indexOf(',') > -1) { String[] rgb = s.split(","); color = new Color( Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2])); } else { color = new Color(Integer.parseInt(s)); } } else color = IMPLIED_COLOR; if (shape.hasAttribute(ATR_TRANSPARENCY)) { int alpha = Integer.parseInt(shape.getAttribute(ATR_TRANSPARENCY)); if (alpha < 255) return new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha); } return color; }
private void parsePort(PackageClass newClass, Element portNode) { String name = portNode.getAttribute(ATR_NAME); String type = portNode.getAttribute(ATR_TYPE); String x = portNode.getAttribute(ATR_X); String y = portNode.getAttribute(ATR_Y); String portConnection = portNode.getAttribute(ATR_PORT_CONNECTION); String strict = portNode.getAttribute(ATR_STRICT); String multi = portNode.getAttribute(ATR_MULTI); ClassField cf = newClass.getSpecField(name); if (newClass.getComponentType().hasSpec()) { if (name.indexOf(".") > -1) { // TODO - temporarily do not dig into hierarchy int idx = name.indexOf("."); String root = name.substring(0, idx); if (newClass.getSpecField(root) == null) { collector.collectDiagnostic( "Field " + root + " in class " + newClass.getName() + " is not declared in the specification, variable " + type + " " + name + " ignored "); return; } newClass.addSpecField(new ClassField(name, type)); } else if (!TypeUtil.TYPE_THIS.equalsIgnoreCase(name)) { if (cf == null) { collector.collectDiagnostic( "Port " + type + " " + name + " in class " + newClass.getName() + " does not have the corresponding field in the specification"); } else if (!cf.getType().equals(type) // type may be declared as "alias", however cf.getType() returns e.g. "double[]", ignore // it && !(cf.isAlias() && TypeUtil.TYPE_ALIAS.equals(type))) { collector.collectDiagnostic( "Port " + type + " " + name + " in class " + newClass.getName() + " does not match the field declared in the specification: " + cf.getType() + " " + cf.getName()); } } } Port newPort = new Port( name, type, Integer.parseInt(x), Integer.parseInt(y), portConnection, Boolean.parseBoolean(strict), Boolean.parseBoolean(multi)); if (portNode.hasAttribute(ATR_ID)) newPort.setId(portNode.getAttribute(ATR_ID)); Element gr; // open if ((gr = getElementByName(portNode, EL_OPEN)) != null && (gr = getElementByName(gr, EL_GRAPHICS)) != null) { newPort.setOpenGraphics(getGraphicsParser().parse(gr)); } // closed if ((gr = getElementByName(portNode, EL_CLOSED)) != null && (gr = getElementByName(gr, EL_GRAPHICS)) != null) { newPort.setClosedGraphics(getGraphicsParser().parse(gr)); } newClass.addPort(newPort); }
private void parseField(PackageClass newClass, Element fieldNode) { String name = fieldNode.getAttribute(ATR_NAME); String type = fieldNode.getAttribute(ATR_TYPE); ClassField newField; if (newClass.getComponentType().hasSpec()) { if (name.indexOf(".") > -1) { // TODO - temporarily do not dig into hierarchy int idx = name.indexOf("."); String root = name.substring(0, idx); if (newClass.getSpecField(root) == null) { collector.collectDiagnostic( "Field " + root + " in class " + newClass.getName() + " is not declared in the specification, variable " + type + " " + name + " ignored "); return; } newField = new ClassField(name, type); newClass.addSpecField(newField); } else { newField = newClass.getSpecField(name); if (newField == null) { collector.collectDiagnostic( "Field " + type + " " + name + " in class " + newClass.getName() + " is not declared in the specification"); return; } else if (!newField.getType().equals(type)) { collector.collectDiagnostic( "Field " + type + " " + name + " in class " + newClass.getName() + " does not match the field declared in the specification: " + newField.getType() + " " + newField.getName()); return; } } } else { newField = new ClassField(name, type); newClass.addSpecField(newField); } newField.setValue(fieldNode.hasAttribute(ATR_VALUE) ? fieldNode.getAttribute(ATR_VALUE) : null); newField.setDescription(fieldNode.getAttribute(ATR_DESCRIPTION)); newField.setHidden(Boolean.parseBoolean(fieldNode.getAttribute(ATR_HIDDEN))); String nature = fieldNode.getAttribute(ATR_NATURE); if ("input".equals(nature)) newField.setInput(true); else if ("goal".equals(nature)) newField.setGoal(true); newClass.addField(newField); Element gr; // known if ((gr = getElementByName(fieldNode, EL_KNOWN)) != null && (gr = getElementByName(gr, EL_GRAPHICS)) != null) { newField.setKnownGraphics(getGraphicsParser().parse(gr)); } // default if ((gr = getElementByName(fieldNode, EL_DEFAULT)) != null && (gr = getElementByName(gr, EL_GRAPHICS)) != null) { newField.setDefaultGraphics(getGraphicsParser().parse(gr)); } }
public ShowFileData loadShow(String s) { Vector<Pair> links = new Vector<Pair>(); /* ShowFileData show = new ShowFileData(); show.setSettings(new CameoSettings()); show.setPatch(new CameoPatch(0,0)); show.setCueList(new CueList(0)); show.setMagicSheet(new MagicSheet()); */ SettingsData settingsData = new SettingsData(); MagicSheetData magicSheetData = new MagicSheetData(); CueListData cueListData = new CueListData(); PatchData patchData = new PatchData(); Document doc; try { doc = _builder.parse(s); Element root = doc.getDocumentElement(); Element settings = getElement(root, _settings); Element patch = getElement(root, _patch); Element cues = getElement(root, _cues); Element magic = getElement(root, _magicSheet); // TODO test that all of these are non null and report incorrect file missing ... String recordMode = getElement(settings, _recordMode).getTextContent(); settingsData.put(_recordMode, recordMode); /* if(recordMode.equals(RecordMode.TRACKING.toString())) show._settings._mode = RecordMode.TRACKING; else if(recordMode.equals(RecordMode.CUE_ONLY.toString())) show._settings._mode = RecordMode.CUE_ONLY; */ settingsData.put(_totalChannels, getElement(settings, _totalChannels).getTextContent()); settingsData.put(_totalDimmers, getElement(settings, _totalDimmers).getTextContent()); settingsData.put(_dUpTime, getElement(settings, _dUpTime).getTextContent()); settingsData.put(_dDownTime, getElement(settings, _dDownTime).getTextContent()); settingsData.put(_gotoCueTime, getElement(settings, _gotoCueTime).getTextContent()); settingsData.put(_title, getElement(settings, _title).getTextContent()); settingsData.put(_comment, getElement(settings, _comment).getTextContent()); settingsData.put(_channelPerLine, getElement(settings, _channelPerLine).getTextContent()); settingsData.put(_channelHGroup, getElement(settings, _channelHGroup).getTextContent()); settingsData.put(_channelVGroup, getElement(settings, _channelVGroup).getTextContent()); /* show._settings._totalChannels = Integer.parseInt(getElement(settings, _totalChannels).getTextContent()); show._settings._totalDimmers = Integer.parseInt(getElement(settings, _totalDimmers).getTextContent()); show._settings._upTime = Integer.parseInt(getElement(settings, _dUpTime).getTextContent()); show._settings._downTime = Integer.parseInt(getElement(settings, _dDownTime).getTextContent()); show._settings._gotoCueTime = Integer.parseInt(getElement(settings, _gotoCueTime).getTextContent()); show._settings._showTitle = getElement(settings, _title).getTextContent(); show._settings._showComment = getElement(settings, _comment).getTextContent(); show._settings._ChannelsPerLine = Integer.parseInt(getElement(settings, _channelPerLine).getTextContent()); show._settings._ChannelGrouping = Integer.parseInt(getElement(settings, _channelHGroup).getTextContent()); show._settings._LineGrouping = Integer.parseInt(getElement(settings, _channelVGroup).getTextContent()); */ int totalChannels = Integer.parseInt(settingsData.get(_totalChannels)); patchData.setTotalChannels(totalChannels); patchData.setTotalDimmers(Integer.parseInt(settingsData.get(_totalDimmers))); cueListData.setTotalChannels(totalChannels); // show.setPatch(new CameoPatch(show._settings._totalChannels, show._settings._totalDimmers)); // show.setCueList(new CueList(show._settings._totalChannels)); NodeList list = patch.getElementsByTagName(_channel); for (int x = 0; x < list.getLength(); x++) { Element el = (Element) list.item(x); int number = Integer.parseInt(el.getAttribute(_number)); patchDims(patchData, number, el.getTextContent()); } list = cues.getElementsByTagName(_cue); for (int x = 0; x < list.getLength(); x++) { Element el = (Element) list.item(x); CueData cue = new CueData(); cue.setDescription(el.getAttribute(_discription)); NodeList list2 = el.getElementsByTagName(_channel); for (int y = 0; y < list2.getLength(); y++) { Element chan = (Element) list2.item(y); setLevel(cue, chan.getAttribute(_number), chan.getTextContent()); } int number = Integer.parseInt(el.getAttribute(_number)); int upTime = Integer.parseInt(el.getAttribute(_uptime)); int downTime = Integer.parseInt(el.getAttribute(_downTime)); int delayUpTime = Integer.parseInt(el.getAttribute(_upTimeDelay)); int delayDownTime = Integer.parseInt(el.getAttribute(_downTimeDelay)); FadeData fade = new FadeData(number, upTime, downTime, delayUpTime, delayDownTime, cue); if (el.hasAttribute(_followtime)) fade.setFollowTime(Integer.parseInt(el.getAttribute(_followtime))); if (el.hasAttribute(_nextCue)) fade.setNextCue(Integer.parseInt(el.getAttribute(_nextCue))); cueListData.add(fade); } // TODO this needs to be done in the extractor // for(Pair p : links) // show._cuelist.getCueNumbered(p._first).setNextCue(show._cuelist.getCueNumbered(p._second)); list = magic.getElementsByTagName(_channel); for (int x = 0; x < list.getLength(); x++) { Element el = (Element) list.item(x); // Element xval = getElement(el, _x); // Element yval = getElement(el, _y); Integer number = new Integer(Integer.parseInt(el.getAttribute(_number)) - 1); double xpos = Double.parseDouble(el.getAttribute(_x)); double ypos = Double.parseDouble(el.getAttribute(_y)); magicSheetData.put(number, new MagicChannelData(xpos, ypos)); } } catch (DOMException e) { System.err.println(e); } catch (SAXException e) { System.err.println(e); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog( new JFrame(""), "The show file " + s + " was not found, loading default show."); } catch (IOException e) { System.err.println(e); } return new ShowFileData(settingsData, cueListData, patchData, magicSheetData); }