List of usage examples for org.w3c.dom Element getTagName
public String getTagName();
From source file:com.codename1.android.AndroidLayoutImporter.java
private List<ElementConstraint> getBorderLayoutChildren(Element root) { List<ElementConstraint> out = new ArrayList<ElementConstraint>(); NodeList children = root.getChildNodes(); int len = children.getLength(); for (int i = 0; i < len; i++) { Node n = children.item(i); if (!(n instanceof Element)) { continue; }/* w w w .j av a 2 s. co m*/ Element e = (Element) n; Element constraint = null; NodeList eChildren = e.getChildNodes(); int elen = eChildren.getLength(); for (int j = 0; j < elen; j++) { Node en = eChildren.item(j); if (!(en instanceof Element)) { continue; } Element ee = (Element) en; if (e.getTagName().equals("layoutConstraint")) { constraint = e; break; } } ElementConstraint eConstraint = new ElementConstraint( constraint == null ? null : constraint.getAttribute("value"), e); out.add(eConstraint); } return out; }
From source file:de.uni_weimar.m18.anatomiederstadt.LevelPageFragment.java
private void populateLayoutFromXML() { try {// ww w .j a v a2s . co m LevelStateManager stateManager = ((AnatomieDerStadtApplication) getActivity().getApplicationContext()) .getStateManager(getActivity()); Document levelXml = stateManager.getLevelXML(); Element rootElement = levelXml.getDocumentElement(); Log.v(LOG_TAG, "RootElement: " + rootElement.getTagName()); NodeList pageList = rootElement.getElementsByTagName("page"); Node page = null; // = pageList.item(mPageNum); for (int i = 0; i < pageList.getLength(); ++i) { if (pageList.item(i).getAttributes().getNamedItem("id").getNodeValue().equals(mPageId)) { page = pageList.item(i); // save current page id in shared preferences SharedPreferences sharedPref = PreferenceManager .getDefaultSharedPreferences(getActivity().getApplicationContext()); Editor editor = sharedPref.edit(); editor.putBoolean(getString(R.string.user_is_playing_boolean), true); editor.putString(getString(R.string.resume_base_path), mBasePath); editor.putString(getString(R.string.resume_page_id), mPageId); editor.commit(); } } if (page == null) { Log.e(LOG_TAG, "Error! Page with id " + mPageId + " could not be found in level.xml!"); return; } Log.v(LOG_TAG, "page: nodename: " + page.getNodeName()); NodeList childNodes = page.getChildNodes(); for (int i = 0; i < childNodes.getLength(); ++i) { Log.v(LOG_TAG, "at page-childnode " + Integer.toString(i)); Node item = childNodes.item(i); if (item.getNodeName().equals("text")) { Log.v(LOG_TAG, "text node found - value: " + item.getTextContent()); addText(item.getTextContent()); } if (item.getNodeName().equals("image")) { NamedNodeMap attributes = item.getAttributes(); Node src = attributes.getNamedItem("src"); addImage(src.getNodeValue()); } if (item.getNodeName().equals("quiz")) { String target = ""; String correct = ""; String button1 = ""; String button2 = ""; String button3 = ""; String button4 = ""; String hint = ""; String points = ""; String penalty = ""; NodeList quizParamaters = item.getChildNodes(); for (int k = 0; k < quizParamaters.getLength(); ++k) { Node child = quizParamaters.item(k); String quizParameter = child.getNodeName(); switch (quizParameter) { case "target": target = child.getTextContent(); break; case "correct": correct = child.getTextContent(); break; case "button1": button1 = child.getTextContent(); break; case "button2": button2 = child.getTextContent(); break; case "button3": button3 = child.getTextContent(); break; case "button4": button4 = child.getTextContent(); break; case "hint": hint = child.getTextContent(); break; case "points": points = child.getTextContent(); break; case "penalty": penalty = child.getTextContent(); break; default: break; //throw new IllegalArgumentException("Invalid quiz parameter" + quizParameter); } } addQuiz4Element(target, correct, button1, button2, button3, button4, hint, points, penalty); } /* if (item.getNodeName().equals("quiz")) { NamedNodeMap attributes = item.getAttributes(); Node button1 = attributes.getNamedItem("button1"); Node button2 = attributes.getNamedItem("button2"); Node button3 = attributes.getNamedItem("button3"); Node button4 = attributes.getNamedItem("button4"); Node correctAnswer = attributes.getNamedItem("correctAnswer"); Node correctTarget = attributes.getNamedItem("correctTarget"); addQuizMultipleChoice(button1.getNodeValue(), button2.getNodeValue(), button3.getNodeValue(), button4.getNodeValue(), Integer.parseInt(correctAnswer.getNodeValue()), correctTarget.getNodeValue()); } */ if (item.getNodeName().equals("latex")) { addLatex(item.getTextContent()); } if (item.getNodeName().equals("slider")) { NamedNodeMap attributes = item.getAttributes(); Node min = attributes.getNamedItem("min"); Node max = attributes.getNamedItem("max"); Node granularity = attributes.getNamedItem("granularity"); Node suffix = attributes.getNamedItem("suffix"); Node var = attributes.getNamedItem("var"); addSlider(Integer.parseInt(min.getNodeValue()), Integer.parseInt(max.getNodeValue()), Float.parseFloat(granularity.getNodeValue()), suffix.getNodeValue(), var.getNodeValue()); } if (item.getNodeName().equals("location")) { NamedNodeMap attributes = item.getAttributes(); Node latitude = attributes.getNamedItem("latitude"); Node longitude = attributes.getNamedItem("longitude"); Node target = attributes.getNamedItem("target"); addLocation(latitude.getNodeValue(), longitude.getNodeValue(), target.getNodeValue()); } if (item.getNodeName().equals("button")) { NamedNodeMap attributes = item.getAttributes(); Node caption = attributes.getNamedItem("caption"); Node target = attributes.getNamedItem("target"); addButton(caption.getNodeValue(), target.getNodeValue()); } if (item.getNodeName().equals("evaluate")) { NamedNodeMap attributes = item.getAttributes(); Node var = attributes.getNamedItem("var"); String expression = item.getTextContent(); evaluateMath(var.getNodeValue(), expression); } if (item.getNodeName().equals("var")) { NamedNodeMap attributes = item.getAttributes(); Node name = attributes.getNamedItem("name"); storeVariable(name.getNodeValue(), item.getTextContent()); } if (item.getNodeName().equals("input")) { NamedNodeMap attributes = item.getAttributes(); Node buttonCaption = attributes.getNamedItem("caption"); Node target = attributes.getNamedItem("target"); Node var = attributes.getNamedItem("var"); addInput(buttonCaption.getNodeValue(), var.getNodeValue(), target.getNodeValue()); } if (item.getNodeName().equals("inputcheck")) { NamedNodeMap attributes = item.getAttributes(); Node buttonCaption = attributes.getNamedItem("caption"); Node target = attributes.getNamedItem("target"); Node var = attributes.getNamedItem("var"); Node correct = attributes.getNamedItem("correct"); Node points = attributes.getNamedItem("points"); Node hint = attributes.getNamedItem("hint"); addInputCheck(buttonCaption.getNodeValue(), var.getNodeValue(), target.getNodeValue(), correct.getNodeValue(), points.getNodeValue(), hint.getNodeValue()); } if (item.getNodeName().equals("quizmulti")) { NamedNodeMap attributes = item.getAttributes(); Node target = attributes.getNamedItem("target"); Node points = attributes.getNamedItem("points"); //NodeList optionsList = item.getElementsByTagName("option"); Node parent = item.getParentNode(); ArrayList<String> options = new ArrayList<>(); ArrayList<String> correctList = new ArrayList<>(); if (parent instanceof Element) { final Element e = (Element) parent; NodeList optionsList = e.getElementsByTagName("option"); for (int k = 0; k < optionsList.getLength(); ++k) { Node option = optionsList.item(k); if (option.getAttributes().getNamedItem("correct").getNodeValue().equals("true")) correctList.add("true"); else correctList.add("false"); options.add(option.getTextContent()); } addQuizMulti(options, correctList, target.getNodeValue(), points.getNodeValue()); } } if (item.getNodeName().equals("evalpoints")) { NamedNodeMap attributes = item.getAttributes(); Node var = attributes.getNamedItem("var"); Node correct = attributes.getNamedItem("correct"); Node step = attributes.getNamedItem("step"); Node points = attributes.getNamedItem("points"); Node penalty = attributes.getNamedItem("penalty"); evaluatePoints(var.getNodeValue(), correct.getNodeValue(), step.getNodeValue(), points.getNodeValue(), penalty.getNodeValue()); } if (item.getNodeName().equals("score")) { addScore(); } if (item.getNodeName().equals("survey")) { registerSurveyClickHandler(); } } } catch (Exception e) { Log.e(LOG_TAG, "Error! Exception " + e.getMessage()); e.printStackTrace(); new MaterialDialog.Builder(getActivity()).title("Error") .content("Fehler whrend des Verarbeitens der Level-Datei!\n" + e.getMessage()) .positiveText("OK").show(); } commitChildFragments(); }
From source file:net.wastl.webmail.xml.XMLMessagePart.java
public Enumeration<XMLMessagePart> getParts() { // Sucking NodeList needs a Vector to store Elements that will be removed! Vector<XMLMessagePart> v = new Vector<XMLMessagePart>(); NodeList parts = part.getChildNodes(); for (int j = 0; j < parts.getLength(); j++) { Element elem = (Element) parts.item(j); if (elem.getTagName().equals("PART")) v.addElement(new XMLMessagePart(elem)); }// w w w.j ava2s . c o m return v.elements(); }
From source file:net.wastl.webmail.xml.XMLSystemData.java
protected Element getConfigElementByKey(String key) { NodeList nl = sysdata.getElementsByTagName("KEY"); Element config = null;//from w ww .j ava 2 s . c o m for (int i = 0; i < nl.getLength(); i++) { Element keyelem = (Element) nl.item(i); Element parent = (Element) keyelem.getParentNode(); if (XMLCommon.getElementTextValue(keyelem).equals(key) && parent.getTagName().equals("CONFIG")) { config = parent; break; } } return config; }
From source file:net.wastl.webmail.xml.XMLUserModel.java
/** * Get messagelist for folder. Create if necessary. *///from w w w. j ava2s . co m public synchronized Element getMessageList(Element folder) { NodeList nl = folder.getChildNodes(); Element messagelist = null; for (int i = 0; i < nl.getLength(); i++) { Element tmp = (Element) nl.item(i); if (tmp.getTagName().equals("MESSAGELIST")) { messagelist = tmp; break; } } if (messagelist == null) { messagelist = createMessageList(); folder.appendChild(messagelist); } return messagelist; }
From source file:nl.b3p.ogc.utils.OGCRequest.java
/** * Constructor//from ww w .java 2 s . com * For HTTP POST */ public OGCRequest(Element rootElement, String url) throws ValidationException, Exception { addOpengisNamespaces(); parameters = new HashMap(); setUrl(url); findNameSpace(rootElement); Unmarshaller um; Object o; setFinalVersion(rootElement.getAttribute(OGCConstants.VERSION.toLowerCase())); String version = finalVersion; if (removeNamespace(rootElement.getTagName()).equalsIgnoreCase(OGCConstants.WFS_GETCAPABILITIES)) { if (version.equalsIgnoreCase(OGCConstants.WFS_VERSION_100)) { um = new Unmarshaller(nl.b3p.xml.wfs.v100.GetCapabilities.class); o = um.unmarshal(rootElement); nl.b3p.xml.wfs.v100.GetCapabilities getCapabilities = (nl.b3p.xml.wfs.v100.GetCapabilities) o; setGetCapabilitiesV100(getCapabilities); } else { um = new Unmarshaller(nl.b3p.xml.wfs.v110.GetCapabilities.class); o = um.unmarshal(rootElement); nl.b3p.xml.wfs.v110.GetCapabilities getCapabilities = (nl.b3p.xml.wfs.v110.GetCapabilities) o; setGetCapabilitiesV110(getCapabilities); } } else if (removeNamespace(rootElement.getTagName()) .equalsIgnoreCase(OGCConstants.WFS_DESCRIBEFEATURETYPE)) { if (version.equalsIgnoreCase(OGCConstants.WFS_VERSION_100)) { um = new Unmarshaller(nl.b3p.xml.wfs.v100.DescribeFeatureType.class); o = um.unmarshal(rootElement); nl.b3p.xml.wfs.v100.DescribeFeatureType describeFeatureType = (nl.b3p.xml.wfs.v100.DescribeFeatureType) o; setDescribeFeatureTypeV100(describeFeatureType); } else { um = new Unmarshaller(nl.b3p.xml.wfs.v110.DescribeFeatureType.class); o = um.unmarshal(rootElement); nl.b3p.xml.wfs.v110.DescribeFeatureType describeFeatureType = (nl.b3p.xml.wfs.v110.DescribeFeatureType) o; setDescribeFeatureTypeV110(describeFeatureType); } } else if (removeNamespace(rootElement.getTagName()).equalsIgnoreCase(OGCConstants.WFS_GETFEATURE)) { if (version.equalsIgnoreCase(OGCConstants.WFS_VERSION_100)) { um = new Unmarshaller(nl.b3p.xml.wfs.v100.GetFeature.class); o = um.unmarshal(rootElement); nl.b3p.xml.wfs.v100.GetFeature getFeature = (nl.b3p.xml.wfs.v100.GetFeature) o; setGetFeatureV100(getFeature); } else { um = new Unmarshaller(nl.b3p.xml.wfs.v110.GetFeature.class); o = um.unmarshal(rootElement); nl.b3p.xml.wfs.v110.GetFeature getFeature = (nl.b3p.xml.wfs.v110.GetFeature) o; setGetFeatureV110(getFeature); } } else if (removeNamespace(rootElement.getTagName()).equalsIgnoreCase(OGCConstants.WFS_TRANSACTION)) { if (version.equalsIgnoreCase(OGCConstants.WFS_VERSION_100)) { um = new Unmarshaller(nl.b3p.xml.wfs.v100.capabilities.Transaction.class); o = um.unmarshal(rootElement); nl.b3p.xml.wfs.v100.transaction.Transaction transaction = (nl.b3p.xml.wfs.v100.transaction.Transaction) o; setTransactionV100(transaction); } else { um = new Unmarshaller(nl.b3p.xml.wfs.v110.Transaction.class); o = um.unmarshal(rootElement); nl.b3p.xml.wfs.v110.Transaction transaction = (nl.b3p.xml.wfs.v110.Transaction) o; setTransactionV110(transaction); } } else if (removeNamespace(rootElement.getTagName()).equalsIgnoreCase(OGCConstants.WFS_LOCKFEATURE)) { throw new UnsupportedOperationException( "kaartenbalie doesn't suport " + OGCConstants.WFS_LOCKFEATURE + " yet!"); } else if (removeNamespace(rootElement.getTagName()) .equalsIgnoreCase(OGCConstants.WFS_GETFEATUREWITHLOCK)) { throw new UnsupportedOperationException( "kaartenbalie doesn't suport " + OGCConstants.WFS_GETFEATUREWITHLOCK + " yet!"); } else { throw new UnsupportedOperationException("No supported WFS service found in request!"); } }
From source file:nl.b3p.ogc.utils.OGCResponse.java
public static boolean isWfsV100ErrorResponse(Element rootElement) { String tagName = OGCRequest.removeNamespace(rootElement.getTagName()); if (tagName.equalsIgnoreCase(OGCConstants.WFS_SERVER_EXCEPTION)) { return true; }// w w w .ja v a2 s . com return false; }
From source file:nl.b3p.ogc.utils.OGCResponse.java
public static boolean isOwsV100ErrorResponse(Element rootElement) { String tagName = OGCRequest.removeNamespace(rootElement.getTagName()); if (tagName.equalsIgnoreCase(OGCConstants.WFS_OWS_EXCEPTION)) { return true; }// w w w . j a v a 2 s . c o m return false; }
From source file:nl.b3p.ogc.utils.OgcWfsClient.java
/** *Doe een getCapabilities request naar de host aangegeven in de OGCRequest die meegegeven wordt *//* w w w. j av a2 s .c o m*/ public static WFS_Capabilities getCapabilities(OGCRequest original) throws Exception { WFS_Capabilities returnvalue; OGCRequest or = (OGCRequest) original.clone(); or.removeAllWFSParameters(); or.addOrReplaceParameter(OGCConstants.WMS_SERVICE, OGCConstants.WFS_SERVICE_WFS); or.addOrReplaceParameter(OGCConstants.WMS_REQUEST, OGCConstants.WFS_REQUEST_GetCapabilities); if (original.getParameter(OGCConstants.WMS_VERSION) != null) { or.addOrReplaceParameter(OGCConstants.WMS_VERSION, original.getParameter(OGCConstants.WMS_VERSION)); } String host = or.getUrlWithNonOGCparams(); //Element el=doRequest(getGetCapabilitiesRequest(or),host); String url = or.getUrl(); Element el = doRequest(url, host, or.getNameSpaces(), or.getUsername(), or.getPassword()); if (el.getTagName().contains(OGCConstants.WFS_OBJECT_CAPABILITIES)) { String version = el.getAttribute(OGCConstants.WMS_VERSION.toLowerCase()); if (version.equalsIgnoreCase(OGCConstants.WFS_VERSION_100)) { if (original.getParameter(OGCConstants.WMS_VERSION) == null) { original.addOrReplaceParameter(OGCConstants.WMS_VERSION, version); } returnvalue = getCapabilitiesVersion100(el); } else if (version.equalsIgnoreCase(OGCConstants.WFS_VERSION_110)) { if (original.getParameter(OGCConstants.WMS_VERSION) == null) { original.addOrReplaceParameter(OGCConstants.WMS_VERSION, version); } returnvalue = getCapabilitiesVersion110(el); } else { throw new UnsupportedOperationException( "WFS GetCapabilities version: " + version + " not supported"); } } else { log.error("Unexpected element returned: " + el.getTagName()); throw new Exception("Unexpected element returned: " + el.getTagName()); } original.setCapabilities(returnvalue); return returnvalue; }
From source file:nl.b3p.ogc.utils.OgcWfsClient.java
public static Element doRequest(Object o, String host, HashMap namespaces, String username, String password) throws Exception { Element el = readXml2Element( new InputStreamReader(getInputStreamReader(o, host, namespaces, username, password))); if (OGCRequest.removeNamespace(el.getTagName()) .equalsIgnoreCase(OGCConstants.WFS_OBJECT_SERVICEEXCEPTIONREPORT)) { nl.b3p.xml.ogc.v100.exception.ServiceExceptionReport ser = getServiceExceptionReport(el); StringBuffer sb = new StringBuffer(); nl.b3p.xml.ogc.v100.exception.ServiceException se = null; for (int i = 0; i < ser.getServiceExceptionCount(); i++) { if (i != 0) { sb.append(" and "); }/*from w w w.j a v a2s . co m*/ se = ser.getServiceException(i); sb.append(se.getContent()); } throw new Exception(sb.toString()); } return el; }