Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2008 Day Management AG
* Barfuesserplatz 6, 4001 Basel, Switzerland
* All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Day Management AG, ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Day.
*/
package com.day.cq.wcm.offline;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.List;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.commons.jcr.JcrConstants;
import com.day.cq.commons.jcr.JcrUtil;
/**
* Importer class for converting MS Word documents to CQ5 pages.
* @deprecated since 6.3
*/
@Deprecated
public class OfflineImporter {
private static final Logger log = LoggerFactory.getLogger(OfflineImporter.class);
private final Node parent;
private final TextDocumentImporter importer;
private String filename;
private String resourceType;
private String template;
private ValueMap config;
/**
* Creates an importer for importing the given Word document to the given
* target node.
*
* @param parent parent node under which the imported pages are created
* @param stream stream containing the Word document
* @throws IOException if the Word document could not be loaded
* @throws TextImportException if the document uses an unknown format
* @deprecated
*/
public OfflineImporter(Node parent, InputStream stream) throws IOException, TextImportException {
this.parent = parent;
this.importer = new DocImporter(stream);
}
/**
* Creates an importer for importing the given Word document to the given
* target node.
*
* @param parent parent node under which the imported pages are created
* @param rp sling request parameter containing the document
* @throws IOException if the Word document could not be loaded
* @throws TextImportException if the document uses an unknown format
*/
public OfflineImporter(Node parent, RequestParameter rp) throws IOException, TextImportException {
this.parent = parent;
this.importer = getImporter(rp);
}
private static TextDocumentImporter getImporter(RequestParameter rp) throws IOException, TextImportException {
try {
return new DocImporter(rp.getInputStream());
}
catch (TextImportException ex){
return new DocxImporter(rp.getInputStream());
}
}
public void setFilename(String filename) {
this.filename = filename;
}
public void setResourceType(String resourceType) {
this.resourceType = resourceType;
}
public void setTemplate(String template) {
this.template = template;
}
/**
* Imports the document to the given target node.
*
* @throws RepositoryException if a repository error occurs
*/
public void importDocument() throws RepositoryException {
String title = getTitle(filename);
Node node = parent.addNode(getNodeName(filename), "cq:Page");
Node content = node.addNode(JcrConstants.JCR_CONTENT, "cq:PageContent");
if (resourceType != null) {
content.setProperty("sling:resourceType", resourceType);
}
if (template != null) {
content.setProperty("cq:template", template);
}
content.setProperty(JcrConstants.JCR_TITLE, title);
content.setProperty("pageTitle", title);
Node parsys = content.addNode("par", JcrConstants.NT_UNSTRUCTURED);
parsys.setProperty("sling:resourceType", "foundation/components/parsys");
for (int i = 0; i < this.importer.getNumberOfParagraphs(); i++) {
Node paragraph = parsys.addNode("par" + i, "nt:unstructured");
Paragraph p = this.importer.getParagraph(i);
String html = p.getHTML();
List