Java Code Examples for org.jdom.Document#getRootElement()
The following examples show how to use
org.jdom.Document#getRootElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SAXBuilder_JDOMTest.java From learnjavabug with MIT License | 6 votes |
public static void main(String[] args) throws JDOMException, IOException { //todo 存在xxe漏洞 SAXBuilder saxBuilder = new SAXBuilder(); //todo 修复方式1 // SAXBuilder saxBuilder = new SAXBuilder(true); //todo 修复方式2 // SAXBuilder saxBuilder = new SAXBuilder(); // saxBuilder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); // saxBuilder.setFeature("http://xml.org/sax/features/external-general-entities", false); // saxBuilder.setFeature("http://xml.org/sax/features/external-parameter-entities", false); // saxBuilder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(Payloads.FEEDBACK.getBytes()); Document document = saxBuilder.build(byteArrayInputStream); Element element = document.getRootElement(); List<Content> contents = element.getContent(); for (Content content : contents) { System.out.println(content.getValue()); } }
Example 2
Source File: UtilityTest.java From BART with MIT License | 6 votes |
private static AccessConfiguration loadTargetAccessConfiguration(String fileTask) { Document document = daoUtility.buildDOM(fileTask); Element rootElement = document.getRootElement(); Element databaseElement = rootElement.getChild("target"); Element dbmsElement = databaseElement.getChild("access-configuration"); if (dbmsElement == null) { throw new DAOException("Unable to load scenario from file " + fileTask + ". Missing tag <access-configuration>"); } AccessConfiguration accessConfiguration = new AccessConfiguration(); accessConfiguration.setDriver(dbmsElement.getChildText("driver").trim()); accessConfiguration.setUri(dbmsElement.getChildText("uri").trim()); accessConfiguration.setSchemaName(dbmsElement.getChildText("schema").trim()); accessConfiguration.setLogin(dbmsElement.getChildText("login").trim()); accessConfiguration.setPassword(dbmsElement.getChildText("password").trim()); return accessConfiguration; }
Example 3
Source File: MarketUpdate.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public MarketUpdate ( String xml, boolean isNew ) { SAXBuilder builder = new SAXBuilder(); Document doc = null; try { Reader string_reader = new StringReader(xml); doc = builder.build(string_reader); } catch (Exception e) { System.out.println("Caught exception during XML parsing of a Trade"); e.printStackTrace(); } Element root_element = doc.getRootElement (); this.ccy = getStringElement(root_element, "ccy"); this.ValueDate = getStringElement(root_element, "ValueDate"); this.value = getDoubleElement(root_element, "value"); this.spot = getDoubleElement(root_element, "spot"); this.discount_factor = getDoubleElement(root_element, "discount_factor"); this.tickId = getIntegerElement(root_element, "TickId" ); //this.wanIdentity = wanIdentity; this.isNew = isNew; }
Example 4
Source File: CreoleAnnotationHandler.java From gate-core with GNU Lesser General Public License v3.0 | 6 votes |
/** * Fetches the directory information for this handler's creole plugin and adds * additional RESOURCE elements to the given JDOM document so that it contains * a RESOURCE for every resource type defined in the plugin's directory info. * * @param jdomDoc * JDOM document which should be the parsed creole.xml that this * handler was configured for. */ public void createResourceElementsForDirInfo(Document jdomDoc) throws MalformedURLException { Element jdomElt = jdomDoc.getRootElement(); //URL directoryUrl = new URL(creoleFileUrl, "."); //DirectoryInfo dirInfo = Gate.getDirectoryInfo(directoryUrl,jdomDoc); //if(dirInfo != null) { Map<String, Element> resourceElements = new HashMap<String, Element>(); findResourceElements(resourceElements, jdomElt); for(ResourceInfo resInfo : plugin .getResourceInfoList()) { if(!resourceElements.containsKey(resInfo.getResourceClassName())) { // no existing RESOURCE element for this resource type (so it // was // auto-discovered from a <JAR SCAN="true">), so add a minimal // RESOURCE element which will be filled in by the annotation // processor. jdomElt.addContent(new Element("RESOURCE").addContent(new Element( "CLASS").setText(resInfo.getResourceClassName()))); } } //} }
Example 5
Source File: BeastImporter.java From beast-mcmc with GNU Lesser General Public License v2.1 | 6 votes |
public BeastImporter(Reader reader) throws IOException, JDOMException, Importer.ImportException { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(reader); root = doc.getRootElement(); if (!root.getName().equalsIgnoreCase("beast")) { throw new Importer.ImportException("Unrecognized root element in XML file"); } dateFormat = DateFormat.getDateInstance(java.text.DateFormat.SHORT, Locale.UK); dateFormat.setLenient(true); Calendar cal = Calendar.getInstance(Locale.getDefault()); // set uses a zero based month (Jan = 0): cal.set(0000, 00, 01); // origin = cal.getTime(); cal.setTimeInMillis(0); origin = cal.getTime(); }
Example 6
Source File: IndexCreator.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public void createIndex() throws JDOMException, IOException, MappingException, ClassNotFoundException { buildAnalyzerMap(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(config); Element root = doc.getRootElement(); SessionFactory sf = createSessionFactory(root.getAttributeValue("url"), root.getAttributeValue("login"), root.getAttributeValue("passwd"), root.getAttributeValue("dialect"), root.getAttributeValue("driverClass"), root.getAttributeValue("mappedClasses")); Directory indexDir = FSDirectory.open(new File(output)); Version lucene47 = Version.LUCENE_47; IndexWriter writer = new IndexWriter(indexDir,new IndexWriterConfig(lucene47,new StandardAnalyzer(lucene47))); for (Element classToIndex:(Collection<Element>)root.getChildren("index-class")) { processClass(classToIndex,writer,sf); } log.info("Closing index"); writer.close(); log.info("All done!"); }
Example 7
Source File: MarketUpdate.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public MarketUpdate ( String xml, boolean isNew ) { SAXBuilder builder = new SAXBuilder(); Document doc = null; try { Reader string_reader = new StringReader(xml); doc = builder.build(string_reader); } catch (Exception e) { System.out.println("Caught exception during XML parsing of a Trade"); e.printStackTrace(); } Element root_element = doc.getRootElement (); this.ccy = getStringElement(root_element, "ccy"); this.ValueDate = getStringElement(root_element, "ValueDate"); this.value = getDoubleElement(root_element, "value"); this.spot = getDoubleElement(root_element, "spot"); this.discount_factor = getDoubleElement(root_element, "discount_factor"); this.tickId = getIntegerElement(root_element, "TickId" ); //this.wanIdentity = wanIdentity; this.isNew = isNew; }
Example 8
Source File: TradeLoader.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * NB: duration will be exposed as microseconds * <br />the output of this log will include: * <br />the time the write of this row was started, the region and tradeId of this trade, and the duration the write took * */ protected void bracketLog(long writeStartTime, long duration, String xml) { Document doc = null; duration = duration / 1000l; try { Reader string_reader = new StringReader(xml); doc = builder.build(string_reader); } catch (Exception e) { System.out.println("Caught exception during XML parsing"); e.printStackTrace(); } root_element = doc.getRootElement(); String id = getStringElement(root_element, "TradeId"); String region = getStringElement(root_element,"Entity"); String timeStamp = formatter.format(new java.util.Date(writeStartTime)); //logger.info(timeStamp + "," + region +"_"+ id + "," + duration); }
Example 9
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 6 votes |
public static Element parseDocument(final InputStream is) { try { final SAXBuilder builder = new SAXBuilder(); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); final Document doc = builder.build(is); if (doc == null) { return null; } final Element root = doc.getRootElement(); return root; } catch (final IOException ioe) { LOGGER.warn("parse error", ioe); return null; } catch (final JDOMException jdome) { LOGGER.warn("parse error", jdome); return null; } }
Example 10
Source File: SlackNotificationSettingsTest.java From tcSlackBuildNotifier with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Test public void test_ReadXml() throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); //builder.setValidation(true); builder.setIgnoringElementContentWhitespace(true); Document doc = builder.build("src/test/resources/testdoc1.xml"); Element root = doc.getRootElement(); System.out.println(root.toString()); if(root.getChild("slackNotifications") != null){ Element child = root.getChild("slackNotifications"); if ((child.getAttribute("enabled") != null) && (child.getAttribute("enabled").equals("true"))){ List<Element> namedChildren = child.getChildren("slackNotification"); for(Iterator<Element> i = namedChildren.iterator(); i.hasNext();) { Element e = i.next(); System.out.println(e.toString() + e.getAttributeValue("url")); //assertTrue(e.getAttributeValue("url").equals("http://something")); if(e.getChild("parameters") != null){ Element eParams = e.getChild("parameters"); List<Element> paramsList = eParams.getChildren("param"); for(Iterator<Element> j = paramsList.iterator(); j.hasNext();) { Element eParam = j.next(); System.out.println(eParam.toString() + eParam.getAttributeValue("name")); System.out.println(eParam.toString() + eParam.getAttributeValue("value")); } } } } } }
Example 11
Source File: Trade.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public Trade(String xml) throws JDOMException, IOException { // actually parse the xml here SAXBuilder builder = new SAXBuilder(); Document doc = null; try { Reader string_reader = new StringReader(xml); doc = builder.build(string_reader); } catch (Exception e) { System.out.println("Caught exception during XML parsing of a Trade"); e.printStackTrace(); } Element root_element = doc.getRootElement (); TradeId = getIntegerElement(root_element, "TradeId"); Trader = getStringElement(root_element, "Trader").trim(); Entity = getStringElement(root_element, "Entity").trim(); Currency = getStringElement(root_element, "Currency"); Amount = getDoubleElement(root_element, "Amount"); ContractRate = getDoubleElement(root_element, "ContractRate"); CtrCurrency = getStringElement(root_element, "CtrCurrency"); //TODO The trade file is missing this property, we will need to get an update. Use 1 for now. //BaseUSEquiv = getDoubleElement(root_element, "BaseUSEquiv"); BaseUSEquiv = 1; CcyDollarDiscountFactor = getDoubleElement(root_element, "CcyDollarDiscountFactor"); CcySpotRate = getDoubleElement(root_element, "CcySpotRate"); TradeDate = getStringElement(root_element, "TradeDate"); ValueDate = getStringElement(root_element, "ValueDate"); counterparty = getStringElement(root_element, "CounterParty" ).trim(); ctr_amt = Amount*ContractRate*-1; ctr_us_equiv = 1.0/(ContractRate/BaseUSEquiv); if("USD".equals(CtrCurrency))ctr_spot = 1.0; else ctr_spot = 1.0/(ContractRate/CcySpotRate); }
Example 12
Source File: SeoPageExtraConfigDOM.java From entando-components with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void addExtraConfig(PageMetadata pageMetadata, Document doc) { super.addExtraConfig(pageMetadata, doc); if (!(pageMetadata instanceof SeoPageMetadata)) { return; } Element root = doc.getRootElement(); SeoPageMetadata seoPage = (SeoPageMetadata) pageMetadata; Element useExtraDescriptionsElement = root.getChild(USE_EXTRA_DESCRIPTIONS_ELEMENT_NAME); if (null != useExtraDescriptionsElement) { Boolean value = Boolean.valueOf(useExtraDescriptionsElement.getText()); seoPage.setUseExtraDescriptions(value.booleanValue()); } Element descriptionsElement = root.getChild(DESCRIPTIONS_ELEMENT_NAME); this.extractMultilangProperty(descriptionsElement, seoPage.getDescriptions(), "description"); Element keywordsElement = root.getChild(KEYWORDS_ELEMENT_NAME); this.extractMultilangProperty(keywordsElement, seoPage.getKeywords(), "keywords"); Element friendlyCodeElement = root.getChild(FRIENDLY_CODE_ELEMENT_NAME); if (null != friendlyCodeElement) { seoPage.setFriendlyCode(friendlyCodeElement.getText()); } Element xmlConfigElement = root.getChild(XML_CONFIG_ELEMENT_NAME); if (null != xmlConfigElement) { //Used to guarantee porting with previous versions of the plugin String xml = xmlConfigElement.getText(); seoPage.setComplexParameters(this.extractComplexParameters(xml)); } else { Element complexParamElement = root.getChild(COMPLEX_PARAMS_ELEMENT_NAME); if (null != complexParamElement) { List<Element> elements = complexParamElement.getChildren(); seoPage.setComplexParameters(this.extractComplexParameters(elements)); } } }
Example 13
Source File: StepConfigsDOM.java From entando-components with GNU Lesser General Public License v3.0 | 5 votes |
protected Element getRootElement(String xmlText) throws ApsSystemException { SAXBuilder builder = new SAXBuilder(); builder.setValidation(false); StringReader reader = new StringReader(xmlText); Element root = null; try { Document doc = builder.build(reader); root = doc.getRootElement(); } catch (Throwable t) { _logger.error("Error parsing xml: {}", xmlText, t); throw new ApsSystemException("Error parsing xml", t); } return root; }
Example 14
Source File: SimpleLanguageTranslatorTest.java From ghidra with Apache License 2.0 | 5 votes |
private OldLanguage readOldLanguage(String oldLanguageXML) throws Exception { Reader r = new StringReader(oldLanguageXML); SAXBuilder sax = XmlUtilities.createSecureSAXBuilder(false, false); Document document = sax.build(r); Element root = document.getRootElement(); return new OldLanguage(root); }
Example 15
Source File: Main.java From Llunatic with GNU General Public License v3.0 | 5 votes |
public static boolean isDEScenario(String fileScenario) { Document document = new DAOXmlUtility().buildDOM(fileScenario); Element rootElement = document.getRootElement(); Element dependenciesElement = rootElement.getChild("dependencies"); if (dependenciesElement == null) { return false; } String dependenciesString = dependenciesElement.getValue().trim(); return !(dependenciesString.contains("ExtEGDs") && !dependenciesString.contains("DED-")); }
Example 16
Source File: SAT.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private byte[] calcDigest(SoapConverter sc){ try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); Document doc = sc.getXML(); Element eRoot = doc.getRootElement(); Element body = eRoot.getChild("Body", SoapConverter.ns); addParameters(body, digest); return digest.digest(); } catch (NoSuchAlgorithmException e) { ExHandler.handle(e); } return null; }
Example 17
Source File: StartupActionScriptManager.java From consulo with Apache License 2.0 | 4 votes |
private static List<ActionCommand> loadStartActions(Logger logger) throws IOException { List<ActionCommand> actionCommands = loadObsoleteActionScriptFile(logger); if (!actionCommands.isEmpty()) { return actionCommands; } File file = new File(getStartXmlFilePath()); if (file.exists()) { try { SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING); Document document = builder.build(file); Element rootElement = document.getRootElement(); List<ActionCommand> list = new ArrayList<ActionCommand>(); for (Element element : rootElement.getChildren()) { String name = element.getName(); if (DeleteCommand.action.equals(name)) { String path = element.getAttributeValue("source"); list.add(new DeleteCommand(new File(path))); } else if (UnzipCommand.action.equals(name)) { String sourceValue = element.getAttributeValue("source"); String descriptionValue = element.getAttributeValue("description"); String filter = element.getAttributeValue("filter"); FilenameFilter filenameFilter = null; if ("import".equals(filter)) { Set<String> names = new HashSet<String>(); for (Element child : element.getChildren()) { names.add(child.getTextTrim()); } filenameFilter = new ImportSettingsFilenameFilter(names); } list.add(new UnzipCommand(new File(sourceValue), new File(descriptionValue), filenameFilter)); } } return list; } catch (Exception e) { logger.error(e); return Collections.emptyList(); } } else { logger.warn("No " + ourStartXmlFileName + " file"); return Collections.emptyList(); } }
Example 18
Source File: DAOMCScenarioCF.java From Llunatic with GNU General Public License v3.0 | 4 votes |
public Scenario loadScenario(String fileScenario, DAOConfiguration config) throws DAOException { long start = new Date().getTime(); try { long startLoadXML = new Date().getTime(); Document document = daoUtility.buildDOM(fileScenario); long endLoadXML = new Date().getTime(); ChaseStats.getInstance().addStat(ChaseStats.LOAD_XML_SCENARIO_TIME, endLoadXML - startLoadXML); Element rootElement = document.getRootElement(); //CONFIGURATION Element configurationElement = rootElement.getChild("configuration"); LunaticConfiguration configuration = daoConfiguration.loadConfiguration(fileScenario, rootElement, configurationElement, config.getChaseMode()); Scenario scenario = new Scenario(fileScenario, config.getSuffix(), configuration); if (config.getUseDictionaryEncoding() != null) { configuration.setUseDictionaryEncoding(config.getUseDictionaryEncoding()); } if (config.getPrintTargetStats()!= null) { configuration.setPrintTargetStats(config.getPrintTargetStats()); } if (config.getUseCompactAttributeName() != null) { configuration.setUseCompactAttributeName(config.getUseCompactAttributeName()); } if (configuration.isUseDictionaryEncoding()) { if (config.isImportData()) { scenario.setValueEncoder(new DictionaryEncoder(DAOUtility.extractScenarioName(fileScenario))); if (config.isRemoveExistingDictionary()) { scenario.getValueEncoder().removeExistingEncoding(); } scenario.getValueEncoder().prepareForEncoding(); } else { scenario.setValueEncoder(new DummyEncoder()); } } //SOURCE Element sourceElement = rootElement.getChild("source"); IDatabase sourceDatabase = daoDatabaseConfiguration.loadDatabase(sourceElement, null, fileScenario, scenario.getValueEncoder(), configuration.isUseCompactAttributeName()); //Source schema doesn't need suffix scenario.setSource(sourceDatabase); //TARGET Element targetElement = rootElement.getChild("target"); IDatabase targetDatabase = daoDatabaseConfiguration.loadDatabase(targetElement, config.getSuffix(), fileScenario, scenario.getValueEncoder(), configuration.isUseCompactAttributeName()); scenario.setTarget(targetDatabase); long end = new Date().getTime(); ChaseStats.getInstance().addStat(ChaseStats.LOAD_TIME, end - start); //InitDB (out of LOAD_TIME stat) if (config.isImportData()) { daoDatabaseConfiguration.initDatabase(scenario); } start = new Date().getTime(); //AUTHORITATIVE SOURCES Element authoritativeSourcesElement = rootElement.getChild("authoritativeSources"); List<String> authoritativeSources = daoDatabaseConfiguration.loadAuthoritativeSources(authoritativeSourcesElement, scenario); scenario.setAuthoritativeSources(authoritativeSources); //DEPENDENCIES Element dependenciesElement = rootElement.getChild("dependencies"); Element queriesElement = rootElement.getChild("queries"); loadDependenciesAndQueries(dependenciesElement, queriesElement, config, scenario); //CONFIGURATION daoConfiguration.loadOtherScenarioElements(rootElement, scenario); //QUERIES end = new Date().getTime(); ChaseStats.getInstance().addStat(ChaseStats.LOAD_TIME, end - start); if (configuration.isUseDictionaryEncoding()) { if (config.isImportData()) { scenario.getValueEncoder().closeEncoding(); } } return scenario; } catch (Throwable ex) { logger.error(ex.getLocalizedMessage()); ex.printStackTrace(); String message = "Unable to load scenario from file " + fileScenario; if (ex.getMessage() != null && !ex.getMessage().equals("NULL")) { message += "\n" + ex.getMessage(); } throw new DAOException(message); } finally { } }
Example 19
Source File: DAOMCScenarioStandard.java From Llunatic with GNU General Public License v3.0 | 4 votes |
public Scenario loadScenario(String fileScenario, DAOConfiguration config) throws DAOException { long start = new Date().getTime(); try { long startLoadXML = new Date().getTime(); Document document = daoUtility.buildDOM(fileScenario); long endLoadXML = new Date().getTime(); ChaseStats.getInstance().addStat(ChaseStats.LOAD_XML_SCENARIO_TIME, endLoadXML - startLoadXML); Element rootElement = document.getRootElement(); //CONFIGURATION Element configurationElement = rootElement.getChild("configuration"); LunaticConfiguration configuration = daoConfiguration.loadConfiguration(fileScenario, rootElement, configurationElement, config.getChaseMode()); Scenario scenario = new Scenario(fileScenario, config.getSuffix(), configuration); if (config.getUseDictionaryEncoding() != null) { configuration.setUseDictionaryEncoding(config.getUseDictionaryEncoding()); } if (config.getPrintTargetStats()!= null) { configuration.setPrintTargetStats(config.getPrintTargetStats()); } if (configuration.isUseDictionaryEncoding()) { if (config.isImportData()) { scenario.setValueEncoder(new DictionaryEncoder(DAOUtility.extractScenarioName(fileScenario))); if (config.isRemoveExistingDictionary()) { scenario.getValueEncoder().removeExistingEncoding(); } scenario.getValueEncoder().prepareForEncoding(); } else { scenario.setValueEncoder(new DummyEncoder()); } } //SOURCE Element sourceElement = rootElement.getChild("source"); IDatabase sourceDatabase = daoDatabaseConfiguration.loadDatabase(sourceElement, null, fileScenario, scenario.getValueEncoder(), false); //Source schema doesn't need suffix scenario.setSource(sourceDatabase); //TARGET Element targetElement = rootElement.getChild("target"); IDatabase targetDatabase = daoDatabaseConfiguration.loadDatabase(targetElement, config.getSuffix(), fileScenario, scenario.getValueEncoder(), false); scenario.setTarget(targetDatabase); long end = new Date().getTime(); ChaseStats.getInstance().addStat(ChaseStats.LOAD_TIME, end - start); //InitDB (out of LOAD_TIME stat) if (config.isImportData()) daoDatabaseConfiguration.initDatabase(scenario); start = new Date().getTime(); //AUTHORITATIVE SOURCES Element authoritativeSourcesElement = rootElement.getChild("authoritativeSources"); List<String> authoritativeSources = daoDatabaseConfiguration.loadAuthoritativeSources(authoritativeSourcesElement, scenario); scenario.setAuthoritativeSources(authoritativeSources); //DEPENDENCIES Element dependenciesElement = rootElement.getChild("dependencies"); loadDependencies(dependenciesElement, config, scenario); //CONFIGURATION daoConfiguration.loadOtherScenarioElements(rootElement, scenario); //QUERIES Element queriesElement = rootElement.getChild("queries"); loadQueries(queriesElement, scenario); end = new Date().getTime(); ChaseStats.getInstance().addStat(ChaseStats.LOAD_TIME, end - start); if (configuration.isUseDictionaryEncoding()) { if (config.isImportData()) scenario.getValueEncoder().closeEncoding(); } return scenario; } catch (Throwable ex) { logger.error(ex.getLocalizedMessage()); ex.printStackTrace(); String message = "Unable to load scenario from file " + fileScenario; if (ex.getMessage() != null && !ex.getMessage().equals("NULL")) { message += "\n" + ex.getMessage(); } throw new DAOException(message); } finally { } }
Example 20
Source File: JDOMStreamReader.java From cxf with Apache License 2.0 | 4 votes |
/** * @param document */ public JDOMStreamReader(Document document) { this(document.getRootElement()); }