List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:org.ale.scanner.zotero.web.zotero.ZoteroAPIClient.java
public static Access parsePermissions(String resp, Account user) { /* example:/*from w ww .ja v a2 s . c o m*/ <key key="xxx"> <access library="1" files="1" notes="1" write="1"/> <access group="12345" write="1"/> <access group="all" write="1"/> </key> */ Document doc = ZoteroAPIClient.parseXML(resp); if (doc == null) return null; NodeList keys = doc.getElementsByTagName("key"); if (keys.getLength() == 0) return null; Node keyNode = keys.item(0); Node keyAttr = keyNode.getAttributes().getNamedItem("key"); if (keyAttr == null) return null; String key = keyAttr.getNodeValue(); if (!key.equals(user.getKey())) return null; NodeList accessTags = doc.getElementsByTagName("access"); int[] groups = new int[accessTags.getLength()]; int[] permissions = new int[accessTags.getLength()]; for (int i = 0; i < accessTags.getLength(); i++) { permissions[i] = Access.READ; NamedNodeMap attr = accessTags.item(i).getAttributes(); Node groupNode = attr.getNamedItem("group"); if (groupNode == null) { // Library access? groupNode = attr.getNamedItem("library"); if (groupNode == null) return null; groups[i] = Group.GROUP_LIBRARY; } else { // Individual group or all groups if (groupNode.getNodeValue().equals("all")) groups[i] = Group.GROUP_ALL; else groups[i] = Integer.parseInt(groupNode.getNodeValue()); } Node writeNode = attr.getNamedItem("write"); if (writeNode != null && writeNode.getNodeValue().equals("1")) { permissions[i] |= Access.WRITE; } Node noteNode = attr.getNamedItem("notes"); if (noteNode != null && noteNode.getNodeValue().equals("1")) { permissions[i] |= Access.NOTE; } } return new Access(user.getDbId(), groups, permissions); }
From source file:com.ryderbot.utils.ModelUtils.java
public static Contract generateContract(NamedNodeMap attributes) { DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Long contractID = Long.parseLong(attributes.getNamedItem("contractID").getNodeValue()); Long issuerID = Long.parseLong(attributes.getNamedItem("issuerID").getNodeValue()); Long issuerCorpID = Long.parseLong(attributes.getNamedItem("issuerCorpID").getNodeValue()); Long assigneeID = Long.parseLong(attributes.getNamedItem("assigneeID").getNodeValue()); Long acceptorID = Long.parseLong(attributes.getNamedItem("acceptorID").getNodeValue()); Long startStationID = Long.parseLong(attributes.getNamedItem("startStationID").getNodeValue()); Long endStationID = Long.parseLong(attributes.getNamedItem("endStationID").getNodeValue()); String type = attributes.getNamedItem("type").getNodeValue(); String status = attributes.getNamedItem("status").getNodeValue(); String title = attributes.getNamedItem("title").getNodeValue(); boolean forCorp = attributes.getNamedItem("forCorp").getNodeValue().equals("1") ? true : false; String availability = attributes.getNamedItem("availability").getNodeValue(); Integer numDays = Integer.parseInt(attributes.getNamedItem("numDays").getNodeValue()); Double price = Double.parseDouble(attributes.getNamedItem("price").getNodeValue()); Double reward = Double.parseDouble(attributes.getNamedItem("reward").getNodeValue()); ;/*from w ww .java2s .c om*/ Double collateral = Double.parseDouble(attributes.getNamedItem("collateral").getNodeValue()); ; Double buyout = Double.parseDouble(attributes.getNamedItem("buyout").getNodeValue()); ; Double volume = Double.parseDouble(attributes.getNamedItem("volume").getNodeValue()); Date dateIssued = null; Date dateExpired = null; Date dateAccepted = null; Date dateCompleted = null; try { dateIssued = dateFormatter.parse(attributes.getNamedItem("dateIssued").getNodeValue()); dateExpired = dateFormatter.parse(attributes.getNamedItem("dateExpired").getNodeValue()); dateAccepted = dateFormatter.parse(attributes.getNamedItem("dateAccepted").getNodeValue()); dateCompleted = dateFormatter.parse(attributes.getNamedItem("dateCompleted").getNodeValue()); } catch (DOMException | ParseException e) { } Contract contract = new Contract(contractID); contract.setIssuerID(issuerID); contract.setIssuerCorpID(issuerCorpID); contract.setAssigneeID(assigneeID); contract.setAcceptorID(acceptorID); contract.setStartStationID(startStationID); contract.setEndStationID(endStationID); contract.setType(type); contract.setStatus(status); contract.setTitle(title); contract.setForCorp(forCorp); contract.setAvailability(availability); contract.setDateIssued(dateIssued); contract.setDateExpired(dateExpired); contract.setDateAccepted(dateAccepted); contract.setDateCompleted(dateCompleted); contract.setNumDays(numDays); contract.setPrice(price); contract.setReward(reward); contract.setCollateral(collateral); contract.setBuyout(buyout); contract.setVolume(volume); return contract; }
From source file:com.ryderbot.utils.ModelUtils.java
public static CorporationSheet generateCorpSheet(Node node) { Map<String, String> map = new HashMap<>(); Map<Long, String> divisions = new HashMap<>(); Map<Long, String> walletDivisions = new HashMap<>(); Logo logo = new Logo(null); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String key = child.getNodeName(); if (key.equals("rowset")) { String name = child.getAttributes().getNamedItem("name").getNodeValue(); NodeList rowset = child.getChildNodes(); for (int j = 0; j < rowset.getLength(); j++) { try { NamedNodeMap attributes = rowset.item(j).getAttributes(); Long accountKey = Long.parseLong(attributes.getNamedItem("accountKey").getNodeValue()); String description = attributes.getNamedItem("description").getNodeValue(); if (description.equals("Wallet Division 1")) { description = "Master Wallet"; }/*from w w w .j a v a 2s . c o m*/ if (name.equals("divisions")) { divisions.put(accountKey, description); } else if (name.equals("walletDivisions")) { walletDivisions.put(accountKey, description); } } catch (Exception e) { continue; } } } else if (key.equals("logo")) { // Node current = child.getFirstChild(); // Long graphicID = Long.parseLong(current.getTextContent()); // logo = new Logo(graphicID); // // current = current.getNextSibling(); // Integer value = Integer.parseInt(current.getTextContent()); // logo.setShape1(value); // // current = current.getNextSibling(); // value = Integer.parseInt(current.getTextContent()); // logo.setShape2(value); // // current = current.getNextSibling(); // value = Integer.parseInt(current.getTextContent()); // logo.setShape3(value); // // current = current.getNextSibling(); // value = Integer.parseInt(current.getTextContent()); // logo.setColor1(value); // // current = current.getNextSibling(); // value = Integer.parseInt(current.getTextContent()); // logo.setColor2(value); // // current = current.getNextSibling(); // value = Integer.parseInt(current.getTextContent()); // logo.setColor3(value); } else { String value = child.getTextContent(); map.put(key, value); } } Long corporationID = Long.parseLong(map.get("corporationID")); CorporationSheet corpSheet = new CorporationSheet(corporationID); String corporationName = map.get("corporationName"); String ticker = map.get("ticker"); Long ceoID = Long.parseLong(map.get("ceoID")); String ceoName = map.get("ceoName"); Long stationID = Long.parseLong(map.get("stationID")); String stationName = map.get("stationName"); String description = map.get("description"); String url = map.get("url"); Long allianceID = Long.parseLong(map.get("allianceID")); Long factionID = Long.parseLong(map.get("factionID")); String allianceName = map.get("allianceName"); Double taxRate = Double.parseDouble(map.get("taxRate")); Integer memberCount = Integer.parseInt(map.get("memberCount")); Integer memberLimit = Integer.parseInt(map.get("memberLimit")); Long shares = Long.parseLong(map.get("shares")); corpSheet.setCorporationName(corporationName); corpSheet.setTicker(ticker); corpSheet.setCeoID(ceoID); corpSheet.setCeoName(ceoName); corpSheet.setStationID(stationID); corpSheet.setStationName(stationName); corpSheet.setDescription(description); corpSheet.setUrl(url); corpSheet.setAllianceID(allianceID); corpSheet.setFactionID(factionID); corpSheet.setAllianceName(allianceName); corpSheet.setTaxRate(taxRate); corpSheet.setMemberCount(memberCount); corpSheet.setMemberLimit(memberLimit); corpSheet.setShares(shares); corpSheet.setDivisions(divisions); corpSheet.setWalletDivisions(walletDivisions); corpSheet.setLogo(logo); return corpSheet; }
From source file:Main.java
static boolean canBeMerged(Node node1, Node node2, String requiredTagName) { if (node1.getNodeType() != Node.ELEMENT_NODE || node2.getNodeType() != Node.ELEMENT_NODE) return false; Element element1 = (Element) node1; Element element2 = (Element) node2; if (!equals(requiredTagName, element1.getTagName()) || !equals(requiredTagName, element2.getTagName())) return false; NamedNodeMap attributes1 = element1.getAttributes(); NamedNodeMap attributes2 = element2.getAttributes(); if (attributes1.getLength() != attributes2.getLength()) return false; for (int i = 0; i < attributes1.getLength(); i++) { final Attr attr1 = (Attr) attributes1.item(i); final Attr attr2; if (isNotEmpty(attr1.getNamespaceURI())) attr2 = (Attr) attributes2.getNamedItemNS(attr1.getNamespaceURI(), attr1.getLocalName()); else/* w w w . j ava 2s. co m*/ attr2 = (Attr) attributes2.getNamedItem(attr1.getName()); if (attr2 == null || !equals(attr1.getTextContent(), attr2.getTextContent())) return false; } return true; }
From source file:ambit.data.qmrf.QMRFConverter.java
public static ArrayList findNodeIDRef(String name_node, String ref_name, String catalog_name, org.w3c.dom.Document source) throws Exception { source.getDocumentElement();//www . ja v a2 s . c om ArrayList return_list = new ArrayList(); NodeList objCatNodes = source.getElementsByTagName(name_node); Node objNode = objCatNodes.item(0); NodeList objNodes = objNode.getChildNodes(); for (int i = 0; i < objNodes.getLength(); i = i + 1) { if (objNodes.item(i).getNodeName().equals(ref_name)) { NamedNodeMap objAttributes = objNodes.item(i).getAttributes(); Node attribute = objAttributes.getNamedItem("idref"); //attribute.getNodeValue() NodeList objNodesAuthor = source.getElementsByTagName(catalog_name); for (int j = 0; j < objNodesAuthor.getLength(); j = j + 1) { String id = objNodesAuthor.item(j).getAttributes().getNamedItem("id").getNodeValue(); if (id.equals(attribute.getNodeValue())) { //Node name = objNodesAuthor.item(j).getAttributes().getNamedItem(xml_attribute_name); return_list.add(objNodesAuthor.item(j)); } } } } return return_list; }
From source file:apps.ParsedPost.java
public static ParsedPost parsePost(String postText, boolean excludeCode) throws Exception { Document post = XmlHelper.parseDocWithoutXMLDecl(postText); NamedNodeMap attr = post.getDocumentElement().getAttributes(); if (null == attr) { throw new Exception("Invalid entry, no attributes!"); }//from www . j a va 2 s .c o m Node itemId = attr.getNamedItem("Id"); Node itemAcceptedAnswerId = attr.getNamedItem("AcceptedAnswerId"); Node itemParentId = attr.getNamedItem("ParentId"); Node itemPostTypeId = attr.getNamedItem("PostTypeId"); Node itemTitle = attr.getNamedItem("Title"); Node itemBody = attr.getNamedItem("Body"); if (null == itemId) throw new Exception("Missing Id"); if (null == itemPostTypeId) throw new Exception("Missing PostTypeId"); if (null == itemBody) throw new Exception("Missing Body"); String id = XmlHelper.getNodeValue(itemId); String acceptedAnswerId = itemAcceptedAnswerId != null ? XmlHelper.getNodeValue(itemAcceptedAnswerId) : ""; String postIdType = XmlHelper.getNodeValue(itemPostTypeId); String parentId = itemParentId != null ? XmlHelper.getNodeValue(itemParentId) : ""; String title = itemTitle != null ? XmlHelper.getNodeValue(itemTitle) : ""; String body = XmlHelper.getNodeValue(itemBody); return new ParsedPost(id, acceptedAnswerId, parentId, postIdType, (new PostCleaner(title, MIN_CODE_CHARS, true)).getText(), (new PostCleaner(body, MIN_CODE_CHARS, excludeCode)).getText()); }
From source file:sep.gaia.resources.poi.POILoaderWorker.java
/** * Parses XML-data from the Overpass-API containing both nodes and ways and creates * <code>PointOfInterest</code>-objects from it. When a way is contained, one of its nodes * is picked as the describing POIs location. * @param doc The document to parse.// w ww .ja v a2s . c o m * @return The POIs described by the Overpass-data. */ private static Collection<PointOfInterest> parseResponse(Document doc) { // First all ways must be parsed, because later the contained nodes must be known: Collection<Way> ways = new LinkedList<>(); NodeList wayElements = doc.getElementsByTagName("way"); // Iterate all way-elements: for (int i = 0; i < wayElements.getLength(); i++) { Node wayElement = wayElements.item(i); Set<String> nodeReferences = new HashSet<>(); Map<String, String> tags = new HashMap<>(); // Iterate all child-elements of the way-element: NodeList childs = wayElement.getChildNodes(); for (int j = 0; j < childs.getLength(); j++) { Node currentChild = childs.item(j); // If its a node reference if (currentChild.getNodeName().equals("nd")) { // Add its ID to the ways node references: NamedNodeMap attributes = currentChild.getAttributes(); String ref = attributes.getNamedItem("ref").getNodeValue(); nodeReferences.add(ref); // If its an attribute tag-element: } else if (currentChild.getNodeName().equals("tag")) { // Add the k/v-attributes to the ways attributes: NamedNodeMap attributes = currentChild.getAttributes(); String key = attributes.getNamedItem("k").getNodeValue(); String value = attributes.getNamedItem("v").getNodeValue(); tags.put(key, value); } } // Remember the way for later use: Way way = new Way(nodeReferences, tags); ways.add(way); } // Now all node-elements are parsed: NodeList nodeElements = doc.getElementsByTagName("node"); Collection<PointOfInterest> pois = new ArrayList<>(nodeElements.getLength()); for (int i = 0; i < nodeElements.getLength(); i++) { Node node = nodeElements.item(i); // Get the nodes ID and position: NamedNodeMap attributes = node.getAttributes(); String id = attributes.getNamedItem("id").getNodeValue(); float lat = Float.parseFloat(attributes.getNamedItem("lat").getNodeValue()); float lon = Float.parseFloat(attributes.getNamedItem("lon").getNodeValue()); // If the node is part of a way, add its position to the ways position-set: Way containedIn = null; Iterator<Way> wayIter = ways.iterator(); while (wayIter.hasNext() && containedIn == null) { Way current = wayIter.next(); if (current.containsNode(id)) { current.addNode(new FloatVector3D(lat, lon, 0)); containedIn = current; } } // If this node is not a part of a way: if (containedIn == null) { Map<String, String> tags = new HashMap<>(); // Iterate all children of the node: NodeList childs = node.getChildNodes(); for (int j = 0; j < childs.getLength(); j++) { Node currentChild = childs.item(j); NamedNodeMap childAttrs = currentChild.getAttributes(); // Add attribute for each k/v-element: if (currentChild.getNodeName().equals("tag")) { String key = childAttrs.getNamedItem("k").getNodeValue(); String value = childAttrs.getNamedItem("v").getNodeValue(); tags.put(key, value); } } // Valid POIs must have a name: String name = tags.get("name"); if (name != null) { // Create the POI from read data and add it to results: PointOfInterest poi = createPoiFromTags(lat, lon, tags); if (poi != null) { pois.add(poi); } } } } // The last thing to do is to convert all generated ways to POIs: for (Way way : ways) { PointOfInterest poi = wayToPoi(way); if (poi != null) { pois.add(poi); } } return pois; }
From source file:com.connexta.arbitro.attr.AttributeDesignator.java
/** * Creates a new <code>AttributeDesignator</code> based on the DOM root of the XML data. * * @param root the DOM root of the AttributeDesignatorType XML type * @return the designator/*w w w . ja v a 2 s.c o m*/ * @throws ParsingException if the AttributeDesignatorType was invalid */ public static AttributeDesignator getInstance(Node root) throws ParsingException { URI type = null; URI id = null; String issuer = null; boolean mustBePresent = false; URI category = null; int target; String tagName = DOMHelper.getLocalName(root); if (tagName.equals("SubjectAttributeDesignator")) { target = SUBJECT_TARGET; } else if (tagName.equals("ResourceAttributeDesignator")) { target = RESOURCE_TARGET; } else if (tagName.equals("ActionAttributeDesignator")) { target = ACTION_TARGET; } else if (tagName.equals("EnvironmentAttributeDesignator")) { target = ENVIRONMENT_TARGET; } else { throw new ParsingException( "AttributeDesignator cannot be constructed using " + "type: " + DOMHelper.getLocalName(root)); } NamedNodeMap attrs = root.getAttributes(); try { // there's always an Id id = new URI(attrs.getNamedItem("AttributeId").getNodeValue()); } catch (Exception e) { throw new ParsingException("Required AttributeId missing in " + "AttributeDesignator", e); } try { // there's always a data type type = new URI(attrs.getNamedItem("DataType").getNodeValue()); } catch (Exception e) { throw new ParsingException("Required DataType missing in " + "AttributeDesignator", e); } try { // there might be an issuer Node node = attrs.getNamedItem("Issuer"); if (node != null) issuer = node.getNodeValue(); // if it's for the Subject section, there's another attr if (target == SUBJECT_TARGET) { Node scnode = attrs.getNamedItem("SubjectCategory"); if (scnode != null) { category = new URI(scnode.getNodeValue()); } else { category = new URI(SUBJECT_CATEGORY_DEFAULT); } } else if (target == RESOURCE_TARGET) { category = new URI(XACMLConstants.RESOURCE_CATEGORY); } else if (target == ACTION_TARGET) { category = new URI(XACMLConstants.ACTION_CATEGORY); } else if (target == ENVIRONMENT_TARGET) { category = new URI(XACMLConstants.ENT_CATEGORY); } // there might be a mustBePresent flag node = attrs.getNamedItem("MustBePresent"); if (node != null) if (node.getNodeValue().equals("true")) mustBePresent = true; } catch (Exception e) { // this shouldn't ever happen, but in theory something could go // wrong in the code in this try block throw new ParsingException("Error parsing AttributeDesignator " + "optional attributes", e); } return new AttributeDesignator(target, type, id, mustBePresent, issuer, category); }
From source file:com.ryderbot.utils.ModelUtils.java
public static Job generateJob(NamedNodeMap attributes) { DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); Long jobID = Long.parseLong(attributes.getNamedItem("jobID").getNodeValue()); Long installerID = Long.parseLong(attributes.getNamedItem("installerID").getNodeValue()); String installerName = attributes.getNamedItem("installerName").getNodeValue(); Long facilityID = Long.parseLong(attributes.getNamedItem("facilityID").getNodeValue()); Long solarSystemID = Long.parseLong(attributes.getNamedItem("solarSystemID").getNodeValue()); String solarSystemName = attributes.getNamedItem("solarSystemName").getNodeValue(); Long stationID = Long.parseLong(attributes.getNamedItem("stationID").getNodeValue()); Integer activityID = Integer.parseInt(attributes.getNamedItem("activityID").getNodeValue()); Long blueprintID = Long.parseLong(attributes.getNamedItem("blueprintID").getNodeValue()); ;/*from w ww. ja v a 2 s . c o m*/ Long blueprintTypeID = Long.parseLong(attributes.getNamedItem("blueprintTypeID").getNodeValue()); String blueprintTypeName = attributes.getNamedItem("blueprintTypeName").getNodeValue(); Long blueprintLocationID = Long.parseLong(attributes.getNamedItem("blueprintLocationID").getNodeValue()); Long outputLocationID = Long.parseLong(attributes.getNamedItem("outputLocationID").getNodeValue()); Integer runs = Integer.parseInt(attributes.getNamedItem("runs").getNodeValue()); Double cost = Double.parseDouble(attributes.getNamedItem("cost").getNodeValue()); Long teamID = Long.parseLong(attributes.getNamedItem("teamID").getNodeValue()); Integer licensedRuns = Integer.parseInt(attributes.getNamedItem("licensedRuns").getNodeValue()); Double probability = Double.parseDouble(attributes.getNamedItem("probability").getNodeValue()); Long productTypeID = Long.parseLong(attributes.getNamedItem("productTypeID").getNodeValue()); String productTypeName = attributes.getNamedItem("productTypeName").getNodeValue(); Integer status = Integer.parseInt(attributes.getNamedItem("status").getNodeValue()); Long timeInSeconds = Long.parseLong(attributes.getNamedItem("timeInSeconds").getNodeValue()); Long completedCharacterID = Long.parseLong(attributes.getNamedItem("completedCharacterID").getNodeValue()); Integer successfulRuns = Integer.parseInt(attributes.getNamedItem("successfulRuns").getNodeValue()); Date startDate = null; Date endDate = null; Date pauseDate = null; Date completedDate = null; try { startDate = dateFormatter.parse(attributes.getNamedItem("startDate").getNodeValue()); endDate = dateFormatter.parse(attributes.getNamedItem("endDate").getNodeValue()); pauseDate = dateFormatter.parse(attributes.getNamedItem("pauseDate").getNodeValue()); completedDate = dateFormatter.parse(attributes.getNamedItem("completedDate").getNodeValue()); } catch (DOMException | ParseException e) { } Job job = new Job(jobID); job.setInstallerID(installerID); job.setInstallerName(installerName); job.setFacilityID(facilityID); job.setSolarSystemID(solarSystemID); job.setSolarSystemName(solarSystemName); job.setStationID(stationID); job.setBlueprintTypeName(blueprintTypeName); job.setActivityID(activityID); job.setBlueprintID(blueprintID); job.setBlueprintTypeID(blueprintTypeID); job.setBlueprintLocationID(blueprintLocationID); job.setOutputLocationID(outputLocationID); job.setRuns(runs); job.setCost(cost); job.setTeamID(teamID); job.setLicensedRuns(licensedRuns); job.setProbability(probability); job.setProductTypeID(productTypeID); job.setProductTypeName(productTypeName); job.setStatus(status); job.setTimeInSeconds(timeInSeconds); job.setCompletedCharacterID(completedCharacterID); job.setSuccessfulRuns(successfulRuns); job.setStartDate(startDate); job.setEndDate(endDate); job.setPauseDate(pauseDate); job.setCompletedDate(completedDate); return job; }
From source file:com.connexta.arbitro.PolicyReference.java
/** * Creates an instance of a <code>PolicyReference</code> object based on a DOM node. * /*w w w.j a va 2s .c om*/ * @param root the DOM root of a PolicyIdReference or a PolicySetIdReference XML type * @param finder the <code>PolicyFinder</code> used to handle the reference * @param metaData the meta-data associated with the containing policy * @return an instance of PolicyReference * @exception ParsingException if the node is invalid */ public static PolicyReference getInstance(Node root, PolicyFinder finder, PolicyMetaData metaData) throws ParsingException { URI reference; int policyType; // see what type of reference we are String name = DOMHelper.getLocalName(root); if (name.equals("PolicyIdReference")) { policyType = POLICY_REFERENCE; } else if (name.equals("PolicySetIdReference")) { policyType = POLICYSET_REFERENCE; } else { throw new ParsingException("Unknown reference type: " + name); } // next get the reference try { reference = new URI(root.getFirstChild().getNodeValue()); } catch (Exception e) { throw new ParsingException("Invalid URI in Reference", e); } // now get any constraints NamedNodeMap map = root.getAttributes(); String versionConstraint = null; Node versionNode = map.getNamedItem("Version"); if (versionNode != null) versionConstraint = versionNode.getNodeValue(); String earlyConstraint = null; Node earlyNode = map.getNamedItem("EarliestVersion"); if (earlyNode != null) earlyConstraint = earlyNode.getNodeValue(); String lateConstraint = null; Node lateNode = map.getNamedItem("LatestVersion"); if (lateNode != null) lateConstraint = lateNode.getNodeValue(); VersionConstraints constraints = new VersionConstraints(versionConstraint, earlyConstraint, lateConstraint); // finally, create the reference return new PolicyReference(reference, policyType, constraints, finder, metaData); }