List of usage examples for org.jdom2 Element getName
public String getName()
From source file:diuf.diva.dia.ms.script.command.AbstractCommand.java
License:Open Source License
/** * This method return the text contained into the tag. Example <a>hello</a> returns "hello". * Note that this applies also if the element 'e' has children. * * @param e the element from which we want to read * @return the text value contained into the element *//* ww w . j a v a 2 s. co m*/ public String readElement(Element e) { String result = e.getText(); if (result == null) { throw new Error(tagName() + ": Element " + e.getName() + " has no content."); } return script.preprocess(result); }
From source file:diuf.diva.dia.ms.script.command.AbstractCommand.java
License:Open Source License
/** * Return the content of the specified child of the parent element passed. It makes use of * readElement(Element e)./*from ww w.java2 s.co m*/ * @param parent the parent element whose child will be read * @param child the specific child that must be read * @return the text content of the tag */ public String readElement(Element parent, String child) { Element c = parent.getChild(child); if (c == null) { throw new Error(tagName() + ": Cannot find the element <" + child + "> in <" + parent.getName() + ">"); } return readElement(c); }
From source file:diuf.diva.dia.ms.script.command.CreateStackedAE.java
License:Open Source License
@Override public String execute(Element element) throws Exception { String id = readId(element);/*from ww w . ja v a2 s. c o m*/ /* If the <fromClassifier> tag is present, skip * */ if (element.getChild("fromClassifier") != null) { script.scae.put(id, convertFromClassifier(getAE(id), readElement(element, "fromClassifier"))); return ""; } Element unitEl = element.getChild("unit"); if (unitEl == null) { error("require unit tag"); } if (unitEl.getChildren().size() != 1) { error("unit requires one child tag"); } unitEl = unitEl.getChildren().get(0); String type = unitEl.getName(); if (type == null) { error("unit requires a type"); } SCAE scae = getAE(id); int inputDepth = (scae == null) ? script.colorspace.depth : scae.getOutputDepth(); AutoEncoder unit = null; int width = Integer.parseInt(readElement(element, "width")); int height = Integer.parseInt(readElement(element, "height")); int ox = Integer.parseInt(readElement(element, "offset-x")); int oy = Integer.parseInt(readElement(element, "offset-y")); if (type.equalsIgnoreCase("STANDARD")) { // Parse the 'dimensions' text int hidden = Integer.parseInt(readElement(unitEl, "hidden")); // Parse the 'layer' text String encoderClassName = null; String decoderClassName = null; if (unitEl.getChild("layer") != null) { encoderClassName = readElement(unitEl, "layer"); decoderClassName = encoderClassName; } else { encoderClassName = readElement(unitEl, "encoder"); decoderClassName = readElement(unitEl, "decoder"); } // Create the unit with specified parameters unit = new StandardAutoEncoder(width, height, inputDepth, hidden, encoderClassName, decoderClassName); } if (type.equalsIgnoreCase("MAX-POOLER")) { unit = new MaxPooler(width, height, inputDepth); } if (type.equalsIgnoreCase("BasicBBRBM")) { int hidden = Integer.parseInt(readElement(unitEl, "hidden")); unit = new BBRBMUnit(width, height, inputDepth, hidden); } if (type.equalsIgnoreCase("BasicGBRBM")) { int hidden = Integer.parseInt(readElement(unitEl, "hidden")); unit = new GBRBMUnit(width, height, inputDepth, hidden); } if (type.equalsIgnoreCase("PCA")) { // Parse the 'dimensions' text String s = readElement(unitEl, "dimensions"); int dim; if (s.equalsIgnoreCase("FULL")) { // With 'FULL' we keep all dimensions dim = width * height * inputDepth; } else { // We keep the specified number of dimensions dim = Integer.parseInt(readElement(unitEl, "dimensions")); } // Parse the 'layer' text String layerClassName = readElement(unitEl, "layer"); // Create the unit with specified parameters unit = new PCAAutoEncoder(width, height, inputDepth, dim, layerClassName); } if (type.equalsIgnoreCase("LDA")) { // Parse the 'dimensions' text int dim = Integer.parseInt(readElement(unitEl, "dimensions")); // Parse the 'layer' text String layerClassName = readElement(unitEl, "layer"); // Create the unit with specified parameters unit = new LDAAutoEncoder(width, height, inputDepth, dim, layerClassName); } if (type.equalsIgnoreCase("KMeans")) { error("KMeans unit no longer supported after refactor"); } if (unit == null) { error("unknown unit type: " + type); } scae = process(scae, unit, ox, oy); script.scae.put(id, scae); return ""; }
From source file:diuf.diva.dia.ms.script.XMLScript.java
License:Open Source License
/** * Runs the script./*ww w .ja va 2 s . c o m*/ * @return the output of the last command * @throws Exception in unfortunately too many cases */ public String execute() throws Exception { String res = ""; for (Element e : root.getChildren()) { String name = e.getName(); AbstractCommand cmd = commands.get(name); if (cmd == null) { throw new Error("Cannot find command " + name); } String cmdRes = cmd.execute(e); if (res.equals("") || !cmdRes.equals("")) { res = cmdRes; } definitions.put("$ANS", String.valueOf(res)); } return res; }
From source file:docubricks.data.Brick.java
public static Brick fromXML(File basepath, DocubricksProject proj, Element root) { Brick u = new Brick(); u.id = root.getAttributeValue("id"); u.name = root.getChildText("name"); u.vabstract = root.getChildText("abstract"); u.longdesc = root.getChildText("long_description"); u.notes = root.getChildText("notes"); u.license = root.getChildText("license"); for (Element child : root.getChildren()) if (child.getName().equals("author")) { String id = child.getAttributeValue("id"); u.authors.add(proj.getAuthor(id)); }/* www .ja va 2 s . c om*/ for (Element child : root.getChildren()) if (child.getName().equals("logical_part") || child.getName().equals("function")) u.functions.add(Function.fromXML(basepath, proj, child)); for (Element child : root.getChildren()) if (child.getName().equals("instruction")) { StepByStepInstruction i = StepByStepInstruction.fromXML(u, basepath, child); i.name = child.getAttributeValue("name"); u.instructions.add(i); } u.asmInstruction = StepByStepInstruction.fromXML(u, basepath, root.getChild("assembly_instruction")); u.media = MediaSet.fromXML(basepath, root.getChild("media")); return u; }
From source file:edu.kit.iks.CryptographicsLib.Configuration.java
License:MIT License
/** * Parses the values of the configuration XML. * @param child the current child element *///from w ww . j a v a 2 s .c om private void parseConfigElement(Element child) { String value = child.getValue(); String name = child.getName(); switch (name) { case "idleTimeout": this.idleTimeout = Integer.parseInt(value); break; case "resetTimeout": this.resetTimeout = Integer.parseInt(value); break; case "debugMode": this.debugMode = Boolean.parseBoolean(value); break; case "fullscreenMode": this.fullscreenMode = Boolean.parseBoolean(value); break; case "lookAndFeel": this.lookAndFeel = Boolean.parseBoolean(value); break; case "mouseCursor": this.mouseCursor = Boolean.parseBoolean(value); break; case "languageCode": this.languageCode = value; break; default: // Do not use the logger here since this happens very early // and the logger might not be configured yet. System.out.println("Unknown configuration element " + child.getName() + ". Skipping."); break; } }
From source file:edu.ucla.loni.server.ServerUtils.java
License:Open Source License
/** * Parses a .pipe into a Pipefile// w w w .j av a 2 s. c o m */ public static Pipefile parseXML(Document doc) { try { Pipefile pipe = new Pipefile(); Element main = getMainElement(doc); String mainName = main.getName(); if (mainName.equals("dataModule")) { pipe.type = "Data"; } else if (mainName.equals("module")) { pipe.type = "Modules"; } else if (mainName.equals("moduleGroup")) { pipe.type = "Groups"; } else { throw new Exception("Pipefile has unknown type"); } // General Properties pipe.name = main.getAttributeValue("name", ""); pipe.packageName = main.getAttributeValue("package", ""); pipe.description = main.getAttributeValue("description", ""); pipe.tags = getChildrenText(main, "tag", ","); // Get type specific properties if (pipe.type.equals("Data")) { Element values = main.getChild("values"); if (values != null) { pipe.values = getChildrenText(values, "value", "\n"); } Element output = main.getChild("output"); if (output != null) { Element format = output.getChild("format"); if (format != null) { pipe.formatType = format.getAttributeValue("type"); } } } if (pipe.type.equals("Modules")) { pipe.location = main.getAttributeValue("location", ""); } if (pipe.type.equals("Modules") || pipe.type.equals("Groups")) { pipe.uri = main.getChildText("uri"); } return pipe; } catch (Exception e) { return null; } }
From source file:edu.ucsd.crbs.cws.workflow.WorkflowFromAnnotatedVersionTwoFourMomlXmlFactory.java
License:Open Source License
private List<ParameterAttribute> getParameterAttributes(Document doc) throws Exception { XPathExpression<Element> xpath = XPathFactory.instance().compile(MOML_CANVAS_PARAMETER, Filters.element()); List<Element> elements = xpath.evaluate(doc); ArrayList<ParameterAttribute> parameters = new ArrayList<>(); for (Element e : elements) { ParameterAttribute pa = new ParameterAttribute(); pa.setName(e.getAttributeValue(NAME_ATTRIBUTE)); pa.setType(e.getAttributeValue(CLASS)); pa.setValue(e.getAttributeValue(VALUE_ATTRIBUTE)); List<Element> children = e.getChildren(); for (Element child : children) { if (child.getName().equals(DISPLAY_ELEMENT)) { pa.setDisplayName(child.getAttributeValue(NAME_ATTRIBUTE)); } else if (child.getAttributeValue(NAME_ATTRIBUTE).equalsIgnoreCase(LOCATION_ATTRIBUTE)) { pa.setCoordinatesViaString(child.getAttributeValue(VALUE_ATTRIBUTE)); }//from w w w.j a v a2s . c o m } if (pa.getDisplayName() == null) { pa.setDisplayName(pa.getName()); } parameters.add(pa); } return parameters; }
From source file:edu.ucsd.crbs.cws.workflow.WorkflowFromAnnotatedVersionTwoFourMomlXmlFactory.java
License:Open Source License
private List<RectangleAttribute> getRectangleAttributes(Document doc) throws Exception { XPathExpression<Element> xpath = XPathFactory.instance().compile(MOML_RECTANGLE_ATTRIBUTE, Filters.element());/* w w w .j a v a 2 s .c om*/ List<Element> elements = xpath.evaluate(doc); ArrayList<RectangleAttribute> rectangles = new ArrayList<>(); for (Element e : elements) { RectangleAttribute ra = new RectangleAttribute(); boolean centered = false; ra.setName(e.getAttributeValue(NAME_ATTRIBUTE)); List<Element> children = e.getChildren(); for (Element child : children) { if (child.getName().equals(DISPLAY_ELEMENT)) { ra.setDisplayName(child.getAttributeValue(NAME_ATTRIBUTE)); } else if (child.getAttributeValue(NAME_ATTRIBUTE).equalsIgnoreCase(WIDTH)) { ra.setWidth(Double.parseDouble(child.getAttributeValue(VALUE_ATTRIBUTE))); } else if (child.getAttributeValue(NAME_ATTRIBUTE).equalsIgnoreCase(HEIGHT)) { ra.setHeight(Double.parseDouble(child.getAttributeValue(VALUE_ATTRIBUTE))); } else if (child.getAttributeValue(NAME_ATTRIBUTE).equalsIgnoreCase(LOCATION_ATTRIBUTE)) { ra.setCoordinatesViaString(child.getAttributeValue(VALUE_ATTRIBUTE)); } else if (child.getAttributeValue(NAME_ATTRIBUTE).equalsIgnoreCase(CENTERED_ATTRIBUTE)) { centered = Boolean.parseBoolean(child.getAttributeValue(VALUE_ATTRIBUTE)); } } if (ra.getDisplayName() == null) { ra.setDisplayName(ra.getName()); } //if centered we need to adjust x and y coordinate to be upper left corner if (centered == true) { ra.moveCoordinatesToUpperLeftCornerFromCenter(); } rectangles.add(ra); } return rectangles; }
From source file:egovframework.rte.fdl.xml.AbstractXMLUtility.java
License:Apache License
/** * TextNode //from w w w .j a v a2 s . c om * * @param element - ? Element * @param addNDName - ? Element * @param list - TextElement */ public void addTextNode(Element element, String addNDName, List<?> list) { List<?> childList = element.getChildren(); if (childList.size() != 0) { for (int yy = 0; yy < childList.size(); yy++) { Element tmp = (Element) childList.get(yy); if (tmp.getName().equals(addNDName)) { for (int tt = 0; tt < list.size(); tt++) { SharedObject sobj = (SharedObject) list.get(tt); tmp.addContent((String) sobj.getValue()); } } addTextNode(tmp, addNDName, list); } } else { if (element.getName().equals(addNDName)) { for (int tt = 0; tt < list.size(); tt++) { SharedObject sobj = (SharedObject) list.get(tt); element.addContent((String) sobj.getValue()); } } } }