protected final static Logger LOG = Logger
.getLogger(ProjectSettingsServiceImpl.class);
+ /**
+ * Type attribute name.
+ */
+ private final static String TYPE_ATTR = "type";
+
// Non persistent configuration information
/**
* Repository settings.
/**
* Configuration document validation cycles.
*/
- private transient List<ProjectSettingsValidationCycle> _concycles;
+ private transient final List<ProjectSettingsValidationCycle> _concycles = new ArrayList<ProjectSettingsValidationCycle>();
/**
* Document type mappings to file formats which should be imported into SALOME during check-out.
*/
- private transient Map<String, List<String>> _mapimport;
+ private transient final Map<String, List<String>> _mapimport = new HashMap<String, List<String>>();
// Temporary attributes initialized from the configuration file for populating the database with object types
/**
*/
private DocumentTypeService _documentTypeService;
+ /**
+ * Default document types structured by step.formats.
+ */
+ private transient final Map<String, DocumentType> _defdoctype = new LinkedHashMap<String, DocumentType>();
+
+ /**
+ * File naming strategy enumeration.
+ */
public enum FileNaming {
- title, encoded, asis
+ /**
+ * Name by document title.
+ */
+ title,
+ /**
+ * Generate encoded name.
+ */
+ encoded,
+ /**
+ * Keep original file name.
+ */
+ asis
}
/**
format));
}
+ /**
+ * Get default document type for the given file format on the given study step.
+ *
+ * @param step
+ * the study step
+ * @param format
+ * the file format (extension)
+ * @return document type
+ */
+ public DocumentType getDefaultDocumentType(final Step step,
+ final String format) {
+ String[] table = format.split("\\x2E");
+ return _defdoctype
+ .get(step.getNumber() + "." + table[table.length - 1]); // May be null
+ }
+
+ /**
+ * Get the list of default formats for the given study step.
+ *
+ * @param step
+ * the study step
+ * @return list of formats (file extensions)
+ */
+ public List<String> getDefaultFormats(final Step step) {
+ Integer stepNumber = step.getNumber();
+ List<String> result = new ArrayList<String>();
+
+ for (String i : _defdoctype.keySet()) {
+ String[] key = i.split("\\x2E");
+ // PDF is not an authoring format
+ if (stepNumber.equals(Integer.valueOf(key[0]))
+ && (!key[1].equals("pdf"))) {
+ result.add(key[1]); // Formats are unique
+ }
+ }
+ return result;
+ }
+
/**
* Initialize the database: create all necessary default staff defined in the configuration file.
*/
resultype);
}
}
- // Validations tag
- _concycles = loadValidationCycles(children, resultype);
- _mapimport = loadFormatMappings(children);
+ // Validations tag
+ loadValidationCycles(children, resultype);
+ // Load steps result document types mapped to file formats
+ loadFormatMappings(children);
+ // Load default mapping of file formats to document types for each step
+ loadDefaultDocTypes(children);
if (!getDatabase().getCheckedDB().isInitialized()) {
// Load object type definitions
child = nlist.item(i);
if ("article".equals(child.getNodeName())) {
natr = child.getAttributes();
- String type = natr.getNamedItem("type").getNodeValue();
+ String type = natr.getNamedItem(TYPE_ATTR)
+ .getNodeValue();
String uses = null;
child = natr.getNamedItem("uses");
if (child != null) {
*
* @param children
* XML nodes
- * @return map of document type names to lists of file formats
*/
- private Map<String, List<String>> loadFormatMappings(
- final Map<String, Node> children) {
- Map<String, List<String>> res = new HashMap<String, List<String>>();
+ private void loadFormatMappings(final Map<String, Node> children) {
+ _mapimport.clear();
Element maps = (Element) children.get("mappings");
Element doc, imp;
String type, format;
docs = maps.getElementsByTagName("document");
for (int i = 0; i < docs.getLength(); i++) {
doc = (Element) docs.item(i);
- type = doc.getAttribute("type");
+ type = doc.getAttribute(TYPE_ATTR);
if (!type.isEmpty()) {
// Read file formats for the document type
imports = doc.getElementsByTagName("import");
}
}
if (!formats.isEmpty()) {
- res.put(type, formats);
+ _mapimport.put(type, formats);
}
}
}
}
- return res;
+ }
+
+ /**
+ * Load default document types from XML configuration.
+ *
+ * @param children
+ * XML nodes
+ */
+ private void loadDefaultDocTypes(final Map<String, Node> children) {
+ _defdoctype.clear();
+ Node child = children.get("default-doctypes");
+ NodeList nlist = child.getChildNodes();
+
+ List<DocumentType> listype = getDocumentTypeService().selectAllTypes();
+ Map<String, DocumentType> maptype = new HashMap<String, DocumentType>();
+ for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
+ DocumentType type = i.next();
+ maptype.put(type.getName(), type);
+ }
+ for (int i = 0; i < nlist.getLength(); i++) {
+ child = nlist.item(i);
+ if (!child.getNodeName().equals("step")) {
+ continue;
+ }
+
+ String nstep = child.getAttributes().getNamedItem("number")
+ .getNodeValue();
+ NodeList map = child.getChildNodes();
+ for (int j = 0; j < map.getLength(); j++) {
+ child = map.item(j);
+ if (!child.getNodeName().equals("mapping")) {
+ continue;
+ }
+ NamedNodeMap natr = child.getAttributes();
+ String dext = natr.getNamedItem("extension").getNodeValue();
+ String type = natr.getNamedItem(TYPE_ATTR).getNodeValue();
+ _defdoctype.put(nstep + "." + dext, maptype.get(type));
+ }
+ }
}
/**
* XML nodes
* @param resultype
* list of result types
- * @return return list of validation cycles
*/
- private List<ProjectSettingsValidationCycle> loadValidationCycles(
- final Map<String, Node> children, final List<String> resultype) {
+ private void loadValidationCycles(final Map<String, Node> children,
+ final List<String> resultype) {
+ _concycles.clear();
Node child = children.get("validations");
- List<ProjectSettingsValidationCycle> cycles = new ArrayList<ProjectSettingsValidationCycle>();
Map<String, Node> datag = XDOM.getNamedChildNodes(child);
NamedNodeMap natr;
actor[j] = Actor.valueOf(child.getNodeValue()); // Validation step is required
}
}
- cycles.add(new ProjectSettingsValidationCycle(name, actor));
+ _concycles.add(new ProjectSettingsValidationCycle(name, actor));
}
}
- cycles.add(new ProjectSettingsValidationCycle()); // Adds the built-in validation cycle
- return cycles;
+ _concycles.add(new ProjectSettingsValidationCycle()); // Adds the built-in validation cycle
}
/**
for (int i = 0; i < nlist.getLength(); i++) {
child = nlist.item(i);
if (child.getNodeName().equals("article")) {
- articles.add(child.getAttributes().getNamedItem("type")
+ articles.add(child.getAttributes().getNamedItem(TYPE_ATTR)
.getNodeValue());
}
}