List of usage examples for org.jdom2 Element getName
public String getName()
From source file:at.newmedialab.lmf.search.services.cores.SolrCoreServiceImpl.java
License:Apache License
/** * Create/update the schema.xml file for the given core according to the core definition. * * @param engine the engine configuration *//*from w w w .ja va 2s. c o m*/ private void createSchemaXml(SolrCoreConfiguration engine) throws MarmottaException { log.info("generating schema.xml for search program {}", engine.getName()); SAXBuilder parser = new SAXBuilder(XMLReaders.NONVALIDATING); File schemaTemplate = new File(getCoreDirectory(engine.getName()), "conf" + File.separator + "schema-template.xml"); File schemaFile = new File(getCoreDirectory(engine.getName()), "conf" + File.separator + "schema.xml"); try { Document doc = parser.build(schemaTemplate); Element schemaNode = doc.getRootElement(); Element fieldsNode = schemaNode.getChild("fields"); if (!schemaNode.getName().equals("schema") || fieldsNode == null) throw new MarmottaException(schemaTemplate + " is an invalid SOLR schema file"); schemaNode.setAttribute("name", engine.getName()); Program<Value> program = engine.getProgram(); for (FieldMapping<?, Value> fieldMapping : program.getFields()) { String fieldName = fieldMapping.getFieldName(); String solrType = null; try { solrType = solrProgramService.getSolrFieldType(fieldMapping.getFieldType().toString()); } catch (MarmottaException e) { solrType = null; } if (solrType == null) { log.error("field {} has an invalid field type; ignoring field definition", fieldName); continue; } Element fieldElement = new Element("field"); fieldElement.setAttribute("name", fieldName); fieldElement.setAttribute("type", solrType); // Set the default properties fieldElement.setAttribute("stored", "true"); fieldElement.setAttribute("indexed", "true"); fieldElement.setAttribute("multiValued", "true"); // FIXME: Hardcoded Stuff! if (solrType.equals("location")) { fieldElement.setAttribute("indexed", "true"); fieldElement.setAttribute("multiValued", "false"); } // Handle extra field configuration final Map<String, String> fieldConfig = fieldMapping.getFieldConfig(); if (fieldConfig != null) { for (Map.Entry<String, String> attr : fieldConfig.entrySet()) { if (SOLR_FIELD_OPTIONS.contains(attr.getKey())) { fieldElement.setAttribute(attr.getKey(), attr.getValue()); } } } fieldsNode.addContent(fieldElement); if (fieldConfig != null && fieldConfig.keySet().contains(SOLR_COPY_FIELD_OPTION)) { String[] copyFields = fieldConfig.get(SOLR_COPY_FIELD_OPTION).split("\\s*,\\s*"); for (String copyField : copyFields) { if (copyField.trim().length() > 0) { // ignore 'empty' fields Element copyElement = new Element("copyField"); copyElement.setAttribute("source", fieldName); copyElement.setAttribute("dest", copyField.trim()); schemaNode.addContent(copyElement); } } } else { Element copyElement = new Element("copyField"); copyElement.setAttribute("source", fieldName); copyElement.setAttribute("dest", "lmf.text_all"); schemaNode.addContent(copyElement); } //for suggestions, copy all fields to lmf.spellcheck (used for spellcheck and querying); //only facet is a supported type at the moment if (fieldConfig != null && fieldConfig.keySet().contains(SOLR_SUGGESTION_FIELD_OPTION)) { String suggestionType = fieldConfig.get(SOLR_SUGGESTION_FIELD_OPTION); if (suggestionType.equals("facet")) { Element copyElement = new Element("copyField"); copyElement.setAttribute("source", fieldName); copyElement.setAttribute("dest", "lmf.spellcheck"); schemaNode.addContent(copyElement); } else { log.error("suggestionType " + suggestionType + " not supported"); } } } if (!schemaFile.exists() || schemaFile.canWrite()) { FileOutputStream out = new FileOutputStream(schemaFile); XMLOutputter xo = new XMLOutputter(Format.getPrettyFormat().setIndent(" ")); xo.output(doc, out); out.close(); } else { log.error("schema file {} is not writable", schemaFile); } } catch (JDOMException e) { throw new MarmottaException("parse error while parsing SOLR schema template file " + schemaTemplate, e); } catch (IOException e) { throw new MarmottaException("I/O error while parsing SOLR schema template file " + schemaTemplate, e); } }
From source file:ataraxis.passwordmanager.AccountSorter.java
License:Open Source License
/** * Compare first object with second./*from w w w. java 2 s. c om*/ * The result my be: * <ul> * <li>-1 if first is group, second is not a group</li> * <li>1 if first is not a group but second is</li> * <li>any number of the String.compareTo()-Method if first and * second are from the same type</li> * </ul> * * @param first the first object * @param second the second object * @return the result of the comparison */ public int compare(Element first, Element second) { LOGGER.debug("compare(Object, Object) - start"); int result = 0; Element elm0 = (Element) first; Element elm1 = (Element) second; String elm0Type = elm0.getName(); String elm1Type = elm1.getName(); LOGGER.debug("element 0 is: " + elm0Type); LOGGER.debug("element 1 is: " + elm1Type); if (elm0Type.equals("group") && !elm1Type.equals("group")) { result = -1; } else if (!elm0Type.equals("group") && elm1Type.equals("group")) { result = 1; } else { result = (elm0.getAttribute("id").toString().toLowerCase()) .compareTo(elm1.getAttribute("id").toString().toLowerCase()); } LOGGER.debug("result is: " + result); LOGGER.debug("compare(Object, Object) - end"); return result; }
From source file:ataraxis.passwordmanager.XMLHandler.java
License:Open Source License
private List<PasswordEntry> getElementSubTree(Element parent) { List<PasswordEntry> allChildEntries = new ArrayList<PasswordEntry>(); Iterator<Element> topElements = parent.getChildren().iterator(); while (topElements.hasNext()) { Element currentElement = topElements.next(); PasswordEntry entry;//from w ww.ja v a 2 s .c om try { entry = getEntry(currentElement.getAttributeValue("id")); if (entry != null) { allChildEntries.add(entry); } String elementType = currentElement.getName(); if (elementType.equals("group")) { List<PasswordEntry> childs = getElementSubTree(currentElement); if (childs != null && childs.size() > 0) { allChildEntries.addAll(childs); } } } catch (EntryDoesNotExistException e) { logger.fatal(e.getMessage()); } } return allChildEntries; }
From source file:br.com.gsoftwares.util.ImportClient.java
private void trataElement(Element element) throws Exception { //Recuperamos os atributos filhos (Attributes) List atributes = element.getAttributes(); Iterator i_atr = atributes.iterator(); //Iteramos com os atributos filhos while (i_atr.hasNext()) { Attribute atrib = (Attribute) i_atr.next(); //System.out.println("\nattribute de (" + element.getName() + "):" + atrib.getName() + " - valor: " + atrib.getValue()); }//from www .j a v a 2s .com //Recuperamos os elementos filhos (children) List elements = element.getChildren(); Iterator it = elements.iterator(); //Iteramos com os elementos filhos, e filhos do dos filhos while (it.hasNext()) { Element el = (Element) it.next(); //System.out.println(el.getName() + " - " + el.getText()); switch (el.getName()) { case "CPF": CPF = el.getText(); Tipo = "F"; break; case "CNPJ": CPF = el.getText(); Tipo = "J"; break; case "xNome": Nome = el.getText(); Apelido = ""; break; case "xLgr": Rua = el.getText(); break; case "nro": numero = el.getText(); break; case "xCpl": Comp = el.getText(); break; case "xBairro": Bairro = el.getText(); break; case "cMun": Cod_Mun = el.getText(); break; case "xMun": Cidade = el.getText(); break; case "UF": Estado = el.getText(); break; case "CEP": Cep = el.getText(); break; case "fone": Telefone = el.getText(); break; case "IE": if (el.getText().equals("ISENTO")) { Tipo_ins = "2"; Ins = "ISENTO"; } else { if (el.getText().contains("^[0-9]*$")) { Tipo_ins = "1"; Ins = el.getText(); } else { Tipo_ins = "9"; Ins = ""; } break; } case "email": email = el.getText(); break; } trataElement(el); } }
From source file:br.com.gsoftwares.util.ImportProduto.java
private void trataElement(Element element) throws Exception { //Recuperamos os atributos filhos (Attributes) List atributes = element.getAttributes(); Iterator i_atr = atributes.iterator(); //Iteramos com os atributos filhos while (i_atr.hasNext()) { Attribute atrib = (Attribute) i_atr.next(); //System.out.println("\nattribute de (" + element.getName() + "):" + atrib.getName() + " - valor: " + atrib.getValue()); }/*from ww w .ja va 2s. c om*/ //Recuperamos os elementos filhos (children) List elements = element.getChildren(); Iterator it = elements.iterator(); //Iteramos com os elementos filhos, e filhos do dos filhos while (it.hasNext()) { Element el = (Element) it.next(); System.out.println(el.getName() + " - " + el.getText()); switch (el.getName()) { case "cProd": CPF = el.getText(); Tipo = "F"; break; case "xProd": CPF = el.getText(); Tipo = "J"; break; case "NCM": Nome = el.getText(); Apelido = ""; break; case "uCom": Rua = el.getText(); break; case "orig": numero = el.getText(); break; } trataElement(el); } }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a Principal object from a JDOM element. * * @param element The Principal JDOM element. * @return A Principal object./* ww w .j a v a 2s . co m*/ * @throws ReaderException */ protected final Principal getPrincipal(Element element) throws ReaderException { if (element == null) { String error = "null identity element"; throw new ReaderException(error); } if (!element.getName().equals(IDENTITY)) { String error = "expected identity element name, found " + element.getName(); throw new ReaderException(error); } String type = element.getAttributeValue(TYPE); if (type == null) { String error = "type attribute not found in identity element" + element.getName(); throw new ReaderException(error); } String identity = element.getText(); Principal principal; if (type.equals(IdentityType.OPENID.getValue())) { principal = new OpenIdPrincipal(identity); } else if (type.equals(IdentityType.CADC.getValue())) { principal = new NumericPrincipal(UUID.fromString(identity)); } else if (type.equals(IdentityType.USERNAME.getValue())) { principal = new HttpPrincipal(identity); } else if (type.equals(IdentityType.X500.getValue())) { principal = new X500Principal(identity); } else if (type.equals(IdentityType.ENTRY_DN.getValue())) { principal = new DNPrincipal(identity); } else { String error = "Unknown type attribute: " + type; throw new ReaderException(error); } return principal; }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a GroupProperty object from a JDOM element. * * @param element The GroupProperty JDOM element. * @return A GroupProperty object.// w w w .ja v a2 s . com * @throws ReaderException */ protected final GroupProperty getGroupProperty(Element element) throws ReaderException { if (element == null) { String error = "null property element"; throw new ReaderException(error); } if (!element.getName().equals(PROPERTY)) { String error = "expected property element name, found " + element.getName(); throw new ReaderException(error); } String key = element.getAttributeValue(KEY); if (key == null) { String error = "required key attribute not found"; throw new ReaderException(error); } String type = element.getAttributeValue(TYPE); if (type == null) { String error = "required type attribute not found"; throw new ReaderException(error); } Object value; if (type.equals(STRING)) { value = String.valueOf(element.getText()); } else { if (type.equals(INTEGER)) { value = Integer.valueOf(element.getText()); } else { String error = "Unsupported GroupProperty type: " + type; throw new ReaderException(error); } } Boolean readOnly = Boolean.valueOf(element.getAttributeValue(READ_ONLY)); return new GroupProperty(key, value, readOnly); }
From source file:ca.nrc.cadc.ac.xml.GroupListReader.java
License:Open Source License
/** * Construct a List of Group's from a Reader. * /*from www.j av a2s.c o m*/ * @param reader Reader. * @return Groups List of Group. * @throws ReaderException * @throws java.io.IOException * @throws java.net.URISyntaxException */ public List<Group> read(Reader reader) throws ReaderException, IOException, URISyntaxException { if (reader == null) { throw new IllegalArgumentException("reader must not be null"); } Document document; try { document = XmlUtil.buildDocument(reader); } catch (JDOMException jde) { String error = "XML failed validation: " + jde.getMessage(); throw new ReaderException(error, jde); } Element root = document.getRootElement(); String groupElemName = root.getName(); if (!groupElemName.equalsIgnoreCase(GROUPS)) { String error = "Expected groups element, found " + groupElemName; throw new ReaderException(error); } return getGroupList(root); }
From source file:ca.nrc.cadc.ac.xml.GroupReader.java
License:Open Source License
/** * Construct a Group from a Reader.//from w ww . ja v a2s.com * * @param reader Reader. * @return Group Group. * @throws ReaderException * @throws java.io.IOException */ public Group read(Reader reader) throws ReaderException, IOException { if (reader == null) { throw new IllegalArgumentException("reader must not be null"); } Document document; try { document = XmlUtil.buildDocument(reader); } catch (JDOMException jde) { String error = "XML failed validation: " + jde.getMessage(); throw new ReaderException(error, jde); } Element root = document.getRootElement(); String groupElemName = root.getName(); if (!groupElemName.equalsIgnoreCase(GROUP)) { String error = "Expected group element, found " + groupElemName; throw new ReaderException(error); } return getGroup(root); }
From source file:ca.nrc.cadc.ac.xml.UserListReader.java
License:Open Source License
/** * Construct a List of Users from a Reader. * * @param reader Reader.// w w w . j av a 2 s . co m * @return List of Users. * @throws ReaderException * @throws java.io.IOException */ public List<User> read(Reader reader) throws ReaderException, IOException { if (reader == null) { throw new IllegalArgumentException("reader must not be null"); } Document document; try { document = XmlUtil.buildDocument(reader); } catch (JDOMException jde) { String error = "XML failed validation: " + jde.getMessage(); throw new ReaderException(error, jde); } Element root = document.getRootElement(); String userElemName = root.getName(); if (!userElemName.equalsIgnoreCase(USERS)) { String error = "Expected users element, found " + userElemName; throw new ReaderException(error); } return getUserList(root); }