List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:net.unicon.mercury.fac.email.POP3StoreAccount.java
License:Open Source License
public void parse(Element e) throws MercuryException { Attribute t = e.attribute("apop"); if (t != null) setApop("true".equalsIgnoreCase(t.getValue())); }
From source file:net.unicon.mercury.fac.email.SMTPTransportAccount.java
License:Open Source License
public void parse(Element e) throws MercuryException { super.parse(e); Attribute t = e.attribute("quitwait"); if (t != null) { setQuitWait("true".equalsIgnoreCase(t.getValue())); }// w w w. j a va2s .c o m t = e.attribute("ehlo"); if (t != null) { setEhlo("true".equalsIgnoreCase(t.getValue())); } }
From source file:net.unicon.mercury.fac.rdbms.RdbmsMessageRecipient.java
License:Open Source License
public static IRecipient parse(Element e) throws MercuryException { IRecipientType type;//from w w w . j a va 2 s .com IAddress address; // Assertions. if (e == null) { String msg = "Argument 'e [Element]' cannot be null."; throw new IllegalArgumentException(msg); } if (!e.getName().equals("recipient")) { String msg = "Argument 'e [Element]' must be a <recipient> " + "element."; throw new IllegalArgumentException(msg); } // Type attribute. Attribute t = e.attribute("type"); if (t == null) { String msg = "Element <recipient> is missing required " + "attribute 'type'"; throw new XmlFormatException(msg); } type = RdbmsRecipientType.getType(t.getValue()); // Address. List list = e.elements("address"); if (list.size() != 1) { String msg = "Exactly one <address> element required per " + "recipient."; throw new XmlFormatException(msg); } address = AddressImpl.parse(((Element) list.get(0))); return new RdbmsMessageRecipient(address, type, false); }
From source file:net.unicon.toro.installer.tools.MergeConfiguration.java
License:Open Source License
private void mergeChanges(Element targetFileElement) throws Exception { File path = new File(target, targetFileElement.attribute("path").getText()); String absolutePath = path.getAbsolutePath(); if (absolutePath.endsWith("WEB-INF/web.xml")) { mergeWebChanges(targetFileElement, path); } else if (absolutePath.endsWith(".xml") || absolutePath.endsWith(".xsl")) { mergeXmlChanges(targetFileElement, path); } else if (absolutePath.endsWith(".properties")) { mergePropertiesChanges(targetFileElement, path); } else {//w w w . j a v a2 s . c o m throw new RuntimeException("Unsupported configuration file type: " + path + ". Only '.properties', '.xsl' and '.xml' files are supported."); } }
From source file:net.unicon.warlock.fac.SimpleNavigateAction.java
License:Open Source License
public static IAction parse(Element e, IWarlockFactory owner) throws WarlockException { // Assertions. if (e == null) { String msg = "Argument 'e [Element]' cannot be null."; throw new IllegalArgumentException(msg); }/* ww w .j a v a 2 s . co m*/ if (!e.getName().equals("action")) { String msg = "Argument 'e [Element]' must be an <action> element."; throw new IllegalArgumentException(msg); } if (owner == null) { String msg = "Argument 'owner+' cannot be null."; throw new IllegalArgumentException(msg); } // Handle. Attribute h = e.attribute("handle"); if (h == null) { String msg = "Element <action> is missing required attribute " + "'handle'."; throw new XmlFormatException(msg); } Handle handle = Handle.create(h.getValue()); // Choices. String[] choices = new String[0]; Attribute p = e.attribute("inpt"); if (p != null) { StringTokenizer tokens = new StringTokenizer(p.getValue(), ","); choices = new String[tokens.countTokens()]; for (int i = 0; tokens.hasMoreTokens(); i++) { choices[i] = tokens.nextToken(); } } // ToScreen. Attribute s = e.attribute("to-screen"); if (s == null) { String msg = "Element <action> is missing required attribute " + "'to-screen'."; throw new XmlFormatException(msg); } String toScreen = s.getValue(); // Query. String sqXml = "<state />"; // default... Element state = (Element) e.selectSingleNode("state"); if (state != null) { sqXml = state.asXML(); } IStateQuery query = new StateQueryImpl(sqXml); return new SimpleNavigateAction(owner, handle, choices, toScreen, query); }
From source file:net.unicon.warlock.fac.xml.XmlWarlockFactory.java
License:Open Source License
public IScreen parseScreen(Element e, Element[] reference) throws WarlockException { // Assertions. if (e == null) { String msg = "Argument 'e [Element]' cannot be null."; throw new IllegalArgumentException(msg); }//from w w w .jav a 2 s . c om if (reference == null) { String msg = "Argument 'reference' cannot be null."; throw new IllegalArgumentException(msg); } // Resolve the References. List ref = e.selectNodes("//include"); Iterator it = ref.iterator(); while (it.hasNext()) { Element incl = (Element) it.next(); // Read the library handle. Attribute h = incl.attribute("handle"); if (h == null) { String msg = "Element <include> is missing required attribute " + "'handle'."; throw new XmlFormatException(msg); } String handle = h.getValue(); // Read the xpath expression. Attribute x = incl.attribute("xpath"); if (x == null) { String msg = "Element <include> is missing required attribute " + "'xpath'."; throw new XmlFormatException(msg); } String xpath = x.getValue(); // Find the relevent library. Element lib = null; for (int i = 0; i < reference.length; i++) { if (reference[i].valueOf("@handle").equals(handle)) { lib = reference[i]; break; } } if (lib == null) { String msg = "Unable to locate the specified reference " + "library: " + handle; throw new WarlockException(msg); } // Replace the node(s). org.w3c.dom.Element dIncl = DOMNodeHelper.asDOMElement(incl); Iterator targets = lib.selectNodes(xpath).iterator(); while (targets.hasNext()) { Element elm = (Element) targets.next(); org.w3c.dom.Element dElm = DOMNodeHelper.asDOMElement(elm); org.w3c.dom.Element dImp = (org.w3c.dom.Element) dIncl.getOwnerDocument().importNode(dElm, true); dIncl.getParentNode().insertBefore(dImp, dIncl); } dIncl.getParentNode().removeChild(dIncl); } return AbstractWarlockFactory.ScreenImpl.parse(e, this); }
From source file:net.windward.Acquire.Framework.java
License:BEER-WARE LICENSE
public final void IncomingMessage(String message) throws DocumentException, IOException { try {/* www .java 2 s .co m*/ long startTime = System.currentTimeMillis(); // get the xml - we assume we always get a valid message from the server. SAXReader reader = new SAXReader(); Document xml = reader.read(new StringReader(message)); String rootName = xml.getRootElement().getName(); if (rootName.equals("setup")) { System.out.println("Received setup message"); if (log.isInfoEnabled()) log.info("Recieved setup message"); myGuid = xml.getRootElement().attribute("my-guid").getValue(); Element elemMap = xml.getRootElement().element("map"); GameMap map = new GameMap(Integer.parseInt(elemMap.attribute("width").getValue()), Integer.parseInt(elemMap.attribute("height").getValue())); DataObjects dataSetup = xmlToData(xml); brain.Setup(map, dataSetup.me, dataSetup.hotels, dataSetup.players); // say ready Document docSetup = DocumentHelper.createDocument(); Element elem = DocumentHelper.createElement("ready"); docSetup.add(elem); tcpClient.SendMessage(docSetup.asXML()); } else if (rootName.equals("query-card")) { DataObjects dataQuery = xmlToData(xml); int card = brain.QuerySpecialPowerBeforeTurn(dataQuery.map, dataQuery.me, dataQuery.hotels, dataQuery.players); // send the selected card back Document docQueryCard = DocumentHelper.createDocument(); Element elem = DocumentHelper.createElement("reply"); docQueryCard.add(elem); elem.add(DocumentHelper.createAttribute(elem, "cmd", "query-card")); elem.add(DocumentHelper.createAttribute(elem, "msg-id", xml.getRootElement().attribute("msg-id").getValue())); elem.add(DocumentHelper.createAttribute(elem, "card", "" + card)); tcpClient.SendMessage(docQueryCard.asXML()); } else if (rootName.equals("query-tile")) { DataObjects dataQueryTile = xmlToData(xml); PlayerPlayTile playTile = brain.QueryTileOnly(dataQueryTile.map, dataQueryTile.me, dataQueryTile.hotels, dataQueryTile.players); // send the selected tile back Document docQueryCard = DocumentHelper.createDocument(); Element elem = DocumentHelper.createElement("reply"); docQueryCard.add(elem); elem.add(DocumentHelper.createAttribute(elem, "cmd", "query-tile")); elem.add(DocumentHelper.createAttribute(elem, "msg-id", xml.getRootElement().attribute("msg-id").getValue())); if (playTile != null) { if (playTile.tile != null) { elem.add(DocumentHelper.createAttribute(elem, "tile-x", "" + playTile.tile.getX())); elem.add(DocumentHelper.createAttribute(elem, "tile-y", "" + playTile.tile.getY())); } if (playTile.createdHotel != null) { elem.add(DocumentHelper.createAttribute(elem, "created-hotel", playTile.createdHotel.getName())); } if (playTile.mergeSurvivor != null) { elem.add(DocumentHelper.createAttribute(elem, "merge-survivor", playTile.mergeSurvivor.getName())); } } tcpClient.SendMessage(docQueryCard.asXML()); } else if (rootName.equals("query-tile-purchase")) { DataObjects dataQueryTilePur = xmlToData(xml); PlayerTurn playTurn = brain.QueryTileAndPurchase(dataQueryTilePur.map, dataQueryTilePur.me, dataQueryTilePur.hotels, dataQueryTilePur.players); // send the selected card back Document docQueryCard = DocumentHelper.createDocument(); Element elem = DocumentHelper.createElement("reply"); docQueryCard.add(elem); elem.add(DocumentHelper.createAttribute(elem, "cmd", "query-tile-purchase")); elem.add(DocumentHelper.createAttribute(elem, "msg-id", xml.getRootElement().attribute("msg-id").getValue())); if (playTurn != null) { elem.add(DocumentHelper.createAttribute(elem, "card", "" + playTurn.getCard())); if (playTurn.tile != null) { elem.add(DocumentHelper.createAttribute(elem, "tile-x", "" + playTurn.tile.getX())); elem.add(DocumentHelper.createAttribute(elem, "tile-y", "" + playTurn.tile.getY())); } if (playTurn.createdHotel != null) { elem.add(DocumentHelper.createAttribute(elem, "created-hotel", playTurn.createdHotel.getName())); } if (playTurn.mergeSurvivor != null) { elem.add(DocumentHelper.createAttribute(elem, "merge-survivor", playTurn.mergeSurvivor.getName())); } if (playTurn.getBuy() != null && playTurn.getBuy().size() > 0) { StringBuilder buyStock = new StringBuilder(); for (HotelStock stock : playTurn.getBuy()) buyStock.append(stock.getChain().getName() + ':' + stock.getNumShares() + ';'); elem.add(DocumentHelper.createAttribute(elem, "buy", buyStock.toString())); } if (playTurn.getTrade() != null && playTurn.getTrade().size() > 0) { StringBuilder tradeStock = new StringBuilder(); for (PlayerTurn.TradeStock trade : playTurn.getTrade()) tradeStock .append(trade.getTradeIn2().getName() + ':' + trade.getGet1().getName() + ';'); elem.add(DocumentHelper.createAttribute(elem, "trade", tradeStock.toString())); } } tcpClient.SendMessage(docQueryCard.asXML()); } else if (rootName.equals("query-merge")) { DataObjects dataQueryMerge = xmlToData(xml); HotelChain survivor = null; for (HotelChain hotel : dataQueryMerge.hotels) if (hotel.getName().equals(xml.getRootElement().attribute("survivor").getValue())) { survivor = hotel; break; } HotelChain defunct = null; for (HotelChain hotel : dataQueryMerge.hotels) if (hotel.getName().equals(xml.getRootElement().attribute("defunct").getValue())) { defunct = hotel; break; } PlayerMerge merge = brain.QueryMergeStock(dataQueryMerge.map, dataQueryMerge.me, dataQueryMerge.hotels, dataQueryMerge.players, survivor, defunct); // send the selected card back Document docQueryMerge = DocumentHelper.createDocument(); Element elem = DocumentHelper.createElement("reply"); docQueryMerge.add(elem); elem.add(DocumentHelper.createAttribute(elem, "cmd", "query-card")); elem.add(DocumentHelper.createAttribute(elem, "msg-id", xml.getRootElement().attribute("msg-id").getValue())); if (merge != null) { elem.add(DocumentHelper.createAttribute(elem, "keep", "" + merge.getKeep())); elem.add(DocumentHelper.createAttribute(elem, "sell", "" + merge.getSell())); elem.add(DocumentHelper.createAttribute(elem, "trade", "" + merge.getTrade())); } tcpClient.SendMessage(docQueryMerge.asXML()); } else if (xml.getRootElement().getName().equals("exit")) { System.out.println("Received exit message"); if (log.isInfoEnabled()) { log.info("Received exit message"); } System.exit(0); } else { String msg = String.format("ERROR: bad message (XML) from server - root node %1$s", xml.getRootElement().getName()); log.warn(msg); //Trace.WriteLine(msg); } long turnTime = System.currentTimeMillis() - startTime; if (turnTime > 800) { System.out.println("WARNING - turn took " + turnTime / 1000 + " seconds"); } } catch (RuntimeException ex) { System.out.println(String.format("Error on incoming message. Exception: %1$s", ex)); ex.printStackTrace(); log.error("Error on incoming message.", ex); } }
From source file:net.windward.Acquire.Units.GameMap.java
License:BEER-WARE LICENSE
public static GameMap fromXml(Element elemMap, ArrayList<HotelChain> hotels) { GameMap map = new GameMap(Integer.parseInt(elemMap.attribute("width").getValue()), Integer.parseInt(elemMap.attribute("height").getValue())); int x = 0;/*from ww w.j av a 2 s . co m*/ for (Object elem : elemMap.elements("column")) { Element elemColOn = (Element) elem; StringTokenizer tokRows = new StringTokenizer(elemColOn.getStringValue(), ";"); int y = 0; while (tokRows.hasMoreElements()) { String strTile = tokRows.nextToken(); StringTokenizer tokParts = new StringTokenizer(strTile, ":"); int type = Integer.parseInt(tokParts.nextToken()); if (!tokParts.hasMoreElements()) map.tiles[x][y] = new MapTile(type); else { String hotelName = tokParts.nextToken(); HotelChain hotel = null; for (HotelChain h : hotels) if (h.getName().equals(hotelName)) { hotel = h; break; } map.tiles[x][y] = new MapTile(type, hotel); } y++; } x++; } return map; }
From source file:net.windward.Acquire.Units.HotelChain.java
License:BEER-WARE LICENSE
public static ArrayList<HotelChain> fromXml(Element elemHotels) { ArrayList<HotelChain> hotels = new ArrayList<HotelChain>(); for (Object elemOn : elemHotels.elements("hotel")) { Element elemHotelOn = (Element) elemOn; HotelChain hotel = new HotelChain(); hotel.name = elemHotelOn.attribute("name").getValue(); hotel.startPrice = Integer.parseInt(elemHotelOn.attribute("start-price").getValue()); hotel.numTiles = Integer.parseInt(elemHotelOn.attribute("num-tiles").getValue()); hotel.isActive = elemHotelOn.attribute("is-active").getValue().toLowerCase().equals("true"); hotel.isSafe = elemHotelOn.attribute("is-safe").getValue().toLowerCase().equals("true"); hotel.stockPrice = Integer.parseInt(elemHotelOn.attribute("stock-price").getValue()); hotel.firstMajorityBonus = Integer.parseInt(elemHotelOn.attribute("first-majority").getValue()); hotel.secondMajorityBonus = Integer.parseInt(elemHotelOn.attribute("second-majority").getValue()); hotel.numAvailableShares = Integer.parseInt(elemHotelOn.attribute("num-avail-shares").getValue()); hotels.add(hotel);//from w w w. j a v a 2 s . co m } // can't do owners yet. Need players return hotels; }