Example usage for org.dom4j Element getText

List of usage examples for org.dom4j Element getText

Introduction

In this page you can find the example usage for org.dom4j Element getText.

Prototype

String getText();

Source Link

Document

Returns the text value of this element without recursing through child elements.

Usage

From source file:com.wabacus.config.resource.dataimport.DataImportRes.java

License:Open Source License

public Object getValue(Element itemElement) {
    String key = itemElement.attributeValue("key");
    Element eleDataImport = itemElement.element("dataimport");
    if (eleDataImport == null) {
        throw new WabacusConfigLoadingException("???" + key
                + "???<dataimport/>?");
    }/*  ww w  . j a v a  2  s. com*/
    String filetype = eleDataImport.attributeValue("filetype");
    AbsDataImportConfigBean dataimportcbean = AbsDataImportConfigBean.createDataImportConfigBean(key, filetype);
    String filename = eleDataImport.attributeValue("filename");
    if (filename != null) {
        dataimportcbean.setFilename(filename.trim());
    }
    String tablename = eleDataImport.attributeValue("tablename");
    if (tablename == null || tablename.trim().equals("")) {
        throw new WabacusConfigLoadingException(
                "KEY" + key + "???tablename");
    }
    dataimportcbean.setTablename(tablename.trim());

    String importtype = eleDataImport.attributeValue("importtype");
    if (importtype == null || importtype.trim().equals(""))
        importtype = Consts_Private.DATAIMPORTTYPE_OVERWRITE;
    importtype = importtype.toLowerCase().trim();
    if (!importtype.equals(Consts_Private.DATAIMPORTTYPE_APPEND)
            && !importtype.equals(Consts_Private.DATAIMPORTTYPE_OVERWRITE)) {
        throw new WabacusConfigLoadingException(
                "KEY" + key + "???importtype");
    }
    dataimportcbean.setImporttype(importtype);
    String keyfields = eleDataImport.attributeValue("keyfields");
    if (keyfields != null && !keyfields.trim().equals("")) {
        dataimportcbean.setLstKeyfields(Tools.parseStringToList(keyfields.toUpperCase(), ";", false));
    }
    String filepath = eleDataImport.attributeValue("filepath");
    if (filepath == null || filepath.trim().equals("")) {
        filepath = Config.getInstance().getSystemConfigValue("default-dataimport-filepath", "");
        if (filepath.equals(""))
            throw new WabacusConfigLoadingException("KEY" + key
                    + "??wabacus.cfg.xml?default-dataimoprt-filepath??filepath");
    }
    dataimportcbean.setFilepath(FilePathAssistant.getInstance().standardFilePath(filepath.trim()));
    String datasource = eleDataImport.attributeValue("datasource");
    if (datasource != null) {
        dataimportcbean.setDatasource(datasource.trim());
    }
    String interceptor = eleDataImport.attributeValue("interceptor");
    if (interceptor != null && !interceptor.trim().equals("")) {
        try {
            Object o = ConfigLoadManager.currentDynClassLoader.loadClassByCurrentLoader(interceptor.trim())
                    .newInstance();
            if (!(o instanceof IDataImportInterceptor)) {
                throw new WabacusConfigLoadingException(
                        "KEY" + key + "????"
                                + IDataImportInterceptor.class.getName() + "");
            }
            dataimportcbean.setInterceptor((IDataImportInterceptor) o);
        } catch (Exception e) {
            throw new WabacusConfigLoadingException("KEY" + key
                    + "???" + interceptor + "",
                    e);
        }
    }
    String autodetect = eleDataImport.attributeValue("autodetect");
    if (autodetect == null || !autodetect.trim().equals("false")) {
        Config.getInstance().addAutoDetectedDataImportBean(filepath, dataimportcbean);
    }

    Element eleColumnmap = eleDataImport.element("columnmap");
    if (eleColumnmap == null) {
        throw new WabacusConfigLoadingException(
                "KEY" + key + "???<columnmap/>");
    }
    ColumnMapBean cmbean = new ColumnMapBean(dataimportcbean);
    String matchmode = eleColumnmap.attributeValue("matchmode");
    if (matchmode != null) {
        matchmode = matchmode.toLowerCase().trim();
        if (matchmode.equals(""))
            matchmode = Consts_Private.DATAIMPORT_MATCHMODE_INITIAL;
        if (!Consts_Private.LST_DATAIMPORT_MATCHMODES.contains(matchmode)) {
            throw new WabacusConfigLoadingException("KEY" + key
                    + "???matchmode" + matchmode + "??");
        }
        cmbean.setMatchmode(matchmode);
    }
    String type = eleColumnmap.attributeValue("type");
    if (type == null || type.trim().equals("")) {
        throw new WabacusConfigLoadingException("KEY" + key
                + "??<columnmap/>?type");
    }
    type = type.trim().toLowerCase();
    List<String> lstTypes = Tools.parseStringToList(type, "=", false);
    if (lstTypes.size() == 1) {
        String exclusive = eleColumnmap.attributeValue("exclusive");
        List<String> lstExclusives = null;
        if (exclusive != null && !exclusive.trim().equals("")) {
            lstExclusives = Tools.parseStringToList(exclusive.toUpperCase(), ";", false);
        }
        if (lstTypes.get(0).equals("name")) {
            cmbean.setMaptype(ColumnMapBean.MAPTYPE_NAME);
            cmbean.setLstExclusiveColumns(lstExclusives);
        } else if (lstTypes.get(0).equals("index")) {
            cmbean.setMaptype(ColumnMapBean.MAPTYPE_INDEX);
            if (lstExclusives != null) {
                List lstTemp = new ArrayList();
                for (String colTmp : lstExclusives) {
                    if (colTmp.trim().equals(""))
                        continue;
                    lstTemp.add(Integer.parseInt(colTmp.trim()));
                }
                if (lstTemp.size() > 0) {
                    cmbean.setLstExclusiveColumns(lstTemp);
                }
            }
        } else {
            throw new WabacusConfigLoadingException("KEY" + key
                    + "??<columnmap/>?type" + type
                    + "??");
        }
    } else if (lstTypes.size() == 2) {
        String dbcoltype = lstTypes.get(0).trim();
        String filecoltype = lstTypes.get(1).trim();
        String columnmaps = eleColumnmap.getText();
        if (columnmaps == null || columnmaps.trim().equals("")) {
            throw new WabacusConfigLoadingException("KEY" + key
                    + "??<columnmap/>?type" + type
                    + "?");
        }
        columnmaps = Tools.formatStringBlank(columnmaps);
        if (dbcoltype.equals("name") && filecoltype.equals("name")) {
            cmbean.setMaptype(ColumnMapBean.MAPTYPE_NAME_NAME);
        } else if (dbcoltype.equals("name") && filecoltype.equals("index")) {
            cmbean.setMaptype(ColumnMapBean.MAPTYPE_NAME_INDEX);
        } else if (dbcoltype.equals("index") && filecoltype.equals("name")) {
            cmbean.setMaptype(ColumnMapBean.MAPTYPE_INDEX_NAME);
        } else if (dbcoltype.equals("index") && filecoltype.equals("index")) {
            cmbean.setMaptype(ColumnMapBean.MAPTYPE_INDEX_INDEX);
        } else {
            throw new WabacusConfigLoadingException("KEY" + key
                    + "??<columnmap/>?type" + type
                    + "??");
        }
        cmbean.parseColMaps(key, columnmaps);
    } else {
        throw new WabacusConfigLoadingException("KEY" + key
                + "??<columnmap/>?type??");
    }
    dataimportcbean.setColMapBean(cmbean);
    dataimportcbean.loadConfig(eleDataImport);
    dataimportcbean.doPostLoad();
    dataimportcbean.buildImportSqls();
    return dataimportcbean;
}

From source file:com.wabacus.config.resource.InterceptorRes.java

License:Open Source License

public Object getValue(Element itemElement) {
    if (itemElement == null) {
        throw new WabacusConfigLoadingException("???");
    }// ww  w.j a  va 2 s .  co m
    String name = itemElement.attributeValue("key");
    Element eleInterceptor = itemElement.element("interceptor");
    if (eleInterceptor == null) {
        throw new WabacusConfigLoadingException(
                "???" + itemElement.attributeValue("key")
                        + "??<interceptor/>?");
    }
    List<String> lstImportPackages = ConfigLoadAssistant.getInstance().loadImportsConfig(eleInterceptor);
    Element elePreAction = eleInterceptor.element("preaction");
    String preaction = elePreAction == null ? null : elePreAction.getText();
    Element elePostAction = eleInterceptor.element("postaction");
    String postaction = elePostAction == null ? null : elePostAction.getText();
    Element eleSaveaction = eleInterceptor.element("saveaction");
    String saveaction = eleSaveaction == null ? null : eleSaveaction.getText();
    Element eleSaverowaction = eleInterceptor.element("saveaction-perrow");
    String saverowaction = eleSaverowaction == null ? null : eleSaverowaction.getText();
    Element eleSavesqlaction = eleInterceptor.element("saveaction-peraction");
    String savesqlaction = eleSavesqlaction == null ? null : eleSavesqlaction.getText();
    Element eleBeforeLoadData = eleInterceptor.element("beforeloaddata");
    String beforeloaddata = eleBeforeLoadData == null ? null : eleBeforeLoadData.getText();
    Element eleAfterLoadData = eleInterceptor.element("afterloaddata");
    Element eleBeforeDisplay = eleInterceptor.element("beforedisplay");
    String beforedisplay = eleBeforeDisplay == null ? null : eleBeforeDisplay.getText();
    String afterloaddata = eleAfterLoadData == null ? null : eleAfterLoadData.getText();
    Element eleDisplayPerRow = eleInterceptor.element("beforedisplay-perrow");
    String displayperrow = eleDisplayPerRow == null ? null : eleDisplayPerRow.getText();
    Element eleDisplayPerCol = eleInterceptor.element("beforedisplay-percol");
    String displaypercol = eleDisplayPerCol == null ? null : eleDisplayPerCol.getText();

    if (Tools.isEmpty(preaction, true) && Tools.isEmpty(postaction, true) && Tools.isEmpty(saveaction, true)
            && Tools.isEmpty(saverowaction, true) && Tools.isEmpty(savesqlaction, true)
            && Tools.isEmpty(beforeloaddata, true) && Tools.isEmpty(afterloaddata, true)
            && Tools.isEmpty(beforedisplay, true) && Tools.isEmpty(displayperrow, true)
            && Tools.isEmpty(displaypercol, true)) {
        return null;
    }
    Class c = ReportAssistant.getInstance().buildInterceptorClass("resource_" + name, lstImportPackages,
            preaction, postaction, saveaction, saverowaction, savesqlaction, beforeloaddata, afterloaddata,
            beforedisplay, displayperrow, displaypercol);
    if (c != null) {
        try {
            return (IInterceptor) c.newInstance();

        } catch (Exception e) {
            throw new WabacusConfigLoadingException(
                    "?" + name + "", e);
        }
    }
    return null;
}

From source file:com.wabacus.config.resource.StringRes.java

License:Open Source License

public Object getValue(Element itemElement) {
    if (itemElement == null) {
        throw new WabacusConfigLoadingException("?");
    }//from  w ww . ja  v  a 2s  .  c  om
    String value = itemElement.getText();
    value = value == null ? "" : value.trim();
    return value;
}

From source file:com.wabacus.config.resource.TemplateRes.java

License:Open Source License

public Object getValue(Element itemElement) {
    if (itemElement == null) {
        throw new WabacusConfigLoadingException("??");
    }/*w  w  w .  jav  a2s.c o m*/
    String value = itemElement.getText();
    value = value == null ? "" : value.trim();
    return TemplateParser.parseTemplateByContent(value);
}

From source file:com.wabacus.config.xml.XmlAssistant.java

License:Open Source License

public XmlElementBean parseXmlValueToXmlBean(Element element) {
    if (element == null)
        return null;
    if (!isLegalNamespaceElement(element)) {
        throw new WabacusConfigLoadingException("namespace" + element.getNamespacePrefix() + "??");
    }//  w  ww. j a  v  a2s .  com
    XmlElementBean xebean = new XmlElementBean(element.getName());
    String tagContent = element.getText();
    xebean.setContent(tagContent == null ? "" : tagContent.trim());
    Iterator itAttributes = element.attributeIterator();
    Map<String, String> mProps = new HashMap<String, String>();
    xebean.setMProperties(mProps);
    Attribute eleProps;
    while (itAttributes.hasNext()) {
        eleProps = (Attribute) itAttributes.next();
        mProps.put(eleProps.getName(), eleProps.getValue());
    }
    List<XmlElementBean> lstChildren = null;
    List lstChildElements = element.elements();
    if (lstChildElements != null && lstChildElements.size() > 0) {
        lstChildren = new ArrayList<XmlElementBean>();
        XmlElementBean eleTmp;
        for (Object eleObj : lstChildElements) {
            if (eleObj == null)
                continue;
            eleTmp = parseXmlValueToXmlBean((Element) eleObj);
            if (eleTmp == null)
                continue;
            eleTmp.setParentElement(xebean);
            lstChildren.add(eleTmp);
        }
        xebean.setLstChildElements(lstChildren);
    }
    return xebean;
}

From source file:com.waku.mmdataextract.CompareProductions.java

License:Open Source License

@SuppressWarnings("unchecked")
private static void processCompare(boolean single, String... ids) {
    Document document = MyHttpClient.getAsDom4jDoc(urlForCompare(ids));
    if (document == null) {
        if (single) {
            logger.info("####### Skip dirty productId ---> " + ids[0]);
            return;
        }/*from  w ww  .  ja  v  a2s. c om*/
        StringBuffer sb = new StringBuffer();
        for (String id : ids) {
            sb.append(id + "|");
        }
        logger.info("Get compare information failed -> " + sb);
        logger.info("Retry compare each id with NOIKA N95!");
        for (String id : ids) {
            logger.info("Retry compare -> " + id + "|" + NOKIA_N95);
            processCompare(true, id, NOKIA_N95);
        }
        return;
    }

    List<Element> headLine = document.selectNodes("//td[@class='sjbj_r_space']");
    logger.info("head size = " + headLine.size());

    for (Element e : headLine) {
        String head = e.getText();
        if (!HEAD_LIST.contains(head)) {
            HEAD_LIST.add(head);
        }
    }

    int count = 0;
    for (String id : ids) {
        if (id != null) {
            count++;
        }
    }
    logger.info("count = " + count);

    List<Element> eList = document.selectNodes("//td[@class='sjbj_l_space']");
    logger.info("eList size = " + eList.size());

    if (headLine.size() * count != eList.size()) {
        logger.info("Something wrong here! headLine.size() * count != eList.size()");
        logger.info("Try compare each id with NOIKA N95!");
        for (String id : ids) {
            logger.info("Try compare -> " + id + "|" + NOKIA_N95 + "|");
            processCompare(true, id, NOKIA_N95);
        }
        return;
    }

    List<Map<String, String>> list = new ArrayList<Map<String, String>>();
    for (int i = 0; i < eList.size(); i++) {
        String value = eList.get(i).getText();
        if (i < count) {
            list.add(new HashMap<String, String>());
            String toFileName = ids[i] + ".gif";
            ComprehensiveSearch.saveImage(eList.get(i).element("img").attributeValue("src"), toFileName);
            value = toFileName;
        }
        if (i / count == 2) { // ?
            value = customIconMap.get(eList.get(i).element("img").attributeValue("src"));
        }
        list.get(i % count).put(headLine.get(i / count).getText(), StringUtils.isEmpty(value) ? "N/A" : value);
        if (single) {
            i++; // skip the second one
        }
    }
    logger.info(list);
    RESULT_LIST.addAll(list);
}

From source file:com.waku.mmdataextract.ComprehensiveSearch.java

License:Open Source License

@SuppressWarnings("unchecked")
private static boolean searchDone(FileWriter fw, String brandId, int i) {
    Document resultPage = MyHttpClient.getAsDom4jDoc(SEARCH_ACTION, getMultipartEntity(brandId, i));
    List<Element> products = resultPage.selectNodes("//tr[@onmouseout]");
    logger.info("Get products count -> " + products.size());
    for (Element product : products) {
        List<Element> items = product.elements();
        // Remove last col
        items.remove(items.size() - 1);//from www . j  a  v a2 s.c o  m
        Element firstItem = items.get(0);
        String attributeValue = firstItem.attributeValue("onclick");
        String productId = attributeValue.substring(attributeValue.indexOf("('") + 2,
                attributeValue.indexOf("')"));
        if (prodIdList.contains(productId)) {
            logger.info("Get product id duplicated -> " + productId);
            continue;
        } else {
            logger.info("Get product id add -> " + productId);
            prodIdList.add(productId);
            StringBuilder sb = new StringBuilder();

            // Save image here
            String toFileName = productId + ".gif";
            saveImage(firstItem.element("img").attributeValue("src"), toFileName);
            sb.append(toFileName + ",");

            items.remove(0); // remove first one
            for (Element item : items) {
                sb.append(item.getText() + ",");
            }
            logger.info(sb.toString());
            sb.append("\n");
            try {
                fw.write(sb.toString());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    if (products.size() < 20)
        return true;
    else
        return false;
}

From source file:com.waku.mmdataextract.IMEI.java

License:Open Source License

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    WebDriver driver = new HtmlUnitDriver();
    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("Brand.xml");
    List<Element> brands = new SAXReader().read(in).selectNodes("/brand/option");
    for (Element brand : brands) {
        String bId = brand.attributeValue("value");
        FileWriter fw = new FileWriter(new File("output/" + brand.getText() + ".csv"));
        try {/*from   w ww. j av  a  2 s  .c  o  m*/
            Document doc = HttpCaller.httpGetAsXMLDoc(urlFor(bId));
            List<Element> products = doc.selectNodes("/products/product");
            for (Element e : products) {
                String qString = e.attributeValue("id");
                driver.get(urlFor(1, qString));
                int pageNumber = Integer
                        .parseInt(driver.findElements(By.xpath("//span[@class='font_b2']")).get(1).getText());
                if (pageNumber >= 1) {
                    for (int i = 1; i <= pageNumber; i++) {
                        readForEachPage(fw, driver, urlFor(i, qString));
                    }
                }
            }
            fw.close();
        } catch (RuntimeException e) {
            System.out.println("Skipped " + brand.getText());
            fw.write("Skipped!");
            fw.close();
        }
    }
}

From source file:com.waku.mmdataextract.IMEIMerge.java

License:Open Source License

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("IMEI");
    int colIndex = 0;
    int rowIndex = 0;
    Row row = sheet.createRow(rowIndex++);
    row.createCell(colIndex++).setCellValue("");
    row.createCell(colIndex++).setCellValue("?");
    row.createCell(colIndex++).setCellValue("?");
    row.createCell(colIndex++).setCellValue("IMEI");
    int i = 0;//from   w  w  w .java2 s  .  c  o m
    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("Brand.xml");
    for (Element brand : (List<Element>) new SAXReader().read(in).selectNodes("/brand/option")) {
        String brandName = brand.getText();
        System.out.println(brandName);
        File file = new File("output/" + brandName + ".csv");
        if (file.exists()) {
            System.out.println("Found file ->" + file.getAbsolutePath());
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            String line = null;
            boolean noDataAvailable = true;
            while ((line = br.readLine()) != null) {
                if (line.indexOf(",") != -1) {
                    rowIndex = addRow(line.split(","), sheet, rowIndex);
                    noDataAvailable = false;
                }
            }
            if (noDataAvailable) {
                System.out.println("No data for " + brandName);
                rowIndex = addRow(new String[] { "", brandName, "N/A", "N/A" }, sheet, rowIndex);
            }
            br.close();
        } else {
            System.out.println("No file for " + brandName);
            rowIndex = addRow(new String[] { "", brandName, "N/A", "N/A" }, sheet, rowIndex);
        }
        System.out.println(i++);
    }
    System.out.println(i);
    System.out.println(" ---------------------------------- File saved!");
    wb.write(new FileOutputStream(new File("IMEI.xls")));
}

From source file:com.wavemaker.runtime.data.spring.ConfigurationExt.java

License:Open Source License

@Override
protected void add(org.dom4j.Document doc) throws MappingException {
    Element hmNode = doc.getRootElement();
    Iterator rootChildren = hmNode.elementIterator();

    while (rootChildren.hasNext()) {
        final Element element = (Element) rootChildren.next();
        final String elementName = element.getName();

        if ("query".equals(elementName)) {
            String query = element.getText();
            query = insertTenantIdInQuery(query);
            element.setText(query);/*w w w. ja va  2 s. c  om*/
        }
    }

    super.add(doc);
}