List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:it.unibo.alchemist.language.EnvironmentBuilder.java
/** * Actually builds the environment given the AST built in the constructor. * /*from w ww. ja v a2 s. com*/ * @throws InstantiationException * malformed XML * @throws IllegalAccessException * malformed XML * @throws InvocationTargetException * malformed XML * @throws ClassNotFoundException * your classpath does not include all the classes you are using * @throws IOException * if there is an error reading the file * @throws SAXException * if the XML is not correctly formatted * @throws ParserConfigurationException * should not happen. */ private void buildEnvironment() throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, SAXException, IOException, ParserConfigurationException { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = factory.newDocumentBuilder(); final Document doc = builder.parse(xmlFile); L.debug("Starting processing"); random = null; final Node root = doc.getFirstChild(); if (root.getNodeName().equals("environment") && doc.getChildNodes().getLength() == 1) { final NamedNodeMap atts = root.getAttributes(); String type = atts.getNamedItem(TYPE).getNodeValue(); type = type.contains(".") ? type : "it.unibo.alchemist.model.implementations.environments." + type; result = coreOperations(new ConcurrentHashMap<String, Object>(), root, type, null); synchronized (result) { final Node nameNode = atts.getNamedItem(NAME); final String name = nameNode == null ? "" : nameNode.getNodeValue(); final Map<String, Object> env = new ConcurrentHashMap<String, Object>(); env.put("ENV", result); if (!name.equals("")) { env.put(name, result); } final NodeList children = root.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node son = children.item(i); final String kind = son.getNodeName(); L.debug(kind); if (!kind.equals(TEXT)) { final Node sonNameAttr = son.getAttributes().getNamedItem(NAME); final String sonName = sonNameAttr == null ? "" : sonNameAttr.getNodeValue(); Object sonInstance = null; if (kind.equals("molecule")) { sonInstance = buildMolecule(son, env); } else if (kind.equals("concentration")) { if (concentrationClass == null) { setConcentration(son); } } else if (kind.equals("position")) { if (positionClass == null) { setPosition(son); } } else if (kind.equals("random")) { setRandom(son, env); } else if (kind.equals("linkingrule")) { result.setLinkingRule(buildLinkingRule(son, env)); } else if (kind.equals("condition")) { sonInstance = buildCondition(son, env); } else if (kind.equals("action")) { sonInstance = buildAction(son, env); } else if (kind.equals("reaction")) { sonInstance = buildReaction(son, env); } else if (kind.equals("node")) { final it.unibo.alchemist.model.interfaces.Node<T> node = buildNode(son, env); final Position pos = buildPosition(son, env); sonInstance = node; result.addNode(node, pos); } else if (kind.equals("time")) { sonInstance = buildTime(son, env); } if (sonInstance != null) { env.put(sonName, sonInstance); } } } /* * This operation forces a reset to the random generator. It * ensures that if the user reloads the same random seed she * passed in the specification, the simulation will still be * reproducible. */ random.setSeed(seed); } } else { L.error("XML does not contain one and one only environment."); } }
From source file:com.connexta.arbitro.AbstractPolicy.java
/** * Constructor used by child classes to initialize the shared data from a DOM root node. * * @param root the DOM root of the policy * @param policyPrefix either "Policy" or "PolicySet" * @param combiningName name of the field naming the combining alg * the XACML policy, if null use default factories * @throws ParsingException if the policy is invalid *///from w w w .j a v a 2s.com protected AbstractPolicy(Node root, String policyPrefix, String combiningName) throws ParsingException { // get the attributes, all of which are common to Policies NamedNodeMap attrs = root.getAttributes(); try { // get the attribute Id idAttr = new URI(attrs.getNamedItem(policyPrefix + "Id").getNodeValue()); } catch (Exception e) { throw new ParsingException("Error parsing required attribute " + policyPrefix + "Id", e); } // see if there's a version Node versionNode = attrs.getNamedItem("Version"); if (versionNode != null) { version = versionNode.getNodeValue(); } else { // assign the default version version = "1.0"; } // now get the combining algorithm... try { URI algId = new URI(attrs.getNamedItem(combiningName).getNodeValue()); CombiningAlgFactory factory = Balana.getInstance().getCombiningAlgFactory(); combiningAlg = factory.createAlgorithm(algId); } catch (Exception e) { throw new ParsingException("Error parsing combining algorithm" + " in " + policyPrefix, e); } // ...and make sure it's the right kind if (policyPrefix.equals("Policy")) { if (!(combiningAlg instanceof RuleCombiningAlgorithm)) throw new ParsingException("Policy must use a Rule " + "Combining Algorithm"); } else { if (!(combiningAlg instanceof PolicyCombiningAlgorithm)) throw new ParsingException("PolicySet must use a Policy " + "Combining Algorithm"); } // do an initial pass through the elements to pull out the // defaults, if any, so we can setup the meta-data NodeList children = root.getChildNodes(); String xpathVersion = null; for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (DOMHelper.getLocalName(child).equals(policyPrefix + "Defaults")) handleDefaults(child); } // with the defaults read, create the meta-data metaData = new PolicyMetaData(root.getNamespaceURI(), defaultVersion); // now read the remaining policy elements obligationExpressions = new HashSet<AbstractObligation>(); adviceExpressions = new HashSet<AdviceExpression>(); parameters = new ArrayList<CombinerParameter>(); children = root.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); String cname = DOMHelper.getLocalName(child); if (cname.equals("Description")) { if (child.hasChildNodes()) { description = child.getFirstChild().getNodeValue(); } } else if (cname.equals("Target")) { target = TargetFactory.getFactory().getTarget(child, metaData); } else if (cname.equals("ObligationExpressions") || cname.equals("Obligations")) { parseObligationExpressions(child); } else if (cname.equals("AdviceExpressions")) { parseAdviceExpressions(child); } else if (cname.equals("CombinerParameters")) { handleParameters(child); } } // finally, make sure the obligations and parameters are immutable obligationExpressions = Collections.unmodifiableSet(obligationExpressions); adviceExpressions = Collections.unmodifiableSet(adviceExpressions); parameters = Collections.unmodifiableList(parameters); }
From source file:it.unibo.alchemist.language.EnvironmentBuilder.java
private it.unibo.alchemist.model.interfaces.Node<T> buildNode(final Node rootNode, final Map<String, Object> env) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { final NamedNodeMap attributes = rootNode.getAttributes(); final Node nameNode = attributes.getNamedItem(NAME); final String name = nameNode == null ? "" : nameNode.getNodeValue(); String type = attributes.getNamedItem(TYPE).getNodeValue(); type = type.contains(".") ? type : "it.unibo.alchemist.model.implementations.nodes." + type; final it.unibo.alchemist.model.interfaces.Node<T> res = coreOperations(env, rootNode, type, random); if (res == null) { L.error("Failed to build " + type); }//from w w w .jav a 2 s . co m env.put(name, res); env.put("NODE", res); final NodeList children = rootNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node son = children.item(i); final String kind = son.getNodeName(); if (!kind.equals(TEXT)) { final Node sonNameAttr = son.getAttributes().getNamedItem(NAME); final String sonName = sonNameAttr == null ? "" : sonNameAttr.getNodeValue(); String objType = null; Object sonInstance = null; if (kind.equals("condition")) { final Condition<T> cond = buildCondition(son, env); sonInstance = cond; objType = "CONDITION"; } else if (kind.equals("action")) { final Action<T> act = buildAction(son, env); sonInstance = act; objType = "ACTION"; } else if (kind.equals("content")) { final NamedNodeMap moleculesMap = son.getAttributes(); for (int j = 0; j < moleculesMap.getLength(); j++) { final Node molNode = moleculesMap.item(j); final String molName = molNode.getNodeName(); L.debug("checking molecule " + molName); if (env.containsKey(molName)) { L.debug(molName + " found"); final Object molObj = env.get(molName); if (molObj instanceof Molecule) { L.debug(molName + " matches in environment"); final Molecule mol = (Molecule) molObj; final T conc = buildConcentration(molNode, env); L.debug(molName + " concentration: " + conc); sonInstance = conc; res.setConcentration(mol, conc); } else { L.warn(molObj + "(class " + molObj.getClass().getCanonicalName() + " is not subclass of Molecule!"); } } else { L.warn("molecule " + molName + " is not yet defined."); } } } else if (kind.equals("reaction")) { final Reaction<T> reaction = buildReaction(son, env); res.addReaction(reaction); sonInstance = reaction; objType = "REACTION"; } else if (kind.equals("time")) { sonInstance = buildTime(son, env); } else if (kind.equals("timedistribution")) { sonInstance = buildTimeDist(son, env); objType = "TIMEDIST"; } updateEnv(sonName, objType, sonInstance, env); } } env.remove(name); env.remove("NODE"); return res; }
From source file:net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.java
/** * *//*w w w . j a va 2 s .c o m*/ @SuppressWarnings("deprecation") private SimpleFontFamily parseFontFamily(JasperReportsContext jasperReportsContext, Node fontFamilyNode, boolean loadFonts) throws SAXException { SimpleFontFamily fontFamily = new SimpleFontFamily(jasperReportsContext); NamedNodeMap nodeAttrs = fontFamilyNode.getAttributes(); if (nodeAttrs.getNamedItem(ATTRIBUTE_name) != null) { fontFamily.setName(nodeAttrs.getNamedItem(ATTRIBUTE_name).getNodeValue()); if (log.isDebugEnabled()) { log.debug("Parsing font family " + fontFamily.getName()); } } if (nodeAttrs.getNamedItem(ATTRIBUTE_visible) != null) { fontFamily.setVisible(Boolean.valueOf(nodeAttrs.getNamedItem(ATTRIBUTE_visible).getNodeValue())); } NodeList nodeList = fontFamilyNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { if (NODE_normal.equals(node.getNodeName())) { fontFamily.setNormalFace(parseFontFace(jasperReportsContext, node, loadFonts)); } else if (NODE_bold.equals(node.getNodeName())) { fontFamily.setBoldFace(parseFontFace(jasperReportsContext, node, loadFonts)); } else if (NODE_italic.equals(node.getNodeName())) { fontFamily.setItalicFace(parseFontFace(jasperReportsContext, node, loadFonts)); } else if (NODE_boldItalic.equals(node.getNodeName())) { fontFamily.setBoldItalicFace(parseFontFace(jasperReportsContext, node, loadFonts)); } else if (NODE_normalPdfFont.equals(node.getNodeName())) { fontFamily.setNormalPdfFont(node.getTextContent()); } else if (NODE_boldPdfFont.equals(node.getNodeName())) { fontFamily.setBoldPdfFont(node.getTextContent()); } else if (NODE_italicPdfFont.equals(node.getNodeName())) { fontFamily.setItalicPdfFont(node.getTextContent()); } else if (NODE_boldItalicPdfFont.equals(node.getNodeName())) { fontFamily.setBoldItalicPdfFont(node.getTextContent()); } else if (NODE_pdfEncoding.equals(node.getNodeName())) { fontFamily.setPdfEncoding(node.getTextContent()); } else if (NODE_pdfEmbedded.equals(node.getNodeName())) { fontFamily.setPdfEmbedded(Boolean.valueOf(node.getTextContent())); } else if (NODE_exportFonts.equals(node.getNodeName())) { fontFamily.setExportFonts(parseExportFonts(node)); } else if (NODE_locales.equals(node.getNodeName())) { fontFamily.setLocales(parseLocales(node)); } } } return fontFamily; }
From source file:com.zoho.creator.jframework.XMLParser.java
private static ZCRecord parseAndSetRecord(ZCView zcView, Node recordNode, List<ZCField> subFormFields) { NamedNodeMap recordAttrMap = recordNode.getAttributes(); long recordid = 0L; if (recordAttrMap.getNamedItem("id") != null) { recordid = Long.parseLong(recordAttrMap.getNamedItem("id").getNodeValue()); //No I18N } else {//from w w w . j av a 2 s . com recordid = Long.parseLong(recordAttrMap.getNamedItem("ID").getNodeValue()); //No I18N } List<ZCRecordValue> valueList = new ArrayList<ZCRecordValue>(); NodeList columnList = recordNode.getChildNodes(); for (int l = 0; l < columnList.getLength(); l++) { Node columnNode = columnList.item(l); NamedNodeMap columAttrMap = columnNode.getAttributes(); String fieldName = getDecodedString(columAttrMap.getNamedItem("name").getNodeValue()); //No I18N ZCField zcField = null; if (zcView != null) { zcField = zcView.getColumn(fieldName); } else { for (int m = 0; m < subFormFields.size(); m++) { ZCField fieldToCheck = subFormFields.get(m); if (fieldToCheck.getFieldName().equals(fieldName)) { zcField = fieldToCheck; break; } } } if (zcField == null) { break; } Node valueNode = columnNode.getFirstChild(); String value = getDecodedString(getStringValue(valueNode, "")); NodeList columnvalueList = columnNode.getChildNodes(); List<ZCChoice> selectedChoices = new ArrayList<ZCChoice>(); ZCChoice selectedChoice = null; List<ZCChoice> choices = null; if (zcView == null) { choices = zcField.getRecordValue().getChoices(); if (FieldType.isChoiceField(zcField.getType())) { for (int i = 0; i < columnvalueList.getLength(); i++) { Node columnvaluelistChildnode = columnvalueList.item(i); Node columnvaluelistvaluenode = columnvaluelistChildnode.getAttributes() .getNamedItem("value");//No I18N if (columnvaluelistvaluenode != null) { String key = getDecodedString(columnvaluelistvaluenode.getNodeValue()); for (int j = 0; j < choices.size(); j++) { if (key.equals(choices.get(j).getKey())) { selectedChoices .add(new ZCChoice(key, getStringValue(columnvaluelistChildnode, ""))); break; } } if (zcField.isLookup()) { selectedChoices .add(new ZCChoice(key, getStringValue(columnvaluelistChildnode, ""))); } } } } if (selectedChoices.size() > 0) { selectedChoice = selectedChoices.get(0); } } else { if (value.startsWith("[") && value.endsWith("]")) { value = value.substring(1, value.length() - 1); } String[] tokens = value.split(", "); for (int m = 0; m < tokens.length; m++) { if (!(tokens[m].equals(""))) { String initialValue = tokens[m]; selectedChoices.add(new ZCChoice(initialValue, initialValue)); } } selectedChoice = new ZCChoice(value, value); } ZCRecordValue zcValue = null; if (FieldType.isMultiChoiceField(zcField.getType())) { zcValue = new ZCRecordValue(zcField, selectedChoices); zcValue.addChoices(choices); } else if (FieldType.isSingleChoiceField(zcField.getType())) { zcValue = new ZCRecordValue(zcField, selectedChoice); zcValue.addChoices(choices); } else if (zcField.getType() == FieldType.URL) { String urlLinkNameValue = ""; String urlTitleValue = ""; NodeList urlTagNodes = valueNode.getChildNodes(); for (int m = 0; m < urlTagNodes.getLength(); m++) { Node urlNode = urlTagNodes.item(m); if (urlNode.getNodeName().equals("linkname")) { urlLinkNameValue = getStringValue(urlNode, urlLinkNameValue); } else if (urlNode.getNodeName().equals("url")) { value = getStringValue(urlNode, ""); } else if (urlNode.getNodeName().equals("title")) { urlTitleValue = getStringValue(urlNode, urlTitleValue); } } zcValue = new ZCRecordValue(zcField, getStringValue(valueNode, ""), urlTitleValue, urlLinkNameValue); } else if (FieldType.RICH_TEXT.equals(zcField.getType())) { zcValue = new ZCRecordValue(zcField, getStringValue(valueNode, "")); } else { zcValue = new ZCRecordValue(zcField, value); } if (zcView != null) { zcField.setRecordValue(zcValue); } valueList.add(zcValue); } ZCRecord record = new ZCRecord(recordid, valueList); return record; }
From source file:com.zoho.creator.jframework.XMLParser.java
static List<ZCSection> parseForSectionList(Document rootDocument, String appLinkName, String appOwner) throws ZCException { List<ZCSection> toReturn = new ArrayList<ZCSection>(); NodeList nl = rootDocument.getChildNodes(); 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 responseNodeChild = responseNodes.item(j); if (responseNodeChild.getNodeName().equals("error")) { throw new ZCException(getStringValue(responseNodeChild, "error"), ZCException.ERROR_OCCURED, "");//No I18N } else if (responseNodeChild.getNodeName().equals("Sections")) { NodeList sectionsNodes = responseNodeChild.getChildNodes(); for (int k = 0; k < sectionsNodes.getLength(); k++) { Node sectionNode = sectionsNodes.item(k); if (sectionNode.getNodeName().equals("Section")) { NodeList sectionNodes = sectionNode.getChildNodes(); String sectionName = null; boolean isHidden = false; String sectionLinkName = null; long sectionID = -1L; Date modifiedTime = null; List<ZCComponent> comps = new ArrayList<ZCComponent>(); for (int l = 0; l < sectionNodes.getLength(); l++) { Node sectionNodeChild = sectionNodes.item(l); String nodeName = sectionNodeChild.getNodeName(); if (nodeName.equals("Display_Name")) { sectionName = getStringValue(sectionNodeChild, ""); //No I18N } else if (nodeName.equals("Is_Hidden")) { isHidden = getBooleanValue(sectionNodeChild, isHidden); //No I18N } else if (nodeName.equals("Link_Name")) { sectionLinkName = getStringValue(sectionNodeChild, ""); //No I18N } else if (nodeName.equals("Section_ID")) { sectionID = getLongValue(sectionNodeChild, sectionID); //No I18N } else if (nodeName.equals("Modified_Time")) { modifiedTime = getDateValue(sectionNodeChild, modifiedTime, "yyyy-MM-dd HH:mm:ss.S"); //No I18N // 2013-04-01 14:28:58.0 } else if (nodeName.equals("Components")) { NodeList ComponentsNodes = sectionNodeChild.getChildNodes(); for (int m = 0; m < ComponentsNodes.getLength(); m++) { Node componentNode = ComponentsNodes.item(m); if (componentNode.getNodeName().equals("Component")) { NamedNodeMap attrMap = componentNode.getAttributes(); Node typeNode = attrMap.getNamedItem("type");//No I18N String type = typeNode.getNodeValue(); NodeList componentNodes = componentNode.getChildNodes(); String componentName = null; String componentLinkName = null; int sequenceNumber = -1; long componentID = -1L; for (int n = 0; n < componentNodes.getLength(); n++) { Node componentNodeChild = componentNodes.item(n); String componentNodeName = componentNodeChild.getNodeName(); String nodeValue = getStringValue(componentNodeChild, ""); if (componentNodeName.equals("Display_Name")) { componentName = nodeValue; } else if (componentNodeName.equals("Link_Name")) { componentLinkName = nodeValue; } else if (componentNodeName.equals("Secquence")) { sequenceNumber = Integer.parseInt(nodeValue); } else if (componentNodeName.equals("Component_ID")) { componentID = Long.valueOf(nodeValue); } } if (ZCComponent.isCompTypeSupported(type)) { comps.add(new ZCComponent(appOwner, appLinkName, type, componentName, componentLinkName, sequenceNumber)); } } }/* ww w . j av a 2 s . c o m*/ } } ZCSection zcSection = new ZCSection(appOwner, appLinkName, sectionName, sectionLinkName, isHidden, sectionID, modifiedTime); zcSection.addComponents(comps); toReturn.add(zcSection); } } } } } else if (responseNode.getNodeName().equals("license_enabled")) { //No I18N if (!getBooleanValue(responseNode, false)) { throw new ZCException( resourceString.getString("please_subscribe_to_professional_edition_and_get_access"), ZCException.LICENCE_ERROR); //No I18N } } else if (responseNode.getNodeName().equals("evaluationDays")) { //No I18N ZOHOCreator.setUserProperty("evaluationDays", getStringValue(responseNode, ""));//No I18N } } return toReturn; }
From source file:com.stratio.qa.cucumber.testng.CucumberReporter.java
private int getElementsCountByAttribute(Node node, String attributeName, String attributeValue) { int count = 0; for (int i = 0; i < node.getChildNodes().getLength(); i++) { count += getElementsCountByAttribute(node.getChildNodes().item(i), attributeName, attributeValue); }/*from w w w . j av a 2 s .co m*/ NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { Node namedItem = attributes.getNamedItem(attributeName); if (namedItem != null && namedItem.getNodeValue().matches(attributeValue)) { count++; } } return count; }
From source file:com.zoho.creator.jframework.XMLParser.java
private static void parseAndSetCalendarRecords(ZCView zcView, Node calendarNode) { zcView.setGrouped(true);//from w w w. ja va 2s . c om NodeList eventsList = calendarNode.getChildNodes(); int year = zcView.getRecordsMonthYear().getTwo() - 1900; int month = zcView.getRecordsMonthYear().getOne(); GregorianCalendar cureentmnthcalendar = new GregorianCalendar(); Date currentDate = new Date(); for (int i = 0; i < eventsList.getLength(); i++) { Node eventNode = eventsList.item(i); NamedNodeMap eventAttrMap = eventNode.getAttributes(); long recordid = Long.parseLong(eventAttrMap.getNamedItem("id").getNodeValue()); //No I18N String title = getChildNodeValue(eventNode, "title"); //eventAttrMap.getNamedItem("title").getNodeValue(); //No I18N boolean isAllDay = Boolean.parseBoolean(eventAttrMap.getNamedItem("allDay").getNodeValue()); //No I18N // 07/31/2013 08:00:00 String dateFormat = "MM/dd/yyyy HH:mm:ss"; //No I18N if (isAllDay) { dateFormat = "MM/dd/yyyy"; //No I18N } Date startTime = getDateValue(eventAttrMap.getNamedItem("start").getNodeValue(), dateFormat); //No I18N ZCRecord record = zcView.getRecord(recordid); record.setEventTitle(title); if (isAllDay) { zcView.setIsAllDay(isAllDay); Node endNode = eventAttrMap.getNamedItem("end");//No I18N Date endTime = null; if (endNode != null) { endTime = getDateValue(endNode.getNodeValue(), dateFormat); } int startDay = -1; if (startTime != null) { startDay = startTime.getDate(); } int endDay = -1; if (endTime != null) { endDay = endTime.getDate(); } if (endDay != -1) { currentDate.setDate(1); currentDate.setMonth(month); currentDate.setYear(year); currentDate.setMinutes(0); currentDate.setHours(0); currentDate.setSeconds(0); cureentmnthcalendar.setTime(currentDate); cureentmnthcalendar.add(cureentmnthcalendar.DAY_OF_MONTH, -6); currentDate = cureentmnthcalendar.getTime(); for (int j = 0; j < 42; j++) { if ((currentDate.getDate() == startTime.getDate() && currentDate.getMonth() == startTime.getMonth() && currentDate.getYear() == startTime.getYear()) || (currentDate.after(startTime) && currentDate.before(endTime)) || (currentDate.getDate() == endTime.getDate() && currentDate.getMonth() == endTime.getMonth() && currentDate.getYear() == endTime.getYear())) { zcView.setEvent(record, currentDate); } cureentmnthcalendar.add(cureentmnthcalendar.DAY_OF_MONTH, 1); currentDate = cureentmnthcalendar.getTime(); } //Collections.sort(eventRecords); } record.setEventDate(startTime); } else { // 07/31/2013 08:00:00 Date endTime = getDateValue(eventAttrMap.getNamedItem("end").getNodeValue(), dateFormat); //No I18N record.setStartTime(startTime); record.setEndTime(endTime); Calendar startCalendar = new GregorianCalendar(); startCalendar.setTime(startTime); startCalendar.set(Calendar.HOUR_OF_DAY, 0); startCalendar.set(Calendar.MINUTE, 0); startCalendar.set(Calendar.SECOND, 0); startCalendar.set(Calendar.MILLISECOND, 0); Calendar endCalendar = new GregorianCalendar(); endCalendar.setTime(endTime); endCalendar.set(Calendar.HOUR_OF_DAY, 0); endCalendar.set(Calendar.MINUTE, 0); endCalendar.set(Calendar.SECOND, 0); endCalendar.set(Calendar.MILLISECOND, 0); Date eventDate = new Date(startCalendar.getTimeInMillis()); zcView.setEvent(record, eventDate); while ((startCalendar.get(Calendar.YEAR) != endCalendar.get(Calendar.YEAR)) || (startCalendar.get(Calendar.MONTH) != endCalendar.get(Calendar.MONTH)) || (startCalendar.get(Calendar.DATE) != endCalendar.get(Calendar.DATE))) { startCalendar.add(Calendar.DATE, 1); eventDate = new Date(startCalendar.getTimeInMillis()); zcView.setEvent(record, eventDate); } } } List<ZCGroup> zcGroups = zcView.getGroups(); HashMap<Date, List<ZCRecord>> eventsMap = zcView.getEventRecordsMap(); SortedSet<Date> keys = new TreeSet<Date>(eventsMap.keySet()); for (Date eventDate : keys) { List<ZCRecord> eventRecords = eventsMap.get(eventDate); List<String> groupHeaderValues = new ArrayList<String>(); SimpleDateFormat dateFormat = new SimpleDateFormat(zcView.getDateFormat()); //No I18N groupHeaderValues.add(dateFormat.format(eventDate)); ZCGroup zcGroup = new ZCGroup(groupHeaderValues); zcGroups.add(zcGroup); for (int i = 0; i < eventRecords.size(); i++) { ZCRecord eventRecord = eventRecords.get(i); zcGroup.addRecord(eventRecord); } } zcView.sortRecordsForCalendar(); }
From source file:hoot.services.writers.osm.ChangesetDbWriter.java
private long getOldElementId(final NamedNodeMap nodeAttributes, final DbUtils.EntityChangeType entityChangeType, List<Long> oldElementIds) throws Exception { long oldElementId = Long.parseLong(nodeAttributes.getNamedItem("id").getNodeValue()); // make sure request has no duplicate ID's for new elements // This catches a duplicate create/delete error earlier. Technically, // updating the same // node twice could be allowed (not sure if rails port does), but I'm going // to not allow that // for now.//from www . ja v a2 s.com if (oldElementIds.contains(oldElementId)) { throw new Exception( "Duplicate OSM element ID: " + oldElementId + " in changeset " + requestChangesetId); } if (entityChangeType.equals(EntityChangeType.CREATE)) { // by convention, new element ID's should have a negative value if (oldElementId >= 0) { throw new Exception("Invalid OSM element ID for create: " + oldElementId + " for " + "changeset: " + requestChangesetId + ". Use a negative ID value."); } } else { if (oldElementId < 1) { if (!Boolean.parseBoolean( HootProperties.getInstance().getProperty("hootCoreServicesDatabaseWriterCompatibility", HootProperties.getDefault("hootCoreServicesDatabaseWriterCompatibility")))) { // The hoot command line services database writer will write nodes // with negative ID's to // the database, which isn't allowed in regular OSM. Created a // compatibility mode to // allow for it, so that the hoot --convert functionality can be used // as a source of // test data for the services. throw new Exception("Invalid OSM element ID: " + oldElementId + ". Existing OSM elements cannot have " + "negative ID's."); } } } oldElementIds.add(oldElementId); return oldElementId; }
From source file:it.unibo.alchemist.language.EnvironmentBuilder.java
private LinkingRule<T> buildLinkingRule(final Node rootLinkingRule, final Map<String, Object> env) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException {/* w ww. j av a2 s. c o m*/ final NamedNodeMap attributes = rootLinkingRule.getAttributes(); // final Node nameNode = attributes.getNamedItem(NAME); final String name = "LINKINGRULE"; String type = attributes.getNamedItem(TYPE).getNodeValue(); type = type.contains(".") ? type : LINKINGRULES_DEFAULT_PACKAGE + type; final LinkingRule<T> res = coreOperations(env, rootLinkingRule, type, random); env.put(name, res); return res; }