001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.xslt.project;
020:
021: import java.awt.Dialog;
022:
023: import java.io.File;
024: import java.io.FileOutputStream;
025: import java.net.URI;
026: import java.util.ArrayList;
027: import java.util.HashMap;
028: import java.util.HashSet;
029: import java.util.Iterator;
030: import java.util.List;
031: import org.netbeans.modules.xslt.project.wizard.FoldersListSettings;
032: import org.openide.util.NbBundle;
033: import org.openide.DialogDescriptor;
034: import org.openide.DialogDisplayer;
035:
036: import java.net.URISyntaxException;
037: import java.awt.BorderLayout;
038:
039: import javax.swing.JComponent;
040: import javax.xml.parsers.DocumentBuilder;
041: import javax.xml.parsers.DocumentBuilderFactory;
042: import javax.xml.transform.Transformer;
043: import javax.xml.transform.TransformerFactory;
044: import javax.xml.transform.stream.StreamResult;
045: import javax.xml.transform.dom.DOMSource;
046:
047: import java.util.logging.Logger;
048: import java.text.MessageFormat;
049:
050: import org.netbeans.modules.xml.wsdl.model.WSDLModelFactory;
051:
052: import org.openide.filesystems.FileObject;
053: import org.openide.filesystems.FileUtil;
054:
055: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
056: import org.netbeans.modules.xml.xam.ModelSource;
057: import org.netbeans.modules.xml.schema.model.SchemaModel;
058: import org.netbeans.modules.xml.schema.model.SchemaModelFactory;
059: import org.netbeans.modules.xml.xam.Model;
060: import org.netbeans.modules.xml.xam.locator.CatalogModelException;
061: import org.netbeans.modules.xml.xam.locator.CatalogModelFactory;
062: import org.netbeans.api.progress.ProgressHandleFactory;
063: import org.netbeans.api.progress.ProgressHandle;
064: import org.w3c.dom.Attr;
065: import org.w3c.dom.Document;
066: import org.w3c.dom.Element;
067: import org.w3c.dom.NodeList;
068:
069: /**
070: /**
071: * This class is used to populate catalog
072: *
073: * @author Sreenivasan Genipudi
074: * @author Vitaly Bychkov
075: * @version 1.0
076: */
077: public class XsltProjectRetriever {
078: ProgressHandle pg = null;
079: private RetrieverWrapper retrieveWrap = new RetrieverWrapper();
080:
081: /**
082: * Logger instance
083: */
084: private Logger logger = Logger.getLogger(XsltProjectRetriever.class
085: .getName());
086:
087: private volatile String mStatus = null;
088:
089: private RetrieverUpdater mRetUpd = null;
090: Dialog mDialog = null;
091:
092: /**
093: * Construtor - takes in Project Location (File Object) as parameter
094: * and tries to populate the catalog
095: * @param projectDirectory FileObject instance of project directory
096: */
097: public XsltProjectRetriever(FileObject projectDirectory) {
098: retrieveWrap.mProjectDirectoryPath = projectDirectory.getPath();
099: //mProjectDirectoryPath = projectDirectory.getPath();
100: }
101:
102: private void init() {
103: String initMsg = NbBundle.getMessage(
104: XsltProjectRetriever.class, "LBL_Populate_Catalog");
105: pg = ProgressHandleFactory.createHandle(initMsg,
106: new org.openide.util.Cancellable() {
107: public boolean cancel() {
108: try {
109: pg.finish();
110: } catch (Exception ex) {
111:
112: }
113: return true;
114: }
115: });
116: // pg.setInitialDelay(2000);
117: // pg.setDisplayName(initMsg);
118:
119: mRetUpd = new RetrieverUpdater(pg);
120: DialogDescriptor dd = new DialogDescriptor(mRetUpd,
121: initMsg,
122: true, // modal
123: new Object[0], null, DialogDescriptor.DEFAULT_ALIGN,
124: null, null, true);
125: mDialog = DialogDisplayer.getDefault().createDialog(dd);
126: pg.start();
127:
128: }
129:
130: public void execute() {
131: try {
132: init();
133: Thread t = new Thread(retrieveWrap);
134: t.start();
135: mDialog.setVisible(true);
136:
137: } catch (Exception ex) {
138: mRetUpd.setProgressMessage(NbBundle.getMessage(
139: XsltProjectRetriever.class,
140: "LBL_Populate_Catalog_Error"));
141: } finally {
142: dispose();
143: }
144: }
145:
146: void dispose() {
147: try {
148: mDialog.setVisible(false);
149: mDialog.dispose();
150: mDialog = null;
151: } catch (Exception ex) {
152:
153: }
154: try {
155: pg.finish();
156: } catch (Exception ex) {
157:
158: }
159: }
160:
161: class RetrieverWrapper implements Runnable {
162: private File mProjectDirectory = null;
163: private String mProjectDirectoryPath = null;
164: private String mProjectSourcePath = null;
165: private File mRetrieveToDirectory = null;
166: private HashSet mVisitedXMLResources = new HashSet();
167:
168: public void run() {
169: try {
170: String projectDirPath = mProjectDirectoryPath;
171: String sourceDirectoryPath = projectDirPath + "/"
172: + "src";
173: mProjectSourcePath = sourceDirectoryPath.replace('\\',
174: '/');
175: CommandlineXsltProjectXmlCatalogProvider.getInstance()
176: .setSourceDirectory(sourceDirectoryPath);
177:
178: mProjectDirectory = new File(projectDirPath);
179: File sourceDirectory = new File(sourceDirectoryPath);
180: mRetrieveToDirectory = new File(
181: CommandlineXsltProjectXmlCatalogProvider
182: .getInstance().getRetrieverPath());
183: if (!mRetrieveToDirectory.exists()) {
184: mRetrieveToDirectory.mkdirs();
185: }
186: processSourceDir(sourceDirectory);
187: moveCachedDirs();
188: displayStatus(NbBundle.getMessage(
189: XsltProjectRetriever.class,
190: "LBL_Populate_Catalog_Complete"));
191:
192: } catch (Exception ex) {
193: displayStatus(NbBundle.getMessage(
194: XsltProjectRetriever.class,
195: "LBL_Populate_Catalog_Error"));
196: } finally {
197: File localCatalogFile = new File(
198: CommandlineXsltProjectXmlCatalogProvider
199: .getInstance().getProjectWideCatalog());
200: if (localCatalogFile.exists()
201: && localCatalogFile.length() == 0) {
202: localCatalogFile.delete();
203: }
204: dispose();
205: }
206:
207: }
208:
209: /**
210: * Replace the retrieved dirs with long name to simpler ones...
211: *
212: * @throws Exception
213: */
214: private void moveCachedDirs() throws Exception {
215: File catFile = new File(mRetrieveToDirectory.getParent(),
216: "catalog.xml"); // NOI18N
217: if (catFile.exists()) {
218: DocumentBuilderFactory fact = DocumentBuilderFactory
219: .newInstance();
220: DocumentBuilder builder = fact.newDocumentBuilder();
221: Document catlogDoc = builder.parse(catFile);
222: ArrayList uris = new ArrayList();
223: NodeList sas = catlogDoc.getElementsByTagName("system"); // NOI18N
224: HashMap dirMap = new HashMap();
225: if (sas != null) { // find them
226: for (int i = 0; i < sas.getLength(); i++) {
227: Element sys = (Element) sas.item(i);
228: String furi = sys.getAttribute("uri"); // NOI18N
229: if (!furi.startsWith("src/cached")) { // NOI18N
230: uris.add(furi);
231:
232: // map retreived dir to cached dir..
233: File cf = new File(mRetrieveToDirectory
234: .getParentFile(), furi);
235: File pcf = cf.getParentFile();
236: File mpcf = (File) dirMap.get(pcf);
237: if (mpcf == null) { // create a new cached dir for this
238: String cacheDirName = null;
239: int baseCount = FoldersListSettings
240: .getDefault()
241: .getNewProjectCount() + 1;
242: String formater = NbBundle.getMessage(
243: XsltProjectRetriever.class,
244: "LBL_DefaultCacheDirName"); // NOI18N
245: while ((cacheDirName = validFreeCacheDirName(
246: mRetrieveToDirectory, formater,
247: baseCount)) == null) {
248: baseCount++;
249: }
250: mpcf = new File(mRetrieveToDirectory,
251: cacheDirName);
252: mpcf.mkdirs();
253: dirMap.put(pcf, mpcf);
254: }
255:
256: // move the file
257: FileObject dst = FileUtil
258: .toFileObject(FileUtil
259: .normalizeFile(mpcf));
260: FileObject src = FileUtil
261: .toFileObject(FileUtil
262: .normalizeFile(cf));
263: FileUtil.moveFile(src, dst, src.getName());
264:
265: // update catalog.xml uirs... furi -> mpcf
266: Attr atr = sys.getAttributeNode("uri"); // NOI18N
267: atr.setNodeValue("src/" + mpcf.getName()
268: + "/" + cf.getName());
269: // System.out.println("newURI: "+sys.getAttribute("uri"));
270: }
271: }
272:
273: // remove retreived dirs..
274: Iterator it = dirMap.keySet().iterator();
275: while (it.hasNext()) {
276: File key = (File) it.next();
277: FileObject src = FileUtil.toFileObject(FileUtil
278: .normalizeFile(key));
279: FileObject root = FileUtil
280: .toFileObject(FileUtil
281: .normalizeFile(mRetrieveToDirectory));
282: while (src.getParent() != root) {
283: src = src.getParent();
284: }
285: src.delete();
286: }
287:
288: // update catalog.xml
289: DOMSource src = new DOMSource(catlogDoc);
290: FileOutputStream fos = new FileOutputStream(catFile);
291: StreamResult rest = new StreamResult(fos);
292: TransformerFactory transFact = TransformerFactory
293: .newInstance();
294: Transformer transformer = transFact
295: .newTransformer();
296: transformer.transform(src, rest);
297: }
298: }
299: }
300:
301: private String validFreeCacheDirName(final File parentFolder,
302: final String formater, final int index) {
303: String name = MessageFormat.format(formater,
304: new Object[] { new Integer(index) });
305: File file = new File(parentFolder, name);
306: return file.exists() ? null : name;
307: }
308:
309: /**
310: * Process the list of source directories to generate JBI.xml
311: * @param sourceDirs list of source directory
312: */
313: private void processSourceDirs(List<File> sourceDirs) {
314: Iterator<File> it = sourceDirs.iterator();
315: while (it.hasNext()) {
316: File sourceDir = it.next();
317: processSourceDir(sourceDir);
318: }
319:
320: }
321:
322: /**
323: * Proces the source directory to generate JBI.xml
324: * @param sourceDir
325: */
326: private void processSourceDir(File sourceDir) {
327: processFileObject(sourceDir);
328: }
329:
330: /**
331: * Process the file object to generate JBI.xml
332: * @param file BPEL file location
333: */
334: private void processFileObject(File file) {
335: if (file.isDirectory()) {
336: processFolder(file);
337: } else {
338: processFile(file);
339: }
340: }
341:
342: /**
343: * Process the folder to generate JBI.xml
344: * @param fileDir Folder location
345: */
346: private void processFolder(File fileDir) {
347: File[] children = fileDir.listFiles();
348:
349: for (int i = 0; i < children.length; i++) {
350: processFileObject(children[i]);
351: }
352: }
353:
354: /**
355: * Process the file to generate JBI.xml
356: * @param file input file
357: */
358: private void processFile(File file) {
359: String fileName = file.getName();
360: String fileExtension = null;
361: int dotIndex = fileName.lastIndexOf('.');
362: if (dotIndex != -1) {
363: fileExtension = fileName.substring(dotIndex + 1);
364: }
365:
366: // TODO a&m | r
367: // if (fileExtension != null && fileExtension.equalsIgnoreCase("bpel")) {
368: //
369: // BpelModelFactory bpelFactory = (BpelModelFactory)Lookup.getDefault().lookup(BpelModelFactory.class);
370: // FileObject fobj = FileUtil.toFileObject(FileUtil.normalizeFile(file));
371: // ModelSource ms = null;
372: // try {
373: // ms = Utilities.createModelSource(fobj, true);
374: // }catch (Exception ex) {
375: // logger.log(Level.SEVERE,
376: // "Error encountered while creating module source - " +
377: // file.toURI());
378: // throw new RuntimeException("Error encountered while creating module source - " +
379: // file.toURI());
380: // }
381: //
382: // BpelModel bm = bpelFactory.getModel(ms);
383: // org.netbeans.modules.bpel.model.api.Import[] imports = bm.getProcess().getImports();
384: // WSDLModel wsdlModel= null;
385: // SchemaModel schModel = null;
386: //
387: // for (org.netbeans.modules.bpel.model.api.Import imprt:imports) {
388: // wsdlModel = getWsdlModel(imprt);
389: // if (wsdlModel != null) {
390: // processWSDLImport(wsdlModel, imprt);
391: // } else {
392: //
393: // SchemaModel scMdl = getSchemaModel(imprt);
394: // if (scMdl != null) {
395: // processSchemaImport(scMdl, imprt);
396: // }
397: // }
398: //
399: // }
400: //
401: // }
402:
403: }
404:
405: // void processSchemaImport(SchemaModel scm, org.netbeans.modules.bpel.model.api.Import imports ) {
406: // String importLocation = imports.getLocation();
407: // if (importLocation != null) {
408: // String importLocationLowerCase = importLocation;
409: // if (!mVisitedXMLResources.contains(importLocationLowerCase)) {
410: // mVisitedXMLResources.add(importLocationLowerCase);
411: // String resourceName = null;
412: // Document doc = scm.getDocument();
413: // if (doc != null) {
414: // resourceName= doc.getLocalName();
415: // } else {
416: // resourceName = "";
417: // }
418: // URI resourceURI = externalResource(resourceName, importLocationLowerCase);
419: // if (resourceURI != null) {
420: // if (!ApacheResolverHelper.isPresent(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getProjectWideCatalog()).getAbsolutePath(),
421: // resourceURI.toString())) {
422: // try {
423: // FileObject catalogFO = FileUtil.toFileObject(FileUtil.normalizeFile(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getRetrieverPath())));
424: // displayStatus(importLocationLowerCase);
425: //
426: //
427: // Retriever.getDefault().retrieveResource(catalogFO,
428: // FileUtil.normalizeFile(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getProjectWideCatalog())).toURI(),
429: // resourceURI);
430: //
431: // } catch (Exception ex) {
432: // logger.log(Level.SEVERE,
433: // "Error encountered while retreiving file - " +
434: // importLocation);
435: // }
436: // }
437: // } else {
438: // SchemaModel scMdl = getSchemaModel(imports);
439: // if (scMdl != null) {
440: // Collection<org.netbeans.modules.xml.schema.model.Import> subImports = scMdl.getSchema().getImports();
441: // processSchemaImport(scMdl, subImports);
442: // }
443: // }
444: // } else {
445: // System.out.println(" ALREADY DOWNLOADED!!"+importLocationLowerCase);
446: // }
447: // }
448: //
449: // }
450: // void processSchemaImport(SchemaModel scm, Collection<org.netbeans.modules.xml.schema.model.Import> colImports ) {
451: // for (org.netbeans.modules.xml.schema.model.Import imports: colImports) {
452: // String importLocation = imports.getSchemaLocation();
453: // if (importLocation != null) {
454: // String importLocationLowerCase = importLocation;
455: // if (!mVisitedXMLResources.contains(importLocationLowerCase)) {
456: // mVisitedXMLResources.add(importLocationLowerCase);
457: // String resourceName = null;
458: // Document doc = scm.getDocument();
459: // if (doc != null) {
460: // resourceName= doc.getLocalName();
461: // } else {
462: // resourceName = "";
463: // }
464: // URI resourceURI = externalResource(resourceName, importLocationLowerCase);
465: // if (resourceURI != null) {
466: // if (!ApacheResolverHelper.isPresent(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getProjectWideCatalog()).getAbsolutePath(),
467: // resourceURI.toString())) {
468: // try {
469: // /* Retriever.getDefault().retrieveResource(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getRetrieverPath()),
470: // new URI(importLocation));
471: // */
472: // FileObject catalogFO = FileUtil.toFileObject(FileUtil.normalizeFile(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getRetrieverPath())));
473: // displayStatus(importLocationLowerCase);
474: //
475: //
476: // Retriever.getDefault().retrieveResource(catalogFO,
477: // FileUtil.normalizeFile(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getProjectWideCatalog())).toURI(),
478: // resourceURI);
479: //
480: // } catch (Exception ex) {
481: // logger.log(Level.SEVERE,
482: // "Error encountered while retreiving file - " +
483: // importLocation);
484: // //throw new RuntimeException(ex);
485: // }
486: // }
487: // } else {
488: // SchemaModel scMdl = getSchemaModel(imports);
489: // if (scMdl != null) {
490: // /* String targetNameSpace = scMdl.getSchema().getTargetNamespace();
491: // String versionInfo =scMdl.getSchema().getVersion();
492: // if (versionInfo == null) {
493: // versionInfo = "";
494: // }
495: // String xsdId = scMdl.getSchema().getId();
496: // if (xsdId == null) {
497: // xsdId = "";
498: // }
499: // String xsdKey = targetNameSpace+versionInfo+xsdId;
500: // if (!mVisitedXMLResources.contains(xsdKey)) {
501: // mVisitedXMLResources.add(xsdKey);*/
502: // Collection<org.netbeans.modules.xml.schema.model.Import> subImports = scMdl.getSchema().getImports();
503: // processSchemaImport(scMdl, subImports);
504: // //}
505: // }
506: // }
507: // } else {
508: // System.out.println(" ALREADY DOWNLOADED!!"+importLocationLowerCase);
509: // }
510: // }
511: // }
512: //
513: // }
514: //
515: // void processWSDLImport(WSDLModel wsdlModel, org.netbeans.modules.bpel.model.api.Import imports ) {
516: // String importLocation = imports.getLocation();
517: // String importLocationLowerCase = importLocation;
518: // String wsdlKey = importLocationLowerCase;
519: // if (!mVisitedXMLResources.contains(wsdlKey)) {
520: // mVisitedXMLResources.add(wsdlKey);
521: // String resourceName = null;
522: // Document doc = wsdlModel.getDocument();
523: // if (doc != null) {
524: // resourceName= doc.getLocalName();
525: // } else {
526: // resourceName = "";
527: // }
528: // URI resourceURI = externalResource(wsdlModel.getDocument().getLocalName(), importLocationLowerCase);
529: // if (resourceURI != null) {
530: // if (!ApacheResolverHelper.isPresent(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getProjectWideCatalog()).getAbsolutePath(),
531: // resourceURI.toString())) {
532: // try {
533: // /* Retriever.getDefault().retrieveResource(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getRetrieverPath()),
534: // new URI(importLocation));
535: // */
536: // FileObject catalogFO =
537: // FileUtil.toFileObject(FileUtil.normalizeFile(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getRetrieverPath())));
538: // displayStatus(importLocationLowerCase);
539: //
540: // Retriever.getDefault().retrieveResource(catalogFO,
541: // FileUtil.normalizeFile(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getProjectWideCatalog())).toURI(),
542: // resourceURI);
543: //
544: // } catch (Exception ex) {
545: // logger.log(Level.SEVERE,
546: // "Error encountered while retreiving file - " +
547: // importLocation);
548: // //throw new RuntimeException(ex);
549: // }
550: // }
551: // } else {
552: // WSDLModel wm = wsdlModel;
553: //
554: // Collection<org.netbeans.modules.xml.wsdl.model.Import> subImports =
555: // wm.getDefinitions().getImports();
556: // if (subImports != null && subImports.size() > 0) {
557: // processWSDLImport(wm, subImports);
558: // }
559: // Types types = wm.getDefinitions().getTypes();
560: // if (types != null) {
561: // Collection<org.netbeans.modules.xml.schema.model.Schema> schemas =
562: // types.getSchemas();
563: //
564: // for (Schema schema: schemas) {
565: // Collection<org.netbeans.modules.xml.schema.model.Import> colImports1 =
566: // schema.getImports();
567: // processSchemaImport(schema.getModel(), colImports1);
568: // }
569: // }
570: // }
571: // } else {
572: // System.out.println(" ALREADY DOWNLOADED!!"+importLocationLowerCase);
573: // }
574: // }
575: //
576: //
577: // void processWSDLImport(WSDLModel wsdlModel, Collection<org.netbeans.modules.xml.wsdl.model.Import> colImports) {
578: // for (org.netbeans.modules.xml.wsdl.model.Import imports: colImports) {
579: // String importLocation = imports.getLocation();
580: // String importLocationLowerCase = importLocation;
581: // String wsdlKey = importLocationLowerCase;
582: // if (!mVisitedXMLResources.contains(wsdlKey)) {
583: // mVisitedXMLResources.add(wsdlKey);
584: // String resourceName = null;
585: // Document doc = wsdlModel.getDocument();
586: // if (doc != null) {
587: // resourceName= doc.getLocalName();
588: // } else {
589: // resourceName = "";
590: // }
591: // URI resourceURI = externalResource(wsdlModel.getDocument().getLocalName(), importLocationLowerCase);
592: // if (resourceURI != null) {
593: // if (!ApacheResolverHelper.isPresent(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getProjectWideCatalog()).getAbsolutePath(),
594: // resourceURI.toString())) {
595: // try {
596: // /* Retriever.getDefault().retrieveResource(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getRetrieverPath()),
597: // new URI(importLocation));
598: // */
599: // FileObject catalogFO =
600: // FileUtil.toFileObject(FileUtil.normalizeFile(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getRetrieverPath())));
601: // displayStatus(importLocationLowerCase);
602: //
603: // Retriever.getDefault().retrieveResource(catalogFO,
604: // FileUtil.normalizeFile(new File(CommandlineBpelProjectXmlCatalogProvider.getInstance().getProjectWideCatalog())).toURI(),
605: // resourceURI);
606: //
607: // } catch (Exception ex) {
608: // logger.log(Level.SEVERE,
609: // "Error encountered while retreiving file - " +
610: // importLocation);
611: // //throw new RuntimeException(ex);
612: // }
613: // }
614: // } else {
615: // WSDLModel wm = getWsdlModel(imports);
616: // if (wm != null) {
617: // /* String targetNameSpace =
618: // wm.getDefinitions().getTargetNamespace();
619: // String wsdlName = wm.getDefinitions().getName();
620: // if (wsdlName == null) {
621: // wsdlName = "";
622: // }
623: // String wsdlKey = targetNameSpace + wsdlName;
624: // if (!mVisitedXMLResources.contains(wsdlKey)) {
625: // mVisitedXMLResources.add(wsdlKey);*/
626: //
627: //
628: // Collection<org.netbeans.modules.xml.wsdl.model.Import> subImports =
629: // wm.getDefinitions().getImports();
630: // if (subImports != null && subImports.size() > 0) {
631: // processWSDLImport(wm, subImports);
632: // }
633: // Types types = wm.getDefinitions().getTypes();
634: // if (types != null) {
635: // Collection<org.netbeans.modules.xml.schema.model.Schema> schemas =
636: // types.getSchemas();
637: //
638: // for (Schema schema: schemas) {
639: // /* String targetNameSpace1 =
640: // schema.getTargetNamespace();
641: // String versionInfo1 = schema.getVersion();
642: // if (versionInfo1 == null) {
643: // versionInfo1 = "";
644: // }
645: // String xsdId1 = schema.getId();
646: // if (xsdId1 == null) {
647: // xsdId1 = "";
648: // }
649: // String xsdKey1 =
650: // targetNameSpace1 + versionInfo1 + xsdId1;
651: // if (!mVisitedXMLResources.contains(xsdKey1)) {
652: // mVisitedXMLResources.add(xsdKey1);
653: // */
654: // Collection<org.netbeans.modules.xml.schema.model.Import> colImports1 =
655: // schema.getImports();
656: // processSchemaImport(schema.getModel(), colImports1);
657: // // }
658: // }
659: // }
660: // }
661: // }
662: // } else {
663: // System.out.println(" ALREADY DOWNLOADED!!"+importLocationLowerCase);
664: // }
665: //
666: // }
667: //
668: // }
669:
670: public void displayStatus(String stats) {
671: //pg.progress(stats);
672: mRetUpd.setProgressMessage(NbBundle.getMessage(
673: XsltProjectRetriever.class, "LBL_Retrieving",
674: new Object[] { stats }));
675: }
676:
677: // public WSDLModel getWsdlModel( Import imp ) {
678: // if (!Import.WSDL_IMPORT_TYPE.equals(imp.getImportType())) {
679: // return null;
680: // }
681: // String location = imp.getLocation();
682: // WSDLModel wsdlModel;
683: // if (location == null) {
684: // return null;
685: // }
686: // try {
687: // URI uri = new URI(location);
688: // ModelSource source = CatalogModelFactory.getDefault()
689: // .getCatalogModel(imp.getModel().getModelSource())
690: // .getModelSource(uri, imp.getModel().getModelSource());
691: // wsdlModel = WSDLModelFactory.getDefault().getModel(source);
692: // }
693: // catch (URISyntaxException e) {
694: // wsdlModel = null;
695: // }
696: // catch (CatalogModelException e) {
697: // wsdlModel = null;
698: // }
699: // if (wsdlModel != null && wsdlModel.getState() == Model.State.NOT_WELL_FORMED) {
700: // return null;
701: // }
702: // return wsdlModel;
703: // }
704: //
705: // public SchemaModel getSchemaModel( Import imp ) {
706: // if ( !Import.SCHEMA_IMPORT_TYPE.equals( imp.getImportType())){
707: // return null;
708: // }
709: // String location = imp.getLocation();
710: // SchemaModel schemaModel ;
711: // if (location == null) {
712: // return null;
713: // }
714: // try {
715: // URI uri = new URI( location );
716: // ModelSource modelSource = CatalogModelFactory.getDefault().
717: // getCatalogModel(imp.getModel().getModelSource())
718: // .getModelSource(uri, imp.getModel().getModelSource());
719: //
720: // schemaModel = SchemaModelFactory.getDefault().
721: // getModel( modelSource );
722: // }
723: // catch (URISyntaxException e) {
724: // schemaModel = null;
725: // }
726: // catch (CatalogModelException e) {
727: // schemaModel = null;
728: // }
729: // if (schemaModel != null && schemaModel.getState() == Model.State.NOT_WELL_FORMED) {
730: // schemaModel = null;
731: // }
732: // return schemaModel;
733: // }
734:
735: public SchemaModel getSchemaModel(
736: org.netbeans.modules.xml.schema.model.Import imp) {
737: String location = imp.getSchemaLocation();
738: SchemaModel schemaModel;
739: if (location == null) {
740: return null;
741: }
742: try {
743: URI uri = new URI(location);
744: ModelSource modelSource = CatalogModelFactory
745: .getDefault().getCatalogModel(
746: imp.getModel().getModelSource())
747: .getModelSource(uri,
748: imp.getModel().getModelSource());
749:
750: schemaModel = SchemaModelFactory.getDefault().getModel(
751: modelSource);
752: } catch (URISyntaxException e) {
753: schemaModel = null;
754: } catch (CatalogModelException e) {
755: schemaModel = null;
756: }
757: if (schemaModel != null
758: && schemaModel.getState() == Model.State.NOT_WELL_FORMED) {
759: schemaModel = null;
760: }
761: return schemaModel;
762: }
763:
764: public WSDLModel getWsdlModel(
765: org.netbeans.modules.xml.wsdl.model.Import imp) {
766: String location = imp.getLocation();
767: WSDLModel wsdlModel;
768: if (location == null) {
769: return null;
770: }
771: try {
772: URI uri = new URI(location);
773: ModelSource source = CatalogModelFactory.getDefault()
774: .getCatalogModel(
775: imp.getModel().getModelSource())
776: .getModelSource(uri,
777: imp.getModel().getModelSource());
778: wsdlModel = WSDLModelFactory.getDefault().getModel(
779: source);
780: } catch (URISyntaxException e) {
781: wsdlModel = null;
782: } catch (CatalogModelException e) {
783: wsdlModel = null;
784: }
785: if (wsdlModel != null
786: && wsdlModel.getState() == Model.State.NOT_WELL_FORMED) {
787: return null;
788: }
789: return wsdlModel;
790: }
791:
792: URI externalResource(String resourceName, String location) {
793: try {
794: if (location.startsWith("http:")
795: || location.startsWith("https:")) {
796: return new URI(location);
797: }
798: File resourceFile = null;
799: File normalizedLocation = null;
800: if (location.startsWith("file:")) {
801: URI fileURI = new URI(location);
802: resourceFile = new File(fileURI);
803: normalizedLocation = FileUtil
804: .normalizeFile(resourceFile);
805: if (normalizedLocation.getAbsolutePath().replace(
806: '\\', '/').indexOf(mProjectSourcePath) != -1) {
807: return null;
808: }
809: if (resourceFile.exists()) {
810: return normalizedLocation.toURI();
811: }
812: }
813: if (resourceFile == null) {
814: resourceFile = new File(location);
815: }
816: if (!resourceFile.exists()) {
817: resourceFile = new File(this .mProjectSourcePath,
818: location);
819: }
820: normalizedLocation = FileUtil
821: .normalizeFile(resourceFile);
822: if (normalizedLocation.exists()) {
823: if (normalizedLocation.getAbsolutePath().replace(
824: '\\', '/').indexOf(mProjectSourcePath) != -1) {
825: return null;
826: } else {
827: return normalizedLocation.toURI();
828: }
829: }
830:
831: } catch (Exception ex) {
832: logger.severe("Problem in the imported location "
833: + location + " of " + resourceName);
834: }
835: return null;
836: }
837:
838: }
839:
840: /**
841: *
842: */
843: class RetrieverUpdater extends javax.swing.JPanel {
844:
845: private JComponent progress;
846:
847: /**
848: * Creates new form ModuleUpdaterProgress
849: */
850: public RetrieverUpdater(ProgressHandle handle) {
851: progress = ProgressHandleFactory
852: .createProgressComponent(handle);
853: initComponents();
854: //#67914: On macosx, the background of JTextField is white even if non-editable:
855: message.setBackground(javax.swing.UIManager
856: .getColor("Panel.background")); // NOI18N
857: }
858:
859: /** This method is called from within the constructor to
860: * initialize the form.
861: * WARNING: Do NOT modify this code. The content of this method is
862: * always regenerated by the Form Editor.
863: */
864: private void initComponents() {
865: java.awt.GridBagConstraints gridBagConstraints;
866:
867: innerPanel = new javax.swing.JPanel();
868: message = new javax.swing.JTextField();
869:
870: setLayout(new java.awt.GridBagLayout());
871:
872: setBorder(javax.swing.BorderFactory.createEmptyBorder(11,
873: 11, 11, 11));
874: innerPanel.setLayout(new java.awt.BorderLayout());
875:
876: innerPanel.add(progress, BorderLayout.CENTER);
877:
878: gridBagConstraints = new java.awt.GridBagConstraints();
879: gridBagConstraints.gridx = 0;
880: gridBagConstraints.gridy = 1;
881: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
882: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
883: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
884: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
885: gridBagConstraints.weightx = 1.0;
886: add(innerPanel, gridBagConstraints);
887:
888: message.setColumns(40);
889: message.setEditable(false);
890: message
891: .setFont(javax.swing.UIManager
892: .getFont("Label.font"));
893: message.setBorder(null);
894: message.setDisabledTextColor(javax.swing.UIManager
895: .getColor("Label.foreground"));
896: gridBagConstraints = new java.awt.GridBagConstraints();
897: gridBagConstraints.gridx = 0;
898: gridBagConstraints.gridy = 0;
899: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
900: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
901: gridBagConstraints.weightx = 1.0;
902: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
903: add(message, gridBagConstraints);
904:
905: }
906:
907: // Variables declaration - do not modify
908: public javax.swing.JPanel innerPanel;
909: public javax.swing.JTextField message;
910:
911: // End of variables declaration
912:
913: public void setProgressMessage(String name) {
914: message.setText(name);
915: }
916: }
917: }
|