List of usage examples for org.dom4j Attribute getValue
String getValue();
From source file:net.unicon.mercury.fac.email.EmailRecipient.java
License:Open Source License
/** * Parse a recipient from an XML fragment. * @param e The XML fragment to parse.//from www. j a va2 s. c o m * @return The resultant recipient object. * @throws MercuryException if the parsing fails */ public static IRecipient parse(Element e) throws MercuryException { IRecipientType type; IAddress address; assert e != null : "Argument 'e [Element]' cannot be null."; 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 = EmailRecipientType.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 EmailRecipient(address, type); }
From source file:net.unicon.mercury.fac.email.JavaMailAccount.java
License:Open Source License
/** * Configure the account based on an XML fragment. * @param e Element representing the top node of the XML fragment. *//*from w w w. ja va2 s . co m*/ public void parse(Element e) throws MercuryException { Element e2 = (Element) e.selectSingleNode("host"); if (e2 == null) throw new XmlFormatException("Element <host> required."); setHostname(e2.getText()); e2 = (Element) e.selectSingleNode("port"); if (e2 != null) setPort(Integer.parseInt(e2.getText())); e2 = (Element) e.selectSingleNode("username"); if (e2 != null) setUsername(e2.getText()); e2 = (Element) e.selectSingleNode("password"); if (e2 != null) setPassword(e2.getText()); Attribute t = e.attribute("timeout"); if (t != null) setTimeout(Integer.parseInt(t.getValue())); }
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())); }/*from ww w. j av a 2 s . c om*/ 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 v a 2 s.c om 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.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); }//from w ww . j a v a 2s .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); }/* w ww . j ava 2 s .com*/ 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.Windwardopolis2.api.MapSquare.java
License:BEER-WARE LICENSE
public MapSquare(Element elemTile) { setType(TYPE.valueOf(elemTile.attributeValue("type"))); if (getIsDriveable()) { setDirection(DIRECTION.valueOf(elemTile.attributeValue("direction"))); Attribute attr = elemTile.attribute("stop-sign"); String test = elemTile.attributeValue("stop-sign"); if (test != null) setStopSigns(parseSTOPs(test)); attr = elemTile.attribute("signal"); setSignal(attr != null && attr.getValue().toLowerCase().equals("true")); }//www . j a v a2 s .c om }
From source file:net.windward.Windwardopolis2.Framework.java
License:BEER-WARE LICENSE
public final void IncomingMessage(String message) throws DocumentException { try {/*ww w . ja va 2 s . c o 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"); java.util.ArrayList<Player> players = Player.FromXml(xml.getRootElement().element("players")); java.util.ArrayList<Company> companies = Company.FromXml(xml.getRootElement().element("companies")); java.util.ArrayList<CoffeeStore> stores = CoffeeStore .FromXml(xml.getRootElement().element("stores")); java.util.ArrayList<Passenger> passengers = Passenger .FromXml(xml.getRootElement().element("passengers"), companies); java.util.ArrayList<PowerUp> powerups = PowerUp.FromXml(xml.getRootElement().element("powerups"), companies, passengers); Map map = new Map(xml.getRootElement().element("map"), companies); myGuid = xml.getRootElement().attribute("my-guid").getValue(); Player me2 = null; for (Player plyr : players) { if (myGuid.equals(plyr.getGuid())) me2 = plyr; } brain.Setup(map, me2, players, companies, stores, passengers, powerups, new PlayerAIBase.PlayerOrdersEvent() { public void invoke(String order, ArrayList<Point> path, ArrayList<Passenger> pickUp) { PlayerOrdersEvent(order, path, pickUp); } }, new PlayerAIBase.PlayerCardEvent() { public void invoke(PlayerAIBase.CARD_ACTION action, PowerUp powerup) { PlayerPowerSend(action, powerup); } }); } else if (rootName.equals("powerup-status")) { // may be here because re-started and got this message before the re-send of setup. if (myGuid == null || myGuid.length() == 0) return; synchronized (this) { // bad news - we're throwing this message away. if (signal > 0) return; signal++; } try { // get what was played PlayerAIBase.STATUS puStatus = PlayerAIBase.STATUS .valueOf(xml.getRootElement().attribute("status").getValue()); String puGuid = xml.getRootElement().attribute("played-by") != null ? xml.getRootElement().attribute("played-by").getValue() : myGuid; Player plyrPowerUp = null; for (Player plyr : brain.getPlayers()) { if (puGuid.equals(plyr.getGuid())) plyrPowerUp = plyr; } PowerUp cardPlayed = PowerUp.GenerateFlyweight(xml.getRootElement().element("card"), brain.getCompanies(), brain.getPassengers(), brain.getPlayers()); if (log.isInfoEnabled()) log.info(plyrPowerUp.getName() + " " + puStatus + " on " + cardPlayed); // do we update the card deck? if (cardPlayed.equals(cardLastPlayed) || (System.currentTimeMillis() - cardLastSendTime) > 1000) { // move any not in deck to hand UpdateCards(xml.getRootElement().element("cards-deck").elements("card"), brain.getPowerUpDeck(), brain.getPowerUpHand()); // delete any not in drawn UpdateCards(xml.getRootElement().element("cards-hand").elements("card"), brain.getPowerUpHand(), null); } // pass in to play cards. brain.PowerupStatus(puStatus, plyrPowerUp, cardPlayed); } finally { synchronized (this) { signal--; } } } else if (rootName.equals("status")) { // may be here because re-started and got this message before the re-send of setup. if (net.windward.Windwardopolis2.DotNetToJavaStringHelper.isNullOrEmpty(myGuid)) { return; } synchronized (this) { if (signal > 0) { // bad news - we're throwing this message away. TRAP.trap(); return; } signal++; } try { PlayerAIBase.STATUS status = PlayerAIBase.STATUS .valueOf(xml.getRootElement().attribute("status").getValue()); Attribute attr = xml.getRootElement().attribute("player-guid"); String guid = attr != null ? attr.getValue() : myGuid; Player.UpdateFromXml(brain.getCompanies(), brain.getPlayers(), brain.getPassengers(), xml.getRootElement().element("players")); Passenger.UpdateFromXml(brain.getCompanies(), brain.getPlayers(), brain.getPassengers(), xml.getRootElement().element("passengers")); // update my path & pick-up. Player plyrStatus = null; for (Player plyr : brain.getPlayers()) { if (guid.equals(plyr.getGuid())) plyrStatus = plyr; } Element elem = xml.getRootElement().element("path"); if (elem != null) { String[] path = elem.getText().split(";", 0); plyrStatus.getLimo().getPath().clear(); for (String stepOn : path) { int pos = stepOn.indexOf(','); if (pos > 0) plyrStatus.getLimo().getPath() .add(new Point(Integer.parseInt(stepOn.substring(0, pos)), Integer.parseInt(stepOn.substring(pos + 1)))); } } elem = xml.getRootElement().element("pick-up"); if (elem != null) { String[] names = elem.getText().split(";", 0); plyrStatus.getPickUp().clear(); ArrayList<Passenger> newPsngrList = new ArrayList<Passenger>(); for (String name : names) { for (Passenger ps : brain.getPassengers()) { if (ps.getName().equals(name)) { newPsngrList.add(ps); } } } for (Passenger psngrOn : newPsngrList) { plyrStatus.getPickUp().add(psngrOn); } } // pass in to generate new orders brain.GameStatus(status, plyrStatus); } finally { synchronized (this) { signal--; } } } 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 { TRAP.trap(); 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.yrom.builder.util.ManifestParser.java
License:Apache License
public void newVersionInfo(int versionCode, String versionName) { Attribute code = manifest.attribute(qVersionCode); if (versionCode != 0 && Integer.parseInt(code.getValue()) != versionCode) code.setValue(String.valueOf(versionCode)); if (versionName != null && versionName.trim().length() > 0) manifest.attribute(qVersionName).setValue(versionName); }