List of usage examples for org.dom4j Attribute getValue
String getValue();
From source file:com.lowagie.rups.view.itext.treenodes.XdpTreeNode.java
License:Open Source License
public String toString() { Node node = getNode();//w ww . j av a2s . c o m if (node instanceof Element) { Element e = (Element) node; return e.getName(); } if (node instanceof Attribute) { Attribute a = (Attribute) node; StringBuffer buf = new StringBuffer(); buf.append(a.getName()); buf.append("=\""); buf.append(a.getValue()); buf.append('"'); return buf.toString(); } if (node instanceof Text) { Text t = (Text) node; return t.getText(); } if (node instanceof ProcessingInstruction) { ProcessingInstruction pi = (ProcessingInstruction) node; StringBuffer buf = new StringBuffer("<?"); buf.append(pi.getName()); buf.append(' '); buf.append(pi.getText()); buf.append("?>"); return buf.toString(); } if (node instanceof Document) { return "XFA Document"; } return getNode().toString(); }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.context.GeoEventDispatcher.java
License:Apache License
static Message buildGeoMessageFromPubSubIQ(final IQ geoIQ) { Message geoMessage = null;//from w w w. ja va 2 s.c o m if (IQ.Type.set == geoIQ.getType() && geoIQ.getTo().toString().startsWith("pubsub")) { // find 'geoloc' Element element = geoIQ.getChildElement(); Element action = element.element("publish"); if (action != null) { String nodeID = action.attributeValue("node"); if (nodeID != null && nodeID.endsWith(TopicHelper.TOPIC_GEOLOC)) { // Entity publishes an item geoMessage = new Message(); geoMessage.setType(Message.Type.chat); Map<String, String> geoValues = new HashMap<String, String>(); JID from = geoIQ.getFrom(); String appId = JIDUtil.getAppId(from); geoValues.put(APP_ID, appId); String userId = JIDUtil.getUserId(from); geoValues.put(USER_ID, userId); String deviceId = JIDUtil.getResource(from.toString()); geoValues.put(DEVICE_ID, deviceId); Iterator<Element> items = action.elementIterator("item"); if (items != null) { while (items.hasNext()) { Element item = (Element) items.next(); Element mmx = item.element(Constants.MMX_ELEMENT); if (mmx == null) continue; Element payload = mmx.element(Constants.MMX_PAYLOAD); if (payload == null) return null; // not a valid MMX payload, ignore it Attribute timestamp = payload.attribute(Constants.MMX_ATTR_STAMP); if (timestamp != null) { geoValues.put(Constants.MMX_ATTR_STAMP, timestamp.getValue()); } String geoData = payload.getTextTrim(); GeoLoc geoLoc = GsonData.getGson().fromJson(geoData, GeoLoc.class); if (geoLoc.getAccuracy() != null) { geoValues.put(ACCURACY, geoLoc.getAccuracy().toString()); } if (geoLoc.getLng() != null && geoLoc.getLat() != null) { geoValues.put(LONG, geoLoc.getLng().toString()); geoValues.put(LAT, geoLoc.getLat().toString()); // calculate geohash GeoPoint point = new GeoPointDefaultImpl(geoLoc.getLat(), geoLoc.getLng()); geoValues.put(GEOHASH, localGeoEndocoder.get().encodePoint(point)); } if (geoLoc.getAlt() != null) { geoValues.put(ALTITUDE, Integer.toString((int) geoLoc.getAlt().floatValue())); } Element geoElement = geoMessage.addChildElement(Constants.MMX_ELEMENT, Constants.MMX_NS_CONTEXT); geoElement.addAttribute(Constants.MMX_ATTR_MTYPE, Constants.MMX_MTYPE_GEOLOC); JSONObject geoJson = new JSONObject(geoValues); geoElement.setText(geoJson.toString()); geoMessage.setBody(geoJson.toString()); return geoMessage; } } } } } return null; }
From source file:com.metaware.guihili.builder.Builder.java
License:Open Source License
/** * We override this method to permit undeclared attribute definitions * if we're in "tom" mode. The old guihili treats all attributes * as environment assignments.// w w w .j a v a2 s. co m */ @Override protected void unknownAttribute(Element e, IBinding b, Attribute a) throws SAXException { // legacy=1 is inserted implicitly by guihili parser. if (a.getName().equals("legacy") && a.getValue().equals("1")) { setLegacy(true); return; } if (mTomStyle) { newEnvironment(); _gui.getEnvironment().putSymbolValue(a.getName(), a.getValue()); } else super.unknownAttribute(e, b, a); }
From source file:com.metaware.guihili.builder.legacy.CallBuilder.java
License:Open Source License
@Override public void unknownAttribute(Element e, IBinding binding, Attribute a) throws SAXException { try {/*from w w w . jav a 2 s. co m*/ mEnv.putSymbolValue(a.getName(), _gui.getEvaluator().parseAction(a.getValue())); } catch (Exception x) { error(e, x.getMessage(), x); } }
From source file:com.metaware.guihili.builder.legacy.SetBuilder.java
License:Open Source License
@Override protected void unknownAttribute(Element e, IBinding b, Attribute a) throws SAXException { _gui.getEnvironment().putSymbolValue(a.getName(), a.getValue()); }
From source file:com.mpaike.core.config.xml.elementreader.GenericElementReader.java
License:Open Source License
/** * Creates a ConfigElementImpl object from the given element. * // w w w . j ava 2s . co m * @param element The element to parse * @return The GenericConfigElement representation of the given element */ @SuppressWarnings("unchecked") private GenericConfigElement createConfigElement(Element element) { // get the name and value of the given element String name = element.getName(); // create the config element object and populate with value // and attributes GenericConfigElement configElement = new GenericConfigElement(name); if ((element.hasContent()) && (element.hasMixedContent() == false)) { String value = element.getTextTrim(); if (value != null && value.length() > 0) { if (propertyConfigurer != null) { value = propertyConfigurer.resolveValue(value); } configElement.setValue(value); } } Iterator<Attribute> attrs = element.attributeIterator(); while (attrs.hasNext()) { Attribute attr = attrs.next(); String attrName = attr.getName(); String attrValue = attr.getValue(); if (propertyConfigurer != null) { attrValue = propertyConfigurer.resolveValue(attrValue); } configElement.addAttribute(attrName, attrValue); } return configElement; }
From source file:com.nokia.config.SAXConfigParser.java
License:Open Source License
/** * Constructor/*from w ww . j a v a2 s. co m*/ * @return list of available configurations that can be built. */ public String getConfigs() { File file = new File(sysdefFile); SAXReader reader = new SAXReader(); reader.addHandler("/SystemDefinition/build/target", new ElementHandler() { public void onStart(ElementPath path) { } public void onEnd(ElementPath path) { Element row = path.getCurrent(); Iterator itr = row.attributeIterator(); while (itr.hasNext()) { Attribute child = (Attribute) itr.next(); String attrName = child.getQualifiedName(); if (attrName.equals("name")) { configs += (String) child.getValue() + ","; } } row.detach(); } }); try { Document doc = reader.read(file); } catch (Exception e) { e.printStackTrace(); } return configs; }
From source file:com.nokia.helium.diamonds.XMLMerger.java
License:Open Source License
/** * Compare two elements name and attributes. Returns true if name and all * attributes are matching, false otherwise. * //from w w w . j a v a 2s . co m * @param a * @param b * @return boolean */ @SuppressWarnings("unchecked") protected boolean areSame(Element a, Element b) { log.debug("areSame:" + a + " <=> " + b); if (!a.getName().equals(b.getName())) { return false; } log.debug("same attribute list size?"); if (a.attributes().size() != b.attributes().size()) { return false; } log.debug("same attribute list?"); for (Iterator<Attribute> at = a.attributes().iterator(); at.hasNext();) { Attribute attra = at.next(); Attribute attrb = b.attribute(attra.getName()); if (attrb == null || !attra.getValue().equals(attrb.getValue())) { return false; } } if (!a.getTextTrim().equals(b.getTextTrim())) { return false; } return true; }
From source file:com.nokia.helium.sbs.SAXSysdefParser.java
License:Open Source License
/** * Constructor// ww w . jav a 2s . c om * * @return list of available configurations that can be built. */ public void parseConfig(String nodeToGet) { layers = new ArrayList<String>(); SAXReader reader = new SAXReader(); reader.addHandler("/SystemDefinition/systemModel/" + nodeToGet, new ElementHandler() { public void onStart(ElementPath path) { } public void onEnd(ElementPath path) { Element row = path.getCurrent(); Iterator itr = row.attributeIterator(); while (itr.hasNext()) { Attribute child = (Attribute) itr.next(); String attrName = child.getQualifiedName(); if (attrName.equals("name")) { layers.add(child.getValue()); } } row.detach(); } }); try { reader.read(sysdefFile); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:com.processpuzzle.address.artifact.SettlementDataLoader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// w w w . j a v a 2 s . c om public void loadData() { super.loadData(); countryFactory = applicationContext.getEntityFactory(CountryFactory.class); countryRepository = applicationContext.getRepository(CountryRepository.class); settlementFactory = applicationContext.getEntityFactory(SettlementFactory.class); settlementDataSheetFactory = applicationContext.getEntityFactory(SettlementDataSheetFactory.class); settlementDataSheetRepository = applicationContext.getRepository(SettlementDataSheetRepository.class); zipCodeFactory = applicationContext.getEntityFactory(ZipCodeFactory.class); Document doc = getDocument(); Element root = doc.getRootElement(); for (Iterator<Element> i = root.elementIterator(ROOT_ELEMENT); i.hasNext();) { Element countryElement = i.next(); Attribute countryNameAttribute = countryElement.attribute(COUNTRY_NAME_ATTRIBUTE); String countryName = countryNameAttribute.getValue(); if (countryName != null && !"".equals(countryName)) { Country country = createAndSaveCountry(countryName); for (Iterator<Element> j = countryElement.elementIterator(SETTLEMENT_ELEMENT); j.hasNext();) { Element settlementElement = j.next(); String settlementName = settlementElement.attribute(SETTLEMENT_NAME_ATTRIBUTE).getValue(); if (settlementName != null && !"".equals(settlementName)) { DefaultUnitOfWork work = new DefaultUnitOfWork(true); SettlementDataSheet settlementDataSheet = null; try { settlementDataSheet = createAndSaveSettlement(work, settlementName, country); savedSettlements.add(settlementDataSheet.getSettlement()); for (Iterator<Element> k = settlementElement.elementIterator(DISTRICT_ELEMENT); k .hasNext();) { Element districtElement = k.next(); String districtName = districtElement.attribute(DISTRICT_NAME_ATTRIBUTE).getValue(); District district = settlementFactory.createDistrict(districtName, settlementDataSheet.getSettlement()); // process ZipCodes for (Iterator<Element> l = districtElement.elementIterator(ZIPCODE_ELEMENT); l .hasNext();) { Element zipCodeElement = l.next(); String code = zipCodeElement.attribute(CODE_ATTRIBUTE).getValue(); ZipCode zipCode = zipCodeFactory.createZipCode(new Integer(code), district); } } // process ZipCodes for (Iterator<Element> l = settlementElement.elementIterator(ZIPCODE_ELEMENT); l .hasNext();) { Element zipCodeElement = l.next(); String code = zipCodeElement.attribute(CODE_ATTRIBUTE).getValue(); ZipCode zipCode = zipCodeFactory.createZipCode(new Integer(code), settlementDataSheet.getSettlement()); } } catch (Exception e) { logError(e, settlementName); } finally { work.finish(); logSuccess(settlementDataSheet.getSettlement()); } } } } } }