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