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.globalsight.everest.edit.offline.OfflineEditManagerLocal.java

License:Apache License

/**
 * Only when the source file is XLF, need re-wrap the off-line down-loaded
 * XLIFF file./* w w w. j  a v  a  2  s  . co m*/
 */
private void reWrapXliff(Document doc, HashSet<Long> jobIds) {
    Element root = doc.getRootElement();
    Element bodyElement = root.element(XliffConstants.FILE).element(XliffConstants.BODY);

    // Find TU elements that are from XLF source file.
    List<Element> xlfTuElements = new ArrayList<Element>();
    for (Iterator i = bodyElement.elementIterator(XliffConstants.TRANS_UNIT); i.hasNext();) {
        Element foo = (org.dom4j.Element) i.next();
        if (isSrcFileXlf(foo, jobIds)) {
            xlfTuElements.add(foo);
        }
    }

    if (xlfTuElements.size() == 0)
        return;

    //
    StringBuffer xliffString = new StringBuffer();
    xliffString.append("<?xml version=\"1.0\"?>");
    xliffString.append("<xliff version=\"1.2\">");
    xliffString.append("<file>");
    xliffString.append("<body>");
    Attribute stateAttr = null;
    ArrayList<String> trgStates = new ArrayList<String>();
    for (Element foo : xlfTuElements) {
        Element sourceElement = foo.element(XliffConstants.SOURCE);
        String sourceContent = sourceElement.asXML();
        sourceContent = sourceContent.replaceFirst("<" + XliffConstants.SOURCE + "[^>]*>", "");
        sourceContent = sourceContent.replace("</" + XliffConstants.SOURCE + ">", "");

        Element targetElement = foo.element(XliffConstants.TARGET);

        String targetContent = targetElement.asXML();
        targetContent = targetContent.replaceFirst("<" + XliffConstants.TARGET + "[^>]*>", "");
        targetContent = targetContent.replace("</" + XliffConstants.TARGET + ">", "");

        xliffString.append("<trans-unit>");
        xliffString.append("<source>").append(sourceContent).append("</source>");
        xliffString.append("<target>").append(targetContent).append("</target>");
        xliffString.append("</trans-unit>");

        // Store the state attributes in sequence
        stateAttr = targetElement.attribute(XliffConstants.STATE);
        if (stateAttr == null) {
            trgStates.add("");
        } else {
            trgStates.add(stateAttr.getValue());
        }
    }
    xliffString.append("</body>");
    xliffString.append("</file>");
    xliffString.append("</xliff>");

    // Extract it to get re-wrapped segments.
    DiplomatAPI api = new DiplomatAPI();
    api.setEncoding("UTF-8");
    api.setLocale(new Locale("en_US"));
    api.setInputFormat("xlf");
    api.setSentenceSegmentation(false);
    api.setSegmenterPreserveWhitespace(true);
    api.setSourceString(xliffString.toString());

    ArrayList<String> sourceArray = new ArrayList<String>();
    ArrayList<String> targetArray = new ArrayList<String>();

    try {
        api.extract();
        Output output = api.getOutput();

        for (Iterator it = output.documentElementIterator(); it.hasNext();) {
            DocumentElement element = (DocumentElement) it.next();

            if (element instanceof TranslatableElement) {
                TranslatableElement trans = (TranslatableElement) element;

                SegmentNode src = (SegmentNode) (trans.getSegments().get(0));
                if (trans.getXliffPartByName().equals("source")) {
                    sourceArray.add("<source>" + replaceEntity(src.getSegment()) + "</source>");
                } else if (trans.getXliffPartByName().equals("target")) {
                    targetArray.add("<target>" + replaceEntity(src.getSegment()) + "</target>");
                }
            }
        }
    } catch (Exception e) {
        if (s_category.isDebugEnabled()) {
            s_category.error(e.getMessage(), e);
        }
    }

    // Replace source/target elements
    int index = 0;
    if (sourceArray != null && targetArray != null) {
        for (Iterator i = bodyElement.elementIterator(XliffConstants.TRANS_UNIT); i.hasNext();) {
            if (index >= sourceArray.size()) {
                break;
            }

            Element foo = (org.dom4j.Element) i.next();
            if (!isSrcFileXlf(foo, jobIds)) {
                continue;
            }

            TuImpl tu = getTu(foo, jobIds);
            GxmlElement srcGxmlElement = tu.getSourceTuv().getGxmlElement();
            String newSrc = "<segment>" + GxmlUtil.stripRootTag(sourceArray.get(index)) + "</segment>";
            GxmlElement trgGxmlElement = SegmentUtil2.getGxmlElement(newSrc);
            newSrc = SegmentUtil2.adjustSegmentAttributeValues(srcGxmlElement, trgGxmlElement, "xlf");
            newSrc = "<source>" + GxmlUtil.stripRootTag(newSrc) + "</source>";
            Element sourceElement = foo.element(XliffConstants.SOURCE);
            Element newSourceElement = getDom(newSrc).getRootElement();
            foo.remove(sourceElement);
            foo.add(newSourceElement);

            String newTrg = "<segment>" + GxmlUtil.stripRootTag(targetArray.get(index)) + "</segment>";
            trgGxmlElement = SegmentUtil2.getGxmlElement(newTrg);
            newTrg = SegmentUtil2.adjustSegmentAttributeValues(srcGxmlElement, trgGxmlElement, "xlf");
            newTrg = "<target>" + GxmlUtil.stripRootTag(newTrg) + "</target>";
            Element newTargetElement = getDom(newTrg).getRootElement();
            Element targetElement = foo.element(XliffConstants.TARGET);
            foo.remove(targetElement);
            // If target has "state" attribute, it should be preserved.
            try {
                if (!"".equals(trgStates.get(index))) {
                    newTargetElement.add(new DefaultAttribute(XliffConstants.STATE, trgStates.get(index)));
                }
            } catch (Exception ignore) {

            }

            foo.add(newTargetElement);
            index++;
        }
    }
}

From source file:com.globalsight.everest.edit.offline.OfflineEditManagerLocal.java

License:Apache License

private String convertNode2Pseudo(Document doc, String tagName, String p_fileName, HashSet<Long> jobIds,
        PtagErrorPageWriter m_errWriter) {
    Element root = doc.getRootElement();
    Element foo;/*from w  ww. ja  va2s  .  c o m*/
    String tuId = null;
    boolean hasError = false;

    Element bodyElement = root.element(XliffConstants.FILE).element(XliffConstants.BODY);
    for (Iterator i = bodyElement.elementIterator(XliffConstants.TRANS_UNIT); i.hasNext();) {
        try {
            foo = (org.dom4j.Element) i.next();
            Element sourceElement = foo.element(tagName);
            String textContent = sourceElement.asXML();
            textContent = textContent.replaceFirst("<" + tagName + "[^>]*>", "");
            textContent = textContent.replace("</" + tagName + ">", "");
            textContent = convertSegment2Pseudo(textContent, isSrcFileXlf(foo, jobIds), getTu(foo, jobIds));
            if (tagName.equalsIgnoreCase("target") && textContent.startsWith("#")) {
                textContent = textContent.replaceFirst("#", OfflineConstants.PONUD_SIGN);
            }
            sourceElement.setText(textContent);
        } catch (Exception e) {
            hasError = true;
            m_errWriter.addSegmentErrorMsg(tuId, e.getMessage());
        }
    }

    if (hasError)
        return m_errWriter.buildPage().toString();
    else
        return null;
}

From source file:com.globalsight.everest.edit.offline.OfflineEditManagerLocal.java

License:Apache License

/**
 * Adds all comments to database. The path is trans-unit/note.
 * /*from  www  .j a  v  a  2s  . c o m*/
 * @param doc
 *            The document of the xliff file.
 * @param p_user
 *            The user who uploaded the xliff file.
 */
private void addComment(Document doc, User p_user, HashSet<Long> jobIds) {
    XmlEntities entity = new XmlEntities();

    Element root = doc.getRootElement();
    Element file = root.element(XliffConstants.FILE);
    String target = file.attributeValue("target-language");
    target = target.replace("-", "_");

    org.dom4j.Element bodyElement = file.element(XliffConstants.BODY);
    for (Iterator i = bodyElement.elementIterator(XliffConstants.TRANS_UNIT); i.hasNext();) {
        Element foo = (Element) i.next();
        // For GBS-3643: if resname="SID", do not add note value as comment.
        String resName = foo.attributeValue("resname");
        if ("SID".equalsIgnoreCase(resName)) {
            continue;
        }

        for (Iterator notes = foo.elementIterator(XliffConstants.NOTE); notes.hasNext();) {
            Element note = (Element) notes.next();
            List elements = note.elements();
            String msg = m_resource.getString("msg_note_format_error");

            if (elements == null || note.content().size() == 0) {
                continue;
            }

            for (Object obj : note.content()) {
                if (!(obj instanceof DefaultText)) {
                    s_category.error(msg);
                    s_category.error("Error note: " + note.asXML());
                    throw new IllegalArgumentException(msg);
                }
            }

            String textContent = note.getText();
            if (textContent.startsWith("Match Type:")) {
                continue;
            }
            textContent = entity.decodeString(textContent, null);

            String tuId = foo.attributeValue("id");
            try {
                // As we can not get to know the job ID only by the tuId, we
                // have to loop jobIds until we can get the TU object.
                long jobId = -1;
                TuImpl tu = null;
                for (long id : jobIds) {
                    tu = SegmentTuUtil.getTuById(Long.parseLong(tuId), id);
                    jobId = id;
                    if (tu != null) {
                        break;
                    }
                }
                for (Object ob : tu.getTuvs(true, jobId)) {
                    TuvImpl tuv = (TuvImpl) ob;
                    TargetPage tPage = tuv.getTargetPage(jobId);
                    if (tuv.getGlobalSightLocale().toString().equalsIgnoreCase(target)) {
                        String title = String.valueOf(tu.getId());
                        String priority = "Medium";
                        String status = "open";
                        String category = "Type01";

                        IssueImpl issue = tuv.getComment();
                        if (issue == null) {
                            String key = CommentHelper.makeLogicalKey(tPage.getId(), tu.getId(), tuv.getId(),
                                    0);
                            issue = new IssueImpl(Issue.TYPE_SEGMENT, tuv.getId(), title, priority, status,
                                    category, p_user.getUserId(), textContent, key);
                            issue.setShare(false);
                            issue.setOverwrite(false);
                        } else {
                            issue.setTitle(title);
                            issue.setPriority(priority);
                            issue.setStatus(status);
                            issue.setCategory(category);
                            issue.addHistory(p_user.getUserId(), textContent);
                            issue.setShare(false);
                            issue.setOverwrite(false);
                        }

                        HibernateUtil.saveOrUpdate(issue);
                        break;
                    }
                }
            } catch (Exception e) {
                s_category.error("Failed to add comments", e);
            }
        }
    }
}

From source file:com.globalsight.everest.edit.offline.ttx.TTXParser.java

License:Apache License

/**
 * Parse extra info for uploading such as "pageId", "taskId" etc.
 * /*w w  w  .  j  a v  a2  s  .c o  m*/
 * @param p_rawElement
 */
private void parseHeaderInfo(Element p_rawElement) {
    if (p_rawElement == null) {
        return;
    }

    Iterator utIt = p_rawElement.elementIterator(TTXConstants.UT);
    while (utIt.hasNext()) {
        Element utEle = (Element) utIt.next();
        Attribute displayTextAtt = utEle.attribute(TTXConstants.UT_ATT_DISPLAYTEXT);
        if (displayTextAtt != null) {
            String attValue = displayTextAtt.getValue();
            // ignore locked segment - UT gs:locked segment
            if (TTXConstants.GS_LOCKED_SEGMENT.equalsIgnoreCase(attValue)) {
                continue;
            }

            String utTextNodeValue = utEle.getStringValue();
            int index = utTextNodeValue.lastIndexOf(":");
            if (index == -1) {
                continue;
            }
            String utName = utTextNodeValue.substring(0, index).trim();
            String utValue = utTextNodeValue.substring(index + 1).trim();
            if (TTXConstants.GS_ENCODING.equalsIgnoreCase(attValue) || "Encoding".equalsIgnoreCase(utName)) {
                gs_Encoding = utValue;
            } else if (TTXConstants.GS_DOCUMENT_FORMAT.equalsIgnoreCase(attValue)
                    || "Document Format".equalsIgnoreCase(utName)) {
                gs_DocumentFormat = utValue;
            } else if (TTXConstants.GS_PLACEHOLDER_FORMAT.equalsIgnoreCase(attValue)
                    || "Placeholder Format".equalsIgnoreCase(utName)) {
                gs_PlaceholderFormat = utValue;
            } else if (TTXConstants.GS_SOURCE_LOCALE.equalsIgnoreCase(attValue)
                    || "Source Locale".equalsIgnoreCase(utName)) {
                gs_SourceLocale = utValue;
            } else if (TTXConstants.GS_TARGET_LOCALE.equalsIgnoreCase(attValue)
                    || "Target Locale".equalsIgnoreCase(utName)) {
                gs_TargetLocale = utValue;
            } else if (TTXConstants.GS_PAGEID.equalsIgnoreCase(attValue)
                    || "Page ID".equalsIgnoreCase(utName)) {
                gs_PageID = utValue;
            } else if (TTXConstants.GS_WORKFLOW_ID.equalsIgnoreCase(attValue)
                    || "Workflow ID".equalsIgnoreCase(utName)) {
                gs_WorkflowID = utValue;
            } else if (TTXConstants.GS_TASK_ID.equalsIgnoreCase(attValue)
                    || "Task ID".equalsIgnoreCase(utName)) {
                gs_TaskID = utValue;
            } else if (TTXConstants.GS_EXACT_MATCH_WORD_COUNT.equalsIgnoreCase(attValue)
                    || "Exact Match word count".equalsIgnoreCase(utName)) {
                gs_ExactMatchWordCount = utValue;
            } else if (TTXConstants.GS_FUZZY_MATCH_WORD_COUNT.equalsIgnoreCase(attValue)
                    || "Fuzzy Match word count".equalsIgnoreCase(utName)) {
                gs_FuzzyMatchWordCount = utValue;
            } else if (TTXConstants.GS_EDIT_ALL.equalsIgnoreCase(attValue)
                    || "Edit all".equalsIgnoreCase(utName)) {
                gs_EditAll = utValue;
            } else if (TTXConstants.GS_POPULATE_100_TARGET_SEGMENTS.equals(attValue)
                    || "Populate 100% Target Segments".equalsIgnoreCase(utName)) {
                gs_Populate100TargetSegments = utValue;
            }
        }
    }
}

From source file:com.globalsight.jobsAutoArchiver.AutoArchiver.java

License:Apache License

public void doWork() throws Exception {
    SAXReader saxReader = new SAXReader();
    Document document = saxReader.read(new File(Constants.CONFIG_FILE_NAME));
    Element rootElt = document.getRootElement();
    runOnce = document.selectSingleNode("//runOnce").getText();
    intervalTime = Integer.valueOf(document.selectSingleNode("//intervalTime").getText());
    Iterator serverIter = rootElt.elementIterator("server");
    while (serverIter.hasNext()) {
        final Element serverElement = (Element) serverIter.next();

        Runnable runnable = new Runnable() {
            public void run() {
                try {
                    String hostName = serverElement.elementTextTrim("host");
                    int port = Integer.valueOf(serverElement.elementTextTrim("port"));
                    boolean isUseHTTPS = Boolean.valueOf(serverElement.elementTextTrim("https"));
                    int intervalTimeForArchive = Integer
                            .valueOf(serverElement.elementTextTrim("intervalTimeForArchive"));
                    Iterator usersIter = serverElement.elementIterator("users");
                    while (usersIter.hasNext()) {
                        Element usersElement = (Element) usersIter.next();
                        Iterator userIter = usersElement.elementIterator("user");
                        while (userIter.hasNext()) {
                            Element userElement = (Element) userIter.next();
                            String userName = userElement.elementTextTrim("username");
                            String password = userElement.elementTextTrim("password");
                            autoArchive(hostName, port, isUseHTTPS, userName, password, intervalTimeForArchive);
                        }//from   www .ja v a  2  s.c  o m
                    }
                } catch (Throwable e) {
                    LogUtil.info("error : " + e);
                }
            }
        };
        Thread t = new Thread(runnable);
        t.start();
    }
}

From source file:com.globalsight.jobsAutoArchiver.AutoArchiver.java

License:Apache License

private void autoArchive(String hostName, int port, boolean isUseHTTPS, String userName, String password,
        int intervalTimeForArchive) {
    try {/*from  ww w.j a v a 2s  .  c  o m*/
        Ambassador ambassador = WebServiceClientHelper.getClientAmbassador(hostName, port, userName, password,
                isUseHTTPS);
        String accessToken = ambassador.login(userName, password);
        String result = ambassador.fetchJobsByState(accessToken, Constants.JOB_STATE_EXPORTED, 0, 100, false);
        if (result == null) {
            LogUtil.info(
                    "server " + hostName + " , user " + userName + " : no jobs that are in exported state.");
        } else {
            LogUtil.info("server " + hostName + " , user " + userName
                    + " , returning of fetchJobsByState API:\n" + result);
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
            long diffInHours = 0;
            long now = (new Date()).getTime();

            SAXReader saxReader = new SAXReader();
            Document document2 = saxReader.read(new ByteArrayInputStream(result.getBytes("UTF-8")));
            Element rootEltJob = document2.getRootElement();
            Iterator iterJob = rootEltJob.elementIterator("Job");
            Set<Long> jobIds = new HashSet<Long>();
            while (iterJob.hasNext()) {
                String jobId = null;
                String completedDateStr = null;
                try {
                    Element jobElement = (Element) iterJob.next();
                    jobId = jobElement.elementTextTrim("id");
                    completedDateStr = jobElement.elementTextTrim("completedDate");
                    Date completedDate = sdf.parse(completedDateStr.substring(0, 18).trim());
                    long completedDateLong = completedDate.getTime();
                    diffInHours = (now - completedDateLong) / 1000 / 60 / 60;
                    if (diffInHours >= intervalTimeForArchive) {
                        jobIds.add(Long.parseLong(jobId));
                    }
                } catch (Exception e) {
                    LogUtil.info("Error to check job with jobID: " + jobId + " and completedDate '"
                            + completedDateStr + "'.", e);
                }
            }
            StringBuffer jobs = new StringBuffer();
            for (long id : jobIds) {
                jobs.append(id).append(",");
            }
            if (jobs.length() > 0 && jobs.toString().endsWith(",")) {
                String jobs2 = jobs.toString().substring(0, jobs.length() - 1);
                ambassador.archiveJob(accessToken, jobs2);
                String[] jobs2_array = jobs2.toString().split(",");
                for (String job : jobs2_array) {
                    LogUtil.info("server " + hostName + ", user " + userName + " : the job " + job
                            + " can be archived");
                }
            } else {
                LogUtil.info("server " + hostName + ", user " + userName + " : no jobs that can be archived.");
            }
        }
    } catch (Exception e) {
        LogUtil.info("server " + hostName + ", user " + userName + ", error : " + e);
    }
}

From source file:com.globalsight.webservices.Ambassador.java

License:Apache License

private String nextTm3Tus(ProjectTM ptm, GlobalSightLocale srcGSLocale, GlobalSightLocale trgGSLocale,
        long tuIdToStart, int size) throws WebServiceException {
    Connection conn = null;/*  w  ww  . j  ava  2 s.c o  m*/
    try {
        conn = DbUtil.getConnection();

        String tuTable = "tm3_tu_shared_" + ptm.getCompanyId();
        String tuvTable = "tm3_tuv_shared_" + ptm.getCompanyId();

        StatementBuilder sb = new StatementBuilder();
        if (trgGSLocale != null) {
            sb.append("SELECT tuv.tuId FROM ").append(tuvTable).append(" tuv,");
            sb.append(" (SELECT id FROM ").append(tuTable).append(" tu ").append("WHERE tu.tmid = ? ")
                    .addValue(ptm.getTm3Id()).append(" AND tu.srcLocaleId = ? ").addValue(srcGSLocale.getId())
                    .append(" AND tu.id > ? ").addValue(tuIdToStart).append(" ORDER BY tu.id LIMIT 0, ")
                    .append(String.valueOf(10 * size)).append(") tuids ");
            sb.append(" WHERE tuv.tuId = tuids.id");
            sb.append(" AND tuv.localeId = ? ").addValue(trgGSLocale.getId());
            sb.append(" AND tuv.tmId = ? ").addValue(ptm.getTm3Id());
            sb.append(" ORDER BY tuv.tuId ");
            sb.append(" LIMIT 0, ").append(String.valueOf(size)).append(";");
        } else {
            sb.append("SELECT id FROM ").append(tuTable).append(" WHERE tmid = ? ").addValue(ptm.getTm3Id())
                    .append(" AND srcLocaleId = ? ").addValue(srcGSLocale.getId()).append(" AND id > ? ")
                    .addValue(tuIdToStart).append(" ORDER BY id ").append("LIMIT 0,").append(size + ";");
        }
        List<Long> tuIds = SQLUtil.execIdsQuery(conn, sb);
        if (tuIds == null || tuIds.size() == 0) {
            return null;
        }

        BaseTm tm = TM3Util.getBaseTm(ptm.getTm3Id());
        List<TM3Tu> tm3Tus = tm.getTu(tuIds);

        TM3Attribute typeAttr = TM3Util.getAttr(tm, TYPE);
        TM3Attribute formatAttr = TM3Util.getAttr(tm, FORMAT);
        TM3Attribute sidAttr = TM3Util.getAttr(tm, SID);
        TM3Attribute translatableAttr = TM3Util.getAttr(tm, TRANSLATABLE);
        TM3Attribute fromWsAttr = TM3Util.getAttr(tm, FROM_WORLDSERVER);
        TM3Attribute projectAttr = TM3Util.getAttr(tm, UPDATED_BY_PROJECT);
        List<SegmentTmTu> segTmTus = new ArrayList<SegmentTmTu>();
        for (TM3Tu tm3Tu : tm3Tus) {
            segTmTus.add(TM3Util.toSegmentTmTu(tm3Tu, ptm.getId(), formatAttr, typeAttr, sidAttr, fromWsAttr,
                    translatableAttr, projectAttr));
        }

        List<GlobalSightLocale> targetLocales = null;
        if (trgGSLocale != null) {
            targetLocales = new ArrayList<GlobalSightLocale>();
            targetLocales.add(trgGSLocale);
        }

        StringBuffer result = new StringBuffer();
        IExportManager exporter = null;
        String options = null;
        exporter = TmManagerLocal.getProjectTmExporter(ptm.getName());
        options = exporter.getExportOptions();
        Document doc = DocumentHelper.parseText(options);
        Element rootElt = doc.getRootElement();
        Iterator fileIter = rootElt.elementIterator("fileOptions");
        while (fileIter.hasNext()) {
            Element fileEle = (Element) fileIter.next();
            Element fileTypeElem = fileEle.element("fileType");
            fileTypeElem.setText("xml");
        }

        Iterator filterIter = rootElt.elementIterator("filterOptions");
        while (filterIter.hasNext()) {
            Element filterEle = (Element) filterIter.next();
            Element language = filterEle.element("language");
            if (trgGSLocale != null) {
                language.setText(trgGSLocale.getLanguage() + "_" + trgGSLocale.getCountry());
            }
        }

        options = doc.asXML().substring(doc.asXML().indexOf("<exportOptions>"));
        exporter.setExportOptions(options);

        Tmx tmx = new Tmx();
        tmx.setSourceLang(Tmx.DEFAULT_SOURCELANG);
        tmx.setDatatype(Tmx.DATATYPE_HTML);

        TmxWriter tmxWriter = new TmxWriter(exporter.getExportOptionsObject(), ptm, tmx);
        for (SegmentTmTu segTmTu : segTmTus) {
            result.append(tmxWriter.getSegmentTmForXml(segTmTu));
        }

        return result.toString();
    } catch (Exception e) {
        logger.error(e);
        throw new WebServiceException(e.getMessage());
    } finally {
        DbUtil.silentReturnConnection(conn);
    }
}

From source file:com.globalsight.webservices.Ambassador.java

License:Apache License

private String joinXml(String xml, String startDate, String finishDate, String fileType, String languages,
        String exportedFileName, String projectNames) throws WebServiceException {
    Document doc = null;// w  ww . j  av  a  2  s  . c om
    try {
        doc = DocumentHelper.parseText(xml);
        Element rootElt = doc.getRootElement();
        Iterator fileIter = rootElt.elementIterator("fileOptions");
        while (fileIter.hasNext()) {
            Element fileEle = (Element) fileIter.next();
            if (exportedFileName != null) {
                Element fileNameElem = fileEle.element("fileName");
                if (fileType.equals("xml")) {
                    fileNameElem.setText(exportedFileName + ".xml");
                } else if (fileType.equals("tmx2")) {
                    fileNameElem.setText(exportedFileName + ".tmx");
                }
            }
            Element fileTypeElem = fileEle.element("fileType");
            fileTypeElem.setText(fileType);
            Element fileEncodingElem = fileEle.element("fileEncoding");
            fileEncodingElem.setText("UTF-8");
        }

        Iterator selectIter = rootElt.elementIterator("selectOptions");
        while (selectIter.hasNext()) {
            Element selectEle = (Element) selectIter.next();
            Element selectModeElem = selectEle.element("selectMode");
            // Element selectLanguage = selectEle.element("selectLanguage");
            selectModeElem.setText(com.globalsight.everest.tm.exporter.ExportOptions.SELECT_ALL);
            // if (StringUtil.isEmpty(languages))
            // {
            // }
            // else
            // {
            // selectModeElem
            // .setText(com.globalsight.everest.tm.exporter.ExportOptions.SELECT_FILTERED);
            // selectLanguage.setText(languages);
            // }
        }

        Iterator filterIter = rootElt.elementIterator("filterOptions");
        while (filterIter.hasNext()) {
            Element filterEle = (Element) filterIter.next();
            Element createdafterElem = filterEle.element("createdafter");
            createdafterElem.setText(startDate);
            Element createdbeforeElem = filterEle.element("createdbefore");
            Element language = filterEle.element("language");
            Element projectName = filterEle.element("projectName");
            if (finishDate == null) {
                Date nowDate = new Date();
                SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
                String nowDateStr = sdf.format(nowDate);
                createdbeforeElem.setText(nowDateStr);
            } else {
                createdbeforeElem.setText(finishDate);
            }

            if (StringUtil.isNotEmpty(languages)) {
                language.setText(languages);
            }

            if (StringUtil.isNotEmpty(projectNames)) {
                projectName.setText(projectNames);
            }
        }

        Iterator outputIter = rootElt.elementIterator("outputOptions");
        while (outputIter.hasNext()) {
            Element outputEle = (Element) outputIter.next();
            Element systemFields = outputEle.element("systemFields");
            systemFields.setText("true");
        }

        String xmlDoc = doc.asXML();
        return xmlDoc.substring(xmlDoc.indexOf("<exportOptions>"));
    } catch (DocumentException e) {
        throw new WebServiceException(e.getMessage());
    }
}

From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java

License:Apache License

/**
 * ??? ??nameparentelementelement,//from   www  . ja  va2  s .  c om
 * elementNamenameelement?? 
 *
 * @param parentelement
 *            ?
 * @param elementName
 *            ???
 * @return ?
 */
public Element getElement(Element parentelement, String elementName) {
    Element element = null;
    for (Iterator<?> i = parentelement.elementIterator(elementName); i.hasNext();) {
        element = (Element) i.next();
    }
    return element;
}

From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java

License:Apache License

/**
 * ?/*from   w ww.  j a  v  a  2s .c  om*/
 *
 * @param document
 *            
 * @param elementName
 *            ?
 * @return ?
 */
public Element FindElement(Document document, String elementName) {
    Element root = document.getRootElement();
    Element element = null;
    for (Iterator<?> i = root.elementIterator(elementName); i.hasNext();) {
        element = (Element) i.next();
    }
    return element;
}