Example usage for org.dom4j Element elementText

List of usage examples for org.dom4j Element elementText

Introduction

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

Prototype

String elementText(QName qname);

Source Link

Usage

From source file:aml.match.Alignment.java

License:Apache License

private void loadMappingsRDF(String file) throws DocumentException {
    AML aml = AML.getInstance();//from w w  w  .  jav  a  2 s  .  co m
    URIMap uris = aml.getURIMap();

    //Open the alignment file using SAXReader
    SAXReader reader = new SAXReader();
    File f = new File(file);

    Document doc = reader.read(f);
    //Read the root, then go to the "Alignment" element
    Element root = doc.getRootElement();
    Element align = root.element("Alignment");
    //Get an iterator over the mappings
    Iterator<?> map = align.elementIterator("map");
    while (map.hasNext()) {
        //Get the "Cell" in each mapping
        Element e = ((Element) map.next()).element("Cell");

        if (e == null)
            continue;
        //Get the source class
        String sourceURI = e.element("entity1").attributeValue("resource");

        //Get the target class
        String targetURI = e.element("entity2").attributeValue("resource");

        //Get the similarity measure
        String measure = e.elementText("measure");
        //Parse it, assuming 1 if a valid measure is not found
        double similarity = 1;
        if (measure != null) {
            try {
                similarity = Double.parseDouble(measure);
                if (similarity < 0 || similarity > 1)
                    similarity = 1;
            } catch (Exception ex) {
                /*Do nothing - use the default value*/}
            ;
        }
        //Get the relation
        String r = e.elementText("relation");
        if (r == null)
            r = "?";
        MappingRelation rel = MappingRelation.parseRelation(StringEscapeUtils.unescapeXml(r));
        //Check if the URIs are listed in the URI map 
        int sourceIndex = uris.getIndex(sourceURI);
        int targetIndex = uris.getIndex(targetURI);
        //If they are, add the mapping to the maps and proceed to next mapping
        if (sourceIndex > -1 && targetIndex > -1) {
            if (sourceIndex < targetIndex)
                add(sourceIndex, targetIndex, similarity, rel);
            else
                add(targetIndex, sourceIndex, similarity, rel);
        }
    }
}

From source file:aml.match.Alignment.java

License:Apache License

private void loadMappingsRDF2(String file) throws DocumentException {
    AML aml = AML.getInstance();/* w w  w .j  a  va  2s.  c o m*/
    URIMap uris = aml.getURIMap();

    //Open the alignment file using SAXReader
    SAXReader reader = new SAXReader();
    File f = new File(file);

    Document doc = reader.read(f);
    //Read the root, then go to the "Alignment" element
    Element root = doc.getRootElement();
    Element align = root.element("Alignment");
    //Get an iterator over the mappings
    Iterator<?> map = align.elementIterator("map");
    while (map.hasNext()) {
        //Get the "Cell" in each mapping
        Element e = ((Element) map.next()).element("Cell");

        if (e == null)
            continue;

        //Get the source class
        String sourceURI = e.element("entity1").element("Class").attributeValue("about");

        //Get the target class
        String targetURI = e.element("entity2").element("Class").element("and").element("Class")
                .attributeValue("about");

        //Get the similarity measure
        String measure = e.elementText("measure");
        //Parse it, assuming 1 if a valid measure is not found
        double similarity = 1;
        if (measure != null) {
            try {
                similarity = Double.parseDouble(measure);
                if (similarity < 0 || similarity > 1)
                    similarity = 1;
            } catch (Exception ex) {
                /*Do nothing - use the default value*/}
            ;
        }

        //Get the relation
        String r = e.elementText("relation");
        if (r == null)
            r = "?";

        MappingRelation rel = MappingRelation.parseRelation(StringEscapeUtils.unescapeXml(r));
        //Check if the URIs are listed in the URI map 

        int sourceIndex = uris.getIndex(sourceURI);

        int targetIndex = uris.getIndex(targetURI);

        //If they are, add the mapping to the maps and proceed to next mapping

        if (sourceIndex > -1 && targetIndex > -1) {
            if (sourceIndex < targetIndex)
                add(sourceIndex, targetIndex, similarity, rel);
            else
                add(targetIndex, sourceIndex, similarity, rel);
        }

    }
}

From source file:aml.match.CompoundAlignment.java

License:Apache License

private void loadMappingsRDF(String file) throws DocumentException {
    AML aml = AML.getInstance();//from   w  w w  . ja v a2  s  .c  o  m
    URIMap uris = aml.getURIMap();

    //Open the alignment file using SAXReader
    SAXReader reader = new SAXReader();

    File f = new File(file);

    Document doc = reader.read(f);
    //Read the root, then go to the "Alignment" element
    Element root = doc.getRootElement();

    Element align = root.element("Alignment");
    //Get an iterator over the mappings
    Iterator<?> map = align.elementIterator("map");

    while (map.hasNext()) {

        //Get the "Cell" in each mapping
        Element e = ((Element) map.next()).element("Cell");
        if (e == null) {
            continue;
        }
        //Get the source class
        String sourceURI = e.element("entity1").element("Class").attributeValue("about");
        uris.addURI(sourceURI);
        //Get the target class

        //Get the both target classes
        List<Element> elements = e.element("entity2").element("Class").element("and").elements("Class");

        //Get the target 1
        String targetURI = elements.get(0).attributeValue("about");
        uris.addURI(targetURI);
        //Get the target 2
        String target2URI = elements.get(1).attributeValue("about");

        uris.addURI(target2URI);
        //Get the similarity measure
        String measure = e.elementText("measure");

        //Parse it, assuming 1 if a valid measure is not found
        double similarity = 1;
        if (measure != null) {
            try {
                similarity = Double.parseDouble(measure);
                if (similarity < 0 || similarity > 1)
                    similarity = 1;
            } catch (Exception ex) {
                /*Do nothing - use the default value*/}
            ;
        }

        //Get the relation
        String r = e.elementText("relation");
        if (r == null)
            r = "?";
        MappingRelation rel = MappingRelation.parseRelation(StringEscapeUtils.unescapeXml(r));
        //Check if the URIs are listed in the URI map 
        int sourceIndex = uris.getIndex(sourceURI);
        int targetIndex = uris.getIndex(targetURI);
        int targetIndex2 = uris.getIndex(target2URI);
        //If they are, add the mapping to the maps and proceed to next mapping

        if (sourceIndex > -1 && targetIndex > -1 && targetIndex2 > -1) {
            if (sourceIndex < targetIndex)
                add(sourceIndex, targetIndex, targetIndex2, similarity, rel);
            else
                add(targetIndex, sourceIndex, targetIndex2, similarity, rel);
        }

    }
}

From source file:aml.util.MeSHParser.java

License:Apache License

public static void main(String[] args) throws Exception {
    Vector<String> concepts = new Vector<String>();
    Lexicon lexicon = new Lexicon();

    SAXReader reader = new SAXReader();
    File f = new File("store/knowledge/mesh.xml");
    Document doc = reader.read(f);
    Element root = doc.getRootElement();

    Iterator<?> records = root.elementIterator("DescriptorRecord");
    int index = 0;
    while (records.hasNext()) {
        Element concList = ((Element) records.next()).element("ConceptList");
        Iterator<?> conc = concList.elementIterator("Concept");
        while (conc.hasNext()) {
            Element c = (Element) conc.next();
            String conceptName = c.element("ConceptName").elementText("String");
            concepts.add(conceptName);/*  w  ww  .  jav  a  2 s.  c  om*/
            lexicon.add(index, conceptName, LexicalType.LABEL, "", 0.90);

            String casN1Name = c.elementText("CASN1Name");
            if (casN1Name != null)
                lexicon.add(index, casN1Name, LexicalType.FORMULA, "", 0.85);

            Element termList = c.element("TermList");
            Iterator<?> terms = termList.elementIterator("Term");
            while (terms.hasNext()) {
                Element t = (Element) terms.next();
                String termName = t.elementText("String");
                if (!conceptName.equals(termName))
                    lexicon.add(index, termName, LexicalType.EXACT_SYNONYM, "", 0.85);
            }
            index++;
        }
    }
    lexicon.save("store/knowledge/mesh.lexicon");
}

From source file:android.apn.androidpn.server.xmpp.handler.IQAuthHandler.java

License:Open Source License

/**
 * Handles the received IQ packet./*from  w  ww  . j  ava 2 s.  c o m*/
 * 
 * @param packet the packet
 * @return the response to send back
 * @throws UnauthorizedException if the user is not authorized
 */
public IQ handleIQ(IQ packet) throws UnauthorizedException {
    IQ reply = null;

    ClientSession session = sessionManager.getSession(packet.getFrom());
    if (session == null) {
        log.error("Session not found for key " + packet.getFrom());
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.internal_server_error);
        return reply;
    }

    try {
        Element iq = packet.getElement();
        Element query = iq.element("query");
        Element queryResponse = probeResponse.createCopy();

        if (IQ.Type.get == packet.getType()) { // get query
            String username = query.elementText("username");
            if (username != null) {
                queryResponse.element("username").setText(username);
            }
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(queryResponse);
            if (session.getStatus() != Session.STATUS_AUTHENTICATED) {
                reply.setTo((JID) null);
            }
        } else { // set query
            String resource = query.elementText("resource");
            String username = query.elementText("username");
            String password = query.elementText("password");
            String digest = null;
            if (query.element("digest") != null) {
                digest = query.elementText("digest").toLowerCase();
            }

            // Verify the resource
            if (resource != null) {
                try {
                    resource = JID.resourceprep(resource);
                } catch (StringprepException e) {
                    throw new UnauthorizedException("Invalid resource: " + resource, e);
                }
            } else {
                throw new IllegalArgumentException("Invalid resource (empty or null).");
            }

            // Verify the username
            if (username == null || username.trim().length() == 0) {
                throw new UnauthorizedException("Invalid username (empty or null).");
            }
            try {
                Stringprep.nodeprep(username);
            } catch (StringprepException e) {
                throw new UnauthorizedException("Invalid username: " + username, e);
            }
            username = username.toLowerCase();

            AuthToken token = null;
            /*
            // Verify that username and password are correct
            if (password != null && AuthManager.isPlainSupported()) {
               System.out.println("))))auth name password((((");
            token = AuthManager.authenticate(username, password);
            } else if (digest != null && AuthManager.isDigestSupported()) {
               System.out.println("))))auth name password token((((");
            token = AuthManager.authenticate(username, session
                    .getStreamID().toString(), digest);
            }
                    
            if (token == null) {
            throw new UnauthenticatedException();
            }
            */

            token = new AuthToken(username);
            // Set the session authenticated successfully
            session.setAuthToken(token, resource);
            packet.setFrom(session.getAddress());
            reply = IQ.createResultIQ(packet);
        }
    } catch (Exception ex) {
        log.error(ex);
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        if (ex instanceof IllegalArgumentException) {
            reply.setError(PacketError.Condition.not_acceptable);
        } else if (ex instanceof UnauthorizedException) {
            reply.setError(PacketError.Condition.not_authorized);
        } else if (ex instanceof UnauthenticatedException) {
            reply.setError(PacketError.Condition.not_authorized);
        } else {
            reply.setError(PacketError.Condition.internal_server_error);
        }
    }

    // Send the response directly to the session
    if (reply != null) {
        session.process(reply);
    }
    return null;
}

From source file:android.apn.androidpn.server.xmpp.handler.IQRegisterHandler.java

License:Open Source License

/**
 * Handles the received IQ packet.//from w w  w  .j a v  a 2 s .  c o m
 * 
 * @param packet the packet
 * @return the response to send back
 * @throws UnauthorizedException if the user is not authorized
 */
public IQ handleIQ(IQ packet) throws UnauthorizedException {
    IQ reply = null;

    ClientSession session = sessionManager.getSession(packet.getFrom());
    if (session == null) {
        log.error("Session not found for key " + packet.getFrom());
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.internal_server_error);
        return reply;
    }

    if (IQ.Type.get.equals(packet.getType())) {
        reply = IQ.createResultIQ(packet);
        if (session.getStatus() == Session.STATUS_AUTHENTICATED) {
            // TODO
        } else {
            reply.setTo((JID) null);
            reply.setChildElement(probeResponse.createCopy());
        }
    } else if (IQ.Type.set.equals(packet.getType())) {
        try {
            Element query = packet.getChildElement();
            if (query.element("remove") != null) {
                if (session.getStatus() == Session.STATUS_AUTHENTICATED) {
                    // TODO
                } else {
                    throw new UnauthorizedException();
                }
            } else {
                String username = query.elementText("username");
                String password = query.elementText("password");
                String email = query.elementText("email");
                String name = query.elementText("name");

                // Verify the username
                if (username != null) {
                    Stringprep.nodeprep(username);
                }

                // Deny registration of users with no password
                if (password == null || password.trim().length() == 0) {
                    reply = IQ.createResultIQ(packet);
                    reply.setChildElement(packet.getChildElement().createCopy());
                    reply.setError(PacketError.Condition.not_acceptable);
                    return reply;
                }

                if (email != null && email.matches("\\s*")) {
                    email = null;
                }

                if (name != null && name.matches("\\s*")) {
                    name = null;
                }

                User user;
                if (session.getStatus() == Session.STATUS_AUTHENTICATED) {
                    user = userService.getUser(session.getUsername());
                } else {
                    user = new User();
                }
                user.setUsername(username);
                user.setPassword(password);
                user.setEmail(email);
                user.setName(name);
                userService.saveUser(user);

                reply = IQ.createResultIQ(packet);
            }
        } catch (Exception ex) {
            log.error(ex);
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            if (ex instanceof UserExistsException) {
                reply.setError(PacketError.Condition.conflict);
            } else if (ex instanceof UserNotFoundException) {
                reply.setError(PacketError.Condition.bad_request);
            } else if (ex instanceof StringprepException) {
                reply.setError(PacketError.Condition.jid_malformed);
            } else if (ex instanceof IllegalArgumentException) {
                reply.setError(PacketError.Condition.not_acceptable);
            } else {
                reply.setError(PacketError.Condition.internal_server_error);
            }
        }
    }

    // Send the response directly to the session
    if (reply != null) {
        session.process(reply);
    }
    return null;
}

From source file:batch.core.om.Instance.java

License:Open Source License

/** Creates a test instance from a spec meta file. */
public Instance(URL baseUrl, Element instance) throws IOException {
    this(new URL(baseUrl, instance.attributeValue("href")));

    Iterator itr = instance.elementIterator("property");
    while (itr.hasNext()) {
        Element p = (Element) itr.next();
        properties.put(p.attributeValue("name"), p.elementText("value"));
    }/*w w w  .java2 s  .  c o  m*/
}

From source file:batch.performance.ScriptScenario.java

License:Open Source License

/**
 * Parses ECMAScript-based scenario from XML description
 * of the form:/*from   w  ww  .  java2  s .com*/
 * 
 * <pre><xmp>
 * <scenario>
 *   <prepare> ... </prepare>
 *   <run> ... </run>
 *   <teardown> ... </teardown>
 * </scenario>
 */
public ScriptScenario(Element performanceElement) {
    prepareScript = performanceElement.elementText("prepare");
    runScript = performanceElement.elementText("run");
    teardownScript = performanceElement.elementText("teardown");

    name = performanceElement.attributeValue("name", "script-based scenario");
}

From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java

protected void printHRWorkSchedules(SessionContainerWO sessionContainerWO, AdminPerson activePatient)
        throws Exception {
    table = new PdfPTable(10);
    table.setWidthPercentage(pageWidth);

    // title//from   w w  w.j  ava  2 s .  c  o m
    table.addCell(createTitleCell(getTran("web", "workSchedule"), 10));

    // compose object to pass search criteria with
    Workschedule findObject = new Workschedule();
    findObject.personId = Integer.parseInt(activePatient.personid); // required

    List workschedules = Workschedule.getList(findObject);
    String sReturn = "";

    if (workschedules.size() > 0) {
        // header
        table.addCell(createHeaderCell(getTran("web.hr", "begin"), 1));
        table.addCell(createHeaderCell(getTran("web.hr", "end"), 1));
        table.addCell(createHeaderCell(getTran("web.hr", "fte.short"), 1));
        table.addCell(createHeaderCell(getTran("web.hr", "type"), 2));
        table.addCell(createHeaderCell(getTran("web.hr", "details"), 4));
        table.addCell(createHeaderCell(getTran("web.hr", "duration"), 1));

        Hashtable hSort = new Hashtable();
        Workschedule workschedule;

        // sort on workschedule.getUid
        for (int i = 0; i < workschedules.size(); i++) {
            workschedule = (Workschedule) workschedules.get(i);
            hSort.put(workschedule.getUid() + "=" + workschedule.getUid(), workschedule);
        }

        Vector keys = new Vector(hSort.keySet());
        Collections.sort(keys);
        Collections.reverse(keys);

        Iterator iter = keys.iterator();
        while (iter.hasNext()) {
            workschedule = (Workschedule) hSort.get(iter.next());

            // parse xml
            String sXML = checkString(workschedule.scheduleXml);
            String sScheduleType = "", sScheduleHours = "";

            if (sXML.length() > 0) {
                SAXReader reader = new SAXReader(false);
                org.dom4j.Document xmlDoc = reader.read(new StringReader(sXML));

                // fetch type and hours
                org.dom4j.Element workScheduleElem = xmlDoc.getRootElement();
                if (workScheduleElem != null) {
                    org.dom4j.Element scheduleElem = workScheduleElem.element("Schedule");
                    if (scheduleElem != null) {
                        sScheduleType = checkString(scheduleElem.attributeValue("type"));

                        if (sScheduleType.equalsIgnoreCase("day")) {
                            sScheduleHours = checkString(scheduleElem.elementText("HoursPerDay"));
                        } else if (sScheduleType.equalsIgnoreCase("week")) {
                            org.dom4j.Element weekSchedule = scheduleElem.element("WeekSchedule");
                            if (weekSchedule != null) {
                                sScheduleHours = checkString(weekSchedule.elementText("HoursPerWeek"));
                            }
                        } else if (sScheduleType.equalsIgnoreCase("month")) {
                            sScheduleHours = checkString(scheduleElem.elementText("HoursPerMonth")) + " "
                                    + getTran("web.hr", "hours").toLowerCase();
                        }
                    }
                }
                workschedule.type = sScheduleType;
            }

            // one record
            table.addCell(createValueCell(ScreenHelper.getSQLDate(workschedule.begin), 1));
            table.addCell(createValueCell(ScreenHelper.getSQLDate(workschedule.end), 1));
            table.addCell(createValueCell(workschedule.fte + "%", 1));
            table.addCell(createValueCell(getTran("web.hr", sScheduleType + "Schedule")
                    + (sScheduleType.equals("week") ? " (" + getPredefinedWeekScheduleName(workschedule) + ")"
                            : ""),
                    2));
            table.addCell(createValueCell(getWorkscheduleDetails(workschedule), 4));
            table.addCell(createValueCell(sScheduleHours, 1));

            //addWorkscheduleDetails(table,workschedule);
        }
    } else {
        // no records found
        table.addCell(createValueCell(getTran("web", "noRecordsFound"), 10));
    }

    // add transaction to doc
    if (table.size() > 0) {
        doc.add(new Paragraph(" "));
        doc.add(table);
    }
}

From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java

private void addSalaryDetails(PdfPTable table, Salary salary) {
    PdfPTable detailsTable = new PdfPTable(10);
    detailsTable.setWidthPercentage(100);

    //*** XML 1 - benefits (multi-add) **************************
    if (salary.benefits.length() > 0) {
        detailsTable.addCell(createSubtitleCell(getTran("web.hr", "benefits"), 10));

        // header          
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 3));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 3));

        try {/*  w w  w .jav  a 2s.co  m*/
            // parse benefits from xml           
            SAXReader reader = new SAXReader(false);
            org.dom4j.Document document = reader.read(new StringReader(salary.benefits));
            org.dom4j.Element benefitsElem = document.getRootElement();

            if (benefitsElem != null) {
                String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpAmount;
                org.dom4j.Element benefitElem;

                Iterator benefitsIter = benefitsElem.elementIterator("Benefit");
                while (benefitsIter.hasNext()) {
                    benefitElem = (org.dom4j.Element) benefitsIter.next();

                    sTmpBegin = checkString(benefitElem.elementText("Begin"));
                    sTmpEnd = checkString(benefitElem.elementText("End"));
                    sTmpPeriod = checkString(benefitElem.elementText("Period"));
                    sTmpType = checkString(benefitElem.elementText("Type"));
                    sTmpAmount = checkString(benefitElem.elementText("Amount"));

                    // one benefit
                    detailsTable.addCell(createValueCell(sTmpBegin, 1));
                    detailsTable.addCell(createValueCell(sTmpEnd, 1));
                    detailsTable.addCell(createValueCell(getTran("hr.salary.period", sTmpPeriod), 2));
                    detailsTable.addCell(createValueCell(getTran("hr.salary.benefit.type", sTmpType), 3));

                    cell = createValueCell(
                            sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 3);
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    detailsTable.addCell(cell);
                }
            }
        } catch (Exception e) {
            Debug.printStackTrace(e);
        }
    }

    //*** XML 2 - bonuses (multi-add) **************************        
    if (salary.bonuses.length() > 0) {
        table.addCell(createSubtitleCell(getTran("web.hr", "bonuses"), 10));

        // header
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 2));
        detailsTable.addCell(createHeaderCell(getTran("web", "percentage"), 2));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 2));

        try {
            // parse bonuses from xml           
            SAXReader reader = new SAXReader(false);
            org.dom4j.Document document = reader.read(new StringReader(salary.bonuses));
            org.dom4j.Element bonusesElem = document.getRootElement();

            if (bonusesElem != null) {
                String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpPercentage, sTmpAmount;
                org.dom4j.Element bonusElem;

                Iterator bonusesIter = bonusesElem.elementIterator("Bonus");
                while (bonusesIter.hasNext()) {
                    bonusElem = (org.dom4j.Element) bonusesIter.next();

                    sTmpBegin = checkString(bonusElem.elementText("Begin"));
                    sTmpEnd = checkString(bonusElem.elementText("End"));
                    sTmpPeriod = checkString(bonusElem.elementText("Period"));
                    sTmpType = checkString(bonusElem.elementText("Type"));
                    sTmpPercentage = checkString(bonusElem.elementText("Percentage"));
                    sTmpAmount = checkString(bonusElem.elementText("Amount"));

                    // one record
                    detailsTable.addCell(createValueCell(sTmpBegin, 1));
                    detailsTable.addCell(createValueCell(sTmpEnd, 1));
                    detailsTable.addCell(createValueCell(sTmpPeriod, 2));
                    detailsTable.addCell(createValueCell(sTmpType, 2));
                    detailsTable.addCell(createValueCell(sTmpPercentage + "%", 2));

                    cell = createValueCell(
                            sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 2);
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    detailsTable.addCell(cell);
                }
            }
        } catch (Exception e) {
            Debug.printStackTrace(e);
        }
    }

    //*** XML 3 - otherIncome (multi-add) ***********************
    if (salary.otherIncome.length() > 0) {
        table.addCell(createSubtitleCell(getTran("web.hr", "otherIncome"), 10));

        // header
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 3));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 3));

        try {
            // parse otherIncome from xml           
            SAXReader reader = new SAXReader(false);
            org.dom4j.Document document = reader.read(new StringReader(salary.otherIncome));
            org.dom4j.Element benefitsElem = document.getRootElement();

            if (benefitsElem != null) {
                String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpAmount;
                org.dom4j.Element otherIncomeElem;

                Iterator otherIncomesIter = benefitsElem.elementIterator("OtherIncome");
                while (otherIncomesIter.hasNext()) {
                    otherIncomeElem = (org.dom4j.Element) otherIncomesIter.next();

                    sTmpBegin = checkString(otherIncomeElem.elementText("Begin"));
                    sTmpEnd = checkString(otherIncomeElem.elementText("End"));
                    sTmpPeriod = checkString(otherIncomeElem.elementText("Period"));
                    sTmpType = checkString(otherIncomeElem.elementText("Type"));
                    sTmpAmount = checkString(otherIncomeElem.elementText("Amount"));

                    // one record
                    detailsTable.addCell(createValueCell(sTmpBegin, 1));
                    detailsTable.addCell(createValueCell(sTmpEnd, 1));
                    detailsTable.addCell(createValueCell(sTmpPeriod, 2));
                    detailsTable.addCell(createValueCell(sTmpType, 3));

                    cell = createValueCell(
                            sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 3);
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    detailsTable.addCell(cell);
                }
            }
        } catch (Exception e) {
            Debug.printStackTrace(e);
        }
    }

    //*** XML 4 - deductions (multi-add) ************************
    if (salary.deductions.length() > 0) {
        detailsTable.addCell(createSubtitleCell(getTran("web.hr", "deductions"), 10));

        // header
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 3));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 3));

        try {
            // parse deductions from xml           
            SAXReader reader = new SAXReader(false);
            org.dom4j.Document document = reader.read(new StringReader(salary.deductions));
            org.dom4j.Element deductionsElem = document.getRootElement();

            if (deductionsElem != null) {
                String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpAmount;
                org.dom4j.Element deductionElem;

                Iterator deductionsIter = deductionsElem.elementIterator("Deduction");
                while (deductionsIter.hasNext()) {
                    deductionElem = (org.dom4j.Element) deductionsIter.next();

                    sTmpBegin = checkString(deductionElem.elementText("Begin"));
                    sTmpEnd = checkString(deductionElem.elementText("End"));
                    sTmpPeriod = checkString(deductionElem.elementText("Period"));
                    sTmpType = checkString(deductionElem.elementText("Type"));
                    sTmpAmount = checkString(deductionElem.elementText("Amount"));

                    // one record
                    detailsTable.addCell(createValueCell(sTmpBegin, 1));
                    detailsTable.addCell(createValueCell(sTmpEnd, 1));
                    detailsTable.addCell(createValueCell(sTmpPeriod, 2));
                    detailsTable.addCell(createValueCell(sTmpType, 3));

                    cell = createValueCell(
                            sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 3);
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    detailsTable.addCell(cell);
                }
            }
        } catch (Exception e) {
            Debug.printStackTrace(e);
        }
    }

    if (detailsTable.size() > 0) {
        table.addCell(emptyCell(3));
        cell = createCell(new PdfPCell(detailsTable), table.getNumberOfColumns() - 3, PdfPCell.ALIGN_CENTER,
                PdfPCell.BOX);
        cell.setPadding(2);
        table.addCell(cell);
    }
}