List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:com.devoteam.srit.xmlloader.genscript.ScriptGenerator.java
License:Open Source License
public void generateTest() throws Exception { // Si le fichier n'existe pas dj if (!fileRoot.exists()) { test = new Test("Genscript", "Script converted from capture"); }// www . jav a2 s . c o m // Si le fichier de sortie existe dj else { // On ouvre le fichier existant File xml = fileRoot; Document testDoc; SAXReader reader = new SAXReader(); testDoc = reader.read(xml); Element testExistant = testDoc.getRootElement(); // On gnre un nouvel objet test partir de l'lment existant dans le fichier test = new Test(testExistant.attributeValue("name"), testExistant.attributeValue("description")); test.setTest(testExistant); } // On tente de rcuprer le testcase gnrer Element testcaseExistant = null; for (Iterator i = test.getTest().elements().iterator(); i.hasNext();) { Element elem = (Element) i.next(); if (elem.getName().equals("testcase") && elem.attribute("name").getText().equals(testcaseName)) { testcaseExistant = elem; } } // On rcupre les paramtres existants for (Iterator i = test.getTest().elements().iterator(); i.hasNext();) { Element elem = (Element) i.next(); if (elem.getName().equals("parameter")) { Param p = new Param(elem.attributeValue("name"), "test", elem.attributeValue("operation") + "," + elem.attributeValue("value"), null, Param.TARGET_SENDCLIENT); p.setName(p.getFamily()); p.setRemplacedValue(elem.attributeValue("value")); ParamGenerator.getInstance().recordParam(p); } } // Si le testcase n'existe pas encore if (testcaseExistant == null) { // On le crait testcase = new TestCase(testcaseName, "Testcase generate from capture", "true"); test.getTest().add(testcase.getTestCase()); } // Sinon on gnre un testcase partir de celui existant dans le fichier else { testcase = new TestCase(testcaseExistant.attributeValue("name"), testcaseExistant.attributeValue("description"), testcaseExistant.attributeValue("state")); testcase.setTestCase(testcaseExistant); // On rcupre les paramtres existants for (Iterator i = testcase.getTestCase().elements().iterator(); i.hasNext();) { Element elem = (Element) i.next(); if (elem.getName().equals("parameter")) { Param p = new Param(elem.attributeValue("name"), "testcase", elem.attributeValue("operation") + "," + elem.attributeValue("value"), null, Param.TARGET_SENDCLIENT); p.setName(p.getFamily()); p.setRemplacedValue(elem.attributeValue("value")); ParamGenerator.getInstance().recordParam(p); } } } // On ajoute le testcase dans le test test.addTestCase(testcase); // On tente de rcuprer le scenario Element scenarioExistant = null; // On enregistre les scenarios de ce testcase for (Iterator j = testcase.getTestCase().elements().iterator(); j.hasNext();) { Element elem = (Element) j.next(); if (elem.getName().equals("scenario") && elem.getText().contains(listeFiltre.get(0).getHostPort().toString())) { scenarioExistant = elem; } else if (elem.getName().equals("scenario")) { Scenario sc = new Scenario(elem.attributeValue("name"), elem.getText(), listeFiltre); testcase.addScenario(sc); } } // Si le scenario n'existe pas encore if (scenarioExistant == null) { // On le crait scenario = new Scenario(getScenarioName(), getScenarioPath(), listeFiltre); testcase.getTestCase().add(scenario.toXmlElement()); } else { scenario = new Scenario(scenarioExistant.attributeValue("name"), scenarioExistant.getText(), listeFiltre); scenario.setScenario(scenarioExistant); } // On ajoute ce scenario au testcase testcase.addScenario(scenario); }
From source file:com.devoteam.srit.xmlloader.gui.frames.JFrameEditableParameters.java
License:Open Source License
public void fill(final List<Element> elts, boolean resetDefaults) { if (this.elements == null) { for (Element e : elts) { try { String value = e.attributeValue("value"); if (null != value) { e.attribute("value").setValue(parsing(value)); }//from w w w . j a v a 2 s .co m } catch (Exception ee) { GlobalLogger.instance().getApplicationLogger().error(TextEvent.Topic.CORE, ee, "Error in editable parameters window hile parsing parameters value : ", e); } } this.elements = new LinkedList<Element>(); elementsOrigin = new LinkedList<Element>(); if (resetDefaults) { elementsDefault = new LinkedList<Element>(); this.elements.clear(); for (Element e : elts) { this.elements.add(e.createCopy()); elementsDefault.add(e.createCopy()); } } else { this.elements.clear(); for (Element e : elts) { this.elements.add(e.createCopy()); } } EventQueue.invokeLater(new Runnable() { public void run() { doFill(elements); } }); } }
From source file:com.devoteam.srit.xmlloader.gui.frames.JFrameEditableParameters.java
License:Open Source License
/** * Returns the elements concerned by the key (node selected in the tree) * * @param key - TreePath in string format * @return/*from w ww. j av a 2 s .c o m*/ */ private List<Element> getEltsForTable(String key) { if (key == null) return this.elements; if (key.contains("[root,")) key = key.substring(7, key.length() - 1); // 7 => '[root, ' else key = key.substring(1, key.length() - 1); key = key.replaceAll(", ", "."); List<Element> dispElts = new LinkedList<Element>(); for (Element e : this.elements) { if (e.attributeValue("name").contains(".")) { if (e.attributeValue("name").startsWith("[" + key + ".")) { Element elt = e.createCopy(); elt.attribute("name").setValue(e.attributeValue("name").substring(key.length() + 2, e.attributeValue("name").length() - 1)); dispElts.add(elt); } } else dispElts.add(e.createCopy()); } return dispElts; }
From source file:com.devoteam.srit.xmlloader.gui.frames.JFrameEditableParameters.java
License:Open Source License
public void apply(List<Element> elts) { if (elts != null) { this.jButtonOK.setEnabled(true); valueChanged = true;// w w w . j a va 2s. c o m String key = ""; if (jTree1.getSelectionPath() == null) { for (Element e : elts) { Iterator<Vector> iterator = (Iterator<Vector>) ((ModelEditableParameters) this.jTable1 .getModel()).getElements().iterator(); while (iterator.hasNext()) { Vector pair = iterator.next(); String name = (String) pair.get(0); if (!name.startsWith("[")) name = "[" + name + "]"; if (e.attributeValue("name").equalsIgnoreCase(name)) { e.attribute("value").setValue((String) pair.get(2)); } } } } else { key = jTree1.getSelectionPath().toString(); key = key.substring(7, key.length() - 1); // 7 => '[root, ' key = key.replaceAll(", ", "."); for (Element e : elts) { if (e.attributeValue("name").contains(".")) { Iterator<Vector> iterator = (Iterator<Vector>) ((ModelEditableParameters) this.jTable1 .getModel()).getElements().iterator(); while (iterator.hasNext()) { Vector pair = iterator.next(); if (e.attributeValue("name").equalsIgnoreCase("[" + key + "." + pair.get(0) + "]")) { e.attribute("value").setValue((String) pair.get(2)); } } } else { Iterator<Vector> iterator = (Iterator<Vector>) ((ModelEditableParameters) this.jTable1 .getModel()).getElements().iterator(); while (iterator.hasNext()) { Vector pair = iterator.next(); String name = (String) pair.get(0); if (!name.startsWith("[")) name = "[" + name + "]"; if (e.attributeValue("name").equalsIgnoreCase(name)) { e.attribute("value").setValue((String) pair.get(2)); } } } } } } }
From source file:com.devoteam.srit.xmlloader.gui.model.ModelEditableParameters.java
License:Open Source License
public void apply(List<Element> elts) { Vector dataVector = this.getDataVector(); for (Element element : elts) { Iterator<Vector> iterator = (Iterator<Vector>) dataVector.iterator(); while (iterator.hasNext()) { Vector pair = iterator.next(); if (element.attributeValue("name").equals((String) pair.get(0))) { element.attribute("value").setValue((String) pair.get(2)); }// w ww . j a va2 s .c o m } } }
From source file:com.devoteam.srit.xmlloader.rtp.jmf.StackRtp.java
License:Open Source License
/** Creates a specific RTP Msg */ public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception { MsgRtp msgRtp = new MsgRtp(); // instanciates the channel String channelName = root.attributeValue("sessionName"); Channel channel = getChannel(channelName); if (channel != null) { msgRtp.setChannel(channel);/*from w w w. ja va 2s . c o m*/ } else if ((channel == null) && (root.attribute("listenpoint") == null)) { throw new ExecutionException("The channel <name=" + channelName + "> does not exist"); } if (root.element("flow") != null) { throw new Exception("The JMF RTP stack does not support <flow> tag, use the light RTP stack instead"); } List<Element> listPackets = root.elements("packet"); boolean control = parseChannel(listPackets.get(0)); msgRtp.setControl(control); Iterator<Element> iter = listPackets.iterator(); while (iter.hasNext()) { Element packet = iter.next(); RTPPacket rtpPacket = parsePacket(packet); msgRtp.add(rtpPacket); } return msgRtp; }
From source file:com.doculibre.constellio.izpack.PersistenceXMLUtils.java
License:Open Source License
@SuppressWarnings("unchecked") public static void run(AbstractUIProcessHandler handler, String[] args) { if (args.length != 5) { System.out.println("persistence_mysqlPath defaultPersistencePath server login password"); return;/* w ww . j a v a 2s . c o m*/ } String persistence_mysqlPath = args[0]; String defaultPersistencePath = args[1]; String server = args[2]; String login = args[3]; String password = args[4]; Document xmlDocument; try { xmlDocument = new SAXReader().read(persistence_mysqlPath); Element root = xmlDocument.getRootElement(); Iterator<Element> it = root.elementIterator("persistence-unit"); if (!it.hasNext()) { System.out.println("Corrupt persistence file :" + persistence_mysqlPath); return; } it = it.next().elementIterator("properties"); if (!it.hasNext()) { System.out.println("Corrupt persistence file :" + persistence_mysqlPath); return; } Element properties = it.next(); for (it = properties.elementIterator("property"); it.hasNext();) { Element property = it.next(); String id = property.attributeValue("name"); if (id.equals(SERVER_ELEMENT_ID)) { Attribute att = property.attribute("value"); att.setText(BEFORE_SERVER_NAME + server + AFTER_SERVER_NAME); } else { if (id.equals(LOGIN_ELEMENT_ID)) { Attribute att = property.attribute("value"); att.setText(login); } else { if (id.equals(PASSWORD_ELEMENT_ID)) { Attribute att = property.attribute("value"); att.setText(password); } } } } OutputFormat format = OutputFormat.createPrettyPrint(); File xmlFile = new File(persistence_mysqlPath); XMLWriter writer2 = new XMLWriter(new FileOutputStream(xmlFile), format); writer2.write(xmlDocument); writer2.close(); // copier au fichier de persistence par dfaut: xmlFile = new File(defaultPersistencePath); writer2 = new XMLWriter(new FileOutputStream(xmlFile), format); writer2.write(xmlDocument); writer2.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.doculibre.constellio.izpack.TomcatUtil.java
License:Open Source License
@SuppressWarnings("unchecked") public static void run(AbstractUIProcessHandler handler, String[] args) { if (args.length != 2) { System.out.println("serverPath port"); return;/* w ww .ja va2s .c o m*/ } String serverPath = args[0]; String port = args[1]; if (port.equals("8080")) { // C'est celui par defaut => ne rien faire return; } Document xmlDocument; try { xmlDocument = new SAXReader().read(serverPath); Element root = xmlDocument.getRootElement(); Iterator<Element> it = root.elementIterator("Service"); if (!it.hasNext()) { System.out.println("Corrupt persistence file :" + serverPath); return; } Element connectors = it.next(); for (it = connectors.elementIterator("Connector"); it.hasNext();) { Element connector = it.next(); String id = connector.attributeValue("protocol"); if (id.startsWith("HTTP")) { Attribute att = connector.attribute("port"); att.setText(port); break; } } OutputFormat format = OutputFormat.createPrettyPrint(); File xmlFile = new File(serverPath); XMLWriter writer2 = new XMLWriter(new FileOutputStream(xmlFile), format); writer2.write(xmlDocument); writer2.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.doculibre.constellio.services.SolrServicesImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public Boolean createMissingFieldTypes(Document schemaDocument) { Boolean newFielTypes = false; FieldTypeServices fieldTypeServices = ConstellioSpringUtils.getFieldTypeServices(); ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils.getConnectorManagerServices(); FieldTypeClassServices fieldTypeClassServices = ConstellioSpringUtils.getFieldTypeClassServices(); FilterClassServices filterClassServices = ConstellioSpringUtils.getFilterClassServices(); TokenizerClassServices tokenizerClassServices = ConstellioSpringUtils.getTokenizerClassServices(); AnalyzerClassServices analyzerClassServices = ConstellioSpringUtils.getAnalyzerClassServices(); ConnectorManager connectorManager = connectorManagerServices.getDefaultConnectorManager(); Element typesElement = schemaDocument.getRootElement().element("types"); if (typesElement != null) { List<Element> fieldTypeElements = typesElement.elements("fieldType"); for (Element fieldTypeElement : fieldTypeElements) { String name = fieldTypeElement.attributeValue("name"); FieldType fieldType = fieldTypeServices.get(name); if (fieldType == null) { newFielTypes = true;/* ww w . ja v a2 s.c o m*/ fieldType = new FieldType(); fieldType.setName(name); String fieldTypeClassName = fieldTypeElement.attributeValue("class"); FieldTypeClass fieldTypeClass = fieldTypeClassServices.get(fieldTypeClassName); if (fieldTypeClass == null) { fieldTypeClass = new FieldTypeClass(); fieldTypeClass.setClassName(fieldTypeClassName); fieldTypeClass.setConnectorManager(connectorManager); fieldTypeClassServices.makePersistent(fieldTypeClass); } fieldType.setFieldTypeClass(fieldTypeClass); fieldType.setConnectorManager(connectorManager); setProperty(fieldTypeElement, "indexed", fieldType); // Always true // setProperty(fieldTypeElement, "stored", fieldType); setProperty(fieldTypeElement, "multiValued", fieldType); setProperty(fieldTypeElement, "omitNorms", fieldType); setProperty(fieldTypeElement, "precisionStep", fieldType); setProperty(fieldTypeElement, "positionIncrementGap", fieldType); setProperty(fieldTypeElement, "sortMissingLast", fieldType); List<Element> analyzerElements = fieldTypeElement.elements("analyzer"); Element analyzerElement = null; Element queryAnalyzerElement = null; for (Element element : analyzerElements) { String type = element.attributeValue("type"); if (type == null || type.equals("index")) { analyzerElement = element; } else if (type.equals("query")) { queryAnalyzerElement = element; } } if (analyzerElement != null) { Analyzer analyzer = new Analyzer(); fieldType.setAnalyzer(analyzer); String analyzerClassName = analyzerElement.attributeValue("class"); if (analyzerClassName != null) { AnalyzerClass analyzerClass = analyzerClassServices.get(analyzerClassName); if (analyzerClass == null) { analyzerClass = new AnalyzerClass(); analyzerClass.setClassName(analyzerClassName); analyzerClass.setConnectorManager(connectorManager); analyzerClassServices.makePersistent(analyzerClass, false); } analyzer.setAnalyzerClass(analyzerClass); } Element tokenizerElement = analyzerElement.element("tokenizer"); if (tokenizerElement != null) { String tokenizerClassName = tokenizerElement.attributeValue("class"); TokenizerClass tokenizerClass = tokenizerClassServices.get(tokenizerClassName); if (tokenizerClass == null) { tokenizerClass = new TokenizerClass(); tokenizerClass.setClassName(tokenizerClassName); tokenizerClass.setConnectorManager(connectorManager); tokenizerClassServices.makePersistent(tokenizerClass, false); } analyzer.setTokenizerClass(tokenizerClass); } for (Element filterElement : (List<Element>) analyzerElement.elements("filter")) { AnalyzerFilter filter = new AnalyzerFilter(); filter.setAnalyzer(analyzer); analyzer.getFilters().add(filter); String filterClassName = filterElement.attributeValue("class"); FilterClass filterClass = filterClassServices.get(filterClassName); if (filterClass == null) { filterClass = new FilterClass(); filterClass.setClassName(filterClassName); filterClass.setConnectorManager(connectorManager); filterClassServices.makePersistent(filterClass); } filter.setFilterClass(filterClass); setProperty(filterElement, "catenateAll", filter); setProperty(filterElement, "catenateWords", filter); setProperty(filterElement, "delimiter", filter); setProperty(filterElement, "enablePositionIncrements", filter); setProperty(filterElement, "encoder", filter); setProperty(filterElement, "expand", filter); setProperty(filterElement, "generateNumberParts", filter); setProperty(filterElement, "generateWordParts", filter); setProperty(filterElement, "ignoreCase", filter); setProperty(filterElement, "inject", filter); setProperty(filterElement, "language", filter); setProperty(filterElement, "pattern", filter); if (filterElement.attribute("protected") != null) { filter.setProtectedText(filterElement.attributeValue("protected")); } setProperty(filterElement, "replace", filter); setProperty(filterElement, "replacement", filter); setProperty(filterElement, "splitOnCaseChange", filter); if (filterElement.attribute("synonyms") != null) { filter.setSynonymsText(filterElement.attributeValue("synonyms")); } if (filterElement.attribute("words") != null) { filter.setWordsText(filterElement.attributeValue("words")); } } } if (queryAnalyzerElement != null) { Analyzer queryAnalyzer = new Analyzer(); fieldType.setQueryAnalyzer(queryAnalyzer); String analyzerClassName = queryAnalyzerElement.attributeValue("class"); if (analyzerClassName != null) { AnalyzerClass analyzerClass = analyzerClassServices.get(analyzerClassName); if (analyzerClass == null) { analyzerClass = new AnalyzerClass(); analyzerClass.setClassName(analyzerClassName); analyzerClass.setConnectorManager(connectorManager); analyzerClassServices.makePersistent(analyzerClass, false); } queryAnalyzer.setAnalyzerClass(analyzerClass); } Element tokenizerElement = queryAnalyzerElement.element("tokenizer"); if (tokenizerElement != null) { String tokenizerClassName = tokenizerElement.attributeValue("class"); TokenizerClass tokenizerClass = tokenizerClassServices.get(tokenizerClassName); if (tokenizerClass == null) { tokenizerClass = new TokenizerClass(); tokenizerClass.setClassName(tokenizerClassName); tokenizerClass.setConnectorManager(connectorManager); tokenizerClassServices.makePersistent(tokenizerClass, false); } queryAnalyzer.setTokenizerClass(tokenizerClass); } for (Element filterElement : (List<Element>) queryAnalyzerElement.elements("filter")) { AnalyzerFilter filter = new AnalyzerFilter(); filter.setAnalyzer(queryAnalyzer); queryAnalyzer.getFilters().add(filter); String filterClassName = filterElement.attributeValue("class"); FilterClass filterClass = filterClassServices.get(filterClassName); if (filterClass == null) { filterClass = new FilterClass(); filterClass.setClassName(filterClassName); filterClass.setConnectorManager(connectorManager); filterClassServices.makePersistent(filterClass); } filter.setFilterClass(filterClass); setProperty(filterElement, "catenateAll", filter); setProperty(filterElement, "catenateWords", filter); setProperty(filterElement, "delimiter", filter); setProperty(filterElement, "enablePositionIncrements", filter); setProperty(filterElement, "encoder", filter); setProperty(filterElement, "expand", filter); setProperty(filterElement, "generateNumberParts", filter); setProperty(filterElement, "generateWordParts", filter); setProperty(filterElement, "ignoreCase", filter); setProperty(filterElement, "inject", filter); setProperty(filterElement, "language", filter); setProperty(filterElement, "pattern", filter); if (filterElement.attribute("protected") != null) { filter.setProtectedText(filterElement.attributeValue("protected")); } setProperty(filterElement, "replace", filter); setProperty(filterElement, "replacement", filter); setProperty(filterElement, "splitOnCaseChange", filter); if (filterElement.attribute("synonyms") != null) { filter.setSynonymsText(filterElement.attributeValue("synonyms")); } if (filterElement.attribute("words") != null) { filter.setWordsText(filterElement.attributeValue("words")); } } } fieldTypeServices.makePersistent(fieldType); } } } return newFielTypes; }
From source file:com.doculibre.constellio.services.SolrServicesImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w ww . j a va2 s . com public void resetDefaultDistance(RecordCollection collection) { ensureCore(collection); Document solrConfigDocument = readSolrConfig(collection); Element root = solrConfigDocument.getRootElement(); // 1. remove all requestHandler with name DISMAX_ATTRIBUTE_NAME for (Iterator<Element> it = root.elementIterator("requestHandler"); it.hasNext();) { Element currentRequestHandlerElement = it.next(); String currentSearchComponentName = currentRequestHandlerElement.attribute("name").getText(); if (currentSearchComponentName.equals(DISMAX_ATTRIBUTE_NAME)) { it.remove(); } } // 2. set requestHandler with name DEFAULT_DISTANCE_NAME as the // default distance for (Iterator<Element> it = root.elementIterator("requestHandler"); it.hasNext();) { Element currentRequestHandlerElement = it.next(); String currentSearchComponentName = currentRequestHandlerElement.attribute("name").getText(); if (currentSearchComponentName.equals(DEFAULT_DISTANCE_NAME)) { Attribute defaultAttribute = currentRequestHandlerElement.attribute("default"); if (defaultAttribute != null) { defaultAttribute.setText("true"); } else { currentRequestHandlerElement.addAttribute("default", "true"); } break; } } writeSolrConfig(collection, solrConfigDocument); initCore(collection); }