Skip to content

Commit

Permalink
Improved creation of sample formatter configuration file.
Browse files Browse the repository at this point in the history
  • Loading branch information
tHerrmann committed Feb 6, 2014
1 parent 8be628a commit f90beb7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 53 deletions.
28 changes: 0 additions & 28 deletions modules/org.opencms.workplace.tools.modules/resources/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,34 +160,6 @@
<relations/>
<accesscontrol/>
</file>
<file>
<source>system/modules/org.opencms.workplace.tools.modules/samples/sample-formatter-config.xml</source>
<destination>system/modules/org.opencms.workplace.tools.modules/samples/sample-formatter-config.xml</destination>
<type>formatter_config</type>
<uuidstructure>b885f4fa-8cdb-11e3-955f-094876801169</uuidstructure>
<uuidresource>b885f4fb-8cdb-11e3-955f-094876801169</uuidresource>
<datelastmodified>Mon, 03 Feb 2014 14:11:56 GMT</datelastmodified>
<userlastmodified>Admin</userlastmodified>
<datecreated>Mon, 03 Feb 2014 14:01:47 GMT</datecreated>
<usercreated>Admin</usercreated>
<flags>0</flags>
<properties>
<property>
<name>locale</name>
<value><![CDATA[en]]></value>
</property>
<property>
<name>locale-available</name>
<value><![CDATA[en]]></value>
</property>
<property>
<name>search.exclude</name>
<value><![CDATA[all]]></value>
</property>
</properties>
<relations/>
<accesscontrol/>
</file>
<file>
<source>system/modules/org.opencms.workplace.tools.modules/samples/sample-formatter.jsp</source>
<destination>system/modules/org.opencms.workplace.tools.modules/samples/sample-formatter.jsp</destination>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.opencms.ade.configuration.CmsADEManager;
import org.opencms.ade.configuration.CmsConfigurationReader;
import org.opencms.ade.configuration.formatters.CmsFormatterBeanParser;
import org.opencms.ade.configuration.formatters.CmsFormatterConfigurationCache;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProject;
Expand Down Expand Up @@ -100,9 +101,6 @@ public class CmsModuleAddResourceTypeThread extends A_CmsReportThread {
/** Sample file. */
private static final String SAMPLE_FORMATTER = "/system/modules/org.opencms.workplace.tools.modules/samples/sample-formatter.jsp";

/** Sample file. */
private static final String SAMPLE_FORMATTER_CONFIG = "/system/modules/org.opencms.workplace.tools.modules/samples/sample-formatter-config.xml";

/** Sample file. */
private static final String SAMPLE_ICON_BIG = "/system/modules/org.opencms.workplace.tools.modules/samples/sample-icon_big.png";

Expand Down Expand Up @@ -402,11 +400,15 @@ private void createSampleFormatter(String moduleFolder) throws CmsIllegalArgumen
}
String formatterConfig = CmsStringUtil.joinPaths(formatterFolder, m_resInfo.getName() + "-formatter-config.xml");
if (!cms.existsResource(formatterConfig)) {
// copy the sample config file and adjust it according to the new resource type
cms.copyResource(SAMPLE_FORMATTER_CONFIG, formatterConfig, CmsResource.COPY_AS_NEW);

cms.createResource(
formatterConfig,
OpenCms.getResourceManager().getResourceType(CmsFormatterConfigurationCache.TYPE_FORMATTER_CONFIG).getTypeId());
CmsFile configFile = cms.readFile(formatterConfig);
lockTemporary(configFile);
CmsXmlContent configContent = CmsXmlContentFactory.unmarshal(cms, configFile);
if (!configContent.hasLocale(CmsConfigurationReader.DEFAULT_LOCALE)) {
configContent.addLocale(cms, CmsConfigurationReader.DEFAULT_LOCALE);
}
I_CmsXmlContentValue typeValue = configContent.getValue(
CmsFormatterBeanParser.N_TYPE,
CmsConfigurationReader.DEFAULT_LOCALE);
Expand All @@ -424,6 +426,25 @@ private void createSampleFormatter(String moduleFolder) throws CmsIllegalArgumen
+ (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_resInfo.getNiceName())
? m_resInfo.getNiceName()
: m_resInfo.getName()));
// set matching container width to '-1' to fit everywhere
configContent.addValue(cms, CmsFormatterBeanParser.N_MATCH, CmsConfigurationReader.DEFAULT_LOCALE, 0);
configContent.addValue(
cms,
CmsFormatterBeanParser.N_MATCH + "/" + CmsFormatterBeanParser.N_WIDTH,
CmsConfigurationReader.DEFAULT_LOCALE,
0);
I_CmsXmlContentValue widthValue = configContent.getValue(CmsFormatterBeanParser.N_MATCH
+ "/"
+ CmsFormatterBeanParser.N_WIDTH
+ "/"
+ CmsFormatterBeanParser.N_WIDTH, CmsConfigurationReader.DEFAULT_LOCALE);
widthValue.setStringValue(cms, "-1");

// enable the formatter
I_CmsXmlContentValue enabledValue = configContent.getValue(
CmsFormatterBeanParser.N_AUTO_ENABLED,
CmsConfigurationReader.DEFAULT_LOCALE);
enabledValue.setStringValue(cms, Boolean.TRUE.toString());
configFile.setContents(configContent.marshal());
cms.writeFile(configFile);
}
Expand Down

0 comments on commit f90beb7

Please sign in to comment.