Example usage for org.dom4j Element elementIterator

List of usage examples for org.dom4j Element elementIterator

Introduction

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

Prototype

Iterator<Element> elementIterator(QName qName);

Source Link

Document

Returns an iterator over the elements contained in this element which match the given fully qualified name.

Usage

From source file:com.openedit.users.filesystem.XmlUserArchive.java

License:Open Source License

/**
 * May be subclassed/*from   w  w  w  . j  a  va2s .co m*/
 */
public User loadUser(String inUserName) throws UserManagerException {

    ContentItem userfolder = getPageManager().getRepository().getStub(getUserDirectory() + "/");
    if (!userfolder.exists()) {
        File userfolderfile = new File(userfolder.getAbsolutePath());
        userfolderfile.mkdirs();

    }

    File userFile = loadUserFile(inUserName);
    if (!userFile.exists()) {
        ContentItem stub = getPageManager().getRepository().getStub("/WEB-INF/users/" + inUserName + ".xml");
        userFile = new File(stub.getAbsolutePath());
    }
    if (!userFile.exists()) {
        return null;
    }

    FileSystemUser user = new FileSystemUser();
    user.setUserName(inUserName);

    Element root = getXmlUtil().getXml(userFile, "UTF-8");

    user.setEnabled(true);
    // String enabled = root.attributeValue("enabled");
    // if (enabled != null && Boolean.parseBoolean(enabled) == false)
    // {
    // user.setEnabled(false);
    // }
    // else
    // {
    // user.setEnabled(true);
    // }

    Element passwordElem = root.element("password");
    if (passwordElem != null) {
        user.setPassword(passwordElem.getText());
    }

    Element lastLoginElem = root.element("lastLogined-Time");
    if (lastLoginElem != null) {
        user.setLastLoginTime(lastLoginElem.getText());
    }

    Element creationDateElem = root.element("creation-date");
    if (creationDateElem != null) {
        long time = Long.parseLong(creationDateElem.getText());
        user.setCreationDate(new Date(time));
    }
    MapPropertyContainer container = new MapPropertyContainer();
    container.loadProperties(root.element("properties"));
    user.setPropertyContainer(container);

    for (Iterator iter = root.elementIterator("group"); iter.hasNext();) {
        Element group = (Element) iter.next();
        Group g = getGroup(group.attributeValue("id"));
        if (g != null) {
            user.addGroup(g);
        } else {
            log.error("Missing group " + group.attributeValue("id"));
        }
    }
    // TODO :Replace with cache
    getUserNameToUserMap().put(user.getUserName(), user);

    return user;
}

From source file:com.processpuzzle.address.artifact.SettlementDataLoader.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*  w  w  w . j  a v  a 2 s  .  com*/
public void loadData() {
    super.loadData();

    countryFactory = applicationContext.getEntityFactory(CountryFactory.class);
    countryRepository = applicationContext.getRepository(CountryRepository.class);
    settlementFactory = applicationContext.getEntityFactory(SettlementFactory.class);
    settlementDataSheetFactory = applicationContext.getEntityFactory(SettlementDataSheetFactory.class);
    settlementDataSheetRepository = applicationContext.getRepository(SettlementDataSheetRepository.class);
    zipCodeFactory = applicationContext.getEntityFactory(ZipCodeFactory.class);

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

    for (Iterator<Element> i = root.elementIterator(ROOT_ELEMENT); i.hasNext();) {
        Element countryElement = i.next();

        Attribute countryNameAttribute = countryElement.attribute(COUNTRY_NAME_ATTRIBUTE);
        String countryName = countryNameAttribute.getValue();

        if (countryName != null && !"".equals(countryName)) {

            Country country = createAndSaveCountry(countryName);

            for (Iterator<Element> j = countryElement.elementIterator(SETTLEMENT_ELEMENT); j.hasNext();) {
                Element settlementElement = j.next();

                String settlementName = settlementElement.attribute(SETTLEMENT_NAME_ATTRIBUTE).getValue();
                if (settlementName != null && !"".equals(settlementName)) {
                    DefaultUnitOfWork work = new DefaultUnitOfWork(true);
                    SettlementDataSheet settlementDataSheet = null;
                    try {

                        settlementDataSheet = createAndSaveSettlement(work, settlementName, country);
                        savedSettlements.add(settlementDataSheet.getSettlement());

                        for (Iterator<Element> k = settlementElement.elementIterator(DISTRICT_ELEMENT); k
                                .hasNext();) {
                            Element districtElement = k.next();

                            String districtName = districtElement.attribute(DISTRICT_NAME_ATTRIBUTE).getValue();
                            District district = settlementFactory.createDistrict(districtName,
                                    settlementDataSheet.getSettlement());

                            // process ZipCodes
                            for (Iterator<Element> l = districtElement.elementIterator(ZIPCODE_ELEMENT); l
                                    .hasNext();) {
                                Element zipCodeElement = l.next();
                                String code = zipCodeElement.attribute(CODE_ATTRIBUTE).getValue();
                                ZipCode zipCode = zipCodeFactory.createZipCode(new Integer(code), district);
                            }
                        }

                        // process ZipCodes
                        for (Iterator<Element> l = settlementElement.elementIterator(ZIPCODE_ELEMENT); l
                                .hasNext();) {
                            Element zipCodeElement = l.next();
                            String code = zipCodeElement.attribute(CODE_ATTRIBUTE).getValue();
                            ZipCode zipCode = zipCodeFactory.createZipCode(new Integer(code),
                                    settlementDataSheet.getSettlement());
                        }

                    } catch (Exception e) {
                        logError(e, settlementName);
                    } finally {
                        work.finish();
                        logSuccess(settlementDataSheet.getSettlement());
                    }
                }
            }
        }
    }
}

From source file:com.processpuzzle.address.artifact.SettlementDataLoader.java

License:Open Source License

private void processZipCode(Element element, Settlement settlement) {
    for (Iterator<Element> l = element.elementIterator(ZIPCODE_ELEMENT); l.hasNext();) {

        Element zipCodeElement = l.next();
        String code = zipCodeElement.attribute(CODE_ATTRIBUTE).getValue();

        ZipCode zipCode = zipCodeFactory.createZipCode(new Integer(code), settlement);

    }//from w  w  w .  jav  a  2 s . co m
}

From source file:com.processpuzzle.internalization.domain.LocaleLoader.java

License:Open Source License

public void loadLocaleDefinition(ProcessPuzzleLocale locale) {
    super.loadData();

    Document doc = getDocument();
    Element root = doc.getRootElement();
    for (Iterator<?> i = root.elementIterator("locale"); i.hasNext();) {
        Element localeElement = (Element) i.next();
        try {//from  ww w.ja va 2 s .  c  om
            if (localeElement.attributeValue("language").equals(locale.getLanguage())
                    && localeElement.attributeValue("country").equals(locale.getCountry())) {
                loadQuantityFormatElements(localeElement.element("quantityFormatSpecifier"), locale);
                loadDateFormatElements(localeElement.element("dateFormatSpecifier"), locale);
                loadCurrencyElements(localeElement.element("currency"), locale);
                return;
            }
        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    throw new LocaleDefinitionNotFoundException(locale.getLanguage(), locale.getCountry());
}

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

License:Open Source License

public @Override @SuppressWarnings("unchecked") void loadData() {
    super.loadData();

    companyDataSheetFactory = applicationContext.getEntityFactory(CompanyDataSheetFactory.class);
    addressFactory = applicationContext.getEntityFactory(AddressFactory.class);
    countryFactory = applicationContext.getEntityFactory(CountryFactory.class);
    settlementFactory = applicationContext.getEntityFactory(SettlementFactory.class);
    zipCodeFactory = applicationContext.getEntityFactory(ZipCodeFactory.class);
    artifactRepository = applicationContext.getRepository(CompanyDataSheetRepository.class);

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

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

        Element shortNameElement = companyElement.element(SHORT_NAME_ELEMENT);
        String shortName = shortNameElement.getText();

        try {/*from   w w w  . j a  v a  2  s.c  o  m*/
            Element longNameElement = companyElement.element(LONG_NAME_ELEMENT);
            String longName = longNameElement.getText();

            CompanyDataSheet companyDataSheet = companyDataSheetFactory.create(longName);

            int idx = 1;
            try {

                while (true) {
                    // create geographic address
                    createGeographicAddress(work, companyElement, companyDataSheet, idx);

                    // create phone address
                    createPhoneAddress(companyElement, companyDataSheet, idx);

                    // create email address
                    createEmailAddress(companyElement, companyDataSheet, idx);

                    idx++;

                } //while

            } catch (NullPointerException e) {
                // nothing serious just while(true) loop ends
            }

            //create webAddress
            createWebAddress(companyElement, companyDataSheet);

            if (companyDataSheet != null) {
                saveCompanyDataSheet(work, companyDataSheet);
                logSuccess(companyDataSheet.getCompany());

                savedCompanies.add(companyDataSheet);
            }
        } catch (Exception e) {
            logError(e, shortName);
        } finally {
            work.finish();
        }

    } //end for
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override//  ww  w .  ja  va2  s.  co 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.pureinfo.srm.config.notice.domain.NoticeMgrImpl.java

License:Open Source License

private void insureLoaded() throws PureException {
    if (isLoaded())
        return;//  www  .ja v  a  2 s. c o  m
    synchronized (this) {
        if (isLoaded())
            return;

        String sFileName = ClassResourceUtil.mapFullPath(DATA_FILENAME, true);
        Element element = XMLUtil.fileToElement(sFileName);
        m_notices = new HashMap();
        for (Iterator iter = element.elementIterator(ELEMENT_NOTICE); iter.hasNext();) {
            Notice notice = new Notice();
            notice.fromXML((Element) iter.next());
            m_notices.put(notice.getName(), notice);
        }

        setLoaded(true);
    }
}

From source file:com.pureinfo.srm.config.notice.model.Notice.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element)
 *//*from   ww w. j a v  a2s .c  om*/
public void fromXML(Element _element) throws PureException {
    m_sName = _element.attributeValue(ATTRIBUTE_NAME);
    m_items = new HashMap();
    for (Iterator iter = _element.elementIterator(ELEMENT_ITEM); iter.hasNext();) {
        NoticeItem item = new NoticeItem();
        item.fromXML((Element) iter.next());
        m_items.put(item.getName(), item);
    }
}

From source file:com.pureinfo.srm.config.outlay.OutlayPayoutConfigHelper.java

License:Open Source License

private void init() {
    try {//from   w w w  . ja va 2 s.c om
        String sResource = ClassResourceUtil.mapFullPath(m_sConfigFileName, true);
        Element root = XMLUtil.fileToElement(sResource);
        Element element;
        for (Iterator iter = root.elementIterator("property"); iter.hasNext();) {
            element = (Element) iter.next();

            m_propertyObj = new OutlayPayoutPropertyObj();
            m_propertyObj.fromXML(element);
            map.put(m_propertyObj.getName(), m_propertyObj);
            all.add(m_propertyObj);
        }

    } catch (Exception ex) {
        throw new PureRuntimeException(SRMExceptionTypes.CONFIG_LOAD, m_sConfigFileName, ex);
    }

}

From source file:com.pureinfo.srm.sci.helper.SCIMappingHelper.java

License:Open Source License

private void init() {
    try {//from ww  w  .  j a v a2  s  .co  m
        String sResource = ClassResourceUtil.mapFullPath(m_sConfigFileName, true);
        Element root = XMLUtil.fileToElement(sResource);
        Element element;
        for (Iterator iter = root.elementIterator("dept"); iter.hasNext();) {
            element = (Element) iter.next();

            m_deptObj = new SCIDeptObj();
            m_deptObj.fromXML(element);
            map.put(m_deptObj.getCNName(), m_deptObj);
            all.add(m_deptObj);
        }

    } catch (Exception ex) {
        throw new PureRuntimeException(SRMExceptionTypes.CONFIG_LOAD, m_sConfigFileName, ex);
    }

}