diff --git a/ccm-cms-relationattributeimporter/src/com/arsdigita/cms/relationattributeimporter/RelationAttributeImporter.java b/ccm-cms-relationattributeimporter/src/com/arsdigita/cms/relationattributeimporter/RelationAttributeImporter.java
index 71ceeb6e8..4d8c44a5f 100644
--- a/ccm-cms-relationattributeimporter/src/com/arsdigita/cms/relationattributeimporter/RelationAttributeImporter.java
+++ b/ccm-cms-relationattributeimporter/src/com/arsdigita/cms/relationattributeimporter/RelationAttributeImporter.java
@@ -34,7 +34,8 @@ import org.xml.sax.SAXException;
/**
*
* A simple import tool for {@link RelationAttribute}s. This tool imports the
- * relation attributes from a simple XML file, which looks like this:
+ * relation attributes from a simple XML file or from parameters at the
+ * commandline. The XML file format:
*
*
* <?xml version="1.0"?>
@@ -46,6 +47,7 @@ import org.xml.sax.SAXException;
* <name>...</name>
* <description>...</description>
* </relationAttribute>
+ * ...
* </relationAttributes>
*
*
@@ -53,10 +55,22 @@ import org.xml.sax.SAXException;
* to import is needed. With tools-ng and ECDC, the line for calling the
* RelationAttributeImporter would like the following:
*
+ *
+ * With a XML file:
+ *
*
* ant -Dccm.classname="com.arsdigita.cms.relationattributeimporter.RelationAttributeImporter" -Dccm.parameters="/path/to/relation/attribute/file.xml" ccm-run
*
*
+ * With command line parameters:
+ *
+ *
+ * ant -Dccm.classname="com.arsdigita.cms.relationattributeimporter.RelationAttributeImporter" -Dccm.parameters="attribute key lang name [description]" ccm-run
+ *
+ *
+ * The description parameter is optional.
+ *
+ *
* You have to add the RelationAttributeImporter to add to your
* environment, of course.
*
@@ -68,11 +82,15 @@ import org.xml.sax.SAXException;
public class RelationAttributeImporter extends Program {
public RelationAttributeImporter() {
- super("Relation Attribute Importer", "0.1.0", "FILE");
+ super("Relation Attribute Importer",
+ "0.1.0",
+ "FILE | ATTRIBUTE KEY LANG NAME [DESCRIPTION]");
}
public RelationAttributeImporter(boolean startup) {
- super("Relation Attribute Importer", "0.1.0", "FILE", startup);
+ super("Relation Attribute Importer",
+ "0.1.0",
+ "FILE | ATTRIBUTE KEY LANG NAME [DESCRIPTION]", startup);
}
@Override
@@ -84,56 +102,72 @@ public class RelationAttributeImporter extends Program {
SAXParser saxParser = null;
RelationAttributeParser parser;
args = cmdLine.getArgs();
- if (args.length != 1) {
+ if (args.length == 1) {
+ System.out.printf("Using file %s.", args[0]);
+ relAttrFile = new File(args[0]);
+ if (!relAttrFile.exists()) {
+ System.err.printf("ERROR: File %s does not exist.", args[0]);
+ System.exit(-1);
+ }
+ if (!relAttrFile.isFile()) {
+ System.err.printf("ERROR: Path %s does not point to a file.",
+ args[0]);
+ System.exit(-1);
+ }
+ saxFactory = SAXParserFactory.newInstance();
+ try {
+ saxParser = saxFactory.newSAXParser();
+ } catch (ParserConfigurationException ex) {
+ System.err.printf("Error creating SAXParser: %s",
+ ex.getMessage());
+ ex.printStackTrace();
+ System.exit(-1);
+ } catch (SAXException ex) {
+ System.err.printf("Error creating SAXParser: %s",
+ ex.getMessage());
+ ex.printStackTrace();
+ System.exit(-1);
+ }
+ parser = new RelationAttributeParser();
+ try {
+ saxParser.parse(relAttrFile, parser);
+ } catch (SAXException ex) {
+ System.err.printf("Error parsing file %s: %s",
+ args[0],
+ ex.getMessage());
+ ex.printStackTrace();
+ System.exit(-1);
+ } catch (IOException ex) {
+ System.err.printf("Error parsing file %s: %s",
+ args[0], ex.getMessage());
+ ex.printStackTrace();
+ System.exit(-1);
+ }
+
+ System.out.println(
+ "Parsed XML file successfully. Creating ACSObjects...");
+ for (int i = 0; i < parser.getRelAttrs().size(); i++) {
+ System.out.printf("%d of %d...", (i + 1), parser.getRelAttrs().
+ size());
+ createACSObject(parser.getRelAttrs().get(i));
+ }
+ } else if ((args.length == 4) || (args.length == 5)) {
+ RelAttrBean relAttr;
+
+ relAttr = new RelAttrBean();
+ relAttr.setAttribute(args[0]);
+ relAttr.setKey(args[1]);
+ relAttr.setLang(args[2]);
+ relAttr.setName(args[3]);
+ if (args.length == 5) {
+ relAttr.setDescription(args[4]);
+ }
+
+ createACSObject(relAttr);
+ } else {
help(System.err);
System.exit(-1);
}
-
- System.out.printf("Using file %s.", args[0]);
- relAttrFile = new File(args[0]);
- if (!relAttrFile.exists()) {
- System.err.printf("ERROR: File %s does not exist.", args[0]);
- System.exit(-1);
- }
- if (!relAttrFile.isFile()) {
- System.err.printf("ERROR: Path %s does not point to a file.",
- args[0]);
- System.exit(-1);
- }
- saxFactory = SAXParserFactory.newInstance();
- try {
- saxParser = saxFactory.newSAXParser();
- } catch (ParserConfigurationException ex) {
- System.err.printf("Error creating SAXParser: %s", ex.getMessage());
- ex.printStackTrace();
- System.exit(-1);
- } catch (SAXException ex) {
- System.err.printf("Error creating SAXParser: %s", ex.getMessage());
- ex.printStackTrace();
- System.exit(-1);
- }
- parser = new RelationAttributeParser();
- try {
- saxParser.parse(relAttrFile, parser);
- } catch (SAXException ex) {
- System.err.printf("Error parsing file %s: %s",
- args[0],
- ex.getMessage());
- ex.printStackTrace();
- System.exit(-1);
- } catch (IOException ex) {
- System.err.printf("Error parsing file %s: %s",
- args[0], ex.getMessage());
- ex.printStackTrace();
- System.exit(-1);
- }
-
- System.out.println(
- "Parsed XML file successfully. Creating ACSObjects...");
- for (int i = 0; i < parser.getRelAttrs().size(); i++) {
- System.out.printf("%d of %d...", (i + 1), parser.getRelAttrs().size());
- createACSObject(parser.getRelAttrs().get(i), i);
- }
}
/**
@@ -143,7 +177,7 @@ public class RelationAttributeImporter extends Program {
* @param relAttr
* @param index
*/
- private void createACSObject(final RelAttrBean relAttr, int index) {
+ private void createACSObject(final RelAttrBean relAttr) {
/*System.out.printf("\tattribute = %s\n", relAttr.getAttribute());
System.out.printf("\tkey = %s\n", relAttr.getKey());
@@ -152,6 +186,7 @@ public class RelationAttributeImporter extends Program {
System.out.printf("\tdescription = %s\n", relAttr.getDescription());*/
Transaction transaction = new Transaction() {
+
@Override
public void doRun() {
RelationAttribute attr;