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.processpuzzle.party.artifact.CompanyDataLoader.java

License:Open Source License

private void createEmailAddress(Element element, CompanyDataSheet companyDataSheet, int idx) {
    Element emailAddressElement = element.element(EMAIL_ADDRESS_ELEMENT_PREFIX + idx);
    if (emailAddressElement != null) {
        String emailStr = emailAddressElement.getText();
        String emailAddress = !"".equals(emailStr) ? emailStr : null;
        if (emailAddress != null) {
            EmailAddress email = addressFactory.createEmailAddress(emailAddress);
            if (email != null) {
                if (idx == 1) {
                    email.setIsDefault(true);
                }//ww w.ja  v  a2  s.  c  o m
                companyDataSheet.addAddress(email);
            }
        }
    }
}

From source file:com.processpuzzle.party.artifact.CompanyDataLoader.java

License:Open Source License

private void createPhoneAddress(Element element, CompanyDataSheet companyDataSheet, int idx) {
    String countryCode = null;/* ww  w . j  av a  2s.com*/
    String areaCode = null;
    String number = null;
    Element countryCodeElement = element.element(PHONE_ELEMENT_PREFIX + idx + COUNTRY_CODE_POSTFIX);
    if (countryCodeElement != null) {
        String countryCodeStr = countryCodeElement.getText();
        countryCode = !"".equals(countryCodeStr) ? countryCodeStr : null;
    }

    Element areaCodeElement = element.element(PHONE_ELEMENT_PREFIX + idx + AREA_CODE_POSTFIX);
    if (areaCodeElement != null) {
        String areaCodeStr = areaCodeElement.getText();
        areaCode = !"".equals(areaCodeStr) ? areaCodeStr : null;
    }

    Element numberElement = element.element(PHONE_ELEMENT_PREFIX + idx + NUMBER_POSTFIX);
    if (numberElement != null) {
        String phoneNumberStr = numberElement.getText();
        number = !"".equals(phoneNumberStr) ? phoneNumberStr : null;
    }

    // create phone by factory
    if (!(countryCode == null && areaCode == null && number == null)) {
        TelecomAddress phone = addressFactory.createTelecomAddress(countryCode, areaCode, number);
        if (phone != null) {
            if (idx == 1) {
                phone.setIsDefault(true);
            }
            companyDataSheet.addAddress(phone);
        }
    }
}

From source file:com.processpuzzle.party.artifact.CompanyDataLoader.java

License:Open Source License

private void createGeographicAddress(DefaultUnitOfWork work, Element element, CompanyDataSheet companyDataSheet,
        int idx) {
    Element addressUsedForElement = element.element(GEOG_ADDRESS_ELEMENT_PREFIX + idx + USED_FOR_POSTFIX);
    String addressUsedFor = addressUsedForElement.getText();

    Element addressLandElement = element.element(GEOG_ADDRESS_ELEMENT_PREFIX + idx + LAND_POSTFIX);
    String land = addressLandElement.getText();
    String addressLand = !"".equals(land) ? land : null;

    if (addressLand != null) {

        String addressZipCode = null;
        Element addressZipCodeElement = element.element(GEOG_ADDRESS_ELEMENT_PREFIX + idx + ZIP_CODE_POSTFIX);
        if (addressZipCodeElement != null) {
            String zipCodeStr = addressZipCodeElement.getText();
            addressZipCode = !"".equals(zipCodeStr) ? zipCodeStr : null;
        }/*  w w  w . j  ava2s  .c  om*/

        String addressSettlement = null;
        Element addressSettlementElement = element
                .element(GEOG_ADDRESS_ELEMENT_PREFIX + idx + SETTLEMENT_POSTFIX);
        if (addressSettlementElement != null) {
            String settlementName = addressSettlementElement.getText();
            addressSettlement = !"".equals(settlementName) ? settlementName : null;
        }

        Settlement settlement = null;
        if (addressSettlement != null) {
            settlement = findOrCreateSettlement(work, addressSettlement, addressLand);
        }

        ZipCode zipCode = null;
        if (addressZipCode != null && !"".equals(addressZipCode) && settlement != null) {
            Integer zipCodeInteger = new Integer(addressZipCode);
            zipCode = findOrCreateZipcode(work, zipCodeInteger, settlement);
        }

        String addressStreet = null;
        Element addressStreetElement = element.element(GEOG_ADDRESS_ELEMENT_PREFIX + idx + STREET_POSTFIX);
        if (addressStreetElement != null) {
            String street = addressStreetElement.getText();
            addressStreet = !"".equals(street) ? street : null;
        }

        String addressBuildingNumber = null;
        Element addressBuildingNumberElement = element
                .element(GEOG_ADDRESS_ELEMENT_PREFIX + idx + BUILDING_NUMBER_POSTFIX);
        if (addressBuildingNumberElement != null) {
            String buildingNumber = addressBuildingNumberElement.getText();
            addressBuildingNumber = !"".equals(buildingNumber) ? buildingNumber : null;
        }

        if (!(addressStreet == null && addressBuildingNumber == null && zipCode == null
                && settlement == null)) {
            GeographicAddress address = addressFactory.createGeographicAddress(addressStreet,
                    addressBuildingNumber, zipCode, settlement);
            if (address != null) {
                if (idx == 1) {
                    address.setIsDefault(true);
                }
                if (addressUsedFor != null) {
                    address.setUsedFor(addressUsedFor);
                }

                companyDataSheet.addAddress(address);
            }
        }

    }
}

From source file:com.processpuzzle.party.artifact.PersonDataLoader.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override// w  ww . j a v a2  s  .c o m
public void loadData() {
    super.loadData();

    personDataSheetFactory = applicationContext.getEntityFactory(PersonDataSheetFactory.class);
    addressFactory = applicationContext.getEntityFactory(AddressFactory.class);
    countryFactory = applicationContext.getEntityFactory(CountryFactory.class);
    settlementFactory = applicationContext.getEntityFactory(SettlementFactory.class);
    zipCodeFactory = applicationContext.getEntityFactory(ZipCodeFactory.class);
    artifactRepository = applicationContext.getRepository(PersonDataSheetRepository.class);

    Document doc = getDocument();
    Element root = doc.getRootElement();

    for (Iterator<Element> i = root.elementIterator(ROOT_ELEMENT); i.hasNext();) {
        DefaultUnitOfWork work = new DefaultUnitOfWork(true);
        Element personElement = (Element) i.next();

        Element familyNameElement = personElement.element(FAMILY_NAME_ELEMENT);
        String familyName = familyNameElement.getText();

        try {
            Element prefixElement = personElement.element(NAME_PREFIX_ELEMENT);
            String prefix = !prefixElement.getText().equals("") ? prefixElement.getText() : null;

            Element givenNameElement = personElement.element(GIVEN_NAME_ELEMENT);
            String givenName = givenNameElement.getText();

            Element birthdayElement = personElement.element(BIRTHDAY_ELEMENT);
            String birthdayStr = birthdayElement.getText();

            TimePoint birthDateTP = null;
            if (birthdayStr != null) {
                Date birthDate = formatter.parse(birthdayStr);
                birthDateTP = new TimePoint(birthDate);
            }
            PersonDataSheet personDataSheet = personDataSheetFactory.create(familyName, givenName, birthDateTP);
            personDataSheet.setPrefix(prefix);

            int idx = 1;
            try {

                while (true) {
                    // create geographic address
                    createGeographicAddress(work, personElement, personDataSheet, idx);

                    // create phone address
                    createPhoneAddress(personElement, personDataSheet, idx);

                    // create email address
                    createEmailAddress(personElement, personDataSheet, idx);

                    idx++;

                }
            } catch (NullPointerException e) {
                // nothing serious just while(true) loop ends
            }
            // create webAddress
            createWebAddress(personElement, personDataSheet);

            savePersonDataSheet(work, personDataSheet);
            logSuccess(personDataSheet.getPerson());
            savedPersons.add(personDataSheet);

        } catch (Exception e) {
            logError(e, familyName);
        } finally {
            work.finish();
        }

    }
}

From source file:com.processpuzzle.party.artifact.PersonDataLoader.java

License:Open Source License

private void createWebAddress(Element personElement, PersonDataSheet personDataSheet) {
    Element webAddressElement = personElement.element(WEB_ADDRESS_ELEMENT);
    String webAddressStr = webAddressElement.getText();
    String webPageAddress = !"".equals(webAddressStr) ? webAddressStr : null;

    if (webPageAddress != null) {
        WebPageAddress webAddr = addressFactory.createWebPageAddress(webPageAddress);
        if (webAddr != null) {
            personDataSheet.addAddress(webAddr);
        }/*from   w w  w .  j ava 2 s.  c o m*/
    }
}

From source file:com.processpuzzle.party.artifact.PersonDataLoader.java

License:Open Source License

private void createEmailAddress(Element personElement, PersonDataSheet personDataSheet, int idx) {
    Element emailAddressElement = personElement.element(EMAIL_ADDRESS_ELEMENT_PREFIX + idx);
    if (emailAddressElement != null) {
        String emailStr = emailAddressElement.getText();
        String emailAddress = !"".equals(emailStr) ? emailStr : null;
        if (emailAddress != null) {
            EmailAddress email = addressFactory.createEmailAddress(emailAddress);
            if (email != null) {
                if (idx == 1) {
                    email.setIsDefault(true);
                }//w  w  w. j a va 2 s.co m
                personDataSheet.addAddress(email);
            }
        }
    }
}

From source file:com.processpuzzle.party.artifact.PersonDataLoader.java

License:Open Source License

private void createPhoneAddress(Element personElement, PersonDataSheet personDataSheet, int idx) {
    String countryCode = null;//from w w w.ja  v a2  s . com
    String areaCode = null;
    String number = null;
    Element countryCodeElement = personElement.element(PHONE_ELEMENT_PREFIX + idx + COUNTRY_CODE_POSTFIX);
    if (countryCodeElement != null) {
        String countryCodeStr = countryCodeElement.getText();
        countryCode = !"".equals(countryCodeStr) ? countryCodeStr : null;
    }

    Element areaCodeElement = personElement.element(PHONE_ELEMENT_PREFIX + idx + AREA_CODE_POSTFIX);
    if (areaCodeElement != null) {
        String areaCodeStr = areaCodeElement.getText();
        areaCode = !"".equals(areaCodeStr) ? areaCodeStr : null;
    }

    Element numberElement = personElement.element(PHONE_ELEMENT_PREFIX + idx + NUMBER_POSTFIX);
    if (numberElement != null) {
        String phoneNumberStr = numberElement.getText();
        number = !"".equals(phoneNumberStr) ? phoneNumberStr : null;
    }

    // create phone by factory
    if (!(countryCode == null && areaCode == null && number == null)) {
        TelecomAddress phone = addressFactory.createTelecomAddress(countryCode, areaCode, number);
        if (phone != null) {
            if (idx == 1) {
                phone.setIsDefault(true);
            }
            personDataSheet.addAddress(phone);
        }
    }
}

From source file:com.processpuzzle.party.artifact.PersonDataLoader.java

License:Open Source License

private void createGeographicAddress(DefaultUnitOfWork work, Element personElement,
        PersonDataSheet personDataSheet, int idx) {
    Element addressUsedForElement = personElement.element(GEOG_ADDRESS_ELEMENT_PREFIX + idx + USED_FOR_POSTFIX);
    String addressUsedFor = addressUsedForElement.getText();

    Element addressLandElement = personElement.element(GEOG_ADDRESS_ELEMENT_PREFIX + idx + LAND_POSTFIX);
    String land = addressLandElement.getText();
    String addressLand = !"".equals(land) ? land : null;

    if (addressLand != null) {

        String addressZipCode = null;
        Element addressZipCodeElement = personElement
                .element(GEOG_ADDRESS_ELEMENT_PREFIX + idx + ZIP_CODE_POSTFIX);
        if (addressZipCodeElement != null) {
            String zipCodeStr = addressZipCodeElement.getText();
            addressZipCode = !"".equals(zipCodeStr) ? zipCodeStr : null;
        }//from  w w w  .ja va 2 s . c  o  m

        String addressSettlement = null;
        Element addressSettlementElement = personElement
                .element(GEOG_ADDRESS_ELEMENT_PREFIX + idx + SETTLEMENT_POSTFIX);
        if (addressSettlementElement != null) {
            String settlementName = addressSettlementElement.getText();
            addressSettlement = !"".equals(settlementName) ? settlementName : null;
        }

        Settlement settlement = null;
        if (addressSettlement != null) {
            settlement = findOrCreateSettlement(work, addressSettlement, addressLand);
        }

        ZipCode zipCode = null;
        if (addressZipCode != null && !"".equals(addressZipCode) && settlement != null) {
            Integer zipCodeInteger = new Integer(addressZipCode);
            zipCode = findOrCreateZipcode(work, zipCodeInteger, settlement);
        }

        String addressStreet = null;
        Element addressStreetElement = personElement
                .element(GEOG_ADDRESS_ELEMENT_PREFIX + idx + STREET_POSTFIX);
        if (addressStreetElement != null) {
            String street = addressStreetElement.getText();
            addressStreet = !"".equals(street) ? street : null;
        }

        String addressBuildingNumber = null;
        Element addressBuildingNumberElement = personElement
                .element(GEOG_ADDRESS_ELEMENT_PREFIX + idx + BUILDING_NUMBER_POSTFIX);
        if (addressBuildingNumberElement != null) {
            String buildingNumber = addressBuildingNumberElement.getText();
            addressBuildingNumber = !"".equals(buildingNumber) ? buildingNumber : null;
        }

        if (!(addressStreet == null && addressBuildingNumber == null && zipCode == null
                && settlement == null)) {
            GeographicAddress address = addressFactory.createGeographicAddress(addressStreet,
                    addressBuildingNumber, zipCode, settlement);
            if (address != null) {
                if (idx == 1) {
                    address.setIsDefault(true);
                }
                if (addressUsedFor != null) {
                    address.setUsedFor(addressUsedFor);
                }

                personDataSheet.addAddress(address);
            }
        }

    }
}

From source file:com.pureinfo.dolphin.script.lang.ScriptBlock.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 */// ww w. j  av a  2  s  . com
public void fromXML(Element _element) throws PureException {
    List children = _element.elements();
    if (children == null || children.isEmpty())
        return;

    Element element;
    String sName;
    Statement statement;
    for (int i = 0; i < children.size(); i++) {
        element = (Element) children.get(i);
        sName = element.getName();
        if (sName.equals("statement")) {
            this.addContent(element.getText());
        } else {
            statement = new Statement();
            statement.fromXML(element);
            this.addContent(statement);
        }
    }
}

From source file:com.pureinfo.dolphin.script.param.Parameter.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 *//* ww  w. j a v a 2s  . c  om*/
public void fromXML(Element _element) throws PureException {
    CheckUtils.checkRequestNotNull(_element);

    CheckUtils.checkElementName(_element, ELEMENT_PARAMETER);

    setName(XMLUtil.getRequiredAttributeValue(_element, ATTRIBUTE_NAME));
    setValue(_element.getText());
}