List of usage examples for org.w3c.dom Attr getNodeName
public String getNodeName();
From source file:DOMTreeFull.java
public static String toString(Node node) { StringBuffer sb = new StringBuffer(); // is there anything to do? if (node == null) { return ""; }// ww w .j a v a 2 s .com int type = node.getNodeType(); sb.append(whatArray[type]); sb.append(" : "); sb.append(node.getNodeName()); String value = node.getNodeValue(); if (value != null) { sb.append(" Value: \""); sb.append(value); sb.append("\""); } switch (type) { // document case Node.DOCUMENT_NODE: { break; } // element with attributes case Node.ELEMENT_NODE: { Attr attrs[] = sortAttributes(node.getAttributes()); if (attrs.length > 0) sb.append(" ATTRS:"); for (int i = 0; i < attrs.length; i++) { Attr attr = attrs[i]; sb.append(' '); sb.append(attr.getNodeName()); sb.append("=\""); sb.append(normalize(attr.getNodeValue())); sb.append('"'); } sb.append('>'); break; } // handle entity reference nodes case Node.ENTITY_REFERENCE_NODE: { break; } // cdata sections case Node.CDATA_SECTION_NODE: { break; } // text case Node.TEXT_NODE: { break; } // processing instruction case Node.PROCESSING_INSTRUCTION_NODE: { break; } // comment node case Node.COMMENT_NODE: { break; } // DOCTYPE node case Node.DOCUMENT_TYPE_NODE: { break; } // Notation node case Node.NOTATION_NODE: { sb.append("public:"); String id = ((Notation) node).getPublicId(); if (id == null) { sb.append("PUBLIC "); sb.append(id); sb.append(" "); } id = ((Notation) node).getSystemId(); if (id == null) { sb.append("system: "); sb.append(id); sb.append(" "); } break; } } return sb.toString(); }
From source file:eu.elf.license.LicenseParser.java
/** * Creates LicenseParamInt object/*from ww w . j ava2 s . c o m*/ * * @param parameterElement * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter) * @return */ private static LicenseParamInt createLicenseParamInt(Element parameterElement, String parameterClass) { LicenseParamInt lpInt = new LicenseParamInt(); lpInt.setParameterClass(parameterClass); NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes(); for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) { Attr attrs = (Attr) parameterElementAttributeMap.item(i); if (attrs.getNodeName().equals("name")) { lpInt.setName(attrs.getNodeValue()); } } Element parameterTitleElement = (Element) parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0); if (parameterTitleElement != null) { lpInt.setTitle(parameterTitleElement.getTextContent()); } Element valueElement = (Element) parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value").item(0); if (valueElement != null) { lpInt.setValue(Integer.parseInt(valueElement.getTextContent())); } return lpInt; }
From source file:eu.elf.license.LicenseParser.java
/** * Creates LicenseParamDisplay object//from w w w. j a v a 2 s. c o m * * @param parameterElement * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter) * @return */ private static LicenseParamDisplay createLicenseParamDisplay(Element parameterElement, String parameterClass) { LicenseParamDisplay lpd = new LicenseParamDisplay(); lpd.setParameterClass(parameterClass); NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes(); for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) { Attr attrs = (Attr) parameterElementAttributeMap.item(i); if (attrs.getNodeName().equals("name")) { lpd.setName(attrs.getNodeValue()); } } Element parameterTitleElement = (Element) parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0); if (parameterTitleElement != null) { lpd.setTitle(parameterTitleElement.getTextContent()); } NodeList valueElementList = parameterElement.getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value"); for (int j = 0; j < valueElementList.getLength(); j++) { Element valueElement = (Element) valueElementList.item(j); lpd.addValue(valueElement.getTextContent()); } return lpd; }
From source file:eu.elf.license.LicenseParser.java
/** * Creates LicenseParamText object/* w ww . j av a 2s . c o m*/ * * @param parameterElement * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter) * @return */ private static LicenseParamText createLicenseParamText(Element parameterElement, String parameterClass) { LicenseParamText lpt = new LicenseParamText(); lpt.setParameterClass(parameterClass); NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes(); for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) { Attr attrs = (Attr) parameterElementAttributeMap.item(i); if (attrs.getNodeName().equals("name")) { lpt.setName(attrs.getNodeValue()); } } Element parameterTitleElement = (Element) parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0); if (parameterTitleElement != null) { lpt.setTitle(parameterTitleElement.getTextContent()); } NodeList valueElementList = parameterElement.getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value"); for (int j = 0; j < valueElementList.getLength(); j++) { Element valueElement = (Element) valueElementList.item(j); lpt.addValue(valueElement.getTextContent()); } return lpt; }
From source file:eu.elf.license.LicenseParser.java
/** * Creates LicenseParamBln object/*from w ww . j a v a 2 s.co m*/ * * @param parameterElement * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter) * @return */ private static LicenseParamBln createLicenseParamBln(Element parameterElement, String parameterClass) { LicenseParamBln lpbln = new LicenseParamBln(); lpbln.setParameterClass(parameterClass); NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes(); for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) { Attr attrs = (Attr) parameterElementAttributeMap.item(i); if (attrs.getNodeName().equals("name")) { lpbln.setName(attrs.getNodeValue()); } } Element parameterTitleElement = (Element) parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0); if (parameterTitleElement != null) { lpbln.setTitle(parameterTitleElement.getTextContent()); } Element parameterValueElement = (Element) parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value").item(0); if (parameterValueElement != null) { if (parameterValueElement.getTextContent().equals("true")) { lpbln.setValue(true); } else { lpbln.setValue(false); } } return lpbln; }
From source file:eu.elf.license.LicenseParser.java
/** * Parses a list of active licenses from GetLicenseReferences response string * //from ww w . j a v a 2 s .co m * @param xml - xml response * @return - ArrayList of license identifiers that are active * @throws Exception */ public static ArrayList<String> parseActiveLicensesFromGetLicenseReferencesResponse(String xml) throws Exception { ArrayList<String> activeLicenses = new ArrayList<String>(); try { Document xmlDoc = createXMLDocumentFromString(xml); NodeList licenseReferenceList = xmlDoc.getElementsByTagNameNS("http://www.52north.org/license/0.3.2", "LicenseReference"); for (int i = 0; i < licenseReferenceList.getLength(); i++) { Element licenseReferenceElement = (Element) licenseReferenceList.item(i); NodeList attributeElementList = licenseReferenceElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute"); for (int j = 0; j < attributeElementList.getLength(); j++) { Element attributeElement = (Element) attributeElementList.item(j); Element attributeValueElement = (Element) attributeElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "AttributeValue") .item(0); NamedNodeMap attributeMap = attributeElement.getAttributes(); for (int k = 0; k < attributeMap.getLength(); k++) { Attr attrs = (Attr) attributeMap.item(k); if (attrs.getNodeName().equals("Name")) { if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:LicenseID")) { activeLicenses.add(attributeValueElement.getTextContent()); } } } } } } catch (Exception e) { throw e; } return activeLicenses; }
From source file:eu.elf.license.LicenseParser.java
/** * Creates LicenseParamEnum object// ww w . j a v a2s . c om * * @param parameterElement * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter) * @return */ private static LicenseParamEnum createLicenseParamEnum(Element parameterElement, String parameterClass) { Boolean multiAttributeValue = false; LicenseParamEnum lpEnum = new LicenseParamEnum(); lpEnum.setParameterClass(parameterClass); NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes(); for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) { Attr attrs = (Attr) parameterElementAttributeMap.item(i); if (attrs.getNodeName().equals("name")) { lpEnum.setName(attrs.getNodeValue()); } if (attrs.getNodeName().equals("multi")) { if (attrs.getNodeValue().equals("true")) { multiAttributeValue = true; } else { multiAttributeValue = false; } } } lpEnum.setMulti(multiAttributeValue); Element parameterTitleElement = (Element) parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0); if (parameterTitleElement != null) { lpEnum.setTitle(parameterTitleElement.getTextContent()); } NodeList valueElementList = parameterElement.getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value"); for (int j = 0; j < valueElementList.getLength(); j++) { Element valueElement = (Element) valueElementList.item(j); NamedNodeMap valueElementAttributeMap = valueElement.getAttributes(); for (int k = 0; k < valueElementAttributeMap.getLength(); k++) { Attr attrs = (Attr) valueElementAttributeMap.item(k); if (attrs.getNodeName().equals("selected")) { if (attrs.getNodeValue().equals("true")) { lpEnum.setDefaultValue(valueElement.getTextContent()); lpEnum.addSelection(valueElement.getTextContent()); } } } lpEnum.addOption(valueElement.getTextContent()); } return lpEnum; }
From source file:eu.elf.license.LicenseParser.java
/** * Creates List of LicenseModelGroup objects * * @param productGroupElementList - List of <ns:productGroup> elements * @return list of LicenseModelGroup objects *///from w w w . j a va2 s . c om private static List<LicenseModelGroup> createLicenseModelGroupList(NodeList productGroupElementList) { List<LicenseModelGroup> lmgList = new ArrayList<LicenseModelGroup>(); for (int i = 0; i < productGroupElementList.getLength(); i++) { LicenseModelGroup tempLMG = new LicenseModelGroup(); Boolean isAccountGroup = false; Element productGroupElement = (Element) productGroupElementList.item(i); NamedNodeMap productGroupElementAttributeMap = productGroupElement.getAttributes(); for (int j = 0; j < productGroupElementAttributeMap.getLength(); j++) { Attr attrs = (Attr) productGroupElementAttributeMap.item(j); if (attrs.getNodeName().equals("id")) { if (attrs.getNodeValue().equals("ACCOUNTING_SUMMARY_GROUP")) { // Skip element with id="ACCOUNTING_SUMMARY_GROUP" - do not add to the list isAccountGroup = true; } if (attrs.getNodeName() != null) { tempLMG.setId(attrs.getNodeValue()); } } if (attrs.getNodeName().equals("name")) { if (attrs.getNodeName() != null) { tempLMG.setUrl(attrs.getNodeValue()); } } } if (isAccountGroup == true) { continue; // Skip element with id="ACCOUNTING_SUMMARY_GROUP" - do not add to the list } Element abstractElement = (Element) productGroupElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "abstract").item(0); if (abstractElement != null) { tempLMG.setDescription(abstractElement.getTextContent()); } Element titleElement = (Element) productGroupElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0); if (titleElement != null) { tempLMG.setName(titleElement.getTextContent()); } NodeList productElementList = productGroupElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "product"); tempLMG.setLicenseModels(createLicenseModelList(productElementList)); lmgList.add(tempLMG); } return lmgList; }
From source file:eu.elf.license.LicenseParser.java
/** * Creates LicenseConcludeResponseObject from the concludeLicense operation's response string * //from w ww. ja v a 2s . c o m * @param response * @return * @throws Exception */ public static LicenseConcludeResponseObject parseConcludeLicenseResponse(String response) throws Exception { LicenseConcludeResponseObject lcro = new LicenseConcludeResponseObject(); try { Document xmlDoc = LicenseParser.createXMLDocumentFromString(response); NodeList LicenseReferenceNL = xmlDoc.getElementsByTagNameNS("http://www.52north.org/license/0.3.2", "LicenseReference"); for (int i = 0; i < LicenseReferenceNL.getLength(); i++) { Element attributeStatementElement = (Element) LicenseReferenceNL.item(i); NodeList attributeElementList = attributeStatementElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute"); for (int j = 0; j < attributeElementList.getLength(); j++) { Element attributeElement = (Element) attributeElementList.item(j); Element AttributeValueElement = (Element) attributeElement .getElementsByTagName("AttributeValue").item(0); NamedNodeMap licenseReferenceElementAttributeMap = attributeElement.getAttributes(); for (int k = 0; k < licenseReferenceElementAttributeMap.getLength(); k++) { Attr attrs = (Attr) licenseReferenceElementAttributeMap.item(k); if (attrs.getNodeName().equals("Name")) { if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:NotOnOrAfter")) { lcro.setValidTo(AttributeValueElement.getTextContent()); } if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:ProductID")) { lcro.setProductId(AttributeValueElement.getTextContent()); } if (attrs.getNodeValue().equals("urn:opengeospatial:ows4:geodrm:LicenseID")) { lcro.setLicenseId(AttributeValueElement.getTextContent()); } } } } } } catch (Exception e) { throw e; } return lcro; }
From source file:eu.elf.license.LicenseParser.java
/** * Creates list of LicenseModel elements * * @param productElementList - NodeList of <ns:product> elements: * @return List of LicenseModel objects// w ww . ja v a 2 s .c om */ private static List<LicenseModel> createLicenseModelList(NodeList productElementList) { List<LicenseModel> lmList = new ArrayList<LicenseModel>(); for (int i = 0; i < productElementList.getLength(); i++) { LicenseModel tempLM = new LicenseModel(); Boolean isRestricted = true; Element productElement = (Element) productElementList.item(i); NamedNodeMap productElementAttributeMap = productElement.getAttributes(); for (int j = 0; j < productElementAttributeMap.getLength(); j++) { Attr attrs = (Attr) productElementAttributeMap.item(j); if (attrs.getNodeName().equals("id")) { if (attrs.getNodeName() != null) { tempLM.setId(attrs.getNodeValue()); } } } Element titleElement = (Element) productElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0); if (titleElement != null) { tempLM.setName(titleElement.getTextContent()); } Element abstractElement = (Element) productElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "abstract").item(0); if (abstractElement != null) { tempLM.setDescription(abstractElement.getTextContent()); } Element calculationElement = (Element) productElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "calculation").item(0); Element declarationListElement = (Element) calculationElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "declarationList").item(0); Element predefinedParametersElement = (Element) declarationListElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "predefinedParameters").item(0); NodeList predefinedParametersParameterElementList = predefinedParametersElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter"); for (int k = 0; k < predefinedParametersParameterElementList.getLength(); k++) { Element parameterElement = (Element) predefinedParametersParameterElementList.item(k); NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes(); for (int l = 0; l < parameterElementAttributeMap.getLength(); l++) { Attr attrs = (Attr) parameterElementAttributeMap.item(l); if (attrs.getNodeName().equals("name")) { if (attrs.getNodeName() != null) { if (attrs.getNodeValue().equals("ALL_ROLES")) { Element valueElement = (Element) parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value").item(0); if (valueElement.getTextContent().equals("true")) { isRestricted = false; } } } } if (attrs.getNodeName().equals("name")) { if (attrs.getNodeName() != null) { if (attrs.getNodeValue().equals("ALLOWED_ROLES")) { NodeList valueElementList = parameterElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value"); for (int m = 0; m < valueElementList.getLength(); m++) { tempLM.addRole(valueElementList.item(m).getTextContent()); } } } } } } tempLM.setRestricted(isRestricted); tempLM.setParams(createLicenseModelParamList(declarationListElement)); lmList.add(tempLM); } return lmList; }