Examples of XPDLHandler


Examples of org.enhydra.jawe.base.xpdlhandler.XPDLHandler

        }
    }

    public void addExternalPackage() {
        Package mainPkg = getMainPackage();
        XPDLHandler xpdlhmain = JaWEManager.getInstance().getXPDLHandler();
        getSelectionManager().setSelection(mainPkg.getExternalPackages(), false);

        String filename = "";
        String message = settings.getLanguageDependentString("DialogChooseFile");
        filename = JaWEXMLUtil.dialog(getJaWEFrame(), message, 0, 0, null);
        XPDLHandler xpdlh = null;
        if (filename != null && filename.length() > 0) {
            try {
                xpdlh = JaWEManager.getInstance().createXPDLHandler(xpdlhmain.getXPDLRepositoryHandler());
                Package pkg = xpdlh.openPackage(filename, true);
                // do not allow insertion if package has the same Id as the main one,
                // or as some of its external packages
                Set mainPkgExtPkgIds = new HashSet(mainPkg.getExternalPackageIds());
                boolean canInsert = true;
                if (mainPkgExtPkgIds.contains(pkg.getId())) {
                    canInsert = false;
                }
                if (canInsert) {
                    canInsert = checkInsertion(xpdlhmain, xpdlh, mainPkg.getId());
                }
                if (canInsert) {
                    List l = XMLUtil.getAllExternalPackageIds(xpdlhmain,
                            mainPkg,
                            new HashSet());
                    if (!l.contains(pkg.getId()) && xpdlhmain.getPackageById(pkg.getId()) != null) {
                        canInsert = false;
                    }
                }
                if (canInsert) {
                    Set pkgIdsToInsert = new HashSet(xpdlh.getAllPackageIds());
                    Set otherEPIds = new HashSet(mainPkg.getExternalPackageIds());
                    Set allOtherEPIds = new HashSet(otherEPIds);
                    List l = XMLUtil.getAllExternalPackageIds(xpdlhmain,
                            mainPkg,
                            new HashSet());
                    List ids = new ArrayList(xpdlhmain.getAllPackageIds());
                    ids.removeAll(l);
                    allOtherEPIds.addAll(ids);
                    Iterator it = otherEPIds.iterator();
                    while (it.hasNext()) {
                        String pkgId = (String) it.next();
                        Package p = xpdlhmain.getPackageById(pkgId);
                        allOtherEPIds.addAll(XMLUtil.getAllExternalPackageIds(xpdlhmain,
                                p,
                                new HashSet()));
                    }
                    pkgIdsToInsert.removeAll(allOtherEPIds);

                    Set pkgsToInsert = new HashSet();
                    it = pkgIdsToInsert.iterator();
                    while (it.hasNext()) {
                        String pkgId = (String) it.next();
                        Package tAdd = xpdlh.getPackageById(pkgId);
                        pkgsToInsert.add(tAdd);
                    }

                    xpdlhmain.synchronizePackages(xpdlh);

                    Package realPkg = xpdlhmain.getPackageById(pkg.getId());
                    ExternalPackage ep = null;
                    // insert ExternalPackage
                    ExternalPackages eps = mainPkg.getExternalPackages();
                    File f = new File(xpdlhmain.getAbsoluteFilePath(mainPkg));
                    String parentF = f.getParent();
                    Path newPath = new Path(parentF);
                    String eppath = xpdlhmain.getAbsoluteFilePath(realPkg);
                    String relativePath = Path.getRelativePath(new Path(eppath), newPath);
                    ep = JaWEManager.getInstance().getXPDLObjectFactory().createXPDLObject(eps, "", false);
                    ep.setHref(relativePath);
                    JaWEEAHandler.setExternalPackageEA(ep, realPkg.getId());
                    mainPkg.addExternalPackageMapping(relativePath, realPkg.getId());
                    eps.add(ep);

                    it = pkgsToInsert.iterator();
                    while (it.hasNext()) {
                        Package p = (Package) it.next();
                        boolean changed = adjustXPDL(p);
                        XPDLListenerAndObservable xpdl;
                        xpdl = createNewXPDLListenerObservable(p, false, false);
                        p.setReadOnly(true);
                        xpdl.setModified(changed);
                    }

                    setChanged();
                    notifyObservers(createInfo(mainPkg,
                            new ArrayList(pkgsToInsert),
                            XMLElementChangeInfo.INSERTED));

                    if (ep != null) {
                        getSelectionManager().setSelection(ep, true);
                    }

                } else {
                    getJaWEFrame().message(settings.getLanguageDependentString("InformationExternalPackageCannotBeInserted"),
                            JOptionPane.INFORMATION_MESSAGE);
                    xpdlh.closeAllPackages();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                getJaWEFrame().message(settings.getLanguageDependentString("InformationExternalPackageCannotBeInserted"),
                        JOptionPane.INFORMATION_MESSAGE);
                if (xpdlh != null) {
                    xpdlh.closeAllPackages();
                }
            }
        }
    }
View Full Code Here

Examples of org.enhydra.jawe.base.xpdlhandler.XPDLHandler

        }
    }

    public void removeExternalPackage() {
        Package mainPkg = getMainPackage();
        XPDLHandler xpdlh = JaWEManager.getInstance().getXPDLHandler();
        Package toRemove = (Package) getSelectionManager().getSelectedElement();

        Set pkgIdsToRemove = new HashSet();
        pkgIdsToRemove.add(toRemove.getId());
        pkgIdsToRemove.addAll(XMLUtil.getAllExternalPackageIds(xpdlh,
                toRemove,
                new HashSet()));

        Set otherEPIds = new HashSet(mainPkg.getExternalPackageIds());
        otherEPIds.remove(toRemove.getId());

        Set allOtherEPIds = new HashSet(otherEPIds);
        Iterator it = otherEPIds.iterator();
        while (it.hasNext()) {
            String pkgId = (String) it.next();
            Package p = xpdlh.getPackageById(pkgId);
            allOtherEPIds.addAll(XMLUtil.getAllExternalPackageIds(xpdlh, p, new HashSet()));
        }

        pkgIdsToRemove.removeAll(allOtherEPIds);

        Set pkgsToRemove = new HashSet();
        it = pkgIdsToRemove.iterator();
        while (it.hasNext()) {
            String pkgId = (String) it.next();
            Package tRem = xpdlh.getPackageById(pkgId);
            if (tRem != mainPkg && !tRem.isTransient()) {
                pkgsToRemove.add(tRem);
            }
        }

        ExternalPackages eps = mainPkg.getExternalPackages();
        ExternalPackage ep = mainPkg.getExternalPackage(toRemove.getId());

        if (pkgsToRemove.size() > 0) {
            boolean warningMessage = false;
            it = pkgsToRemove.iterator();
            while (it.hasNext()) {
                Package tRem = (Package) it.next();
                List refs = JaWEManager.getInstance().getXPDLUtils().getReferences(mainPkg,
                        tRem);
                if (refs.size() > 0) {
                    warningMessage = true;
                    break;
                }
            }
            if (warningMessage) {
                int yn = JOptionPane.showConfirmDialog(getJaWEFrame(),
                        settings.getLanguageDependentString("MessageReferencedDoYouReallyWantToDeleteSelectedItem"),
                        settings.getLanguageDependentString("DeletingKey"),
                        JOptionPane.YES_NO_OPTION);
                if (yn != JOptionPane.YES_OPTION) {
                    return;
                }
            }
        }

        try {
            if (ep != null) {
                mainPkg.removeExternalPackageMapping(ep.getHref());
            }
            if (pkgsToRemove.size() > 0) {
                it = pkgsToRemove.iterator();
                while (it.hasNext()) {
                    Package pkg = (Package) it.next();
                    XPDLListenerAndObservable xpdllo = getXPDLListenerObservable(pkg);
                    xpdllo.unregisterFromXPDL();
                    xpdlListenerObservables.remove(xpdllo);
                    xpdlh.closePackageVersion(pkg.getId(), pkg.getInternalVersion());
                }
                setChanged();
                notifyObservers(createInfo(mainPkg,
                        new ArrayList(pkgsToRemove),
                        XMLElementChangeInfo.REMOVED));
View Full Code Here

Examples of org.enhydra.jawe.base.xpdlhandler.XPDLHandler

            }
        }
    }

    public boolean addTransientPackage(String filename) {
        XPDLHandler xpdlhmain = JaWEManager.getInstance().getXPDLHandler();
        XPDLHandler xpdlh = null;
        if (filename != null && filename.length() > 0) {
            try {
                xpdlh = JaWEManager.getInstance().createXPDLHandler(xpdlhmain.getXPDLRepositoryHandler());
                Package pkg = xpdlh.openPackage(filename, false);
                // do not allow insertion if package has the same Id as the main one,
                // or as some of its external packages
                Set allpkgids = new HashSet(xpdlhmain.getAllPackageIds());
                boolean canInsert = true;
                if (allpkgids.contains(pkg.getId())) {
                    canInsert = false;
                }
                if (canInsert) {
                    Package mainPkg = getMainPackage();
                    if (mainPkg != null) {
                        canInsert = checkInsertion(xpdlhmain, xpdlh, mainPkg.getId());
                    }
                }
                if (canInsert) {
                    xpdlhmain.synchronizePackages(xpdlh);

                    Package realPkg = xpdlhmain.getPackageById(pkg.getId());
                    adjustXPDL(realPkg);
                    XPDLListenerAndObservable xpdl = createNewXPDLListenerObservable(realPkg,
                            false,
                            false);
                    realPkg.setReadOnly(true);
                    xpdl.setModified(false);

                    List pkgsToInsert = new ArrayList();
                    pkgsToInsert.add(realPkg);
                    setChanged();
                    notifyObservers(createInfo(realPkg,
                            new ArrayList(pkgsToInsert),
                            XMLElementChangeInfo.INSERTED));

                    return true;
                }
                xpdlh.closeAllPackages();
                return false;
            } catch (Exception ex) {
                ex.printStackTrace();
                if (xpdlh != null) {
                    xpdlh.closeAllPackages();
                }
            }
        }
        return false;
    }
View Full Code Here

Examples of org.enhydra.jawe.base.xpdlhandler.XPDLHandler

        }
        return false;
    }

    public void removeTransientPackage() {
        XPDLHandler xpdlh = JaWEManager.getInstance().getXPDLHandler();
        Package toRemove = XMLUtil.getPackage(getSelectionManager().getSelectedElement());

        try {
            XPDLListenerAndObservable xpdllo = getXPDLListenerObservable(toRemove);
            xpdllo.unregisterFromXPDL();
            xpdlListenerObservables.remove(xpdllo);
            xpdlh.closePackageVersion(toRemove.getId(), toRemove.getInternalVersion());
            setChanged();
            List pkgsToRemove = new ArrayList();
            pkgsToRemove.add(toRemove);
            notifyObservers(createInfo(toRemove, pkgsToRemove, XMLElementChangeInfo.REMOVED));
            getSelectionManager().setSelection(getMainPackage(), true);
View Full Code Here

Examples of org.enhydra.jawe.base.xpdlhandler.XPDLHandler

        return canInsert;
    }

    public void closePackage(String xpdlId, boolean closeTransient) {
        clearAll();
        XPDLHandler xpdlhandler = JaWEManager.getInstance().getXPDLHandler();
        Package mainPackage = getMainPackage();
        if (xpdlId == null && mainPackage != null) {
            xpdlId = mainPackage.getId();
        }
        JaWEManager.getInstance().getLoggingManager().info("JaWEController -> closing package " + xpdlId);
        if (mainPackage != null && mainPackage.getId().equals(xpdlId)) {
            String filePath = JaWEManager.getInstance().getXPDLHandler().getAbsoluteFilePath(mainPackage);
            List allPackages = new ArrayList(xpdlhandler.getAllPackages());
            List notToClose = new ArrayList();
            for (int i = 0; i < allPackages.size(); i++) {
                Package pkg = (Package) allPackages.get(i);
                if (!pkg.isTransient() || closeTransient) {
                    xpdlhandler.closePackageVersion(pkg.getId(), pkg.getInternalVersion());
                } else {
                    notToClose.add(pkg);
                }
            }
            allPackages.removeAll(notToClose);
View Full Code Here

Examples of org.enhydra.jawe.base.xpdlhandler.XPDLHandler

        return false;
    }

    public void savePackage(String xpdlId, String filename) {
        XPDLHandler xpdlhandler = JaWEManager.getInstance().getXPDLHandler();
        Package pkg = xpdlhandler.getPackageById(xpdlId);
        String oldFilename = xpdlhandler.getAbsoluteFilePath(pkg);
        try {

            // if SaveAs was performed and the document was previously saved,
            // change ExternalPackage's relative paths
            boolean isNewFile = !filename.equals(oldFilename);
            if (oldFilename != null && isNewFile) {
                boolean crossRefs = JaWEManager.getInstance().getXPDLUtils().doesCrossreferenceExist(pkg);
                int r = JOptionPane.YES_OPTION;
                if (crossRefs) {
                    r = JOptionPane.showConfirmDialog(getJaWEFrame(),
                            settings.getLanguageDependentString("MessageCrossReferenceExistDoYouWantToProceed"),
                            getJaWEFrame().getAppTitle(),
                            JOptionPane.YES_NO_OPTION);
                }
                if (r == JOptionPane.YES_OPTION) {
                    updateExternalPackagesRelativePaths(pkg, filename);
                } else {
                    return;
                }
            }

            Document document = null;

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder dbuilder = dbf.newDocumentBuilder();
            document = dbuilder.newDocument();

            // retrieve the file writter
            RandomAccessFile raf = xpdlhandler.getRaf(pkg);

            // output stream will either be the FileOutputStream in the
            // case of save as, or the ByteArrayOutputStream if we are
            // saving an existing file
            OutputStream os;
            if (isNewFile) {
                // try to open random access file as rw, if it fails
                // the saving shouldn't occur
                try {
                    File f = new File(filename);
                    RandomAccessFile r = new RandomAccessFile(f, "rw");
                    FileLock flck = r.getChannel().tryLock();
                    flck.release();
                    r.close(); // Harald Meister
                    // this exception happens when using jdk1.4 under Linux
                    // if it happens, just catch it and proceed with saving
                    // because Linux with jdk1.4.0 doesn't support locking
                } catch (IOException ioe) {
                    // ioe.printStackTrace();
                    // this happens when the locking fails, and null is returned,
                    // and after that release method is called on the null;
                    // This means that the file we want to save the given
                    // package as, is already locked, so we do not allow saving
                } catch (NullPointerException npe) {
                    throw new Exception();
                }
                // if we are at this point, this means either the locking
                // succeeded, or we use jdk1.4 under Linux that does not
                // support locking
                os = new FileOutputStream(filename);
            } else {
                os = new ByteArrayOutputStream();
            }

            // Here we get all document elements set
            JaWEManager.getInstance().getXPDLHandler().getXPDLRepositoryHandler().toXML(document, pkg);

            // Use a Transformer for output
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();
            transformer.setOutputProperty("indent", "yes");
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
            transformer.setOutputProperty("encoding", settings.getEncoding());
            DOMSource source = new DOMSource(document);
            StreamResult result = new StreamResult(os);
            transformer.transform(source, result);

            if (!isNewFile && raf != null && os instanceof ByteArrayOutputStream) {
                if (raf != null) {
                    // must go to the beginning - otherwise, it will not
                    // truncate the file correctly in some Java-OS combination
                    raf.seek(0);
                    raf.getChannel().truncate(0);
                    raf.write(((ByteArrayOutputStream) os).toByteArray());
                }
            }

            os.close();

            XPDLListenerAndObservable xpdl = getXPDLListenerObservable(pkg);
            if (xpdl != null) {
                xpdl.setModified(false);
            }

            if (isNewFile) {
                xpdlhandler.registerPackageFilename(filename, pkg);
            }
            try {
                System.setProperty("user.dir", xpdlhandler.getParentDirectory(pkg));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } catch (NonWritableChannelException nwcex) {
            nwcex.printStackTrace();
View Full Code Here

Examples of org.enhydra.jawe.base.xpdlhandler.XPDLHandler

        }
        return null;
    }

    protected void changePackageId(Package pkg, String oldId, String newId) {
        XPDLHandler xpdlhandler = JaWEManager.getInstance().getXPDLHandler();
        xpdlhandler.changePackageId(pkg, oldId, newId);
    }
View Full Code Here

Examples of org.enhydra.jawe.base.xpdlhandler.XPDLHandler

        XPDLHandler xpdlhandler = JaWEManager.getInstance().getXPDLHandler();
        xpdlhandler.changePackageId(pkg, oldId, newId);
    }

    protected void updateExternalPackagesRelativePaths(Package pkg, String newFilename) {
        XPDLHandler xpdlhandler = JaWEManager.getInstance().getXPDLHandler();
        File f = new File(newFilename);
        String parentF = f.getParent();
        Path newPath = new Path(parentF);

        Iterator eps = pkg.getExternalPackages().toElements().iterator();
        while (eps.hasNext()) {
            ExternalPackage ep = (ExternalPackage) eps.next();
            String oldRelativePath = ep.getHref();
            try {
                Package extP = xpdlhandler.getExternalPackageByRelativeFilePath(oldRelativePath,
                        pkg);
                String oldFullPath = xpdlhandler.getAbsoluteFilePath(extP);
                String relativePath = Path.getRelativePath(new Path(oldFullPath), newPath);
                ep.setHref(XMLUtil.replaceBackslashesWithSlashes(relativePath));
            } catch (Exception ex) {
                System.err.println("Failed to update old external package's relative path " + oldRelativePath + " for main package " + pkg.getId() + " with a new filename " + newFilename);
            }
View Full Code Here

Examples of org.enhydra.jawe.base.xpdlhandler.XPDLHandler

        }
        title += " (" + ccn + " " + getSettings().getLanguageDependentString("ConfigurationKey") + ")";

        if (getMainPackage() != null) {
            title += " - ";
            XPDLHandler xpdlh = JaWEManager.getInstance().getXPDLHandler();
            String s = xpdlh.getAbsoluteFilePath(getMainPackage());
            if (s == null || s.equals("")) {
                title += getSettings().getLanguageDependentString("NotSavedKey");
            } else {
                title += s;
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.