private static Element saveReplayElement(FileServerStream replay) { Element result = new Element(XmlNames.REPLAY); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // level Element tournamentElement = saveLevelElement(replay); result.addContent(tournamentElement); // date Element datesElement = saveDateElement(replay); result.addContent(datesElement); // players Element playersElement = savePlayersElement(replay); result.addContent(playersElement); return result; }
/** * Crée un des élements du fichier XML. * * @param aiPreview * Objet décrivant l'agent. * @return * L'élément XML créé. */ private static Element saveAiElement(AiPreview aiPreview) { Element result = new Element(XmlNames.AI); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // notes Element notesElement = saveNotesElement(aiPreview); result.addContent(notesElement); // authors Element authorsElement = saveAuthorsElement(aiPreview); result.addContent(authorsElement); return result; }
/** * Generates the players XML element. * * @param players * Original object. * @return * XML element. */ private static Element savePlayersElement(Players players) { Element result = new Element(XmlNames.PLAYERS); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // locations Map<Integer,PlayerLocation[]> locations = players.getLocations(); Element locationsElement = saveLocationsElement(locations); result.addContent(locationsElement); // items Map<String,Integer> items = players.getInitialItems(); Element itemsElement = saveItemsElement(items); result.addContent(itemsElement); return result; }
/** * Initializes the root element of the xml file. * * @param zone * Zone to record. * @return * Root XML element. */ private static Element saveZoneElement(Zone zone) { Element result = new Element(XmlNames.ZONE); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // tiles random variable Map<String,VariableTile> variableTiles = zone.getVariableTiles(); if(!variableTiles.isEmpty()) { Element variableTilesElement = VariableTilesSaver.saveVariableTilesElement(variableTiles); result.addContent(variableTilesElement); } // matrix Element matrixElement = saveMatrixElement(zone); result.addContent(matrixElement); // events Element eventsElement = saveEventsElement(zone); if(eventsElement!=null) result.addContent(eventsElement); return result; }
private static Element saveGameQuickStartElement(QuickStartConfiguration quickStartConfiguration) { Element result = new Element(XmlNames.GAME_QUICKSTART); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // round Element roundElement = saveRoundELement(quickStartConfiguration); result.addContent(roundElement); // players Element playersElement = new Element(XmlNames.PLAYERS); ProfilesSelection quickStartSelected = quickStartConfiguration.getProfilesSelection(); ProfilesSelectionSaver.saveProfilesSelection(playersElement,quickStartSelected); result.addContent(playersElement); return result; }
/** * Builds an XML element representing * network-related settings. * * @param connectionsConfiguration * Settings to be recorded. * @return * Resulting XML element. */ private static Element saveConnectionsElement(ConnectionsConfiguration connectionsConfiguration) { Element result = new Element(XmlNames.CONNECTIONS); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // central Element centralElement = saveCentralElement(connectionsConfiguration); result.addContent(centralElement); // hosting Element hostingElement = saveHostingElement(connectionsConfiguration); result.addContent(hostingElement); return result; }
private static Element saveEngineElement(EngineConfiguration engineConfiguration) { Element result = new Element(XmlNames.ENGINE); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // timing Element timingElement = saveTimingElement(engineConfiguration); result.addContent(timingElement); // logs Element logElement = saveLogElement(engineConfiguration); result.addContent(logElement); // cache Element cacheElement = saveCacheElement(engineConfiguration); result.addContent(cacheElement); return result; }
private static Element saveProfilesElement(ProfilesConfiguration profilesConfiguration) { Element result = new Element(XmlNames.PROFILES); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // general Element generalElement = saveGeneralElement(profilesConfiguration); result.addContent(generalElement); // list Element listElement = saveListElement(profilesConfiguration); result.addContent(listElement); return result; }
private static Element saveVideoElement(VideoConfiguration videoConfiguration) { Element result = new Element(XmlNames.VIDEO); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // full screen Element fullScreenElement = saveFullScreenElement(videoConfiguration); result.addContent(fullScreenElement); // smoothing Element smoothingElement = saveSmoothGraphicsElement(videoConfiguration); result.addContent(smoothingElement); // panel dimension Element panelElement = savePanelDimensionElement(videoConfiguration); result.addContent(panelElement); // border color Element borderElement = saveBorderElement(videoConfiguration); result.addContent(borderElement); return result; }
/** * Returns a comment node to put * in an XML document. * * @return * The corresponding comment node. */ public static Comment getGplComment() { StringBuffer text = new StringBuffer(); text.append("\n"); text.append("\tTotal Boum Boum\n"); text.append("\tCopyright 2008-2014 Vincent Labatut\n"); text.append("\t\n"); text.append("\tThis file is part of Total Boum Boum.\n"); text.append("\t\n"); text.append("\tTotal Boum Boum is free software: you can redistribute it and/or modify\n"); text.append("\tit under the terms of the GNU General Public License as published by\n"); text.append("\tthe Free Software Foundation, either version 2 of the License, or\n"); text.append("\t(at your option) any later version.\n"); text.append("\t\n"); text.append("\tTotal Boum Boum is distributed in the hope that it will be useful,\n"); text.append("\tbut WITHOUT ANY WARRANTY; without even the implied warranty of\n"); text.append("\tMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"); text.append("\tGNU General Public License for more details.\n"); text.append("\t\n"); text.append("\tYou should have received a copy of the GNU General Public License\n"); text.append("\talong with Total Boum Boum. If not, see http://www.gnu.org/licenses.\n"); Comment result = new Comment(text.toString()); return result; }
private static Element saveGuiElement(MiscConfiguration engineConfiguration) { Element result = new Element(GuiXmlTools.ELT_CONFIGURATION); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // language Element languageElement = saveLanguageElement(engineConfiguration); result.addContent(languageElement); // font Element fontElement = saveFontElement(engineConfiguration); result.addContent(fontElement); // background Element backgroundElement = saveBackgroundElement(engineConfiguration); result.addContent(backgroundElement); return result; }
/** * Get the best content value for a JDOM object. For elements, the content text is returned. * For attributes, the attribute value is returned. For namespaces, the URI is returned. Etc... * @param jdomObject JDOM object such as Element, Attribute, Text, Namespace, Comment, ProcessingInstruction, String * @return Content value for the specified JDOM object * @since 4.2 */ public static String getContentValue( Object jdomObject ) { if(jdomObject == null) { return null; } else if(jdomObject instanceof String) { return (String)jdomObject; } else if(jdomObject instanceof Element) { return ((Element)jdomObject).getText(); } else if(jdomObject instanceof Attribute) { return ((Attribute)jdomObject).getValue(); } else if(jdomObject instanceof Text) { return ((Text)jdomObject).getValue(); } else if(jdomObject instanceof Namespace) { return ((Namespace)jdomObject).getURI(); } else if(jdomObject instanceof Comment) { return ((Comment)jdomObject).getText(); } else if(jdomObject instanceof ProcessingInstruction) { return ((ProcessingInstruction)jdomObject).getData(); } // Default return jdomObject.toString(); }
/** Stop XMLOutputter from printing comment <!-- --> chars if it is just a newline */ @Override protected void printComment(Writer stringWriter, Comment comment) throws IOException { if (comment instanceof NewlineText) { if (!indentBlankLines) { clearIndentationForCurrentLine(stringWriter); } } else { super.printComment(stringWriter, comment); } }
/** * Processes the main profile element of the XML file. * * @param profile * Profile object. * @return * Produced XML element. */ private static Element saveProfileElement(Profile profile) { Element result = new Element(XmlNames.PROFILE); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // general properties Element generalElement = saveGeneralElement(profile); result.addContent(generalElement); // artificial intelligence if(profile.hasAi()) { Element aiElement = saveAiElement(profile); result.addContent(aiElement); } // sprite info Element characterElement = saveCharacterElement(profile); result.addContent(characterElement); // network stuff Element networkElement = saveNetworkElement(profile); result.addContent(networkElement); return result; }
private static Element saveHostsElement(Map<String,HostInfo> hosts) { Element result = new Element(XmlNames.HOST); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); for(HostInfo host: hosts.values()) { Element hostElement = saveHostElement(host); result.addContent(hostElement); } return result; }
/** * Processes the main element of the produced XML file. * * @param gameArchive * Object to record. * @return * XML element. */ private static Element saveArchiveElement(GameArchive gameArchive) { Element result = new Element(XmlNames.ARCHIVE); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // tournament Element tournamentElement = saveTournamentElement(gameArchive); result.addContent(tournamentElement); // played Element playedElement = savePlayedElement(gameArchive); result.addContent(playedElement); // total Element totalElement = saveTotalElement(gameArchive); result.addContent(totalElement); // dates Element datesElement = saveDatesElement(gameArchive); result.addContent(datesElement); // players Element playersElement = savePlayersElement(gameArchive); result.addContent(playersElement); return result; }
private static Element saveGameTournamentElement(TournamentConfiguration tournamentConfiguration) { Element result = new Element(XmlNames.GAME_TOURNAMENT); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // options Element optionsElement = saveTournamentOptionsElement(tournamentConfiguration); result.addContent(optionsElement); // name Element tournamentElement = new Element(XmlNames.TOURNAMENT); String tournament = tournamentConfiguration.getTournamentName().toString(); tournamentElement.setAttribute(XmlNames.NAME,tournament); result.addContent(tournamentElement); // players Element playersElement = new Element(XmlNames.PLAYERS); ProfilesSelection tournamentSelected = tournamentConfiguration.getProfilesSelection(); ProfilesSelectionSaver.saveProfilesSelection(playersElement,tournamentSelected); result.addContent(playersElement); // name Element aaElement = new Element(XmlNames.AUTO_ADVANCE); int aaIndex = tournamentConfiguration.getAutoAdvanceIndex(); String aaIndexStr = Integer.toString(aaIndex); aaElement.setAttribute(XmlNames.INDEX,aaIndexStr); result.addContent(aaElement); return result; }
private static Element saveGameQuickMatchElement(QuickMatchConfiguration quickMatchConfiguration) { Element result = new Element(XmlNames.GAME_QUICKMATCH); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // options Element optionsElement = saveQuickMatchOptionsElement(quickMatchConfiguration); result.addContent(optionsElement); // settings Element settingsElement = saveQuickMatchSettingsElement(quickMatchConfiguration); result.addContent(settingsElement); // players Element playersElement = new Element(XmlNames.PLAYERS); ProfilesSelection quickMatchSelected = quickMatchConfiguration.getProfilesSelection(); ProfilesSelectionSaver.saveProfilesSelection(playersElement,quickMatchSelected); result.addContent(playersElement); // levels Element levelsElement = new Element(XmlNames.LEVELS); LevelsSelection levelsSelection = quickMatchConfiguration.getLevelsSelection(); LevelsSelectionSaver.saveLevelsSelection(levelsElement,levelsSelection); result.addContent(levelsElement); return result; }
private static Element saveControlElement(ControlSettings controlSettings) { Element result = new Element(XmlNames.CONTROLS); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); Map<String,Integer> onEvents = controlSettings.getOnEvents(); Iterator<Entry<String,Integer>> onIt = onEvents.entrySet().iterator(); while(onIt.hasNext()) { // data Entry<String,Integer> onEntry = onIt.next(); String event = onEntry.getKey(); int onKey = onEntry.getValue(); int offKey = controlSettings.getOffKeyFromEvent(event); boolean autofire = controlSettings.isAutofire(event); // main element Element eventElement; { String autofireText = Boolean.toString(autofire); eventElement = new Element(XmlNames.EVENT); eventElement.setAttribute(XmlNames.NAME,event); eventElement.setAttribute(XmlNames.AUTOFIRE,autofireText); result.addContent(eventElement); } // on element { String onText = getKeyName(onKey); Element onElement = new Element(XmlNames.ON); onElement.setAttribute(XmlNames.KEY,onText); eventElement.addContent(onElement); } // off element { String offText = getKeyName(offKey); Element offElement = new Element(XmlNames.OFF); offElement.setAttribute(XmlNames.KEY,offText); eventElement.addContent(offElement); } } return result; }
private static Element saveStatisticsElement(StatisticsConfiguration statisticsConfiguration) { Element result = new Element(XmlNames.STATISTICS); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // include quick starts Element includeQuickStartsElement = saveIncludeQuickStartsElement(statisticsConfiguration); result.addContent(includeQuickStartsElement); // include simulations Element includeSimulationsElement = saveIncludeSimulationsElement(statisticsConfiguration); result.addContent(includeSimulationsElement); // glicko-2 Element glicko2Element = saveGlicko2Element(statisticsConfiguration); result.addContent(glicko2Element); // regular launch Element regularLaunchElement = saveRegularLaunchELement(statisticsConfiguration); result.addContent(regularLaunchElement); // quick launch Element quickLaunchElement = saveQuickLaunchELement(statisticsConfiguration); result.addContent(quickLaunchElement); return result; }
public String translateNamespacePrefixToUri(String prefix, Object context) { Element element = null; if ( context instanceof Element ) { element = (Element) context; } else if ( context instanceof Text ) { element = (Element)((Text)context).getParent(); } else if ( context instanceof Attribute ) { element = ((Attribute)context).getParent(); } else if ( context instanceof XPathNamespace ) { element = ((XPathNamespace)context).getJDOMElement(); } else if ( context instanceof Comment ) { element = (Element)((Comment)context).getParent(); } else if ( context instanceof ProcessingInstruction ) { element = (Element)((ProcessingInstruction)context).getParent(); } if ( element != null ) { Namespace namespace = element.getNamespace( prefix ); if ( namespace != null ) { return namespace.getURI(); } } return null; }
/** * Initilise this JDOM doc - adding comment and setting root node */ protected void init() { Document _model; final Element root = new Element(ROOT_NODE_NAME); _model = new Document(root); for (int i = 0; i < scorm_comments.length; i++) { final Comment comment = new Comment(scorm_comments[i]); _model.getContent().add(0, comment); } this.setDocument(_model); }
XMLComment(Comment c) { super(desc); StringTokenizer tokenizer = new StringTokenizer(c.getText(), "\r\n"); while (tokenizer.hasMoreTokens()) commentLines.add(tokenizer.nextToken()); }
public final void substitute(@NotNull Element e, boolean caseSensitive, final boolean recursively, @Nullable PathMacroFilter filter) { List content = e.getContent(); //noinspection ForLoopReplaceableByForEach for (int i = 0, contentSize = content.size(); i < contentSize; i++) { Object child = content.get(i); if (child instanceof Element) { Element element = (Element)child; substitute(element, caseSensitive, recursively, filter); } else if (child instanceof Text) { Text t = (Text)child; if (filter == null || !filter.skipPathMacros(t)) { t.setText((recursively || (filter != null && filter.recursePathMacros(t))) ? substituteRecursively(t.getText(), caseSensitive) : substitute(t.getText(), caseSensitive)); } } else if (!(child instanceof Comment)) { LOG.error("Wrong content: " + child.getClass()); } } List attributes = e.getAttributes(); //noinspection ForLoopReplaceableByForEach for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) { Object attribute1 = attributes.get(i); Attribute attribute = (Attribute)attribute1; if (filter == null || !filter.skipPathMacros(attribute)) { final String value = (recursively || (filter != null && filter.recursePathMacros(attribute))) ? substituteRecursively(attribute.getValue(), caseSensitive) : substitute(attribute.getValue(), caseSensitive); attribute.setValue(value); } } }
private static Element saveLevelElement(LevelInfo levelInfo) { Element result = new Element(XmlNames.LEVEL); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // title Element titleElement = new Element(XmlNames.TITLE); titleElement.setAttribute(XmlNames.VALUE,levelInfo.getTitle()); result.addContent(titleElement); // author Element authorElement = new Element(XmlNames.AUTHOR); authorElement.setAttribute(XmlNames.VALUE,levelInfo.getAuthor()); result.addContent(authorElement); // source Element sourceElement = new Element(XmlNames.SOURCE); sourceElement.setAttribute(XmlNames.VALUE,levelInfo.getSource()); result.addContent(sourceElement); // preview Element previewElement = new Element(XmlNames.PREVIEW); previewElement.setAttribute(XmlNames.FILE,levelInfo.getPreview()); result.addContent(previewElement); // instance Element instanceElement = new Element(XmlNames.INSTANCE); instanceElement.setAttribute(XmlNames.NAME,levelInfo.getInstanceName()); result.addContent(instanceElement); // theme Element themeElement = new Element(XmlNames.THEME); themeElement.setAttribute(XmlNames.NAME,levelInfo.getThemeName()); result.addContent(themeElement); // global dimension Element globaldimElement = new Element(XmlNames.GLOBAL_DIMENSION); globaldimElement.setAttribute(XmlNames.HEIGHT,Integer.toString(levelInfo.getGlobalHeight())); globaldimElement.setAttribute(XmlNames.WIDTH,Integer.toString(levelInfo.getGlobalWidth())); result.addContent(globaldimElement); // visible dimension Element visibledimElement = new Element(XmlNames.VISIBLE_DIMENSION); visibledimElement.setAttribute(XmlNames.HEIGHT,Integer.toString(levelInfo.getVisibleHeight())); visibledimElement.setAttribute(XmlNames.WIDTH,Integer.toString(levelInfo.getVisibleWidth())); result.addContent(visibledimElement); // visible position Element visibleposeElement = new Element(XmlNames.VISIBLE_POSITION); visibleposeElement.setAttribute(XmlNames.UPLINE,Integer.toString(levelInfo.getVisiblePositionUpRow())); visibleposeElement.setAttribute(XmlNames.LEFTCOL,Integer.toString(levelInfo.getVisiblePositionLeftCol())); result.addContent(visibleposeElement); // display Element displayElement = new Element(XmlNames.DISPLAY); displayElement.setAttribute(XmlNames.FORCE_ALL,Boolean.toString(levelInfo.getForceAll())); displayElement.setAttribute(XmlNames.MAXIMIZE,Boolean.toString(levelInfo.getMaximize())); result.addContent(displayElement); return result; }
/** * Builds an XML element representing * AI-related settings. * * @param aisConfiguration * Settings to be recorded. * @return * Resulting XML element. */ private static Element saveAisElement(AisConfiguration aisConfiguration) { Element result = new Element(XmlNames.AIS); // GPL comment Comment gplComment = XmlTools.getGplComment(); result.addContent(gplComment); // ups Element upsElement = saveUpsElement(aisConfiguration); result.addContent(upsElement); // auto advance Element autoAdvanceElement = saveAutoAdvanceElement(aisConfiguration); result.addContent(autoAdvanceElement); // hide all-ais Element hideAllAisElement = saveHideAllAisElement(aisConfiguration); result.addContent(hideAllAisElement); // bomb useless ais Element bombUselessAisElement = saveBombUselessAisElement(aisConfiguration); result.addContent(bombUselessAisElement); // bomb cycling ais Element bombCyclingAisElement = saveBombCyclingAisElement(aisConfiguration); result.addContent(bombCyclingAisElement); // display exceptions onscreen during game Element displayExceptionsElement = saveDisplayExceptionsElement(aisConfiguration); result.addContent(displayExceptionsElement); // log exceptions during game Element logExceptionsElement = saveLogExceptionsElement(aisConfiguration); result.addContent(logExceptionsElement); // automatically record player stats Element recordStatsElement = saveRecordStatsElement(aisConfiguration); result.addContent(recordStatsElement); return result; }
public boolean isComment(Object obj) { return obj instanceof Comment; }
public Iterator getParentAxisIterator(Object contextNode) { Object parent = null; if ( contextNode instanceof Document ) { return JaxenConstants.EMPTY_ITERATOR; } else if ( contextNode instanceof Element ) { parent = ((Element)contextNode).getParent(); if ( parent == null ) { if ( ((Element)contextNode).isRootElement() ) { parent = ((Element)contextNode).getDocument(); } } } else if ( contextNode instanceof Attribute ) { parent = ((Attribute)contextNode).getParent(); } else if ( contextNode instanceof XPathNamespace ) { parent = ((XPathNamespace)contextNode).getJDOMElement(); } else if ( contextNode instanceof ProcessingInstruction ) { parent = ((ProcessingInstruction)contextNode).getParent(); } else if ( contextNode instanceof Comment ) { parent = ((Comment)contextNode).getParent(); } else if ( contextNode instanceof Text ) { parent = ((Text)contextNode).getParent(); } if ( parent != null ) { return new SingleObjectIterator( parent ); } return JaxenConstants.EMPTY_ITERATOR; }
public String getCommentStringValue(Object obj) { Comment cmt = (Comment) obj; return cmt.getText(); }
public void writeFields(Object o, Element parent) { // get the class of the object // get its fields // then get the value of each one // and call write to put the value in the Element Class cl = o.getClass(); Field[] fields = getFields(cl); String name = null; for (int i = 0; i < fields.length; i++) { if ((doStatic || !Modifier.isStatic(fields[i].getModifiers())) && (doFinal || !Modifier.isFinal(fields[i].getModifiers()))) try { fields[i].setAccessible(true); name = fields[i].getName(); // need to handle shadowed fields in some way... // one way is to add info about the declaring class // but this will bloat the XML file if we di it for // every field - might be better to just do it for // the shadowed fields // name += "." + fields[i].getDeclaringClass().getName(); // fields[i]. Object value = fields[i].get(o); Element field = new Element(FIELD); field.setAttribute(NAME, name); if (shadowed(fields, name)) { field.setAttribute(DECLARED, fields[i].getDeclaringClass().getName()); } if (fields[i].getType().isPrimitive()) { // this is not always necessary - so it's optional if (writePrimitiveTypes) { field.setAttribute(TYPE, fields[i].getType().getName()); } field.setAttribute(VALUE, value.toString()); } else { field.addContent(write(value)); } parent.addContent(field); } catch (Exception e) { e.printStackTrace(); System.out.println(e); // at least comment on what went wrong parent.addContent(new Comment(e.toString())); } } }
/** * Creates a <code>Document</code> object for the current state of * this xml database. * @return a <code>Document</code> object. */ private Document getDocument() { Document document = new Document(); Comment comment = new Comment(" generated on " + new Date() + " "); document.addContent(comment); Element rootElement = new Element(ROOT_ELEMENT_NAME); rootElement.setAttribute(MASTER_LANGUAGE_ATTRIBUTE_NAME, getMasterLanguage()); for (Attribute attribute : additionalRootAttrs) { // need to set the attribute like a new attribute, // as the original one stored the parent element and cannot be set to a new parent rootElement.setAttribute(attribute.getName(), attribute.getValue(), attribute.getNamespace()); } // set the namespace, this makes sure that it is written into the trema node for (Namespace namespace : additionalNamespaces) { rootElement.addNamespaceDeclaration(namespace); } for (ITextNode textNode : textNodeList) { String key = textNode.getKey(); Element textElement = new Element(TEXT_ELEMENT_NAME); textElement.setAttribute(KEY_ATTRIBUTE_NAME, key); String context = textNode.getContext(); Element contextElement = new Element(CONTEXT_ELEMENT_NAME); contextElement.setText(context); textElement.addContent(contextElement); IValueNode[] valueNodes = textNode.getValueNodes(); for (IValueNode valueNode : valueNodes) { Element valueElement = new Element(VALUE_ELEMENT_NAME); valueElement.setAttribute(LANGUAGE_ATTRIBUTE_NAME, valueNode.getLanguage()); valueElement.setAttribute(STATUS_ATTRIBUTE_NAME, valueNode.getStatus().getName()); valueElement.setText(valueNode.getValue()); textElement.addContent(valueElement); } rootElement.addContent(textElement); } document.setRootElement(rootElement); return document; }
private void addMeasurement(Element service, String name) { log.debug("addMeasurement " + name); NameRecord nameRecord = index.getNameRecord(name); if (nameRecord == null) { log.error("unknown name " + name); return; } if (nameRecord.getAccess() == null) { log.debug("name getAccess() null " + name); return; } if (!nameRecord.getAccess().canRead()) { log.debug("cannot read"); return; } MibTypeTag tag = nameRecord.getSyntax().getTag(); String dataType; String desc = nameRecord.getDesc(); String units = null; boolean trait = false; // true if probably a trait boolean last = false; desc = desc.replaceAll("[\\n\\r\\t]", " "); desc = desc.replaceAll(" +", " "); if (guess) { if (desc.matches("(?i).*\\b(number|count).*")) tag = MibTypeTags.Gauge; if (desc.matches("(?i).*\\btotal.*")) tag = MibTypeTags.Counter; units = units(desc); if (desc.matches("(?i).*\\b(last|recent|previous|prior)")) last = true; if (units == null && tag == nameRecord.getSyntax().getTag() && trait(desc)) { trait = true; } log.debug("desc " + desc); log.debug("trait " + trait + " units " + units + " tag " + tag); } if (desc.length() > MAX_DESC_LEN) { desc = desc.substring(0, MAX_DESC_LEN); } Map<Integer, String> mapping = index.getMapping(name); boolean hasMapping = mapping != null && !mapping.isEmpty(); if (hasMapping) { Comment c = new Comment(name + " values: " + mapping); service.addContent(c); trait = true; } if (MibTypeTags.isMeasurement(tag) && !trait) { dataType = "measurement"; } else { dataType = "trait"; } Element metric = new Element("metric"); metric.setAttribute("property", name). setAttribute("description", desc). setAttribute("displayType", "detail"). setAttribute("dataType", dataType); if (MibTypeTags.Counter.equals(tag) && !last) { metric.setAttribute("measurementType", "trendsup"); } if (MibTypeTags.TimeTicks.equals(tag)) { metric.setAttribute("units", "milliseconds"); } else if (MibTypeTags.TimeTicks.equals(tag)) { metric.setAttribute("units", "milliseconds"); } else if (units != null) { metric.setAttribute("units", units); } service.addContent(metric); }