001: package com.calipso.reportgenerator.userinterface;
002:
003: import org.apache.commons.vfs.FileSystemManager;
004: import org.apache.commons.vfs.FileObject;
005: import org.apache.commons.vfs.FileSystemException;
006: import org.exolab.castor.xml.Unmarshaller;
007: import com.calipso.reportgenerator.services.FileSystemResolver;
008: import com.calipso.reportgenerator.common.ReportManagerLogger;
009: import com.calipso.reportgenerator.common.LanguageTraslator;
010: import com.calipso.reportgenerator.common.InfoException;
011: import com.calipso.reportgenerator.common.ReportGeneratorConfiguration;
012: import com.calipso.reportgenerator.reportdefinitions.ReportDefinition;
013: import com.calipso.reportgenerator.reportdefinitions.ReportSourceDefinition;
014:
015: import java.io.FileReader;
016: import java.io.IOException;
017:
018: /**
019: * User: alorenzo
020: * Date: 05-ene-2006
021: * Time: 15:09:11
022: *
023: */
024: public class DefinitionEditor {
025:
026: private static String nameFileReportDefinitionSchema = "ReportDefinition.xsd";
027: private static String nameFileReportSourceDefinitionSchema = "ReportSourceDefinition.xsd";
028: private static String pathSchema;
029: private static String reportDefinitionID;
030: private static String reportSourceDefinitionID;
031: private static ReportGeneratorConfiguration reportGeneratorConfiguration;
032:
033: public static void reportDefinitionEditor(String reportDefID,
034: ReportGeneratorConfiguration reportGenerator)
035: throws InfoException {
036: try {
037: reportDefinitionID = reportDefID;
038: reportGeneratorConfiguration = reportGenerator;
039: pathSchema = reportGenerator.getSourceReportSchemasPath();
040: String pathReportDefinition = pathReportDefinitionResolver();
041: String pathReportDefinitionSchema = pathReportDefinitionSchemaResolver();
042: if (!(pathReportDefinition.equalsIgnoreCase(""))) {
043: runPollo(pathReportDefinition,
044: pathReportDefinitionSchema, reportGenerator
045: .getPolloPath());
046: }
047: } catch (Exception e) {
048: throw new InfoException(LanguageTraslator.traslate("541"),
049: e);
050: }
051: }
052:
053: private static String pathReportDefinitionResolver()
054: throws InfoException {
055: String pathReportDefinition = "";
056: try {
057: FileSystemManager fileSystemManager = FileSystemResolver
058: .getFileSystemManager(reportGeneratorConfiguration);
059: FileObject fileObject = fileSystemManager
060: .resolveFile(reportGeneratorConfiguration
061: .getSourceReportDefinitionsPath());
062: String fileName;
063: for (int i = 0; i < fileObject.getChildren().length; i++) {
064: fileName = fileObject.getChildren()[i].getName()
065: .getBaseName();
066: if (!fileName.endsWith(".xml")) {
067: continue;
068: }
069: String reportDefinitionIDViewer;
070: reportDefinitionIDViewer = ((ReportDefinition) Unmarshaller
071: .unmarshal(
072: ReportDefinition.class,
073: new FileReader(
074: reportGeneratorConfiguration
075: .getSourceReportDefinitionsPath()
076: + "/" + fileName)))
077: .getId();
078: if (reportDefinitionID
079: .equalsIgnoreCase(reportDefinitionIDViewer)) {
080: pathReportDefinition = reportGeneratorConfiguration
081: .getSourceReportDefinitionsPath()
082: + "/" + fileName;
083: }
084: }
085: } catch (Exception e) {
086: throw new InfoException(LanguageTraslator.traslate("542"),
087: e);
088: }
089: return pathReportDefinition;
090: }
091:
092: private static String pathReportDefinitionSchemaResolver()
093: throws InfoException {
094: String pathReportDefinitionSchema = "";
095: try {
096: pathReportDefinitionSchema = pathSchema + "/"
097: + nameFileReportDefinitionSchema;
098: new FileReader(pathReportDefinitionSchema);
099: } catch (Exception e) {
100: pathReportDefinitionSchema = "";
101: }
102: return pathReportDefinitionSchema;
103: }
104:
105: public static void reportSourceDefinitionEditor(String reportDefID,
106: ReportGeneratorConfiguration reportGenerator)
107: throws InfoException {
108: try {
109: reportDefinitionID = reportDefID;
110: reportGeneratorConfiguration = reportGenerator;
111: pathSchema = reportGenerator.getSourceReportSchemasPath();
112: String pathReportDefinition = pathReportDefinitionResolver();
113: if (!(pathReportDefinition.equalsIgnoreCase(""))) {
114: reportSourceDefinitionID = ((ReportDefinition) Unmarshaller
115: .unmarshal(ReportDefinition.class,
116: new FileReader(pathReportDefinition)))
117: .getReportSource();
118: String pathReportSourceDefinition = pathReportSourceDefinitionResolver();
119: String pathReportSourceDefinitionSchema = pathReportSourceDefinitionSchemaResolver();
120: if (!(pathReportSourceDefinition.equalsIgnoreCase(""))) {
121: runPollo(pathReportSourceDefinition,
122: pathReportSourceDefinitionSchema,
123: reportGenerator.getPolloPath());
124: }
125: }
126: } catch (Exception e) {
127: throw new InfoException(LanguageTraslator.traslate("543"),
128: e);
129: }
130: }
131:
132: private static void runPollo(String pathReportSourceDefinition,
133: String pathReportSourceDefinitionSchema, String polloPath)
134: throws IOException {
135: Runtime.getRuntime().exec(
136: "java -jar " + polloPath + " "
137: + pathReportSourceDefinition + " "
138: + pathReportSourceDefinitionSchema);
139: }
140:
141: private static String pathReportSourceDefinitionResolver()
142: throws InfoException {
143: String pathReportSourceDefinition = "";
144: try {
145: FileSystemManager fileSystemManager = FileSystemResolver
146: .getFileSystemManager(reportGeneratorConfiguration);
147: FileObject fileObject = fileSystemManager
148: .resolveFile(reportGeneratorConfiguration
149: .getSourceReportSourceDefinitionsPath());
150: String fileName;
151: for (int i = 0; i < fileObject.getChildren().length; i++) {
152: fileName = fileObject.getChildren()[i].getName()
153: .getBaseName();
154: if (!fileName.endsWith(".xml")) {
155: continue;
156: }
157: String reportSourceDefinitionIDViewer;
158: reportSourceDefinitionIDViewer = ((ReportSourceDefinition) Unmarshaller
159: .unmarshal(
160: ReportSourceDefinition.class,
161: new FileReader(
162: reportGeneratorConfiguration
163: .getSourceReportSourceDefinitionsPath()
164: + "/" + fileName)))
165: .getId();
166: if (reportSourceDefinitionID
167: .equalsIgnoreCase(reportSourceDefinitionIDViewer)) {
168: pathReportSourceDefinition = reportGeneratorConfiguration
169: .getSourceReportSourceDefinitionsPath()
170: + "/" + fileName;
171: }
172: }
173: } catch (Exception e) {
174: throw new InfoException(LanguageTraslator.traslate("544"),
175: e);
176: }
177: return pathReportSourceDefinition;
178: }
179:
180: private static String pathReportSourceDefinitionSchemaResolver()
181: throws InfoException {
182: String pathReportSourceDefinitionSchema = "";
183: try {
184: pathReportSourceDefinitionSchema = pathSchema + "/"
185: + nameFileReportSourceDefinitionSchema;
186: new FileReader(pathReportSourceDefinitionSchema);
187: } catch (Exception e) {
188: pathReportSourceDefinitionSchema = "";
189: }
190: return pathReportSourceDefinitionSchema;
191: }
192: }
|