cmsresourcecomparisondialog.java
来自「找了很久才找到到源代码」· Java 代码 · 共 784 行 · 第 1/2 页
JAVA
784 行
originalSource = textExtractor.extractText(content1).getContent();
copySource = textExtractor.extractText(content2).getContent();
} else if ((resourceType instanceof CmsResourceTypePlain) || (resourceType instanceof CmsResourceTypeJsp)) {
originalSource = new String(content1);
copySource = new String(content2);
}
fileInfo.writeDialog();
twoLists.writeDialog();
if (CmsStringUtil.isNotEmpty(originalSource) && CmsStringUtil.isNotEmpty(copySource)) {
m_differenceDialog.setCopySource(copySource);
m_differenceDialog.setOriginalSource(originalSource);
// same as for CmsImageComparisonDialog
m_differenceDialog.displayDialog();
}
} else {
// display attributes and properties
lists.add(propertyDiff);
CmsMultiListDialog twoLists = new CmsMultiListDialog(lists);
twoLists.displayDialog(true);
if (twoLists.isForwarded()) {
return;
}
fileInfo.writeDialog();
twoLists.writeDialog();
}
}
/**
* Displays the difference dialog.<p>
* @throws Exception if something goes wrong
*/
public void displayDifferenceDialog() throws Exception {
m_differenceDialog.displayDialog();
}
/**
* Converts an attribute list to a string.<p>
*
* @param attributes a list of compared attributes to be converted to a string
* @return a string respresentation of the attribute list
*/
public String[] getAttributesAsString(List attributes) {
Iterator i = attributes.iterator();
StringBuffer res1 = new StringBuffer(512);
StringBuffer res2 = new StringBuffer(512);
while (i.hasNext()) {
CmsAttributeComparison compare = (CmsAttributeComparison)i.next();
res1.append(key(compare.getName())).append(": ").append(compare.getVersion1()).append("\n");
res2.append(key(compare.getName())).append(": ").append(compare.getVersion2()).append("\n");
}
return new String[] {res1.toString(), res2.toString()};
}
/**
* Returns the paramCompare.<p>
*
* @return the paramCompare
*/
public String getParamCompare() {
return m_paramCompare;
}
/**
* Returns the paramElement.<p>
*
* @return the paramElement
*/
public String getParamElement() {
return m_paramElement;
}
/**
* Returns the paramId1.<p>
*
* @return the paramId1
*/
public String getParamId1() {
return m_paramId1;
}
/**
* Returns the paramId2.<p>
*
* @return the paramId2
*/
public String getParamId2() {
return m_paramId2;
}
/**
* Returns the paramLocale.<p>
*
* @return the paramLocale
*/
public String getParamLocale() {
return m_paramLocale;
}
/**
* Returns the paramTextmode.<p>
*
* @return the paramTextmode
*/
public String getParamTextmode() {
return m_paramTextmode;
}
/**
* Returns the paramVersion1.<p>
*
* @return the paramVersion1
*/
public String getParamVersion1() {
return m_paramVersion1;
}
/**
* Returns the paramVersion2.<p>
*
* @return the paramVersion2
*/
public String getParamVersion2() {
return m_paramVersion2;
}
/**
* Converts an attribute list to a string.<p>
*
* @param properties a list of compared properties to be converted to a string
* @return a string respresentation of the attribute list
*/
public String[] getPropertiesAsString(List properties) {
Iterator i = properties.iterator();
StringBuffer res1 = new StringBuffer(512);
StringBuffer res2 = new StringBuffer(512);
while (i.hasNext()) {
CmsAttributeComparison compare = (CmsAttributeComparison)i.next();
res1.append(compare.getName()).append(": ").append(compare.getVersion1()).append("\n");
res2.append(compare.getName()).append(": ").append(compare.getVersion2()).append("\n");
}
return new String[] {res1.toString(), res2.toString()};
}
/**
* Sets the paramCompare.<p>
*
* @param paramCompare the paramCompare to set
*/
public void setParamCompare(String paramCompare) {
m_paramCompare = paramCompare;
}
/**
* Sets the paramElement.<p>
*
* @param paramElement the paramElement to set
*/
public void setParamElement(String paramElement) {
m_paramElement = paramElement;
}
/**
* Sets the paramId1.<p>
*
* @param paramId1 the paramId1 to set
*/
public void setParamId1(String paramId1) {
m_paramId1 = paramId1;
}
/**
* Sets the paramId2.<p>
*
* @param paramId2 the paramId2 to set
*/
public void setParamId2(String paramId2) {
m_paramId2 = paramId2;
}
/**
* Sets the paramLocale.<p>
*
* @param paramLocale the paramLocale to set
*/
public void setParamLocale(String paramLocale) {
m_paramLocale = paramLocale;
}
/**
* Sets the paramTextmode.<p>
*
* @param paramTextmode the paramTextmode to set
*/
public void setParamTextmode(String paramTextmode) {
m_paramTextmode = paramTextmode;
}
/**
* Sets the paramVersion1.<p>
*
* @param paramVersion1 the paramVersion1 to set
*/
public void setParamVersion1(String paramVersion1) {
m_paramVersion1 = paramVersion1;
}
/**
* Sets the paramVersion2.<p>
*
* @param paramVersion2 the paramVersion2 to set
*/
public void setParamVersion2(String paramVersion2) {
m_paramVersion2 = paramVersion2;
}
/**
* @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
*/
protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
super.initWorkplaceRequestValues(settings, request);
try {
CmsResource resource1 = CmsResourceComparisonDialog.readResource(
getCms(),
new CmsUUID(getParamId1()),
getParamVersion1());
CmsResource resource2 = CmsResourceComparisonDialog.readResource(
getCms(),
new CmsUUID(getParamId2()),
getParamVersion2());
// if certain element is compared, use html difference dialog
if (CmsStringUtil.isNotEmpty(getParamElement())) {
m_differenceDialog = new CmsHtmlDifferenceDialog(getJsp());
} else {
m_differenceDialog = new CmsDifferenceDialog(getJsp());
}
if (CmsResourceComparisonDialog.COMPARE_ATTRIBUTES.equals(getParamCompare())) {
List comparedAttributes = CmsResourceComparison.compareAttributes(getCms(), resource1, resource2);
String[] attributeStrings = getAttributesAsString(comparedAttributes);
m_differenceDialog.setOriginalSource(attributeStrings[0]);
m_differenceDialog.setCopySource(attributeStrings[1]);
} else if (CmsResourceComparisonDialog.COMPARE_PROPERTIES.equals(getParamCompare())) {
List comparedProperties = CmsResourceComparison.compareProperties(
getCms(),
resource1,
getParamVersion1(),
resource2,
getParamVersion2());
String[] propertyStrings = getPropertiesAsString(comparedProperties);
m_differenceDialog.setOriginalSource(propertyStrings[0]);
m_differenceDialog.setCopySource(propertyStrings[1]);
} else if (resource1.isFile()) {
CmsFile file1 = readFile(getCms(), new CmsUUID(getParamId1()), getParamVersion1());
CmsFile file2 = readFile(getCms(), new CmsUUID(getParamId2()), getParamVersion2());
setContentAsSource(file1, file2);
}
} catch (CmsException e) {
LOG.error(e.getMessage(), e);
} catch (UnsupportedEncodingException e) {
LOG.error(e.getMessage(), e);
}
}
/**
* Returns the content of all elements of an xml document appended.<p>
*
* @param xmlDoc the xml document to extract the elements from
* @return the content of all elements of an xml document appended
*/
private String extractElements(I_CmsXmlDocument xmlDoc) {
StringBuffer result = new StringBuffer();
if (xmlDoc instanceof CmsXmlPage) {
List locales = xmlDoc.getLocales();
Iterator i = locales.iterator();
boolean firstIter = true;
while (i.hasNext()) {
if (!firstIter) {
result.append("\n\n-----");
}
Locale locale = (Locale)i.next();
result.append("\n\n[").append(locale.toString()).append(']');
List elements = xmlDoc.getValues(locale);
Iterator j = elements.iterator();
while (j.hasNext()) {
I_CmsXmlContentValue value = (I_CmsXmlContentValue)j.next();
result.append("\n\n[");
// output value of name attribute
result.append(value.getElement().attribute(0).getValue());
result.append("]\n\n");
try {
I_CmsWidget widget = value.getDocument().getContentDefinition().getContentHandler().getWidget(
value);
result.append(widget.getWidgetStringValue(
getCms(),
new CmsResourceInfoDialog(getJsp()),
(I_CmsWidgetParameter)value));
} catch (CmsXmlException e) {
LOG.error(e.getMessage(), e);
}
}
firstIter = false;
}
} else if (xmlDoc instanceof CmsXmlContent) {
CmsXmlContentTextExtractor visitor = new CmsXmlContentTextExtractor(result);
((CmsXmlContent)xmlDoc).visitAllValuesWith(visitor);
}
return result.toString();
}
/**
* Extracts the content from the files according to the file type.<p>
*
* @param file1 the first file to compare
* @param file2 the second file to compare
*
* @throws CmsException if something goes wrong
* @throws UnsupportedEncodingException if the encoding of one file is not supported
*/
private void setContentAsSource(CmsFile file1, CmsFile file2) throws CmsException, UnsupportedEncodingException {
CmsObject cms = getCms();
if (CmsStringUtil.isNotEmpty(getParamElement())) {
I_CmsXmlDocument resource1;
I_CmsXmlDocument resource2;
if (CmsResourceTypeXmlPage.isXmlPage(file1)) {
resource1 = CmsXmlPageFactory.unmarshal(cms, file1);
} else {
resource1 = CmsXmlContentFactory.unmarshal(cms, file1);
}
if (CmsResourceTypeXmlPage.isXmlPage(file2)) {
resource2 = CmsXmlPageFactory.unmarshal(cms, file2);
} else {
resource2 = CmsXmlContentFactory.unmarshal(cms, file2);
}
I_CmsXmlContentValue value1 = resource1.getValue(getParamElement(), new Locale(getParamLocale()));
I_CmsXmlContentValue value2 = resource2.getValue(getParamElement(), new Locale(getParamLocale()));
if (value1 == null) {
m_differenceDialog.setOriginalSource("");
} else {
m_differenceDialog.setOriginalSource(value1.getStringValue(cms));
}
if (value2 == null) {
m_differenceDialog.setCopySource("");
} else {
m_differenceDialog.setCopySource(value2.getStringValue(cms));
}
} else if (CmsResourceComparisonDialog.COMPARE_ALL_ELEMENTS.equals(getParamCompare())) {
I_CmsXmlDocument resource1;
I_CmsXmlDocument resource2;
if (CmsResourceTypeXmlPage.isXmlPage(file1)) {
resource1 = CmsXmlPageFactory.unmarshal(cms, file1);
} else {
resource1 = CmsXmlContentFactory.unmarshal(cms, file1);
}
if (CmsResourceTypeXmlPage.isXmlPage(file2)) {
resource2 = CmsXmlPageFactory.unmarshal(cms, file2);
} else {
resource2 = CmsXmlContentFactory.unmarshal(cms, file2);
}
m_differenceDialog.setOriginalSource(extractElements(resource1));
m_differenceDialog.setCopySource(extractElements(resource2));
} else {
// compare whole plain text file
m_differenceDialog.setOriginalSource(new String(file1.getContents(), cms.getRequestContext().getEncoding()));
m_differenceDialog.setCopySource(new String(file2.getContents(), cms.getRequestContext().getEncoding()));
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?