01: package com.bostechcorp.cbesb.ui.variant.utils;
02:
03: import java.util.regex.Matcher;
04: import java.util.regex.Pattern;
05:
06: import javax.xml.namespace.QName;
07:
08: import com.bostechcorp.cbesb.common.mdl.IContentElement;
09: import com.bostechcorp.cbesb.common.mdl.IContentNode;
10: import com.bostechcorp.cbesb.common.mdl.IElementDefinition;
11: import com.bostechcorp.cbesb.common.mdl.IMDLDocument;
12:
13: public class FileChange {
14:
15: public static IMDLDocument copyChangeDoc(IMDLDocument mdlDoc,
16: String filename, String var_type) {
17: IMDLDocument doc = null;
18: doc = mdlDoc;
19: IElementDefinition[] ed = doc.getAllElementDefinitions();
20: IContentNode[] node = ed[0].getChildren();
21: String old_name = ed[0].getName();
22: ed[0].setName(filename);
23:
24: for (int i = 1; i < ed.length; i++) {
25: if (ed[i].getName().startsWith(old_name)) {
26: ed[i].setName(filename
27: + ed[i].getName().substring(old_name.length(),
28: ed[i].getName().length()));
29: }
30:
31: }
32:
33: for (int i = 0; i < node.length; i++) {
34: IContentElement element = (IContentElement) node[i];
35: if (var_type.equals("x12")) {
36:
37: if (null != element.getRef()) {
38: String ref_loc_part = element.getRef()
39: .getLocalPart();
40: if (ref_loc_part.startsWith(old_name)) {
41: QName qname = new QName(mdlDoc
42: .getTargetNamespace(), filename
43: + ref_loc_part.substring(old_name
44: .length(), ref_loc_part
45: .length()));
46: element.setRef(qname);
47: }
48: } else {
49: String res_ele_def = element
50: .getResolvedElementDef().getName();
51: if (res_ele_def.startsWith(old_name)) {
52:
53: element.getResolvedElementDef().setName(
54: filename
55: + res_ele_def.substring(
56: old_name.length(),
57: res_ele_def.length()));
58: }
59:
60: }
61: } else {
62: element.setElementDefName(filename
63: + element.getElementDefName().substring(
64: old_name.length(),
65: element.getElementDefName().length()));
66:
67: }
68:
69: }
70:
71: return doc;
72: }
73:
74: public static boolean isNum(String str) {
75: Pattern p = Pattern.compile("[0-9]+");
76: Matcher m = p.matcher(str);
77: return m.matches();
78:
79: }
80: }
|