List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:com.beyondb.geocoding.BaiduAPI.java
public static String getPointByAddress(String address, String city) throws IOException { String resultPoint = ""; try {/*from w ww . ja v a 2s . c o m*/ URL url = new URL("http://api.map.baidu.com/geocoder/v2/?ak=" + ak + "&output=xml&address=" + address + "&" + city); URLConnection connection = url.openConnection(); /** * ??URLConnection?Web * URLConnection???Web??? */ connection.setDoOutput(true); OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "utf-8"); // remember to clean up out.flush(); out.close(); // ????? String res; InputStream l_urlStream; l_urlStream = connection.getInputStream(); if (l_urlStream != null) { BufferedReader in = new BufferedReader(new InputStreamReader(l_urlStream, "UTF-8")); StringBuilder sb = new StringBuilder(""); while ((res = in.readLine()) != null) { sb.append(res.trim()); } String str = sb.toString(); System.out.println(str); Document doc = DocumentHelper.parseText(str); // XML Element rootElt = doc.getRootElement(); // ? // System.out.println("" + rootElt.getName()); // ?? Element resultElem = rootElt.element("result"); if (resultElem.hasContent()) { Element locationElem = resultElem.element("location"); Element latElem = locationElem.element("lat"); // System.out.print("lat:"+latElem.getTextTrim()+","); Element lngElem = locationElem.element("lng"); // System.out.println("lng:"+lngElem.getTextTrim()); resultPoint = lngElem.getTextTrim() + "," + latElem.getTextTrim(); } else { System.out.println("can't compute the coor"); resultPoint = " , "; } } else { resultPoint = " , "; } } catch (DocumentException ex) { Logger.getLogger(BaiduAPI.class.getName()).log(Level.SEVERE, null, ex); } return resultPoint; }
From source file:com.beyondb.geocoding.SkyMapAPI.java
/** * ??????/*from w w w .j a v a 2 s . c o m*/ *??????? * @param address * @param city * @return */ public Map<String, Coordinate> getPlaces(String address, String city) { Map<String, Coordinate> map = null; try { URL url = new URL(requestURL);//webService?XML? String soapRequest = getRequestXML( city == null || city.isEmpty() ? ("" + address) : (city + " " + address)); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows XP; DigExt)"); con.setRequestProperty("Content-Length", String.valueOf(soapRequest.length())); con.setRequestProperty("Content-Type", "text/xml; charset=UTF-8"); // con.setRequestProperty("SOAPAction",_soap_action_str); con.setDoOutput(true); con.setConnectTimeout(3000);//3?,??ip???socket?????? con.setRequestMethod("POST"); con.setUseCaches(false);//post? OutputStream out = con.getOutputStream(); out.write(soapRequest.getBytes()); out.flush(); out.close(); int code = 0; StringBuilder content = new StringBuilder(); code = con.getResponseCode(); //????? BufferedReader br; String line = ""; if (code == HttpURLConnection.HTTP_OK) { br = new BufferedReader(new InputStreamReader(con.getInputStream())); while ((line = br.readLine()) != null) { content.append(line); } //? XML?? // <?xml version="1.0" encoding="UTF-8"?><wfs:FeatureCollection xmlns:topp="http://www.openplans.org/topp" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd" service="WFS" outputFormat="gml" version="1.0"> //<gml:featureMember xmlns:iso19112="SI_Gazetteer"><iso19112:SI_Gazetteer><Geometry><gml:Point srsName="-1"><gml:coordinates>116.394272,39.900472</gml:coordinates></gml:Point></Geometry><ogc:id>1003716709</ogc:id><ogc:name></ogc:name><ogc:tel>010-65243322</ogc:tel><ogc:addnamel>44?</ogc:addnamel><ogc:admin>156110101</ogc:admin><ogc:cls>100102 100100 100000</ogc:cls><ogc:level/><ogc:zip/></iso19112:SI_Gazetteer></gml:featureMember> //<gml:featureMember xmlns:iso19112="SI_Gazetteer"><iso19112:SI_Gazetteer><Geometry><gml:Point srsName="-1"><gml:coordinates>116.394504,39.9013</gml:coordinates></gml:Point></Geometry><ogc:id>1003546134</ogc:id><ogc:name></ogc:name><ogc:tel>010-65241304</ogc:tel><ogc:addnamel>37?</ogc:addnamel><ogc:admin>156110101</ogc:admin><ogc:cls>100501 100500 100000 100105 100100 100000</ogc:cls><ogc:level/><ogc:zip/></iso19112:SI_Gazetteer></gml:featureMember> //<gml:featureMember xmlns:iso19112="SI_Gazetteer"><iso19112:SI_Gazetteer><Geometry><gml:Point srsName="-1"><gml:coordinates>116.393824,39.900068</gml:coordinates></gml:Point></Geometry><ogc:id>1025053239</ogc:id><ogc:name>?</ogc:name><ogc:tel>010-65122265</ogc:tel><ogc:addnamel>44?</ogc:addnamel><ogc:admin>156110101</ogc:admin><ogc:cls>010100 010000</ogc:cls><ogc:level/><ogc:zip/></iso19112:SI_Gazetteer></gml:featureMember> //<gml:featureMember xmlns:iso19112="SI_Gazetteer"><iso19112:SI_Gazetteer><Geometry><gml:Point srsName="-1"><gml:coordinates>116.3938,39.899528</gml:coordinates></gml:Point></Geometry><ogc:id>1003552834</ogc:id><ogc:name>?</ogc:name><ogc:tel>010-65241042</ogc:tel><ogc:addnamel>44?</ogc:addnamel><ogc:admin>156110101</ogc:admin><ogc:cls>010116 010100 010000</ogc:cls><ogc:level/><ogc:zip/></iso19112:SI_Gazetteer></gml:featureMember> // <gml:featureMember xmlns:iso19112="SI_Gazetteer"> // <iso19112:SI_Gazetteer> // <Geometry> // <gml:Point srsName="-1"> // <gml:coordinates>116.3938,39.899532</gml:coordinates> // </gml:Point> // </Geometry> // <ogc:id>1021636362</ogc:id> // <ogc:name>?</ogc:name> // <ogc:tel>010-65241042</ogc:tel> // <ogc:addnamel>44?</ogc:addnamel> // <ogc:admin>156110101</ogc:admin> // <ogc:cls>010116 010100 010000</ogc:cls> // <ogc:level/> // <ogc:zip/> // </iso19112:SI_Gazetteer> // </gml:featureMember> //</wfs:FeatureCollection> Document doc = DocumentHelper.parseText(content.toString()); // XML Element rootElt = doc.getRootElement(); // ?FeatureCollection for (Iterator it = rootElt.elementIterator("featureMember"); it.hasNext();) { if (map == null) { map = new HashMap<>(); } Element featureMemberElement = (Element) it.next(); Element gazetterEle = featureMemberElement.element("SI_Gazetteer"); Element geoEle = gazetterEle.element("Geometry"); Element pointEle = geoEle.element("Point"); Element coordEle = pointEle.element("coordinates"); String[] coordinate = coordEle.getTextTrim().split(","); Coordinate tmpCoordinate = new Coordinate(); tmpCoordinate.Longitude = Double.parseDouble(coordinate[0]); tmpCoordinate.Latitude = Double.parseDouble(coordinate[1]); Element nameEle = gazetterEle.element("name"); map.put(nameEle.getTextTrim(), tmpCoordinate); } } else { //?HTTP??HTTP_OK?? InputStream is = con.getErrorStream(); //getErrorStreamXML??JDOM?? InputStreamReader isr = new InputStreamReader(is, "utf-8"); br = new BufferedReader(isr); while ((line = br.readLine()) != null) { content.append(line); } Logger.getLogger(SkyMapAPI.class.getName()).log(Level.SEVERE, "??"); } } catch (MalformedURLException e) { Logger.getLogger(SkyMapAPI.class.getName()).log(Level.SEVERE, null, e); } catch (IOException | DocumentException e) { Logger.getLogger(SkyMapAPI.class.getName()).log(Level.SEVERE, null, e); } return map; }
From source file:com.bluexml.side.framework.alfresco.sharePortalExtension.PresetsManagerExtension.java
License:Open Source License
/** * Construct the model objects for a given preset. * Objects persist to the default store for the appropriate object type. * /* w w w . ja v a 2s . c o m*/ * @param id * Preset ID to use * @param tokens * Name value pair tokens to replace in preset definition */ public void constructPreset(String id, Map<String, String> tokens) { if (id == null) { throw new IllegalArgumentException("Preset ID is mandatory."); } // perform one time init - this cannot be perform in an app handler or by the // framework init - as it requires the Alfresco server to be started... synchronized (this) { if (this.documents == null) { init(); } } for (Document doc : this.documents) { for (Element preset : (List<Element>) doc.getRootElement().elements("preset")) { // found preset with matching id? if (id.equals(preset.attributeValue("id"))) { // any components in the preset? Element components = preset.element("components"); if (components != null) { for (Element c : (List<Element>) components.elements("component")) { // apply token replacement to each value as it is retrieved String title = replace(c.elementTextTrim(Component.PROP_TITLE), tokens); String titleId = replace(c.elementTextTrim(Component.PROP_TITLE_ID), tokens); String description = replace(c.elementTextTrim(Component.PROP_DESCRIPTION), tokens); String descriptionId = replace(c.elementTextTrim(Component.PROP_DESCRIPTION_ID), tokens); String typeId = replace(c.elementTextTrim(Component.PROP_COMPONENT_TYPE_ID), tokens); String scope = replace(c.elementTextTrim(Component.PROP_SCOPE), tokens); String regionId = replace(c.elementTextTrim(Component.PROP_REGION_ID), tokens); String sourceId = replace(c.elementTextTrim(Component.PROP_SOURCE_ID), tokens); String url = replace(c.elementTextTrim(Component.PROP_URL), tokens); String chrome = replace(c.elementTextTrim(Component.PROP_CHROME), tokens); // validate mandatory values if (scope == null || scope.length() == 0) { throw new IllegalArgumentException( "Scope is a mandatory property for a component preset."); } if (regionId == null || regionId.length() == 0) { throw new IllegalArgumentException( "RegionID is a mandatory property for a component preset."); } if (sourceId == null || sourceId.length() == 0) { throw new IllegalArgumentException( "SourceID is a mandatory property for a component preset."); } // generate component Component component = modelObjectService.newComponent(scope, regionId, sourceId); component.setComponentTypeId(typeId); component.setTitle(title); component.setTitleId(titleId); component.setDescription(description); component.setDescriptionId(descriptionId); component.setURL(url); component.setChrome(chrome); // apply arbituary custom properties if (c.element("properties") != null) { for (Element prop : (List<Element>) c.element("properties").elements()) { String propName = replace(prop.getName(), tokens); String propValue = replace(prop.getTextTrim(), tokens); component.setCustomProperty(propName, propValue); } } // persist the object modelObjectService.saveObject(component); } } // any pages in the preset? Element pages = preset.element("pages"); if (pages != null) { for (Element p : (List<Element>) pages.elements("page")) { // apply token replacement to each value as it is retrieved String pageId = replace(p.attributeValue(Page.PROP_ID), tokens); String title = replace(p.elementTextTrim(Page.PROP_TITLE), tokens); String titleId = replace(p.elementTextTrim(Page.PROP_TITLE_ID), tokens); String description = replace(p.elementTextTrim(Page.PROP_DESCRIPTION), tokens); String descriptionId = replace(p.elementTextTrim(Page.PROP_DESCRIPTION_ID), tokens); String typeId = replace(p.elementTextTrim(Page.PROP_PAGE_TYPE_ID), tokens); String auth = replace(p.elementTextTrim(Page.PROP_AUTHENTICATION), tokens); String template = replace(p.elementTextTrim(Page.PROP_TEMPLATE_INSTANCE), tokens); // validate mandatory values if (pageId == null || pageId.length() == 0) { throw new IllegalArgumentException( "ID is a mandatory attribute for a page preset."); } if (template == null || template.length() == 0) { throw new IllegalArgumentException( "Template is a mandatory property for a page preset."); } // generate page Page page = modelObjectService.newPage(pageId); page.setPageTypeId(typeId); page.setTitle(title); page.setTitleId(titleId); page.setDescription(description); page.setDescriptionId(descriptionId); page.setAuthentication(auth); page.setTemplateId(template); // apply arbituary custom properties if (p.element("properties") != null) { for (Element prop : (List<Element>) p.element("properties").elements()) { String propName = replace(prop.getName(), tokens); String propValue = replace(prop.getTextTrim(), tokens); page.setCustomProperty(propName, propValue); } } // persist the object modelObjectService.saveObject(page); } } // any template instances in the preset? Element templates = preset.element("template-instances"); if (templates != null) { for (Element t : (List<Element>) templates.elements("template-instance")) { // apply token replacement to each value as it is retrieved String templateId = replace(t.attributeValue(TemplateInstance.PROP_ID), tokens); String title = replace(t.elementTextTrim(TemplateInstance.PROP_TITLE), tokens); String titleId = replace(t.elementTextTrim(TemplateInstance.PROP_TITLE_ID), tokens); String description = replace(t.elementTextTrim(TemplateInstance.PROP_DESCRIPTION), tokens); String descriptionId = replace(t.elementTextTrim(TemplateInstance.PROP_DESCRIPTION_ID), tokens); String templateType = replace(t.elementTextTrim(TemplateInstance.PROP_TEMPLATE_TYPE), tokens); // validate mandatory values if (templateId == null || templateId.length() == 0) { throw new IllegalArgumentException( "ID is a mandatory attribute for a template-instance preset."); } if (templateType == null || templateType.length() == 0) { throw new IllegalArgumentException( "Template is a mandatory property for a page preset."); } // generate template-instance TemplateInstance template = modelObjectService.newTemplate(templateId); template.setTitle(title); template.setTitleId(titleId); template.setDescription(description); template.setDescriptionId(descriptionId); template.setTemplateTypeId(templateType); // apply arbituary custom properties if (t.element("properties") != null) { for (Element prop : (List<Element>) t.element("properties").elements()) { String propName = replace(prop.getName(), tokens); String propValue = replace(prop.getTextTrim(), tokens); template.setCustomProperty(propName, propValue); } } // persist the object modelObjectService.saveObject(template); } } // TODO: any chrome, associations, types, themes etc. in the preset... // found our preset - no need to process further break; } } } }
From source file:com.bluexml.side.Framework.alfresco.workflow.pdfGenerator.action.PdfActionHandler.java
License:Open Source License
private Map<String, String> getScriptAsKeysValues() throws EmptyScriptException { Map<String, String> commands = new HashMap<String, String>(); Element expressionElement = script.element("expression"); String expression = null;/*from www . j a v a2s. co m*/ if (expressionElement != null) { expression = expressionElement.getTextTrim(); } else { throw new EmptyScriptException(EmptyScriptException.EMPTY_SCRIPT); } //Delete comments expression = expression.replaceAll("/\\*[^(*/)]*\\*/", ""); String[] expressions = expression.split(ConstantsLanguage.COMMANDS_SEPARATOR_SPACE); for (int index = 0; index < expressions.length; index++) { String[] keyValue = expressions[index].split(ConstantsLanguage.KEY_VALUE_SEPARATOR); if (index == expressions.length - 1) { keyValue[1] = keyValue[1].split(ConstantsLanguage.COMMANDS_SEPARATOR)[0]; } commands.put(keyValue[0].trim(), keyValue[1].trim()); } return commands; }
From source file:com.church.gateway.Global.java
/** * Load transition effects./*from w ww . j a v a2s . c om*/ */ private static void loadTransitionEffects() { ArrayList<String> display = new ArrayList<String>(); ArrayList<String> classname = new ArrayList<String>(); try { byte[] xmlbytes = Network.getLocalFile("transitions.xml"); Document doc = DocumentHelper.parseText(new String(xmlbytes)); Element root = doc.getRootElement(); List<Node> nodes = root.selectNodes("transition"); transitionParameters = new HashMap<String, Object[]>(); for (Node n : nodes) { Element elmt = (Element) n; display.add(elmt.selectSingleNode("display").getText()); classname.add(elmt.selectSingleNode("class").getText()); List<Node> ps = elmt.selectNodes("parameter"); if (ps != null) { Object[] arr = new Object[ps.size()]; for (int i = 0; i < ps.size(); i++) { Element ep = (Element) ps.get(i); arr[i] = ep.getTextTrim(); } transitionParameters.put(elmt.selectSingleNode("display").getText(), arr); } else transitionParameters.put(elmt.selectSingleNode("display").getText(), new Object[] {}); } } catch (DocumentException e) { Logger.getLogger(Global.class).error(e, e); } supportedTransitionClasses = new String[classname.size()]; supportedTransitions = new String[display.size()]; for (int i = 0; i < classname.size(); i++) { supportedTransitionClasses[i] = classname.get(i) + ":" + display.get(i); supportedTransitions[i] = display.get(i); } }
From source file:com.denimgroup.threadfix.service.SurveyServiceImpl.java
License:Mozilla Public License
private SurveyLevel constructLevel(Element levelElement) { SurveyLevel level = new SurveyLevel(); level.setNumber(Integer.parseInt(levelElement.attributeValue("number"))); level.setDescription(levelElement.getTextTrim()); return level; }
From source file:com.denimgroup.threadfix.service.SurveyServiceImpl.java
License:Mozilla Public License
private SurveyQuestion constructQuestion(Element questionElement) { SurveyQuestion question = new SurveyQuestion(); question.setSurveyQuestion(questionElement.getTextTrim()); for (Object assertionElement : questionElement.elements("assertion")) { question.getSurveyAssertions().add(constructAssertion((Element) assertionElement)); }/*from w w w . j a v a2 s .co m*/ for (SurveyAssertion assertion : question.getSurveyAssertions()) { assertion.setSurveyQuestion(question); } return question; }
From source file:com.denimgroup.threadfix.service.SurveyServiceImpl.java
License:Mozilla Public License
private SurveyAssertion constructAssertion(Element assertionElement) { SurveyAssertion assertion = new SurveyAssertion(); assertion.setDescription(assertionElement.getTextTrim()); return assertion; }
From source file:com.devoteam.srit.xmlloader.asn1.XMLToASNParser.java
License:Open Source License
public Object parseField(String resultPath, ASNMessage message, Element element, Field field, String type, Object object, String className) throws Exception { // manage the embedded objects Embedded embedded = message.getEmbeddedByInitial(type); if (embedded == null && field != null) { embedded = message.getEmbeddedByInitial(field.getName()); }// ww w.jav a 2s. c o m if (embedded != null) { String replace = embedded.getReplace(); Class subClass = Class.forName(replace); Object objEmbbeded = subClass.newInstance(); parseFromXML(resultPath, message, objEmbbeded, (Element) element.elements().get(0), className); IEncoder<Object> encoderEmbedded = CoderFactory.getInstance().newEncoder("BER"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); encoderEmbedded.encode(objEmbbeded, outputStream); byte[] bytesEmbedded = outputStream.toByteArray(); //Array arraybytesEmbedded = new DefaultArray(bytesEmbedded); Object obj = null; if (!type.equals("byte[]")) { Class cl = Class.forName(type); Constructor constr = cl.getConstructor(); constr.setAccessible(true); obj = constr.newInstance(); Field[] fields = cl.getDeclaredFields(); fields[0].setAccessible(true); fields[0].set(obj, bytesEmbedded); } else { obj = bytesEmbedded; } return obj; } Object value = null; if (type.equals("java.lang.Boolean") || type.equals("boolean")) { value = Boolean.valueOf(element.getTextTrim()).booleanValue(); } else if (type.equals("java.lang.String") || type.equals("String")) { value = element.getTextTrim(); } else if (type.equals("java.lang.Integer") || type.equals("int")) { value = Integer.parseInt(element.getTextTrim()); } else if (type.equals("java.lang.Float") || type.equals("float")) { value = Float.parseFloat(element.getTextTrim()); } else if (type.equals("java.lang.Short") || type.equals("short")) { value = Short.parseShort(element.getTextTrim()); } else if (type.equals("java.lang.Long") || type.equals("long")) { value = Long.parseLong(element.getTextTrim()); } else if (type.equals("java.lang.Byte") || type.equals("byte")) { value = Byte.parseByte(element.getTextTrim()); } else if (type.equals("byte[]")) { // not a simple value so return return new DefaultArray(Utils.parseBinaryString("h" + element.getTextTrim())).getBytes(); } else if (type.endsWith(".EnumType")) { String elementText = element.getTextTrim(); int pos = elementText.indexOf(ASNToXMLConverter.TAG_SEPARATOR); if (pos > 0) { elementText = elementText.substring(0, pos); } Class[] classes = object.getClass().getClasses(); Object[] objects = null; if (classes.length >= 1) { objects = classes[0].getEnumConstants(); Object objFind = null; for (int i = 0; i < objects.length; i++) { objFind = objects[i]; if (objFind.toString().equals(elementText)) { break; } } // not a simple value so return return objFind; } return null; } else { String classNameCurrent = type.substring(type.lastIndexOf(".") + 1); if (!className.equals("") && (type.contains(className)) && (!(type.equals(className + classNameCurrent)))) { // static class : h225.h323_className$staticClass type = type.substring(0, type.lastIndexOf(".")) + "$" + type.substring(type.lastIndexOf(".") + 1); } // calculate the element name to build the result path String elementName = element.getName(); int iPos = elementName.indexOf(ASNToXMLConverter.TAG_SEPARATOR); if (iPos > 0) { elementName = elementName.substring(0, iPos); } resultPath = resultPath + "." + elementName; Object obj = Class.forName(type).newInstance(); //Object objComplexClass = this.instanceClass(obj.getClass().getName(), className); parseFromXML(resultPath, message, obj, element, className); // not a simple value so return return obj; } // get the condition for embedded objects String elementName = resultPath; int iPos = resultPath.lastIndexOf("."); if (iPos > 0) { elementName = resultPath.substring(iPos + 1); } String condition = elementName + "=" + value; List<Embedded> embeddedList = ASNDictionary.getInstance().getEmbeddedByCondition(condition); if (embeddedList != null) { message.addConditionalEmbedded(embeddedList); } return value; }
From source file:com.devoteam.srit.xmlloader.h323.h225cs.XmlToAsn1.java
License:Open Source License
public Object parseField(Element element, String type, String className) throws IllegalArgumentException, IllegalAccessException, ClassNotFoundException, InstantiationException, InvocationTargetException, NoSuchMethodException { if (type.equals("java.lang.Boolean") || type.equals("boolean")) { return Boolean.valueOf(element.getTextTrim()).booleanValue(); } else if (type.equals("java.lang.String") || type.equals("String")) { return element.getTextTrim(); } else if (type.equals("java.lang.Integer") || type.equals("int")) { return Integer.parseInt(element.getTextTrim()); } else if (type.equals("java.lang.Float") || type.equals("float")) { return Float.parseFloat(element.getTextTrim()); } else if (type.equals("java.lang.Short") || type.equals("short")) { return Short.parseShort(element.getTextTrim()); } else if (type.equals("java.lang.Long") || type.equals("long")) { return Long.parseLong(element.getTextTrim()); } else if (type.equals("java.lang.Byte") || type.equals("byte")) { return Byte.parseByte(element.getTextTrim()); } else if (type.equals("byte[]")) { return new DefaultArray(Utils.parseBinaryString(element.getTextTrim())).getBytes(); } else {/*from w w w. j a v a 2s.com*/ String classNameCurrent = type.substring(type.lastIndexOf(".") + 1); if ((type.contains(className)) && (!(type.equals(className + classNameCurrent)))) { // static class : h225.h323_className$staticClass type = type.substring(0, type.lastIndexOf(".")) + "$" + type.substring(type.lastIndexOf(".") + 1); } if (!type.contains(className)) { className = ""; } Object obj = Class.forName(type).newInstance(); Object objComplexClass = this.instanceClass(obj.getClass().getName(), className); initObject(objComplexClass, element, className); return objComplexClass; } }