View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.frontend.xeditor.target;
20  
21  import javax.servlet.ServletContext;
22  
23  import org.jdom2.Document;
24  import org.mycore.common.content.MCRContent;
25  import org.mycore.common.content.MCRJDOMContent;
26  import org.mycore.common.xml.MCRLayoutService;
27  import org.mycore.frontend.servlets.MCRServletJob;
28  import org.mycore.frontend.xeditor.MCREditorSession;
29  import org.mycore.frontend.xeditor.tracker.MCRChangeTracker;
30  
31  /**
32   * @author Frank L\u00FCtzenkirchen
33   */
34  public class MCRLayoutServiceTarget implements MCREditorTarget {
35  
36      @Override
37      public void handleSubmission(ServletContext context, MCRServletJob job, MCREditorSession session, String style)
38          throws Exception {
39          session.getSubmission().setSubmittedValues(job.getRequest().getParameterMap());
40          Document result = session.getEditedXML();
41  
42          if (session.getValidator().isValid()) {
43              result = MCRChangeTracker.removeChangeTracking(result);
44              result = session.getXMLCleaner().clean(result);
45              result = session.getPostProcessor().process(result);
46  
47              if ((style != null) && (!style.isEmpty()))
48                  job.getRequest().setAttribute("XSL.Style", style);
49  
50              MCRContent editedXML = new MCRJDOMContent(result);
51              MCRLayoutService.instance().doLayout(job.getRequest(), job.getResponse(), editedXML);
52              session.setBreakpoint("After handling target layout " + style);
53          } else {
54              session.setBreakpoint("After validation failed, target layout " + style);
55              job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(session.getRedirectURL(null)));
56          }
57      }
58  }