Kleine Änderung beim RelationAttributeImporter: Einzelne RelationAttributes können jetzt auch per Kommandozeile, ohne XML Datei, angelegt werden.
git-svn-id: https://svn.libreccm.org/ccm/trunk@573 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
e994fe7bda
commit
cb6af4338c
|
|
@ -34,7 +34,8 @@ import org.xml.sax.SAXException;
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* A simple import tool for {@link RelationAttribute}s. This tool imports the
|
* 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:
|
||||||
* </p>
|
* </p>
|
||||||
* <pre>
|
* <pre>
|
||||||
* <?xml version="1.0"?>
|
* <?xml version="1.0"?>
|
||||||
|
|
@ -46,6 +47,7 @@ import org.xml.sax.SAXException;
|
||||||
* <name>...</name>
|
* <name>...</name>
|
||||||
* <description>...</description>
|
* <description>...</description>
|
||||||
* </relationAttribute>
|
* </relationAttribute>
|
||||||
|
* ...
|
||||||
* </relationAttributes>
|
* </relationAttributes>
|
||||||
* </pre>
|
* </pre>
|
||||||
* <p>
|
* <p>
|
||||||
|
|
@ -53,10 +55,22 @@ import org.xml.sax.SAXException;
|
||||||
* to import is needed. With tools-ng and ECDC, the line for calling the
|
* to import is needed. With tools-ng and ECDC, the line for calling the
|
||||||
* <code>RelationAttributeImporter</code> would like the following:
|
* <code>RelationAttributeImporter</code> would like the following:
|
||||||
* </p>
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* With a XML file:
|
||||||
|
* </p>
|
||||||
* <pre>
|
* <pre>
|
||||||
* ant -Dccm.classname="com.arsdigita.cms.relationattributeimporter.RelationAttributeImporter" -Dccm.parameters="/path/to/relation/attribute/file.xml" ccm-run
|
* ant -Dccm.classname="com.arsdigita.cms.relationattributeimporter.RelationAttributeImporter" -Dccm.parameters="/path/to/relation/attribute/file.xml" ccm-run
|
||||||
* </pre>
|
* </pre>
|
||||||
* <p>
|
* <p>
|
||||||
|
* With command line parameters:
|
||||||
|
* </p>
|
||||||
|
* <pre>
|
||||||
|
* ant -Dccm.classname="com.arsdigita.cms.relationattributeimporter.RelationAttributeImporter" -Dccm.parameters="attribute key lang name [description]" ccm-run
|
||||||
|
* </pre>
|
||||||
|
* <p>
|
||||||
|
* The description parameter is optional.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
* You have to add the <code>RelationAttributeImporter</code> to add to your
|
* You have to add the <code>RelationAttributeImporter</code> to add to your
|
||||||
* environment, of course.
|
* environment, of course.
|
||||||
* </p>
|
* </p>
|
||||||
|
|
@ -68,11 +82,15 @@ import org.xml.sax.SAXException;
|
||||||
public class RelationAttributeImporter extends Program {
|
public class RelationAttributeImporter extends Program {
|
||||||
|
|
||||||
public RelationAttributeImporter() {
|
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) {
|
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
|
@Override
|
||||||
|
|
@ -84,11 +102,7 @@ public class RelationAttributeImporter extends Program {
|
||||||
SAXParser saxParser = null;
|
SAXParser saxParser = null;
|
||||||
RelationAttributeParser parser;
|
RelationAttributeParser parser;
|
||||||
args = cmdLine.getArgs();
|
args = cmdLine.getArgs();
|
||||||
if (args.length != 1) {
|
if (args.length == 1) {
|
||||||
help(System.err);
|
|
||||||
System.exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.printf("Using file %s.", args[0]);
|
System.out.printf("Using file %s.", args[0]);
|
||||||
relAttrFile = new File(args[0]);
|
relAttrFile = new File(args[0]);
|
||||||
if (!relAttrFile.exists()) {
|
if (!relAttrFile.exists()) {
|
||||||
|
|
@ -104,11 +118,13 @@ public class RelationAttributeImporter extends Program {
|
||||||
try {
|
try {
|
||||||
saxParser = saxFactory.newSAXParser();
|
saxParser = saxFactory.newSAXParser();
|
||||||
} catch (ParserConfigurationException ex) {
|
} catch (ParserConfigurationException ex) {
|
||||||
System.err.printf("Error creating SAXParser: %s", ex.getMessage());
|
System.err.printf("Error creating SAXParser: %s",
|
||||||
|
ex.getMessage());
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
} catch (SAXException ex) {
|
} catch (SAXException ex) {
|
||||||
System.err.printf("Error creating SAXParser: %s", ex.getMessage());
|
System.err.printf("Error creating SAXParser: %s",
|
||||||
|
ex.getMessage());
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
@ -131,8 +147,26 @@ public class RelationAttributeImporter extends Program {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
"Parsed XML file successfully. Creating ACSObjects...");
|
"Parsed XML file successfully. Creating ACSObjects...");
|
||||||
for (int i = 0; i < parser.getRelAttrs().size(); i++) {
|
for (int i = 0; i < parser.getRelAttrs().size(); i++) {
|
||||||
System.out.printf("%d of %d...", (i + 1), parser.getRelAttrs().size());
|
System.out.printf("%d of %d...", (i + 1), parser.getRelAttrs().
|
||||||
createACSObject(parser.getRelAttrs().get(i), i);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,7 +177,7 @@ public class RelationAttributeImporter extends Program {
|
||||||
* @param relAttr
|
* @param relAttr
|
||||||
* @param index
|
* @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("\tattribute = %s\n", relAttr.getAttribute());
|
||||||
System.out.printf("\tkey = %s\n", relAttr.getKey());
|
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());*/
|
System.out.printf("\tdescription = %s\n", relAttr.getDescription());*/
|
||||||
|
|
||||||
Transaction transaction = new Transaction() {
|
Transaction transaction = new Transaction() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doRun() {
|
public void doRun() {
|
||||||
RelationAttribute attr;
|
RelationAttribute attr;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue