📄 cmsimportversion1.java
字号:
+ this.getClass().getName()
+ ".convertPageBody()]: No <edittemplate> found, creating it.");
}
createTemplateTags = true;
nodeName = "TEMPLATE";
List templateNodes = root.elements(nodeName.toLowerCase());
List attributes;
templateNodes.addAll(root.elements(nodeName.toUpperCase()));
// create an <edittemplate> tag for each <template> tag
Element templateTag;
for (int i = 0; i < templateNodes.size(); i++) {
// get the CDATA content of the <template> tags
templateTag = (Element)templateNodes.get(i);
editString = templateTag.getText();
templateString = editString;
// substitute the links in the <template> tag String
try {
templateString = CmsXmlTemplateLinkConverter.convertFromImport(
templateString,
m_webappUrl,
fileName);
} catch (CmsException e) {
throw new CmsLegacyException("["
+ this.getClass().getName()
+ ".convertPageBody()] can't parse the content: ", e);
}
// look for the "name" attribute of the <template> tag
attributes = ((Element)templateNodes.get(i)).attributes();
String templateName = "";
if (attributes.size() > 0) {
templateName = ((Attribute)attributes.get(0)).getName();
}
// create the new <edittemplate> node
nodeName = "edittemplate";
Element newNode = DocumentHelper.createElement(nodeName.toLowerCase());
if (newNode == null) {
newNode = root.addElement(nodeName.toUpperCase());
}
newNode.addCDATA(editString);
// set the "name" attribute, if necessary
attributes = newNode.attributes();
if (!templateName.equals("")) {
newNode.addAttribute("name", templateName);
}
// append the new edittemplate node to the document
((Element)root.elements("XMLTEMPLATE").get(0)).add(newNode);
// store modified <template> node Strings in Hashtable
if (templateName.equals("")) {
templateName = "noNameKey";
}
templateElements.put(templateName, templateString);
}
// finally, delete old <TEMPLATE> tags from document
while (templateNodes.size() > 0) {
((Element)root.elements("XMLTEMPLATE").get(0)).remove((Element)templateNodes.get(0));
}
}
// check the content of the <edittemplate> nodes
Element editTemplate;
for (int i = 0; i < editNodes.size(); i++) {
// editString = editNodes.item(i).getFirstChild().getNodeValue();
editTemplate = (Element)editNodes.get(i);
editString = editTemplate.getText();
for (int k = 0; k < m_webAppNames.size(); k++) {
editString = CmsStringUtil.substitute(
editString,
(String)m_webAppNames.get(k),
CmsStringUtil.MACRO_OPENCMS_CONTEXT + "/");
}
// There is a setText(String) but no corresponding setCDATA in dom4j.
editTemplate.clearContent();
editTemplate.addCDATA(editString);
}
// convert XML document back to String
content = CmsXmlUtils.marshal(doc, OpenCms.getSystemInfo().getDefaultEncoding());
// rebuild the template tags in the document!
if (createTemplateTags) {
content = content.substring(0, content.lastIndexOf("</XMLTEMPLATE>"));
// get the keys
Enumeration en = templateElements.keys();
while (en.hasMoreElements()) {
String key = (String)en.nextElement();
String value = (String)templateElements.get(key);
// create the default template
if (key.equals("noNameKey")) {
content += "\n<TEMPLATE><![CDATA[" + value;
} else {
// create template with "name" attribute
content += "\n<TEMPLATE name=\"" + key + "\"><![CDATA[" + value;
}
content += "]]></TEMPLATE>\n";
}
content += "\n</XMLTEMPLATE>";
}
} catch (Exception exc) {
// ignore
}
}
return content;
}
/**
* Scans the given content of a frametemplate and returns the result.<p>
*
* @param content the filecontent
* @return modified content
*/
private String scanFrameTemplate(String content) {
// no Meta-Tag present, insert it!
if (content.toLowerCase().indexOf("http-equiv=\"content-type\"") == -1) {
content = CmsStringUtil
.substitute(
content,
"</head>",
"<meta http-equiv=\"content-type\" content=\"text/html; charset=]]><method name=\"getEncoding\"/><![CDATA[\">\n</head>");
} else {
// Meta-Tag present
if (content.toLowerCase().indexOf("charset=]]><method name=\"getencoding\"/>") == -1) {
String fileStart = content.substring(0, content.toLowerCase().indexOf("charset=") + 8);
String editContent = content.substring(content.toLowerCase().indexOf("charset="));
editContent = editContent.substring(editContent.indexOf("\""));
String newEncoding = "]]><method name=\"getEncoding\"/><![CDATA[";
content = fileStart + newEncoding + editContent;
}
}
return content;
}
/**
* Performs all required pre-import steps.<p>
*
* The content *IS* changed in the implementation of this class (edittemplate/displaytemplate,
* links, paths including the webapps name etc.).<p>
*
* @see org.opencms.importexport.CmsImportVersion2#convertContent(java.lang.String, java.lang.String, byte[], java.lang.String)
*/
protected byte[] convertContent(String source, String destination, byte[] content, String resType) {
// check and convert old import files
if (getVersion() < 2) {
// convert content from pre 5.x must be activated
if ("page".equals(resType) || ("plain".equals(resType)) || ("XMLTemplate".equals(resType))) {
if (DEBUG > 0) {
System.err.println("#########################");
System.err.println("["
+ this.getClass().getName()
+ ".convertContent()]: starting conversion of \""
+ resType
+ "\" resource "
+ source
+ ".");
}
// change the filecontent for encoding if necessary
content = convertFile(source, content);
}
// only check the file type if the version of the export is 0
if (getVersion() == 0) {
// ok, a (very) old system exported this, check if the file is ok
if (!(new CmsCompatibleCheck()).isTemplateCompatible(m_importPath + destination, content, resType)) {
resType = CmsResourceTypeCompatiblePlain.getStaticTypeName();
m_report.print(Messages.get().container(Messages.RPT_MUST_SET_TO_1, resType), I_CmsReport.FORMAT_WARNING);
}
}
}
// drag the content also through the conversion method in the super class
return super.convertContent(source, destination, content, resType);
}
/**
* Creates a dom4j document out of a specified stream.<p>
*
* @param stream the stream
* @return a dom4j document
* @throws CmsXmlException if something goes wrong
*/
public static Document getXmlDocument(InputStream stream) throws CmsXmlException {
return CmsXmlUtils.unmarshalHelper(new InputSource(stream), null);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -