1 19 20 package org.netbeans.modules.xml.xam.ui; 21 22 import java.io.File ; 23 import java.net.URI ; 24 import java.net.URISyntaxException ; 25 import org.openide.filesystems.FileUtil; 26 27 31 public enum NamespaceLocation { 32 OTA("http://www.opentravel.org/OTA/2003/05", "resources/J1_TravelItinerary.xsd"), 33 ORGCHART("http://www.xmlspy.com/schemas/orgchart", "resources/OrgChart.xsd"), 34 IPO("http://www.altova.com/IPO", "resources/ipo.xsd"), 35 CUTPASTE("resources/CutPasteTest_before.xsd"), 36 EXPREPORT("resources/ExpReport.xsd"), 37 KEYREF("namespace1", "resources/KeyRef.xsd"), 38 TEST_INCLUDE("http://www.example.com/testInclude", "resources/testInclude.xsd"), 39 SOMEFILE("http://www.example.com/testInclude", "resources/somefile.xsd"), 40 TEST_LENGTH("resources/testLength.xsd"), 41 TEST_LIST("resources/testList.xsd"), 42 TEST_BAD("resources/testBad.xsd"), 43 LOANAPP("resources/loanApplication.xsd"), 44 ADDRESS("resources/address.xsd"), 45 REORDER_TEST("resources/ReorderTest.xsd"), 46 SYNCTEST_PO("resources/PurchaseOrderSyncTest.xsd"), 47 SYNCTEST_GLOBAL("resources/SyncTestGlobal_before.xsd"), 48 SYNCTEST_NONGLOBAL("resources/SyncTestNonGlobal_before.xsd"), 49 PO("http://www.example.com/PO1", "resources/PurchaseOrder.xsd"); 50 51 private String namespace; 52 private String resourcePath; 53 private String location; 54 55 56 NamespaceLocation(String location) { 57 this("http://www.example.com/" +nameFromLocation(location), location); 58 } 59 60 NamespaceLocation(String namespace, String resourcePath) { 61 this.namespace = namespace; 62 this.resourcePath = resourcePath; 63 this.location = resourcePath.substring(resourcePath.lastIndexOf("resources/")+10); 64 } 65 66 private static String nameFromLocation(String loc) { 67 File f = new File (loc); 68 String name = f.getName(); 69 return name.substring(0, name.length()-4); 70 } 71 72 public String getNamespace() { return namespace; } 73 public String getResourcePath() { return resourcePath; } 74 public String getLocationString() { return location; } 75 public URI getNamespaceURI() throws URISyntaxException { return new URI (getNamespace()); } 76 public static File schemaTestDir = null; 77 public static File getSchemaTestTempDir() throws Exception { 78 if (schemaTestDir == null) { 79 schemaTestDir = Util.getTempDir("schematest"); 80 } 81 return schemaTestDir; 82 } 83 public File getResourceFile() throws Exception { 84 return new File (getSchemaTestTempDir(), Util.getFileName(getResourcePath())); 85 } 86 public void refreshResourceFile() throws Exception { 87 Util.copyResource(getResourcePath(), FileUtil.toFileObject(getSchemaTestTempDir().getCanonicalFile())); 88 } 89 public URI getResourceURI() throws Exception { 90 return getResourceFile().toURI(); 91 } 92 public URI getLocationURI() throws Exception { return new URI (location); } 93 94 public static NamespaceLocation valueFromResourcePath(String resourcePath) { 95 for (NamespaceLocation nl : values()) { 96 if (nl.getResourcePath().equals(resourcePath)) { 97 return nl; 98 } 99 } 100 return null; 101 } 102 } 103 | Popular Tags |