1 11 package org.eclipse.pde.internal.core.target; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.core.runtime.Platform; 16 import org.eclipse.pde.internal.core.itarget.IEnvironmentInfo; 17 import org.eclipse.pde.internal.core.itarget.ITargetModel; 18 import org.w3c.dom.Node ; 19 import org.w3c.dom.NodeList ; 20 21 public class EnvironmentInfo extends TargetObject implements IEnvironmentInfo { 22 23 private static final long serialVersionUID = 1L; 24 25 private String fOS; 26 private String fWS; 27 private String fArch; 28 private String fNL; 29 30 public EnvironmentInfo(ITargetModel model) { 31 super(model); 32 } 33 34 public String getOS() { 35 return fOS; 36 } 37 38 public String getWS() { 39 return fWS; 40 } 41 42 public String getArch() { 43 return fArch; 44 } 45 46 public String getNL() { 47 return fNL; 48 } 49 50 public void setOS(String os) { 51 String oldValue = fOS; 52 fOS = os; 53 firePropertyChanged(P_OS, oldValue, fOS); 54 } 55 56 public void setWS(String ws) { 57 String oldValue = fWS; 58 fWS = ws; 59 firePropertyChanged(P_WS, oldValue, fWS); 60 } 61 62 public void setArch(String arch) { 63 String oldValue = fArch; 64 fArch = arch; 65 firePropertyChanged(P_ARCH, oldValue, fArch); 66 } 67 68 public void setNL(String nl) { 69 String oldValue = fNL; 70 fNL = nl; 71 firePropertyChanged(P_NL, oldValue, fNL); 72 } 73 74 public void parse(Node node) { 75 NodeList list = node.getChildNodes(); 76 for (int i = 0; i < list.getLength(); i++) { 77 Node child = list.item(i); 78 if (child.getNodeType() == Node.ELEMENT_NODE) { 79 if (child.getNodeName().equals(P_OS)) { 80 fOS = getText(child); 81 } else if (child.getNodeName().equals(P_WS)) { 82 fWS = getText(child); 83 } else if (child.getNodeName().equals(P_ARCH)) { 84 fArch = getText(child); 85 } else if (child.getNodeName().equals(P_NL)) { 86 fNL = getText(child); 87 } 88 } 89 } 90 } 91 92 private String getText(Node node) { 93 node.normalize(); 94 Node text = node.getFirstChild(); 95 if (text != null && text.getNodeType() == Node.TEXT_NODE) { 96 return text.getNodeValue(); 97 } 98 return ""; } 100 101 public void write(String indent, PrintWriter writer) { 102 if ((fOS == null || fOS.length() == 0) && (fWS == null || fWS.length() == 0) && 104 (fArch == null || fArch.length() == 0) && (fNL == null || fNL.length() == 0)) 105 return; 106 writer.println(); 107 writer.println(indent + "<environment>"); if (fOS != null && fOS.length() > 0) 109 writer.println(indent + " <" + P_OS + ">" + getWritableString(fOS) + "</" + P_OS + ">"); if (fWS != null && fWS.length() > 0) 111 writer.println(indent + " <" + P_WS + ">" + getWritableString(fWS) + "</" + P_WS + ">"); if (fArch != null && fArch.length() > 0) 113 writer.println(indent + " <" + P_ARCH + ">" + getWritableString(fArch) + "</" + P_ARCH + ">"); if (fNL != null && fNL.length() > 0) 115 writer.println(indent + " <" + P_NL + ">" + getWritableString(fNL) + "</" + P_NL + ">"); writer.println(indent + "</environment>"); } 118 119 public String getDisplayOS() { 120 if (fOS == null || fOS.trim().length() == 0) 121 return Platform.getOS(); 122 return fOS.trim(); 123 } 124 125 public String getDisplayWS() { 126 if (fWS == null || fWS.trim().length() == 0) 127 return Platform.getWS(); 128 return fWS.trim(); 129 } 130 131 public String getDisplayArch() { 132 if (fArch == null || fArch.trim().length() == 0) 133 return Platform.getOSArch(); 134 return fArch.trim(); 135 } 136 137 public String getDisplayNL() { 138 if (fNL == null || fNL.trim().length() == 0) 139 return Platform.getNL(); 140 return fNL.trim(); 141 } 142 143 } 144 | Popular Tags |