001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workplace.tools.content.convertxml;
029
030import org.opencms.db.CmsResourceState;
031import org.opencms.file.CmsFile;
032import org.opencms.file.CmsObject;
033import org.opencms.file.CmsProject;
034import org.opencms.file.CmsPropertyDefinition;
035import org.opencms.file.CmsResource;
036import org.opencms.file.CmsResourceFilter;
037import org.opencms.i18n.CmsEncoder;
038import org.opencms.lock.CmsLock;
039import org.opencms.main.CmsException;
040import org.opencms.main.CmsLog;
041import org.opencms.main.OpenCms;
042import org.opencms.publish.CmsPublishManager;
043import org.opencms.report.A_CmsReportThread;
044import org.opencms.report.I_CmsReport;
045import org.opencms.util.CmsStringUtil;
046import org.opencms.util.CmsUUID;
047import org.opencms.util.CmsXsltUtil;
048import org.opencms.xml.CmsXmlException;
049import org.opencms.xml.content.CmsXmlContent;
050import org.opencms.xml.content.CmsXmlContentFactory;
051
052import java.util.Iterator;
053import java.util.List;
054
055import org.apache.commons.logging.Log;
056
057/**
058 * Converting xml contents according to new schema.
059 * <p>
060 *
061 * @since 7.0.5
062 */
063public class CmsConvertXmlThread extends A_CmsReportThread {
064
065    /** The log object for this class. */
066    private static final Log LOG = CmsLog.getLog(CmsConvertXmlThread.class);
067
068    /** Number of files transformed already. */
069    private int m_alreadyTransformed;
070
071    /** Current CmsObject. */
072    private CmsObject m_cmsObject;
073
074    /** Number of errors while transforming. */
075    private int m_errorTransform;
076
077    /** Number of locked files during of transformation. */
078    private int m_lockedFiles;
079
080    /** Number of files where encoding type could not become get. */
081    private int m_missingEncodingType;
082
083    /** Settings. */
084    private CmsConvertXmlSettings m_settings;
085
086    /**
087     * Creates a replace html tag Thread.<p>
088     *
089     * @param cms the current cms context.
090     *
091     * @param settings the settings needed to perform the operation.
092     */
093    public CmsConvertXmlThread(CmsObject cms, CmsConvertXmlSettings settings) {
094
095        super(cms, Messages.get().getBundle().key(Messages.GUI_CONVERTXML_THREAD_NAME_0));
096        initHtmlReport(cms.getRequestContext().getLocale());
097        m_cmsObject = cms;
098        m_settings = settings;
099    }
100
101    /**
102     * @see org.opencms.report.A_CmsReportThread#getReportUpdate()
103     */
104    @Override
105    public String getReportUpdate() {
106
107        return getReport().getReportUpdate();
108    }
109
110    /**
111     * @see java.lang.Runnable#run()
112     */
113    @Override
114    public void run() {
115
116        I_CmsReport report = getReport();
117        report.println(
118            Messages.get().container(Messages.RPT_CONVERTXML_BEGIN_TRANSFORM_THREAD_0),
119            I_CmsReport.FORMAT_HEADLINE);
120        try {
121            // convert xml contents
122            mainTransform(
123                report,
124                m_settings.getResourceType(),
125                m_settings.getVfsFolder(),
126                m_settings.getIncludeSubFolders(),
127                m_settings.getXslFile(),
128                m_cmsObject,
129                m_settings.getOnlyCountFiles());
130        } catch (Throwable f) {
131            m_errorTransform += 1;
132            report.println(Messages.get().container(Messages.RPT_CONVERTXML_TRANSFORMATION_ERROR_0));
133            if (LOG.isErrorEnabled()) {
134                LOG.error(f.toString());
135            }
136        }
137
138        // append runtime statistics to report
139        getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_STAT_0));
140        getReport().println(
141            org.opencms.report.Messages.get().container(
142                org.opencms.report.Messages.RPT_STAT_DURATION_1,
143                getReport().formatRuntime()));
144        getReport().println(
145            Messages.get().container(Messages.RPT_CONVERTXML_THREAD_END_0),
146            I_CmsReport.FORMAT_HEADLINE);
147    }
148
149    /**
150     * Locks the current resource.<p>
151     *
152     * @param cms the current CmsObject
153     * @param cmsProject the current project
154     * @param cmsResource the resourcfe to lock
155     * @param report the report
156     *
157     * @throws CmsException if some goes wrong
158     */
159    private boolean lockResource(CmsObject cms, CmsProject cmsProject, CmsResource cmsResource, I_CmsReport report)
160    throws CmsException {
161
162        cms.getRequestContext().setCurrentProject(cmsProject);
163        CmsLock lock = cms.getLock(getCms().getSitePath(cmsResource));
164        // check the lock
165        if ((lock != null)
166            && lock.isOwnedBy(getCms().getRequestContext().getCurrentUser())
167            && lock.isOwnedInProjectBy(getCms().getRequestContext().getCurrentUser(), cmsProject)) {
168            // prove is current lock from current user in current project
169            return true;
170        } else if ((lock != null)
171            && !lock.isUnlocked()
172            && !lock.isOwnedBy(getCms().getRequestContext().getCurrentUser())) {
173            // the resource is not locked by the current user, so can not lock it
174            m_lockedFiles += 1;
175            return false;
176        } else if ((lock != null)
177            && !lock.isUnlocked()
178            && lock.isOwnedBy(getCms().getRequestContext().getCurrentUser())
179            && !lock.isOwnedInProjectBy(getCms().getRequestContext().getCurrentUser(), cmsProject)) {
180            // prove is current lock from current user but not in current project
181            // file is locked by current user but not in current project
182            // change the lock
183            cms.changeLock(getCms().getSitePath(cmsResource));
184        } else if ((lock != null) && lock.isUnlocked()) {
185            // lock resource from current user in current project
186            cms.lockResource(getCms().getSitePath(cmsResource));
187        }
188        lock = cms.getLock(getCms().getSitePath(cmsResource));
189        if ((lock != null)
190            && lock.isOwnedBy(getCms().getRequestContext().getCurrentUser())
191            && !lock.isOwnedInProjectBy(getCms().getRequestContext().getCurrentUser(), cmsProject)) {
192            // resource could not be locked
193            m_lockedFiles += 1;
194
195            return false;
196        }
197        // resource is locked successfully
198        return true;
199    }
200
201    /**
202     * Main method to transforms xml contents from files of one format because
203     * of new xsd file.<p>
204     *
205     * @param report I_CmsReport
206     * @param fileFormat File format of xml contents to transform
207     * @param resourcePath Path where to transform xml contents
208     * @param inclSubFolder True, if also transform xml contents in sub folders
209     * @param xsltFile XLST file which includes logic for transforming
210     * @param cmsObject Current CmsObject
211     * @param countFilesToTransformOnly Only count files to transform
212     *
213     * @return True if transformation of all xml contents was successful
214     */
215    @SuppressWarnings("unchecked")
216    private boolean mainTransform(
217        I_CmsReport report,
218        int fileFormat,
219        String resourcePath,
220        boolean inclSubFolder,
221        String xsltFile,
222        CmsObject cmsObject,
223        boolean countFilesToTransformOnly) {
224
225        boolean transformSuccess = true;
226        boolean transformConditions = true;
227        // write parameters to report
228        report.println(Messages.get().container(Messages.RPT_CONVERTXML_BEGIN_TRANSFORM_0), I_CmsReport.FORMAT_NOTE);
229        report.println(Messages.get().container(Messages.RPT_CONVERTXML_PARAMETERS_0), I_CmsReport.FORMAT_NOTE);
230        report.println(
231            Messages.get().container(Messages.RPT_CONVERTXML_PARAMETERS_RESOURCE_PATH_1, resourcePath),
232            I_CmsReport.FORMAT_NOTE);
233        report.println(
234            Messages.get().container(
235                Messages.RPT_CONVERTXML_PARAMETERS_INC_SUBFOLDERS_1,
236                Boolean.valueOf(inclSubFolder).toString()),
237            I_CmsReport.FORMAT_NOTE);
238        report.println(
239            Messages.get().container(Messages.RPT_CONVERTXML_PARAMETERS_XSLT_FILE_1, xsltFile),
240            I_CmsReport.FORMAT_NOTE);
241        report.println(
242            Messages.get().container(
243                Messages.RPT_CONVERTXML_PARAMETERS_ONLY_COUNT_1,
244                Boolean.valueOf(countFilesToTransformOnly).toString()),
245            I_CmsReport.FORMAT_NOTE);
246        // check if xslt file is available
247        if (CmsStringUtil.isEmpty(xsltFile)) {
248            report.println(Messages.get().container(Messages.RPT_CONVERTXML_NO_XSLT_FILE_0), I_CmsReport.FORMAT_ERROR);
249            transformConditions = false;
250        }
251        // check if new xsd main file is available
252        String newXsdMainFile = "";
253        String xsltString = "";
254        try {
255            xsltString = new String(cmsObject.readFile(xsltFile).getContents());
256        } catch (CmsException e) {
257            if (LOG.isErrorEnabled()) {
258                LOG.error(e.getMessageContainer(), e);
259            }
260        }
261        // get main xsd file string in xml content in format: xsi:noNamespaceSchemaLocation="opencms://system/modules/org.opencms.frontend.templatetwo.demo/schemas/article.xsd"
262        int posMainFileBegin = xsltString.indexOf("xsi:noNamespaceSchemaLocation=\"");
263        if (posMainFileBegin > 0) {
264            String fileName = xsltString.substring(posMainFileBegin + "xsi:noNamespaceSchemaLocation=\"".length());
265            int posMainFileEnd = fileName.indexOf("\"");
266            if (posMainFileEnd > 0) {
267                newXsdMainFile = fileName.substring(0, posMainFileEnd);
268            }
269        }
270        // check file
271        int fileLength = newXsdMainFile.length();
272        if ((fileLength < 5) || !newXsdMainFile.substring(fileLength - 4, fileLength).toUpperCase().equals(".XSD")) {
273            newXsdMainFile = "";
274        }
275        if (CmsStringUtil.isEmpty(newXsdMainFile)) {
276            report.println(Messages.get().container(Messages.RPT_CONVERTXML_NO_XSD_FILE_0), I_CmsReport.FORMAT_ERROR);
277            transformConditions = false;
278        } else {
279            report.println(
280                Messages.get().container(Messages.RPT_CONVERTXML_PARAMETERS_NEW_XSD_MAINFILE_1, newXsdMainFile),
281                I_CmsReport.FORMAT_NOTE);
282        }
283        // check if vfs folder is set
284        if (CmsStringUtil.isEmpty(resourcePath)) {
285            report.println(Messages.get().container(Messages.RPT_CONVERTXML_NO_VFS_FOLDER_0), I_CmsReport.FORMAT_ERROR);
286            transformConditions = false;
287        }
288        // only start actions if all conditions are okay
289        if (!transformConditions) {
290            return false;
291        }
292        // read all files to transform
293        report.println(Messages.get().container(Messages.RPT_CONVERTXML_START_SEARCHING_0), I_CmsReport.FORMAT_NOTE);
294        List<CmsResource> files2Transform = null;
295        try {
296            files2Transform = cmsObject.readResources(
297                resourcePath,
298                CmsResourceFilter.requireType(fileFormat),
299                inclSubFolder);
300        } catch (CmsException e) {
301            m_errorTransform += 1;
302            report.println(Messages.get().container(Messages.RPT_CONVERTXML_SEARCH_ERROR_0), I_CmsReport.FORMAT_ERROR);
303            if (LOG.isErrorEnabled()) {
304                LOG.error(e.getMessageContainer(), e);
305            }
306            report.println(Messages.get().container(Messages.RPT_CONVERTXML_TRANSFORM_END_0), I_CmsReport.FORMAT_NOTE);
307            return false;
308        }
309        int file2Transform = 0;
310        if (files2Transform != null) {
311            file2Transform = files2Transform.size();
312            report.println(
313                Messages.get().container(Messages.RPT_CONVERTXML_FOUND_FILES_1, Integer.valueOf(file2Transform).toString()),
314                I_CmsReport.FORMAT_OK);
315        } else {
316            report.println(Messages.get().container(Messages.RPT_CONVERTXML_NO_FILES_FOUND_0), I_CmsReport.FORMAT_OK);
317            return false;
318        }
319        if (countFilesToTransformOnly || (file2Transform < 1)) {
320            report.println(Messages.get().container(Messages.RPT_CONVERTXML_NO_FILES_FOUND_0), I_CmsReport.FORMAT_OK);
321            return false;
322        }
323        // transform and write files
324        CmsObject cmsObject2Publish = transformAndWriteFiles(
325            files2Transform,
326            xsltFile,
327            cmsObject,
328            newXsdMainFile,
329            report);
330        // publish files in project
331        report.println(Messages.get().container(Messages.RPT_CONVERTXML_PUBLISHING_FILES_0), I_CmsReport.FORMAT_NOTE);
332        CmsPublishManager cmsPublishManager = OpenCms.getPublishManager();
333        try {
334            cmsPublishManager.publishProject(cmsObject2Publish);
335        } catch (Exception e) {
336            m_errorTransform += 1;
337            report.println(
338                Messages.get().container(Messages.RPT_CONVERTXML_TRANSFORMATION_ERROR_0),
339                I_CmsReport.FORMAT_ERROR);
340            if (LOG.isErrorEnabled()) {
341                LOG.error(e.toString());
342            }
343        }
344        // output from the results
345        report.println(Messages.get().container(Messages.RPT_CONVERTXML_RESULT_0), I_CmsReport.FORMAT_NOTE);
346        report.println(
347            Messages.get().container(Messages.RPT_CONVERTXML_FOUND_FILES_1, Integer.valueOf(file2Transform).toString()),
348            I_CmsReport.FORMAT_NOTE);
349        report.println(
350            Messages.get().container(
351                Messages.RPT_CONVERTXML_FILES_ALREADY_TRANSFORMED_1,
352                Integer.valueOf(m_alreadyTransformed).toString()),
353            I_CmsReport.FORMAT_NOTE);
354        report.println(
355            Messages.get().container(
356                Messages.RPT_CONVERTXML_TRANSFORM_NUMBER_ERRORS_1,
357                Integer.valueOf(m_errorTransform).toString()),
358            I_CmsReport.FORMAT_NOTE);
359        report.println(
360            Messages.get().container(Messages.RPT_CONVERTXML_LOCKED_FILES_1, Integer.valueOf(m_lockedFiles).toString()),
361            I_CmsReport.FORMAT_NOTE);
362        if ((m_lockedFiles > 0) || (m_errorTransform > 0)) {
363            report.println(
364                Messages.get().container(Messages.RPT_CONVERTXML_TRANSFORMING_FAILED_0),
365                I_CmsReport.FORMAT_ERROR);
366        } else {
367            report.println(
368                Messages.get().container(Messages.RPT_CONVERTXML_TRANSFORMING_SUCCESS_0),
369                I_CmsReport.FORMAT_OK);
370        }
371
372        report.println(Messages.get().container(Messages.RPT_CONVERTXML_TRANSFORM_END_0), I_CmsReport.FORMAT_NOTE);
373        return transformSuccess;
374    }
375
376    /**
377     * Gets file xml content.<p>
378     *
379     * @param cmsResource current resource CmsResource
380     * @param cmsFile current CmsFile
381     * @param cmsObject current CmsObject
382     * @param xmlContent xml content to write
383     * @param encodingType encoding type
384     * @param report I_CmsReport
385     */
386    private void setXmlContentFromFile(
387        CmsResource cmsResource,
388        CmsFile cmsFile,
389        CmsObject cmsObject,
390        String xmlContent,
391        String encodingType,
392        I_CmsReport report) {
393
394        try {
395            byte[] fileContent = xmlContent.getBytes(encodingType);
396            cmsFile.setContents(fileContent);
397            // write into file
398            cmsObject.writeFile(cmsFile);
399            // unlock resource
400            try {
401                cmsObject.unlockResource(cmsObject.getSitePath(cmsResource));
402            } catch (CmsException e) {
403                m_errorTransform += 1;
404                report.println(
405                    Messages.get().container(Messages.RPT_CONVERTXML_UNLOCK_FILE_1, cmsObject.getSitePath(cmsResource)),
406                    I_CmsReport.FORMAT_ERROR);
407                if (LOG.isErrorEnabled()) {
408                    LOG.error(e.getMessageContainer(), e);
409                }
410            }
411        } catch (Exception e) {
412            m_errorTransform += 1;
413            String reportContent = "<br/>";
414            reportContent = reportContent + CmsEncoder.escapeXml(xmlContent);
415            reportContent = reportContent.replaceAll("\r\n", "<br/>");
416            report.println(
417                Messages.get().container(Messages.RPT_CONVERTXML_WRITE_ERROR_1, reportContent),
418                I_CmsReport.FORMAT_ERROR);
419            if (LOG.isErrorEnabled()) {
420                LOG.error(e.toString());
421            }
422        }
423    }
424
425    /**
426     * Transforms and write files.<p>
427     *
428     * @param files2Transform Files to transform
429     * @param xsltFile XLST file which includes logic for transforming
430     * @param cmsObject Current CmsObject
431     * @param newXsdMainFile New xsd main file
432     * @param report I_CmsReport
433     *
434     * @return Project with files to publish
435     *
436     * @throws CmsException Can become thrown while creating temporary OpenCms Projects
437     */
438    private CmsObject transformAndWriteFiles(
439        List<CmsResource> files2Transform,
440        String xsltFile,
441        CmsObject cmsObject,
442        String newXsdMainFile,
443        I_CmsReport report) {
444
445        // the CmsObject to publish resources
446        CmsObject cms1 = null;
447        // the CmsObject to handle resources which are not to publish
448        CmsObject cms2 = null;
449        // the publish project
450        CmsProject project2Publish = null;
451        // initialize the CmsObjects and the publish project
452        try {
453            cms1 = OpenCms.initCmsObject(cmsObject);
454            cms2 = OpenCms.initCmsObject(cmsObject);
455            cms1.copyResourceToProject("/");
456            project2Publish = cms1.createTempfileProject(); // init new
457            cms1.getRequestContext().setCurrentProject(project2Publish);
458        } catch (CmsException e) {
459            report.println(Messages.get().container(Messages.RPT_CONVERTXML_INITIALIZE_CMS_ERROR_0));
460            if (LOG.isErrorEnabled()) {
461                LOG.error(e.toString());
462            }
463            return cms1;
464        }
465
466        // iterate over all the resources to transform
467        Iterator<CmsResource> iter = files2Transform.iterator();
468        while (iter.hasNext()) {
469            // get the next resource to transform
470            CmsResource cmsResource = iter.next();
471            // check if the resource has to be published after transforming
472            boolean resource2Publish = false;
473            // get info if resource shall become published
474            CmsResourceState cmsResourceState = cmsResource.getState();
475            if (!(cmsResourceState.equals(CmsResourceState.STATE_CHANGED)
476                || cmsResourceState.equals(CmsResourceState.STATE_NEW))) {
477                // resource is not touched or is not new
478                resource2Publish = true;
479            }
480
481            // get current lock from file
482            if (resource2Publish) {
483                // lock the resource in the publish project
484                try {
485                    // try to lock the resource
486                    if (!lockResource(cms1, project2Publish, cmsResource, report)) {
487                        report.println(
488                            Messages.get().container(
489                                Messages.RPT_CONVERTXML_LOCKED_FILE_1,
490                                cmsObject.getSitePath(cmsResource)),
491                            I_CmsReport.FORMAT_ERROR);
492                        continue;
493                    }
494                } catch (CmsException e) {
495                    report.println(
496                        Messages.get().container(
497                            Messages.RPT_CONVERTXML_LOCKED_FILE_1,
498                            cmsObject.getSitePath(cmsResource)),
499                        I_CmsReport.FORMAT_ERROR);
500                    if (LOG.isErrorEnabled()) {
501                        LOG.error(e.getMessageContainer(), e);
502                    }
503                    continue;
504                }
505            } else {
506                // lock the resource in the project where the resource was last modified in
507                try {
508                    // get the project id from the project where the resource is last modified in
509                    CmsUUID pid = cmsResource.getProjectLastModified();
510                    CmsProject fileProject = cms2.readProject(pid);
511                    cms2.getRequestContext().setCurrentProject(fileProject);
512                    // try to lock the resource
513                    if (!lockResource(cms2, fileProject, cmsResource, report)) {
514                        report.println(
515                            Messages.get().container(
516                                Messages.RPT_CONVERTXML_LOCKED_FILE_1,
517                                cmsObject.getSitePath(cmsResource)),
518                            I_CmsReport.FORMAT_ERROR);
519                        continue;
520                    }
521                } catch (CmsException e) {
522                    report.println(
523                        Messages.get().container(
524                            Messages.RPT_CONVERTXML_LOCKED_FILE_1,
525                            cmsObject.getSitePath(cmsResource)),
526                        I_CmsReport.FORMAT_ERROR);
527                    if (LOG.isErrorEnabled()) {
528                        LOG.error(e.getMessageContainer(), e);
529                    }
530                    continue;
531                }
532            }
533
534            // get CmsFile object and the xml content
535            CmsFile cmsFile = null;
536            String fileXmlContent = "";
537            try {
538                cmsFile = cmsObject.readFile(cmsResource);
539                CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), cmsFile);
540                fileXmlContent = xmlContent.toString();
541            } catch (CmsException e) {
542                m_errorTransform += 1;
543                report.println(
544                    Messages.get().container(Messages.RPT_CONVERTXML_TRANSFORMATION_ERROR_0),
545                    I_CmsReport.FORMAT_ERROR);
546                if (LOG.isErrorEnabled()) {
547                    LOG.error(e.getMessageContainer(), e);
548                }
549                continue;
550            }
551
552            // get encoding per resource
553            String encodingType = "";
554            try {
555                encodingType = cmsObject.readPropertyObject(
556                    cmsResource.getRootPath(),
557                    CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING,
558                    true).getValue(OpenCms.getSystemInfo().getDefaultEncoding());
559            } catch (CmsException e) {
560                encodingType = OpenCms.getSystemInfo().getDefaultEncoding();
561            }
562
563            // check transform conditions per resource
564            // encoding type given?
565            if (CmsStringUtil.isEmpty(encodingType)) {
566                m_missingEncodingType += 1;
567                report.println(
568                    Messages.get().container(
569                        Messages.RPT_CONVERTXML_MISSION_ENCODING_TYPE_1,
570                        cmsResource.getRootPath()),
571                    I_CmsReport.FORMAT_ERROR);
572                continue;
573            }
574            // already transformed?
575            if (fileXmlContent.toUpperCase().contains(newXsdMainFile.toUpperCase())) {
576                m_alreadyTransformed += 1;
577                report.println(
578                    Messages.get().container(
579                        Messages.RPT_CONVERTXML_FILE_ALREADY_TRANSFORMED_1,
580                        cmsResource.getRootPath()),
581                    I_CmsReport.FORMAT_OK);
582                continue;
583            }
584
585            // create and write the changed xml content
586            try {
587                String transformedXmlContent = CmsXsltUtil.transformXmlContent(cmsObject, xsltFile, fileXmlContent);
588                transformedXmlContent = "<?xml version=\"1.0\" encoding=\"".concat(encodingType).concat("\"?>").concat(
589                    transformedXmlContent);
590                // write file xml content
591                if (resource2Publish) {
592                    report.println(
593                        Messages.get().container(
594                            Messages.RPT_CONVERTXML_TRANSFORM_CURRENT_FILE_NAME2_2,
595                            cmsResource.getRootPath(),
596                            encodingType),
597                        I_CmsReport.FORMAT_OK);
598                    cms1.getRequestContext().setCurrentProject(project2Publish);
599                    setXmlContentFromFile(cmsResource, cmsFile, cms1, transformedXmlContent, encodingType, report);
600                } else {
601                    report.println(Messages.get().container(
602                        Messages.RPT_CONVERTXML_TRANSFORM_CURRENT_FILE_NAME_2,
603                        cmsResource.getRootPath(),
604                        encodingType), I_CmsReport.FORMAT_OK);
605                    setXmlContentFromFile(cmsResource, cmsFile, cms2, transformedXmlContent, encodingType, report);
606                }
607            } catch (CmsXmlException e) {
608                m_errorTransform += 1;
609                report.println(
610                    Messages.get().container(Messages.RPT_CONVERTXML_TRANSFORMATION_ERROR_0),
611                    I_CmsReport.FORMAT_ERROR);
612                if (LOG.isErrorEnabled()) {
613                    LOG.error(e.getMessageContainer(), e);
614                }
615            } catch (CmsException e) {
616                m_errorTransform += 1;
617                report.println(
618                    Messages.get().container(Messages.RPT_CONVERTXML_TRANSFORMATION_ERROR_0),
619                    I_CmsReport.FORMAT_ERROR);
620                if (LOG.isErrorEnabled()) {
621                    LOG.error(e.getMessageContainer(), e);
622                }
623            }
624
625        }
626        return cms1;
627    }
628}