List of usage examples for org.dom4j Element addAttribute
Element addAttribute(QName qName, String value);
From source file:com.doculibre.constellio.services.SolrServicesImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// ww w . j av a 2s. c o m public void updateSchemaFieldTypes(RecordCollection collection) { String collectionName = SolrCoreContext.DEFAULT_COLLECTION_NAME; if (collection != null) { collectionName = collection.getName(); } Document schemaDocument = readSchema(collectionName); Element typesElement = schemaDocument.getRootElement().element("types"); List<Element> fieldTypeElements = typesElement.elements("fieldType"); for (Iterator<Element> it = fieldTypeElements.iterator(); it.hasNext();) { it.next(); it.remove(); } FieldTypeServices fieldTypeServices = ConstellioSpringUtils.getFieldTypeServices(); for (FieldType fieldType : fieldTypeServices.list()) { Element fieldTypeElement = DocumentHelper.createElement("fieldType"); typesElement.add(fieldTypeElement); FieldTypeClass fieldTypeClass = fieldType.getFieldTypeClass(); addNotNullAttribute(fieldTypeElement, "name", fieldType); addNotNullAttribute(fieldTypeElement, "class", fieldTypeClass.getClassName()); addNotNullAttribute(fieldTypeElement, "indexed", fieldType); // Always true addNotNullAttribute(fieldTypeElement, "stored", true); addNotNullAttribute(fieldTypeElement, "multiValued", fieldType); addNotNullAttribute(fieldTypeElement, "omitNorms", fieldType); addNotNullAttribute(fieldTypeElement, "precisionStep", fieldType); addNotNullAttribute(fieldTypeElement, "positionIncrementGap", fieldType); addNotNullAttribute(fieldTypeElement, "sortMissingLast", fieldType); Analyzer analyzer = fieldType.getAnalyzer(); Analyzer queryAnalyzer = fieldType.getQueryAnalyzer(); if (analyzer != null) { Element analyzerElement = DocumentHelper.createElement("analyzer"); fieldTypeElement.add(analyzerElement); if (queryAnalyzer != null) { analyzerElement.addAttribute("type", "index"); } AnalyzerClass analyzerClass = analyzer.getAnalyzerClass(); if (analyzerClass != null) { analyzerElement.addAttribute("class", analyzerClass.getClassName()); } TokenizerClass tokenizerClass = analyzer.getTokenizerClass(); if (tokenizerClass != null) { Element tokenizerElement = DocumentHelper.createElement("tokenizer"); analyzerElement.add(tokenizerElement); tokenizerElement.addAttribute("class", tokenizerClass.getClassName()); } Collection<AnalyzerFilter> filters = analyzer.getFilters(); for (AnalyzerFilter filter : filters) { FilterClass filterClass = filter.getFilterClass(); Element filterElement = DocumentHelper.createElement("filter"); analyzerElement.add(filterElement); filterElement.addAttribute("class", filterClass.getClassName()); addNotNullAttribute(filterElement, "catenateAll", filter); addNotNullAttribute(filterElement, "catenateWords", filter); addNotNullAttribute(filterElement, "delimiter", filter); addNotNullAttribute(filterElement, "enablePositionIncrements", filter); addNotNullAttribute(filterElement, "encoder", filter); addNotNullAttribute(filterElement, "expand", filter); addNotNullAttribute(filterElement, "generateNumberParts", filter); addNotNullAttribute(filterElement, "generateWordParts", filter); addNotNullAttribute(filterElement, "ignoreCase", filter); addNotNullAttribute(filterElement, "inject", filter); addNotNullAttribute(filterElement, "language", filter); addNotNullAttribute(filterElement, "pattern", filter); if (filter.getProtectedText() != null) { filterElement.addAttribute("protected", filter.getProtectedText()); } addNotNullAttribute(filterElement, "replace", filter); addNotNullAttribute(filterElement, "replacement", filter); addNotNullAttribute(filterElement, "splitOnCaseChange", filter); if (filter.getSynonymsText() != null) { filterElement.addAttribute("synonyms", filter.getSynonymsText()); } if (filter.getWordsText() != null) { filterElement.addAttribute("words", filter.getWordsText()); } } } if (queryAnalyzer != null) { Element analyzerElement = DocumentHelper.createElement("analyzer"); fieldTypeElement.add(analyzerElement); analyzerElement.addAttribute("type", "query"); AnalyzerClass analyzerClass = queryAnalyzer.getAnalyzerClass(); if (analyzerClass != null) { analyzerElement.addAttribute("class", analyzerClass.getClassName()); } TokenizerClass tokenizerClass = queryAnalyzer.getTokenizerClass(); if (tokenizerClass != null) { Element tokenizerElement = DocumentHelper.createElement("tokenizer"); analyzerElement.add(tokenizerElement); tokenizerElement.addAttribute("class", tokenizerClass.getClassName()); } Collection<AnalyzerFilter> filters = queryAnalyzer.getFilters(); for (AnalyzerFilter filter : filters) { FilterClass filterClass = filter.getFilterClass(); Element filterElement = DocumentHelper.createElement("filter"); analyzerElement.add(filterElement); filterElement.addAttribute("class", filterClass.getClassName()); addNotNullAttribute(filterElement, "catenateAll", filter); addNotNullAttribute(filterElement, "catenateWords", filter); addNotNullAttribute(filterElement, "delimiter", filter); addNotNullAttribute(filterElement, "enablePositionIncrements", filter); addNotNullAttribute(filterElement, "encoder", filter); addNotNullAttribute(filterElement, "expand", filter); addNotNullAttribute(filterElement, "generateNumberParts", filter); addNotNullAttribute(filterElement, "generateWordParts", filter); addNotNullAttribute(filterElement, "ignoreCase", filter); addNotNullAttribute(filterElement, "inject", filter); addNotNullAttribute(filterElement, "language", filter); addNotNullAttribute(filterElement, "pattern", filter); if (filter.getProtectedText() != null) { filterElement.addAttribute("protected", filter.getProtectedText()); } addNotNullAttribute(filterElement, "replace", filter); addNotNullAttribute(filterElement, "replacement", filter); addNotNullAttribute(filterElement, "splitOnCaseChange", filter); if (filter.getSynonymsText() != null) { filterElement.addAttribute("synonyms", filter.getSynonymsText()); } if (filter.getWordsText() != null) { filterElement.addAttribute("words", filter.getWordsText()); } } } } writeSchema(collectionName, schemaDocument); if (collection != null) { // for _default_constellio, we do not need initialize initCore(collection); } }
From source file:com.doculibre.constellio.services.SolrServicesImpl.java
License:Open Source License
private static void addNotNullAttribute(Element element, String attributeName, Object attributeValue) { if (attributeValue != null) { element.addAttribute(attributeName, attributeValue.toString()); }/* w ww .j a v a2 s . c o m*/ }
From source file:com.doculibre.constellio.services.SolrServicesImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* ww w .j a v a 2 s. c om*/ 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); }
From source file:com.doculibre.constellio.services.SolrServicesImpl.java
License:Open Source License
private Element getDismaxElement(RecordCollection collection) { BaseElement disMaxElement = new BaseElement("requestHandler"); disMaxElement.addAttribute("name", DISMAX_ATTRIBUTE_NAME); disMaxElement.addAttribute("class", "solr.SearchHandler"); disMaxElement.addAttribute("default", "true"); Element lst = disMaxElement.addElement("lst"); lst.addAttribute("name", "defaults"); Element defType = lst.addElement("str"); defType.addAttribute("name", "defType"); defType.setText("edismax");// au lieu de "dismax" pour utiliser le // plugin/*from w ww.j a va 2s. co m*/ // :com.doculibre.constellio.solr.handler.component.DisMaxQParserPlugin Element qf = lst.addElement("str"); qf.addAttribute("name", "qf"); StringBuilder boostsDismaxField = new StringBuilder(); for (IndexField current : collection.getIndexedIndexFields()) { if (current.getBoostDismax() != 1 || IndexField.DEFAULT_SEARCH_FIELD.equals(current.getName())) { boostsDismaxField.append(" " + current.getName() + "^" + current.getBoostDismax()); } } qf.setText(boostsDismaxField.toString()); Element tie = lst.addElement("float"); tie.addAttribute("name", "tie"); tie.setText("0.01"); // <requestHandler name="dismax" class="solr.SearchHandler" // default="true"> // <lst name="defaults"> // <str name="defType">dismax</str> // <str name="qf">a_name a_alias^0.8 a_member_name^0.4</str> // <float name="tie">0.1</float> // </lst> // </requestHandler> return disMaxElement; }
From source file:com.doculibre.constellio.utils.izpack.UsersXmlFileUtils.java
License:Open Source License
private static Element toXmlElement(ConstellioUser constellioUser) { BaseElement user = new BaseElement(USER); user.addAttribute(FIRST_NAME, constellioUser.getFirstName()); user.addAttribute(LAST_NAME, constellioUser.getLastName()); user.addAttribute(LOGIN, constellioUser.getUsername()); user.addAttribute(PASSWORD_HASH, constellioUser.getPasswordHash()); if (constellioUser.getLocale() != null) { user.addAttribute(LOCALE, constellioUser.getLocaleCode()); }// w ww .j a va2s .com Set<String> constellioRoles = constellioUser.getRoles(); if (!constellioRoles.isEmpty()) { Element roles = user.addElement(ROLES); for (String constellioRole : constellioRoles) { Element role = roles.addElement(ROLE); role.addAttribute(VALUE, constellioRole); } } return user; }
From source file:com.dreikraft.axbo.sound.SoundPackageUtil.java
/** * creates a package-info.xml from the SoundPackage Bean * * @param soundPackage a SoundPackage Bean containing all the meta information * @return a dom4j document//from w w w . ja va2 s .com */ public static Document createPackageInfoXml(final SoundPackage soundPackage) { Document document = DocumentHelper.createDocument(); document.setXMLEncoding(ENCODING); Element rootNode = document.addElement(SoundPackageNodes.axboSounds.toString()); rootNode.addElement(SoundPackageNodes.packageName.toString()).addText(soundPackage.getName()); rootNode.addElement(SoundPackageNodes.creator.toString()).addText(soundPackage.getCreator()); rootNode.addElement(SoundPackageNodes.creationDate.toString()) .addText(new SimpleDateFormat(pattern).format(soundPackage.getCreationDate())); Element securityNode = rootNode.addElement(SoundPackageNodes.security.toString()); securityNode.addElement(SoundPackageNodes.serialNumber.toString()).addText(soundPackage.getSerialNumber()); securityNode.addElement(SoundPackageNodes.enforced.toString()) .addText("" + soundPackage.isSecurityEnforced()); Element soundsNode = rootNode.addElement(SoundPackageNodes.sounds.toString()); int id = 1; for (Sound sound : soundPackage.getSounds()) { Element soundNode = soundsNode.addElement(SoundPackageNodes.sound.toString()); soundNode.addAttribute(SoundPackageAttributes.id.toString(), String.valueOf(id)); soundNode.addElement(SoundPackageNodes.displayName.toString()).addText(sound.getName()); Element axboFileNode = soundNode.addElement(SoundPackageNodes.axboFile.toString()); axboFileNode.addElement(SoundPackageNodes.path.toString()).setText(sound.getAxboFile().extractName()); axboFileNode.addElement(SoundPackageNodes.type.toString()) .setText(sound.getAxboFile().getType().toString()); id++; } return document; }
From source file:com.dtolabs.client.services.JobDefinitionSerializer.java
License:Apache License
/** * Add nodefilter and dispatch element to job element for the nodeset, if not null * * @param job job element//from w ww . j ava 2 s. c o m * @param threadCount thread count * @param excludePrecedence exclude precedence set * @param nodeFilter node filter string */ private static void addNodefilters(final Element job, int threadCount, boolean keepgoing, boolean excludePrecedence, String nodeFilter) { final int threadcount = (threadCount > 1) ? threadCount : 1; if (null != nodeFilter) { final Element filters = job.addElement("nodefilters"); ; filters.addElement("filter").addText(nodeFilter); filters.addAttribute("excludeprecedence", Boolean.toString(excludePrecedence)); } final Element dispatch = job.addElement("dispatch"); dispatch.addElement("threadcount").addText(Integer.toString(threadcount)); dispatch.addElement("keepgoing").addText(Boolean.toString(keepgoing)); }
From source file:com.dtolabs.rundeck.core.cli.util.MvnPomInfoTool.java
License:Apache License
Document generateData() { Document doc = DocumentHelper.createDocument(); Element el = doc.addElement("packages"); String basepath = basedir.getAbsolutePath(); if (basepath.endsWith("/")) { basepath = basepath.substring(0, basepath.length() - 1); }/*from ww w. j a v a 2 s . c om*/ el.addAttribute("basedir", basepath); for (Iterator iterator = data.keySet().iterator(); iterator.hasNext();) { String file = (String) iterator.next(); Map data = (Map) this.data.get(file); logger.info(file + ": " + data); Element pkgelem = el.addElement("package"); pkgelem.addAttribute("name", data.get("artifactId") + "-" + data.get("version") + "." + data.get("packaging")); File f = new File(file); String relpom = file.substring(basepath.length() + 1); pkgelem.addAttribute("pom-path", relpom); String groupId = (String) data.get("groupId"); String relpath = groupId.replaceAll("\\.", "/"); pkgelem.addAttribute("repo-path", relpath); } return doc; }
From source file:com.dtolabs.shared.resources.ResourceXMLGenerator.java
License:Apache License
/** * Generate resources section and resource references * * @param ent element//from w w w. j ava 2 s. c o m * @param entity entity */ private void genAttributes(final Element ent, final ResourceXMLParser.Entity entity) { if (null == entity.getProperties()) { return; } for (final String key : entity.getProperties().stringPropertyNames()) { if (!ResourceXMLConstants.allPropSet.contains(key)) { //test attribute name is a valid XML attribute name if (XMLChar.isValidName(key) && !key.contains(":") && !key.contains(".")) { ent.addAttribute(key, entity.getProperties().getProperty(key)); } else { //add sub element final Element atelm = ent.addElement(ATTRIBUTE_TAG); atelm.addAttribute(ATTRIBUTE_NAME_ATTR, key); atelm.addAttribute(ATTRIBUTE_VALUE_ATTR, entity.getProperties().getProperty(key)); } } } }
From source file:com.dtolabs.shared.resources.ResourceXMLGenerator.java
License:Apache License
/** * Gen "node" tag contents//from w w w.j a va2 s . c o m * * @param ent element * @param entity entity */ private void genNode(final Element ent, final ResourceXMLParser.Entity entity) { for (final String nodeProp : nodeProps) { ent.addAttribute(nodeProp, notNull(entity.getProperty(nodeProp))); } genAttributes(ent, entity); }