List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:com.zoho.creator.jframework.XMLParser.java
public static ZCView parseForView(Document rootDocument, String appLinkName, String appOwner, String componentType, int month, int year) throws ZCException { NodeList nl = rootDocument.getChildNodes(); ZCView toReturn = null;/*ww w. j a v a 2s . com*/ for (int i = 0; i < nl.getLength(); i++) { Node responseNode = nl.item(i); if (responseNode.getNodeName().equals("response")) { NodeList responseNodes = responseNode.getChildNodes(); for (int j = 0; j < responseNodes.getLength(); j++) { Node responseChildNode = responseNodes.item(j); if (responseChildNode.getNodeName().equals("errorlist")) { NodeList errorListNodes = responseChildNode.getChildNodes(); for (int o = 0; o < errorListNodes.getLength(); o++) { Node errorlistNode = errorListNodes.item(o); if (errorlistNode.getNodeName().equals("error")) { NodeList errorlistchildNodes = errorlistNode.getChildNodes(); int code = 0; boolean hasErrorOcured = false; String errorMessage = ""; for (int p = 0; p < errorlistchildNodes.getLength(); p++) { Node errorlistchildNode = errorlistchildNodes.item(p); if (errorlistchildNode.getNodeName().equals("code")) { code = getIntValue(errorlistchildNode, code); } else if (errorlistchildNode.getNodeName().equals("message")) { hasErrorOcured = true; errorMessage = getDecodedString(getStringValue(errorlistchildNode, "")); } } if (hasErrorOcured) { ZCException exception = new ZCException(errorMessage, ZCException.ERROR_OCCURED, ""); exception.setCode(code); throw exception; } } } } if (responseChildNode.getNodeName().equals("metadata")) { NodeList viewNodes = responseChildNode.getChildNodes(); for (int k = 0; k < viewNodes.getLength(); k++) { Node viewNode = viewNodes.item(k); if (viewNode.getNodeName().equals("View")) { NamedNodeMap attrMap = viewNode.getAttributes(); String componentLinkName = getDecodedString( attrMap.getNamedItem("LinkName").getNodeValue());//No I18N String componentName = getDecodedString(getChildNodeValue(viewNode, "DisplayName")); //No I18N String dateFormat = getDecodedString( attrMap.getNamedItem("DateFormat").getNodeValue());//No I18N //String appOwner, String appLinkName, String componentName, String componentLinkName toReturn = new ZCView(appOwner, appLinkName, componentType, componentName, componentLinkName); toReturn.setDateFormat(dateFormat); NodeList viewChildNodes = viewNode.getChildNodes(); for (int l = 0; l < viewChildNodes.getLength(); l++) { Node viewChildNode = viewChildNodes.item(l); if (viewChildNode.getNodeName().equals("BaseForm")) { NamedNodeMap baseFormAttrMap = viewChildNode.getAttributes(); String baseFormLinkName = getDecodedString( baseFormAttrMap.getNamedItem("linkname").getNodeValue()); //No I18N toReturn.setBaseFormLinkName(baseFormLinkName); } else if (viewChildNode.getNodeName().equals("customFilters")) { NodeList customFilterNodeList = viewChildNode.getChildNodes(); List<ZCCustomFilter> customFilters = new ArrayList<ZCCustomFilter>(); for (int m = 0; m < customFilterNodeList.getLength(); m++) { Node customFilterNode = customFilterNodeList.item(m); NamedNodeMap customFilterAttrMap = customFilterNode.getAttributes(); long id = Long.parseLong( customFilterAttrMap.getNamedItem("Id").getNodeValue()); //No I18N String customFilterName = getDecodedString( getChildNodeValue(customFilterNode, "DisplayName"));//No I18N ZCCustomFilter customFilter = new ZCCustomFilter(customFilterName, id); customFilters.add(customFilter); } toReturn.addCustomFilters(customFilters); } else if (viewChildNode.getNodeName().equals("filters")) { NodeList filterNodeList = viewChildNode.getChildNodes(); List<ZCFilter> filters = new ArrayList<ZCFilter>(); for (int m = 0; m < filterNodeList.getLength(); m++) { Node filterNode = filterNodeList.item(m); NamedNodeMap filterAttrMap = filterNode.getAttributes(); String FilterLinkName = getDecodedString( filterAttrMap.getNamedItem("name").getNodeValue()); //No I18N String filterName = getDecodedString( getChildNodeValue(filterNode, "displayname")); //filterAttrMap.getNamedItem("displayname").getNodeValue(); //No I18N ZCFilter filter = new ZCFilter(FilterLinkName, filterName); NodeList filterValuesList = filterNode.getChildNodes(); List<ZCFilterValue> filterValues = new ArrayList<ZCFilterValue>(); for (int n = 0; n < filterValuesList.getLength(); n++) { Node filterValueNode = filterValuesList.item(n); if (filterValueNode.getNodeName().equals("value")) { String filterValue = getDecodedString( getStringValue(filterValueNode, "")); //No I18N filterValue = filterValue .substring(filterValue.indexOf(":") + 1); String displayValue = filterValue; NamedNodeMap filterValAttrMap = filterValueNode.getAttributes(); if (filterValAttrMap.getLength() > 0) { displayValue = getDecodedString(filterValAttrMap .getNamedItem("display").getNodeValue());//No I18N } filterValues.add(new ZCFilterValue(filterValue, displayValue)); } } filter.addValues(filterValues); filters.add(filter); } toReturn.addFilters(filters); // } else if(viewChildNode.getNodeName().equals("rec_filter")) { // } else if(viewChildNode.getNodeName().equals("groupby")) { // } else if(viewChildNode.getNodeName().equals("opensearch")) { } else if (viewChildNode.getNodeName().equals("permissions")) { NamedNodeMap permissionAttrMap = viewChildNode.getAttributes(); boolean isAddAllowed = Boolean .parseBoolean(permissionAttrMap.getNamedItem("add").getNodeValue()); //No I18N boolean isEditAllowed = Boolean.parseBoolean( permissionAttrMap.getNamedItem("edit").getNodeValue()); //No I18N boolean isDeleteAllowed = Boolean.parseBoolean( permissionAttrMap.getNamedItem("delete").getNodeValue()); //No I18N boolean isDuplicateAllowed = Boolean.parseBoolean( permissionAttrMap.getNamedItem("duplicate").getNodeValue()); //No I18N boolean isBulkEditAllowed = Boolean.parseBoolean( permissionAttrMap.getNamedItem("bulkedit").getNodeValue()); //No I18N toReturn.setAddAllowed(isAddAllowed); toReturn.setEditAllowed(isEditAllowed); toReturn.setDeleteAllowed(isDeleteAllowed); toReturn.setDuplicateAllowed(isDuplicateAllowed); toReturn.setBulkEditAllowed(isBulkEditAllowed); } else if (viewChildNode.getNodeName().equals("Actions")) { NodeList actionList = viewChildNode.getChildNodes(); List<ZCCustomAction> headerCustomActions = new ArrayList<ZCCustomAction>(); List<ZCCustomAction> recordCustomActions = new ArrayList<ZCCustomAction>(); for (int m = 0; m < actionList.getLength(); m++) { Node actionNode = actionList.item(m); NamedNodeMap actionAttrMap = actionNode.getAttributes(); String actionType = getDecodedString( actionAttrMap.getNamedItem("type").getNodeValue()); //No I18N String actionName = getDecodedString( getChildNodeValue(actionNode, "name")); //actionAttrMap.getNamedItem("name").getNodeValue(); //No I18N String headerAction = getDecodedString( getChildNodeValue(actionNode, "isHeaderAction"));//No I18N Long actionId = Long .parseLong(actionAttrMap.getNamedItem("id").getNodeValue()); //No I18N ZCCustomAction action = new ZCCustomAction(actionType, actionName, actionId); if (actionType.equals("row")) { recordCustomActions.add(action); } if (headerAction.equals("true")) { headerCustomActions.add(action); } } toReturn.addHeaderCustomActions(headerCustomActions); toReturn.addRecordCustomActions(recordCustomActions); } else if (viewChildNode.getNodeName().equals("Fields")) { // String fieldName, int type, String displayName, String delugeType, long compID List<ZCColumn> columns = new ArrayList<ZCColumn>(); NodeList fieldList = viewChildNode.getChildNodes(); for (int m = 0; m < fieldList.getLength(); m++) { Node fieldNode = fieldList.item(m); NamedNodeMap fieldAttrMap = fieldNode.getAttributes(); String displayName = getDecodedString( getChildNodeValue(fieldNode, "DisplayName")); //fieldAttrMap.getNamedItem("DisplayName").getNodeValue(); //No I18N String fieldName = getDecodedString( fieldAttrMap.getNamedItem("BaseLabelName").getNodeValue()); //No I18N String compType = getDecodedString( fieldAttrMap.getNamedItem("ComponentType").getNodeValue()); //No I18N FieldType fieldType = FieldType.getFieldType(compType); int seqNo = Integer.parseInt( fieldAttrMap.getNamedItem("SequenceNumber").getNodeValue()); //No I18N ZCColumn column = new ZCColumn(fieldName, fieldType, displayName); column.setSequenceNumber(seqNo); columns.add(column); } Collections.sort(columns); toReturn.addColumns(columns); } } } } } else if (responseChildNode.getNodeName().equals("records")) { parseAndSetRecords(toReturn, responseChildNode); } else if (responseChildNode.getNodeName().equals("calendar")) { toReturn.setRecordsMonthYear(new ZCPair<Integer, Integer>(month, year)); parseAndSetCalendarRecords(toReturn, responseChildNode); } } } } //printDocument(rootDocument); return toReturn; }
From source file:de.unigoettingen.sub.commons.contentlib.imagelib.JpegInterpreter.java
/************************************************************************************ * get Dom {@link Node} of attribute from parent {@link Node} with given name * // w w w . j a v a 2 s . c om * @param inNode the parent {@link Node} * @param attributeName the name of the attribute to look for ************************************************************************************/ private Node getAttributeByName(Node inNode, String attributeName) { NamedNodeMap nnm = inNode.getAttributes(); return nnm.getNamedItem(attributeName); }
From source file:com.connexta.arbitro.ConfigurationStore.java
/** * Private helper that gets a default factory identifier, or fills in the default value if no * identifier is provided.//from w ww . j a v a 2s. com */ private String getDefaultFactory(NamedNodeMap attrs, String factoryName) { Node node = attrs.getNamedItem(factoryName); if (node != null) return node.getNodeValue(); else return XACMLConstants.XACML_1_0_IDENTIFIER; }
From source file:com.fluidops.iwb.provider.XMLProvider.java
protected String getNodeTextContent(NamedNodeMap nnm, String prop) { Node n = nnm.getNamedItem(prop); return n == null ? null : n.getTextContent(); }
From source file:hoot.services.models.osm.Element.java
protected long parseChangesetId(final NamedNodeMap xmlAttributes) throws Exception { long elementChangesetId = -1; try {/*w ww. j a v a 2 s . com*/ elementChangesetId = Long.parseLong(xmlAttributes.getNamedItem("changeset").getNodeValue()); } catch (NumberFormatException e) { } if (elementChangesetId != requestChangesetId) { throw new Exception("Invalid changeset ID: " + elementChangesetId + " for " + toString() + ". Expected changeset ID: " + requestChangesetId); } return elementChangesetId; }
From source file:org.kuali.mobility.maps.service.LocationServiceImpl.java
private List<MapsGroup> iterateMapsGroupNodes(NodeList nodes, Map<String, MapsGroup> map, MapsGroup mapsGroupParent) {/*from w ww. java2s. com*/ List<MapsGroup> mapsGroups = new ArrayList<MapsGroup>(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); NamedNodeMap nodeMap = node.getAttributes(); try { if (node.getNodeName().equals("group")) { String mapsGroupCode = nodeMap.getNamedItem("groupCode").getNodeValue(); if (map.get(mapsGroupCode) == null) { MapsGroup mapsGroup = new MapsGroup(); mapsGroup.setGroupCode(nodeMap.getNamedItem("groupCode").getNodeValue()); mapsGroup.setName(nodeMap.getNamedItem("name").getNodeValue()); mapsGroup.setShortName(nodeMap.getNamedItem("shortName").getNodeValue()); if (mapsGroupParent != null) { mapsGroup.setMapsGroupParent(mapsGroupParent); } // Store group to map so we don't run it more than once map.put(mapsGroup.getGroupCode(), mapsGroup); // Store group to list for returning processed MapsGroups to calling method mapsGroups.add(mapsGroup); // Done processing mapsgroup node, find children of this mapsgroup NodeList childNodes = node.getChildNodes(); Set<MapsGroup> mapsGroupChildren = new HashSet<MapsGroup>(); mapsGroupChildren.addAll(this.iterateMapsGroupNodes(childNodes, map, mapsGroup)); mapsGroup.setMapsGroupChildren(mapsGroupChildren); } else { // LOG.info("MapsGroup code already loaded in this run: " + mapsGroupCode); } } else if (node.getNodeName().equals("location")) { Location location = new Location(); location.setCode(nodeMap.getNamedItem("code").getNodeValue()); if (mapsGroupParent != null) { if (mapsGroupParent.getMapsLocations() == null) { mapsGroupParent.setMapsLocations(new HashSet<Location>()); } mapsGroupParent.getMapsLocations().add(location); } } } catch (Exception e) { // LOG.error("Error loading data from node: ", e); } } return mapsGroups; }
From source file:XMLConfig.java
private void getMultipleAddAttributesHelper(String path, Node n, List<Node> accum) { if ((path.indexOf('.') > -1) || (path.indexOf('/') > -1)) { throw new XMLConfigException( "An attribute cannot have subparts (foo.bar.fum and foo.bar/fum not allowed)"); }/* w ww . java2s . c o m*/ NamedNodeMap attrMap = n.getAttributes(); if (path.equals("*")) { for (int i = 0; i < attrMap.getLength(); ++i) { Node attr = attrMap.item(i); accum.add(attr); } } else { Node attr = attrMap.getNamedItem(path); if (attr != null) { accum.add(attr); } } }
From source file:net.sf.l2j.gameserver.instancemanager.DimensionalRiftManager.java
public void loadSpawns() { int countGood = 0, countBad = 0; try {// w w w. j ava 2 s .c o m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringComments(true); File file = new File(Config.DATAPACK_ROOT + "/data/dimensionalRift.xml"); if (!file.exists()) throw new IOException(); Document doc = factory.newDocumentBuilder().parse(file); NamedNodeMap attrs; byte type, roomId; int mobId, x, y, z, delay, count; L2Spawn spawnDat; L2NpcTemplate template; for (Node rift = doc.getFirstChild(); rift != null; rift = rift.getNextSibling()) { if ("rift".equalsIgnoreCase(rift.getNodeName())) { for (Node area = rift.getFirstChild(); area != null; area = area.getNextSibling()) { if ("area".equalsIgnoreCase(area.getNodeName())) { attrs = area.getAttributes(); type = Byte.parseByte(attrs.getNamedItem("type").getNodeValue()); for (Node room = area.getFirstChild(); room != null; room = room.getNextSibling()) { if ("room".equalsIgnoreCase(room.getNodeName())) { attrs = room.getAttributes(); roomId = Byte.parseByte(attrs.getNamedItem("id").getNodeValue()); for (Node spawn = room.getFirstChild(); spawn != null; spawn = spawn .getNextSibling()) { if ("spawn".equalsIgnoreCase(spawn.getNodeName())) { attrs = spawn.getAttributes(); mobId = Integer.parseInt(attrs.getNamedItem("mobId").getNodeValue()); delay = Integer.parseInt(attrs.getNamedItem("delay").getNodeValue()); count = Integer.parseInt(attrs.getNamedItem("count").getNodeValue()); template = NpcTable.getInstance().getTemplate(mobId); if (template == null) _log.warn("Template " + mobId + " not found!"); if (!_rooms.containsKey(type)) _log.warn("Type " + type + " not found!"); else if (!_rooms.get(type).containsKey(roomId)) _log.warn("Room " + roomId + " in Type " + type + " not found!"); for (int i = 0; i < count; i++) { DimensionalRiftRoom riftRoom = _rooms.get(type).get(roomId); x = riftRoom.getRandomX(); y = riftRoom.getRandomY(); z = riftRoom.getTeleportCoords()[2]; if (template != null && _rooms.containsKey(type) && _rooms.get(type).containsKey(roomId)) { spawnDat = new L2Spawn(template); spawnDat.setAmount(1); spawnDat.setLocx(x); spawnDat.setLocy(y); spawnDat.setLocz(z); spawnDat.setHeading(-1); spawnDat.setRespawnDelay(delay); SpawnTable.getInstance().addNewSpawn(spawnDat, false); _rooms.get(type).get(roomId).getSpawns().add(spawnDat); countGood++; } else { countBad++; } } } } } } } } } } } catch (Exception e) { _log.warn("Error on loading dimensional rift spawns: " + e); e.printStackTrace(); } _log.info("DimensionalRiftManager: Loaded " + countGood + " dimensional rift spawns, " + countBad + " errors."); }
From source file:com.connexta.arbitro.ConfigurationStore.java
/** * Private helper used by the three factory routines to see if the given factory should be based * on the standard setup/*from ww w. j a va 2 s . co m*/ */ private boolean useStandard(Node node, String attributeName) { NamedNodeMap map = node.getAttributes(); if (map == null) return true; Node attrNode = map.getNamedItem(attributeName); if (attrNode == null) return true; return attrNode.getNodeValue().equals("true"); }
From source file:com.connexta.arbitro.ConfigurationStore.java
/** * Private helper function used by both constructors to actually load the configuration data. * This is the root of several private methods used to setup all the pdps and factories. * * @param configFile The configuration {@link File} to be loaded *///from w w w .j ava2 s. c om private void setupConfig(File configFile) throws ParsingException { logger.info("Loading runtime configuration"); // load our classloader loader = getClass().getClassLoader(); // get the root node from the configuration file Node root = getRootNode(configFile); // initialize all the maps pdpConfigMap = new HashMap(); attributeMap = new HashMap(); combiningMap = new HashMap(); functionMap = new HashMap(); // get the default names NamedNodeMap attrs = root.getAttributes(); String defaultPDP = attrs.getNamedItem("defaultPDP").getNodeValue(); String defaultAF = getDefaultFactory(attrs, "defaultAttributeFactory"); String defaultCAF = getDefaultFactory(attrs, "defaultCombiningAlgFactory"); String defaultFF = getDefaultFactory(attrs, "defaultFunctionFactory"); // loop through all the root-level elements, for each one getting its // name and then loading the right kind of element NodeList children = root.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String childName = DOMHelper.getLocalName(child); String elementName = null; // get the element's name if (child.getNodeType() == Node.ELEMENT_NODE) elementName = child.getAttributes().getNamedItem("name").getNodeValue(); // see if this is a pdp or a factory, and load accordingly, // putting the new element into the respective map...make sure // that we're never loading something with the same name twice if (childName.equals("pdp")) { if (logger.isDebugEnabled()) logger.debug("Loading PDP: " + elementName); if (pdpConfigMap.containsKey(elementName)) throw new ParsingException("more that one pdp with " + "name \"" + elementName + "\""); pdpConfigMap.put(elementName, parsePDPConfig(child)); } else if (childName.equals("attributeFactory")) { if (logger.isDebugEnabled()) logger.debug("Loading AttributeFactory: " + elementName); if (attributeMap.containsKey(elementName)) throw new ParsingException( "more that one " + "attributeFactory with name " + elementName + "\""); attributeMap.put(elementName, parseAttributeFactory(child)); } else if (childName.equals("combiningAlgFactory")) { if (logger.isDebugEnabled()) logger.debug("Loading CombiningAlgFactory: " + elementName); if (combiningMap.containsKey(elementName)) throw new ParsingException( "more that one " + "combiningAlgFactory with " + "name \"" + elementName + "\""); combiningMap.put(elementName, parseCombiningAlgFactory(child)); } else if (childName.equals("functionFactory")) { if (logger.isDebugEnabled()) logger.debug("Loading FunctionFactory: " + elementName); if (functionMap.containsKey(elementName)) throw new ParsingException( "more that one functionFactory" + " with name \"" + elementName + "\""); functionMap.put(elementName, parseFunctionFactory(child)); } } // finally, extract the default elements defaultPDPConfig = (PDPConfig) (pdpConfigMap.get(defaultPDP)); defaultAttributeFactoryProxy = (AttributeFactoryProxy) (attributeMap.get(defaultAF)); if (defaultAttributeFactoryProxy == null) { try { defaultAttributeFactoryProxy = new AFProxy(AttributeFactory.getInstance(defaultAF)); } catch (Exception e) { throw new ParsingException("Unknown AttributeFactory", e); } } defaultCombiningFactoryProxy = (CombiningAlgFactoryProxy) (combiningMap.get(defaultCAF)); if (defaultCombiningFactoryProxy == null) { try { defaultCombiningFactoryProxy = new CAFProxy(CombiningAlgFactory.getInstance(defaultCAF)); } catch (Exception e) { throw new ParsingException("Unknown CombininAlgFactory", e); } } defaultFunctionFactoryProxy = (FunctionFactoryProxy) (functionMap.get(defaultFF)); if (defaultFunctionFactoryProxy == null) { try { defaultFunctionFactoryProxy = FunctionFactory.getInstance(defaultFF); } catch (Exception e) { throw new ParsingException("Unknown FunctionFactory", e); } } }