List of usage examples for org.dom4j Element elements
List<Element> elements();
From source file:com.doculibre.constellio.services.SolrServicesImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w w w . j ava 2s . co m public void updateDismax(RecordCollection collection) { ensureCore(collection); Element dismaxElement = getDismaxElement(collection); Document solrConfigDocument = readSolrConfig(collection); Element root = solrConfigDocument.getRootElement(); boolean defaultSearchFieldFound = false; // 1. keep only one 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)) { // first copy other fields that are not defaults if the // query was set as default if (!defaultSearchFieldFound) { Attribute defaultAttribute = currentRequestHandlerElement.attribute("default"); if (defaultAttribute != null && defaultAttribute.getText().equals("true")) { defaultSearchFieldFound = true; defaultAttribute.setText("false"); List<Element> elements = currentRequestHandlerElement.elements(); for (Element element : elements) { if (element.attribute("name") != null && !element.attribute("name").getValue().equals("defaults")) { BaseElement cloneElement = new BaseElement(element.getName()); cloneElement.appendAttributes(element); cloneElement.appendContent(element); dismaxElement.add(cloneElement); } } } } it.remove(); } } if (!defaultSearchFieldFound) { // 2. add the parameters of the default RequestHandler to dismax // requestHandler (escape the parameter with name="defaults") for (Iterator<Element> it = root.elementIterator("requestHandler"); it.hasNext();) { Element currentRequestHandlerElement = it.next(); Attribute defaultAttribute = currentRequestHandlerElement.attribute("default"); if (defaultAttribute != null && defaultAttribute.getText().equals("true")) { defaultAttribute.setText("false"); List<Element> elements = currentRequestHandlerElement.elements(); for (Element element : elements) { if (element.attribute("name") != null && !element.attribute("name").getValue().equals("defaults")) { BaseElement cloneElement = new BaseElement(element.getName()); cloneElement.appendAttributes(element); cloneElement.appendContent(element); dismaxElement.add(cloneElement); } } break; } } } root.add(dismaxElement); writeSolrConfig(collection, solrConfigDocument); initCore(collection); }
From source file:com.easyjf.web.config.BeanConfigReader.java
License:Apache License
public static List parseBeansFromDocument(Document doc) { List ret = new ArrayList(); Element beans = XmlElementUtil.findElement("beans", doc.getRootElement()); if (beans == null) return ret; List list = beans.elements(); try {/*from w w w .j a v a2 s . co m*/ if (list != null) { for (int i = 0; i < list.size(); i++) { Element e = (Element) list.get(i); BeanDefinitionImpl definition = new BeanDefinitionImpl(); // ? definition.setBeanName(e.attributeValue("name")); Class clz = ClassUtils.forName(e.attributeValue("class")); definition.setBeanClass(clz); if (e.attributeValue("scope") != null) definition.setScope(e.attributeValue("scope")); if (e.attributeValue("factory-method") != null) definition.setFactoryMethod(e.attributeValue("factory-method")); // ??? List ps = XmlElementUtil.findElements("property", e); MutablePropertyValues mpv = parsePropertyValues(ps); definition.setPropertyValues(mpv); // ???? String autoInject = e.attributeValue("auto");// auto? if (autoInject == null) autoInject = e.attributeValue("inject"); handleAutoInject(definition, autoInject);// ? ps = XmlElementUtil.findElements("constructor-arg", e); ps = e.selectNodes("constructor-arg"); definition.setConstructorArguments(parseConstructorArguments(ps)); ret.add(definition); } } } catch (Exception e) { logger.error(I18n.getLocaleMessage("core.web.loading.Bean.configuration.information.error") + e); throw new com.easyjf.web.exception.FrameworkException( I18n.getLocaleMessage("core.web.loading.Bean.configuration.information.error"), e); } return ret; }
From source file:com.easyjf.web.config.XMLConfigFactory.java
License:Apache License
public void initForm(Map forms) { Element root = findElement("forms", getRootElement()); if (root == null) return;// ww w . jav a2 s .c o m List nodes = root.elements(); // ??forms // formsform?? // FromConfig?forms for (int i = 0; i < nodes.size(); i++) { Element e = (Element) nodes.get(i); FormConfig fc = new FormConfig(); // ???js?page????EasyJWeb?? fc.setAlertType(e.attributeValue("alertType")); // Formbean??WebForm fc.setBean(e.attributeValue("bean")); // ??? fc.setClientValidate(e.attributeValue("clientValidate")); // form?? fc.setName(e.attributeValue("name")); // ???? fc.setServerValidate(e.attributeValue("serverValidate")); // Form String events = e.attributeValue("event"); if (events != null && (!events.equals(""))) { String[] s = events.split(","); if (s != null) { List event = new ArrayList(); for (int t = 0; t < s.length; t++) { if (!s[t].equals("")) event.add(s[t]); } fc.setEvent(event); } } // form List lPage = findElements("property", e); Map pages = new HashMap(); for (int j = 0; j < lPage.size(); j++) { Element p = (Element) lPage.get(j); FormProperty prop = new FormProperty(); prop.setInitial(p.attributeValue("initial")); prop.setName(p.attributeValue("name")); prop.setNotNull(p.attributeValue("notNull")); prop.setSize(p.attributeValue("size")); prop.setType(p.attributeValue("type")); events = p.attributeValue("event"); if (events != null && (!events.equals(""))) { String[] s = events.split(","); if (s != null) { List event = new ArrayList(); for (int t = 0; t < s.length; t++) { if (!s[t].equals("")) event.add(s[t]); } prop.setEvent(event); } } pages.put(prop.getName(), prop); } fc.setPropertys(pages); forms.put(fc.getName(), fc); } }
From source file:com.easyjf.web.config.XMLConfigFactory.java
License:Apache License
public void initModule(Map modules) { Element root = findElement("modules", getRootElement()); if (root == null) return;// w ww .ja v a 2 s .co m // ??modules // modulesmodule?? // FromConfig?forms String injectType = "none"; if (root.attributeValue("inject") != null) injectType = root.attributeValue("inject"); List nodes = root.elements(); for (int i = 0; i < nodes.size(); i++) { Element e = (Element) nodes.get(i); Module mc = new Module(); // ??action mc.setAction(e.attributeValue("action")); // ?token if (e.attributeValue("autoToken") != null) mc.setAutoToken(Boolean.valueOf(e.attributeValue("autoToken"))); if (e.attributeValue("alias") != null) { mc.setAlias(e.attributeValue("alias")); } // ? if (e.attributeValue("defaultPage") != null) mc.setDefaultPage(e.attributeValue("defaultPage")); // ?? mc.setForm(e.attributeValue("form")); // ? /hello.ejf /hello mc.setPath(e.attributeValue("path")); // bean // singleton if (e.attributeValue("scope") != null) mc.setScope(e.attributeValue("scope")); if (e.attributeValue("method") != null) mc.setMethod(e.attributeValue("method")); if (e.attributeValue("inject") != null) mc.setInject(e.attributeValue("inject")); else mc.setInject(injectType); if (e.attributeValue("views") != null) mc.setViews(e.attributeValue("views")); if (e.attributeValue("view") != null) mc.setViews(e.attributeValue("view")); if (e.attributeValue("validate") != null) mc.setValidate(Boolean.parseBoolean(e.attributeValue("validate"))); if (e.attributeValue("messageResource") != null) { mc.setMessageResource(e.attributeValue("messageResource")); } List lPage = findElements("page", e); for (int j = 0; j < lPage.size(); j++) { Element p = (Element) lPage.get(j); Page page = new Page(); // Page?? modulePage?? page.setName(p.attributeValue("name")); if (mc.getDefaultPage() == null || mc.getDefaultPage().equals("")) { mc.setDefaultPage(page.getName()); } // Page html/template // ?,html page.setType(p.attributeValue("type")); // Pageurl, page.setUrl(p.attributeValue("url")); if (p.attributeValue("contentType") != null) page.setContentType(p.attributeValue("contentType")); // pages.put(page.getName(), page); mc.getPages().put(page.getName(), page); } // ,?? List interceptors = findElements("interceptor", e); for (int j = 0; j < interceptors.size(); j++) { Element p = (Element) interceptors.get(j); String interceptorClazz = p.attributeValue("class"); try { mc.getInterceptors().add(Class.forName(interceptorClazz).newInstance()); } catch (Exception ex) { } } // ?modulepropertyproperty mc.setPropertyValues(BeanConfigReader.parsePropertyValues(findElements("property", e))); modules.put(mc.getPath(), mc); } }
From source file:com.easyjf.web.config.XMLConfigFactory.java
License:Apache License
public void initPage(Map pages) { Element root = findElement("pages", getRootElement()); if (root == null) return;// w w w . ja va 2 s .c om List nodes = root.elements(); for (int i = 0; i < nodes.size(); i++) { Element e = (Element) nodes.get(i); Page page = new Page(); page.setName(e.attributeValue("name")); page.setType(e.attributeValue("type")); page.setUrl(e.attributeValue("url")); if (e.attributeValue("contentType") != null) page.setContentType(e.attributeValue("contentType")); pages.put(page.getName(), page); } }
From source file:com.ewcms.content.particular.util.XmlConvert.java
License:Open Source License
@SuppressWarnings("unchecked") public static List<Map<String, Object>> importXML(File xmlFile, String fileType) { if (xmlFile != null) { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); try {/*from ww w . j av a 2s .co m*/ List<InputStream> inputStreams = new ArrayList<InputStream>(); //FileType fileType = FileTypeJudge.getType(xmlFile); if (fileType.toLowerCase().equals("application/zip")) { inputStreams = parseXmlZIPFile(xmlFile); } else if (fileType.toLowerCase().equals("text/xml")) { InputStream in = new FileInputStream(xmlFile); inputStreams.add(in); } else { return null; } if (!inputStreams.isEmpty()) { SAXReader reader = new SAXReader(); Document doc = null; for (InputStream inputStream : inputStreams) { try { doc = reader.read(inputStream); if (doc != null) { Element root = doc.getRootElement(); Element metaViewData; Element projecties; for (Iterator<?> metaViewDataIterator = root .elementIterator("MetaViewData"); metaViewDataIterator.hasNext();) { metaViewData = (Element) metaViewDataIterator.next(); for (Iterator<?> projectiesIterator = metaViewData .elementIterator("PROPERTIES"); projectiesIterator.hasNext();) { projecties = (Element) projectiesIterator.next(); List<Element> elements = projecties.elements(); if (!elements.isEmpty()) { Map<String, Object> map = new HashMap<String, Object>(); for (Element element : elements) { map.put(element.getName(), element.getData()); } list.add(map); } } } } } catch (DocumentException e) { } finally { if (doc != null) { doc.clearContent(); doc = null; } } } } } catch (IOException e) { return null; } return list; } return null; }
From source file:com.footprint.server.common.config.ConfigHelper.java
License:Open Source License
private static MenuNode createMenuTree(Element element, MenuNode parent) { MenuNode menu = new MenuNode(); menu.setId(element.attributeValue("url")); menu.setName(element.attributeValue("name")); menu.setUrl(element.attributeValue("url")); menu.setParent(parent);/* www . j a va 2 s .c o m*/ if ("perm".equals(element.getName())) { menu.setPerm(true); } List<Element> elements = element.elements(); for (Element childElement : elements) { if ("perm".equals(childElement.getName()) || "menu".equals(childElement.getName())) { MenuNode child = createMenuTree(childElement, menu); menu.getChildren().add(child); } } return menu; }
From source file:com.founder.fix.fixflow.core.impl.util.XmlUtil.java
License:Apache License
@SuppressWarnings("rawtypes") public static List getChildElements(Element parent) { return parent.elements(); }
From source file:com.github.ipaas.ifw.util.XmlUtil.java
License:Apache License
/** * dom4jElement?map/*from www . ja v a 2s . c o m*/ * * @param elem * -- dom4j Element * @return -- map */ public static Map toMap(Element elem) { if (null == elem) { throw new IllegalArgumentException("XML Element , ?null"); } List<Element> elems = elem.elements(); Map tar = new LinkedHashMap(); for (Element item : elems) { generateMap(tar, item); } return tar; }
From source file:com.github.ipaas.ifw.util.XmlUtil.java
License:Apache License
/** * , dom4j Element???map/* w w w .j a va 2s. c o m*/ * * @param container * -- ?dom4j Elementmap * @param elem * -- dom4j Element * @return -- map */ private static Map generateMap(Map container, Element elem) { String name = elem.getName(); Object obj = container.get(name); // ???? if (null != obj) { if (!List.class.isInstance(obj)) { // ??,?List(List) List<Object> newBean = new LinkedList<Object>(); newBean.add(obj); container.put(name, newBean); generateMap(container, elem); } else { // ??,List(?elem?List) List<Object> bean = (List<Object>) obj; if (elem.isTextOnly()) { bean.add(elem.getStringValue()); } else { List<Element> subs = elem.elements(); Map nodes = new LinkedHashMap(); bean.add(nodes); for (Element item : subs) { generateMap(nodes, item); } } } return container; } // ????? if (elem.isTextOnly()) { // ?xml,? container.put(name, elem.getStringValue()); } else { List<Element> subs = elem.elements(); Map nodes = new LinkedHashMap(); container.put(name, nodes); for (Element item : subs) { generateMap(nodes, item); } } return container; }