Example usage for java.io File toURL

List of usage examples for java.io File toURL

Introduction

In this page you can find the example usage for java.io File toURL.

Prototype

@Deprecated
public URL toURL() throws MalformedURLException 

Source Link

Document

Converts this abstract pathname into a file: URL.

Usage

From source file:dalma.container.ClassLoaderImpl.java

/**
 * Returns the URL of a given resource in the given file which may
 * either be a directory or a zip file.//www  . j  av  a2  s.  c o m
 *
 * @param file The file (directory or jar) in which to search for
 *             the resource. Must not be <code>null</code>.
 * @param resourceName The name of the resource for which a stream
 *                     is required. Must not be <code>null</code>.
 *
 * @return a stream to the required resource or <code>null</code> if the
 *         resource cannot be found in the given file object.
 */
protected URL getResourceURL(File file, String resourceName) {
    try {
        if (!file.exists()) {
            return null;
        }

        if (file.isDirectory()) {
            File resource = new File(file, resourceName);

            if (resource.exists()) {
                try {
                    return resource.toURL();
                } catch (MalformedURLException ex) {
                    return null;
                }
            }
        } else {
            ZipFile zipFile = zipFiles.get(file);
            if (zipFile == null) {
                zipFile = new ZipFile(file);
                zipFiles.put(file, zipFile);
            }

            ZipEntry entry = zipFile.getEntry(resourceName);
            if (entry != null) {
                try {
                    return new URL("jar:" + file.toURL() + "!/" + entry);
                } catch (MalformedURLException ex) {
                    return null;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

From source file:org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.java

/**
 * DOC Administrator Comment method "createLauncherFile".
 * /* w w w  .  ja  v a  2  s .c  o m*/
 * @param process
 * @param list
 * @param cmdPrimary
 * @param cmdSecondary
 * @param tmpFold
 */
private void createLauncherFile(ProcessItem process, List<URL> list, String cmd, String fileName,
        String tmpFold) {
    PrintWriter pw = null;
    try {
        String cmdPrimary = cmd;
        // add for bug TDI-24935, add a string on comPrimary's start position.
        if (cmdPrimary != null && UNIX_LAUNCHER.equals(fileName)) {
            StringBuffer strBuffer = new StringBuffer(cmdPrimary);
            strBuffer.insert(0, "#!/bin/sh\n");
            cmdPrimary = strBuffer.toString();
        }
        File file = new File(tmpFold, process.getProperty().getLabel() + "_" + fileName); //$NON-NLS-1$
        file.createNewFile();
        pw = new PrintWriter(new FileOutputStream(file));
        pw.print(cmdPrimary);
        pw.flush();
        list.add(file.toURL());
        pw.close();
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        try {
            if (pw != null) {
                pw.close();
            }
        } catch (Exception e) {
            // do nothing here
        }
    }
}

From source file:org.deegree.portal.context.WebMapContextFactory.java

/**
 * creates an instance of a class encapsulating the deegree specific extensions of the general section of a web map
 * context document//from  w ww  .ja v  a2s  .  c  o  m
 * 
 * @param element
 *            <Extension>
 * @param xml
 * 
 * @return instance of <tt>GeneralExtension</tt>
 * 
 * @throws XMLParsingException
 * @throws SAXException
 * @throws IOException
 */
private static GeneralExtension createGeneralExtension(Element element, XMLFragment xml)
        throws XMLParsingException, IOException, SAXException {

    GeneralExtension ge = null;

    if (element != null) {

        // retunrs the current mode of a client using a WMC
        String mode = XMLTools.getStringValue("Mode", CommonNamespaces.DGCNTXTNS, element, "ZOOMIN");

        // <AuthentificationSettings>
        Element elem = XMLTools.getChildElement("AuthentificationSettings", CommonNamespaces.DGCNTXTNS,
                element);
        AuthentificationSettings authSettings = null;
        if (elem != null) {
            authSettings = createAuthentificationSettings(elem);
        }
        // <IOSetiings>
        elem = XMLTools.getChildElement("IOSettings", CommonNamespaces.DGCNTXTNS, element);
        IOSettings ioSettings = null;
        if (elem != null) {
            ioSettings = createIOSettings(elem, xml);
        }
        // <Frontend>
        elem = XMLTools.getChildElement("Frontend", CommonNamespaces.DGCNTXTNS, element);
        Frontend frontend = null;
        if (elem != null) {
            frontend = createFrontend(elem, xml);
        }
        // <MapParameter>
        elem = XMLTools.getRequiredChildElement("MapParameter", CommonNamespaces.DGCNTXTNS, element);
        MapParameter mapParameter = createMapParameter(elem);

        // <LayerTree> old version
        elem = XMLTools.getChildElement("LayerTree", CommonNamespaces.DGCNTXTNS, element);

        Node layerTreeRoot = null;
        if (elem != null) {
            Element nodeElem = XMLTools.getRequiredChildElement("Node", CommonNamespaces.DGCNTXTNS, elem);
            layerTreeRoot = createNode(nodeElem, null);
        } else {
            try {
                layerTreeRoot = new Node(0, null, "root", false, false);
                Node[] nodes = new Node[] { new Node(1, layerTreeRoot, "deegree", false, false) };
                layerTreeRoot.setNodes(nodes);
            } catch (ContextException e) {
                throw new XMLParsingException("couldn't create layertree node", e);
            }
        }

        elem = XMLTools.getChildElement("MapModel", CommonNamespaces.DGCNTXTNS, element);
        MapModel mapModel = null;
        if (elem != null) {
            MapModelDocument doc = new MapModelDocument(elem);
            mapModel = doc.parseMapModel();
        }

        String tmp = XMLTools.getStringValue("XSLT", CommonNamespaces.DGCNTXTNS, element, "context2HTML.xsl");
        URL xslt = xml.resolve(tmp);
        File file = new File(xslt.getFile());
        if (!file.exists()) {
            // address xslt script from WEB-INF/conf/igeoportal
            file = new File(
                    file.getParentFile().getParentFile().getParent() + File.separatorChar + file.getName());
            xslt = file.toURL();
        }

        ge = new GeneralExtension(ioSettings, frontend, mapParameter, authSettings, mode, layerTreeRoot,
                mapModel, xslt);
    }

    return ge;
}

From source file:org.apache.axis2.deployment.util.Utils.java

public static URL[] getURLsForAllJars(URL url, File tmpDir) {
    FileInputStream fin = null;/*w  w w. ja  va  2  s .  c  om*/
    InputStream in = null;
    ZipInputStream zin = null;
    try {
        ArrayList array = new ArrayList();
        in = url.openStream();
        String fileName = url.getFile();
        int index = fileName.lastIndexOf('/');
        if (index != -1) {
            fileName = fileName.substring(index + 1);
        }
        final File f = createTempFile(fileName, in, tmpDir);

        fin = (FileInputStream) org.apache.axis2.java.security.AccessController
                .doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws FileNotFoundException {
                        return new FileInputStream(f);
                    }
                });
        array.add(f.toURL());
        zin = new ZipInputStream(fin);

        ZipEntry entry;
        String entryName;
        while ((entry = zin.getNextEntry()) != null) {
            entryName = entry.getName();
            /**
             * id the entry name start with /lib and end with .jar then
             * those entry name will be added to the arraylist
             */
            if ((entryName != null) && entryName.toLowerCase().startsWith("lib/")
                    && entryName.toLowerCase().endsWith(".jar")) {
                String suffix = entryName.substring(4);
                File f2 = createTempFile(suffix, zin, tmpDir);
                array.add(f2.toURL());
            }
        }
        return (URL[]) array.toArray(new URL[array.size()]);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (fin != null) {
            try {
                fin.close();
            } catch (IOException e) {
                //
            }
        }
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                //
            }
        }
        if (zin != null) {
            try {
                zin.close();
            } catch (IOException e) {
                //
            }
        }
    }
}

From source file:edu.harvard.i2b2.eclipse.LoginView.java

/**
 * This is a callback that will allow us
 * to create the viewer and initialize it.
 *//*from   ww  w . j  av  a 2 s .c  o  m*/
@Override
public void createPartControl(final Composite parent) {
    log.info(Messages.getString("LoginView.PluginVersion")); //$NON-NLS-1$

    parent.getShell();
    userInfoBean = UserInfoBean.getInstance();
    if (userInfoBean == null) {
        log.debug("user info bean is null"); //$NON-NLS-1$
        return;
    }

    // local variable to get system fonts and colors
    final Display display = parent.getDisplay();

    /* TODO disabled screensaver */

    user = userInfoBean.getUserName();
    //password = userInfoBean.getOrigPassword();
    project = Application.project;
    new Thread() {
        public void run() {
            while (true) {
                try {
                    Thread.sleep(1000);
                } catch (Throwable th) {
                }
                if (display.isDisposed())
                    return;
                display.asyncExec(new Runnable() {
                    public void run() {
                        checkSessionExpired();
                        try {
                            checkScreenSaver(parent.getShell(), Application.getLastUsed()); //display.getActiveShell());
                        } catch (Exception e) {
                            return;
                        }
                    }
                });
            }
        }
    }.start();

    final Font headerFont = new Font(display, "Tahoma", 12, SWT.BOLD); //$NON-NLS-1$
    final Font normalFont = new Font(display, "Tahoma", 12, SWT.NORMAL); //$NON-NLS-1$
    final Font buttonFont = new Font(display, "Tahoma", 9, SWT.NORMAL); //$NON-NLS-1$

    String environment = userInfoBean.getEnvironment();
    if (UserInfoBean.selectedProject().getWiki() != null
            && !UserInfoBean.selectedProject().getWiki().equals("")) //$NON-NLS-1$
        helpURL = UserInfoBean.selectedProject().getWiki();
    //if (userInfoBean.getHelpURL()!=null && !userInfoBean.getHelpURL().equals(""))
    //   helpURL=userInfoBean.getHelpURL();
    // set banner color
    // if environment not specified defaults to development (dark gray)
    APP_CURRENT = environment.toUpperCase();
    if (APP_CURRENT.equals(APP_PROD)) {
        backColor = display.getSystemColor(SWT.COLOR_WHITE);
    } else if (APP_CURRENT.equals(APP_TEST)) {
        backColor = display.getSystemColor(SWT.COLOR_GRAY);
    } else {
        // default to development
        backColor = display.getSystemColor(SWT.COLOR_DARK_GRAY);
    }

    log.info("Currently running in: " + APP_CURRENT); //$NON-NLS-1$
    final Color foreColor = display.getSystemColor(SWT.COLOR_BLACK);
    warningColor = display.getSystemColor(SWT.COLOR_YELLOW);

    goColor = display.getSystemColor(SWT.COLOR_GREEN);
    badColor = display.getSystemColor(SWT.COLOR_RED);

    // create top composite
    top = new Composite(parent, SWT.NONE);

    FormLayout topCompositeLayout = new FormLayout();
    top.setLayout(topCompositeLayout);

    // BannerC composite
    banner = new Composite(top, SWT.NONE);

    FormData bannerData = new FormData();
    bannerData.left = new FormAttachment(0);
    bannerData.right = new FormAttachment(100);
    banner.setLayoutData(bannerData);

    // The Banner itself is configured and layout is set
    FormLayout bannerLayout = new FormLayout();
    bannerLayout.marginWidth = 2;
    if (OS.startsWith("windows")) //$NON-NLS-1$
        bannerLayout.marginHeight = 8;
    else
        bannerLayout.marginHeight = 18;
    bannerLayout.spacing = 5;
    banner.setLayout(bannerLayout);

    banner.setBackground(backColor);
    banner.setForeground(foreColor);

    PlatformUI.getWorkbench().getHelpSystem().setHelp(banner, LOGIN_VIEW_CONTEXT_ID);

    // add banner components and then configure layout
    // the label on the left is added
    titleLabel = new CLabel(banner, SWT.NO_FOCUS);
    titleLabel.setBackground(backColor);
    msTitle = System.getProperty("applicationName") + Messages.getString("LoginView.StatusTitle") //$NON-NLS-1$//$NON-NLS-2$
            + UserInfoBean.selectedProject().getName();
    titleLabel.setText(msTitle);
    titleLabel.setFont(headerFont);
    titleLabel.setForeground(foreColor);
    titleLabel.setImage(new Image(display, LoginView.class.getResourceAsStream("big-hive.gif"))); //$NON-NLS-1$

    // the general application area toolbar is added
    titleToolBar = new ToolBar(banner, SWT.FLAT);
    titleToolBar.setBackground(backColor);
    titleToolBar.setFont(headerFont);

    menu = new Menu(banner.getShell(), SWT.POP_UP);

    // Authorization label is made
    authorizationLabel = new Label(banner, SWT.NO_FOCUS);
    authorizationLabel.setBackground(backColor);
    authorizationLabel.setText(userInfoBean.getUserFullName());
    authorizationLabel.setAlignment(SWT.RIGHT);
    authorizationLabel.setFont(normalFont);
    authorizationLabel.setForeground(foreColor);
    ArrayList<String> roles = (ArrayList<String>) UserInfoBean.selectedProject().getRole();

    String rolesStr = ""; //$NON-NLS-1$
    if (roles != null) {
        for (String param : roles)
            rolesStr += param + "\n"; //$NON-NLS-1$
        if (rolesStr.length() > 1)
            rolesStr = rolesStr.substring(0, rolesStr.length() - 1);
    }
    authorizationLabel.setToolTipText(rolesStr);

    // the staus indicator is shown
    statusLabel = new Label(banner, SWT.NO_FOCUS);
    statusLabel.setBackground(backColor);
    statusLabel.setText(Messages.getString("LoginView.StatusStatus")); //$NON-NLS-1$
    statusLabel.setAlignment(SWT.RIGHT);
    statusLabel.setFont(normalFont);
    statusLabel.setForeground(foreColor);

    statusOvalLabel = new Label(banner, SWT.NO_FOCUS);
    statusOvalLabel.setBackground(backColor);

    statusOvalLabel.setSize(20, 20);
    statusOvalLabel.setForeground(foreColor);
    statusOvalLabel.redraw();

    statusOvalLabel.addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event arg0) {
            statusOvalLabel.setSize(20, 20);
            statusOvalLabel.redraw();
        }
    });

    // add selection listener so that clicking on status oval label shows error log
    // dialog
    statusOvalLabel.addListener(SWT.MouseDown, new Listener() {

        public void handleEvent(Event arg0) {
            //log.info(getNow() + "Status Listener Clicked");
            Display display = statusOvalLabel.getDisplay();
            final Shell shell = statusOvalLabel.getShell();
            // run asyncExec so that other pending ui events finished first
            display.asyncExec(new Runnable() {

                public void run() {
                    File file = new File(logFileName);
                    URL url = null;
                    // Convert the file object to a URL with an absolute path
                    try {
                        url = file.toURL();
                    } catch (MalformedURLException e) {
                        log.error(e.getMessage());
                    }
                    final URL myurl = url;
                    new HelpBrowser().run(myurl.toString(), shell);
                }
            });

        }
    });

    // add status label paint listener so that it changes color
    statusLabelPaintListener = new StatusLabelPaintListener();
    statusOvalLabel.addPaintListener(statusLabelPaintListener);
    statusLabelPaintListener.setOvalColor(goColor);

    getCellStatus(statusLabelPaintListener, statusOvalLabel);
    //if (cellStatus == null)
    //   {
    //   statusLabelPaintListener.setOvalColor(goColor);
    //}
    //else
    //   {
    //   statusOvalLabel.setToolTipText(Messages.getString("LoginView.TooltipCellUnavailable") + cellStatus); //$NON-NLS-1$
    //   statusLabelPaintListener.setOvalColor(warningColor);
    //   }

    statusOvalLabel.setSize(20, 20);
    statusOvalLabel.redraw();

    // Help button is made
    final Button rightButton = new Button(banner, SWT.PUSH | SWT.LEFT);
    rightButton.setFont(buttonFont);
    rightButton.setText(Messages.getString("LoginView.StatusWiki")); //$NON-NLS-1$
    if (helpURL.equals("")) { //$NON-NLS-1$
        rightButton.setEnabled(false);
    }
    rightButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            final Button myButton = (Button) event.widget;
            Display display = myButton.getDisplay();
            final Shell myShell = myButton.getShell();
            display.asyncExec(new Runnable() {

                public void run() {
                    new HelpBrowser().run(helpURL, myShell);
                }
            });
        }
    });

    final Button passwordButton = new Button(banner, SWT.PUSH | SWT.LEFT);
    passwordButton.setFont(buttonFont);
    passwordButton.setText("Password");
    passwordButton.setToolTipText("Display Set Password Dialog");
    passwordButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            final Button myButton = (Button) event.widget;
            Display display = myButton.getDisplay();
            //final Shell myShell=myButton.getShell();
            display.asyncExec(new Runnable() {
                public void run() {
                    java.awt.EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            SetPasswordJDialog dialog = new SetPasswordJDialog(new javax.swing.JFrame(), true);
                            dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                                @Override
                                public void windowClosing(java.awt.event.WindowEvent e) {
                                    //System.exit(0);
                                }
                            });
                            dialog.setSize(304, 237);
                            dialog.setLocation(400, 200);
                            dialog.setVisible(true);
                        }
                    });
                }
            });
        }
    });

    // attach titlelabel to left and align vertically with tool bar
    FormData titleLabelFormData = new FormData();

    titleLabelFormData.top = new FormAttachment(titleToolBar, 0, SWT.CENTER);
    titleLabelFormData.left = new FormAttachment(0, 10);
    titleLabel.setLayoutData(titleLabelFormData);

    // attach left of tool bar to title label, attach top to banner
    // attach right to authorization label so that it will resize and remain
    // visible when tool bar text changes
    FormData titleToolBarFormData = new FormData();
    titleToolBarFormData.left = new FormAttachment(titleLabel);
    titleToolBarFormData.top = new FormAttachment(0);
    titleToolBarFormData.right = new FormAttachment(authorizationLabel, 0, 0);

    titleToolBar.setLayoutData(titleToolBarFormData);

    // attach authorization label on right to status label and center
    // vertically

    FormData authorizationLabelFormData = new FormData();
    authorizationLabelFormData.right = new FormAttachment(passwordButton, -10);
    authorizationLabelFormData.top = new FormAttachment(passwordButton, 0, SWT.CENTER);
    authorizationLabel.setLayoutData(authorizationLabelFormData);

    FormData passwordButtonFormData = new FormData();
    passwordButtonFormData.right = new FormAttachment(statusLabel, -10);
    passwordButtonFormData.top = new FormAttachment(statusLabel, 0, SWT.CENTER);
    passwordButton.setLayoutData(passwordButtonFormData);

    FormData statusLabelFormData = new FormData();
    // statusLabelFormData.right = new FormAttachment(rightButton,0);
    statusLabelFormData.right = new FormAttachment(statusOvalLabel, 0);
    statusLabelFormData.top = new FormAttachment(statusOvalLabel, 0, SWT.CENTER);
    statusLabel.setLayoutData(statusLabelFormData);

    // attach status label on right to loginbutton and center vertically

    FormData statusOvalLabelFormData = new FormData();
    //add offset 
    statusOvalLabelFormData.right = new FormAttachment(rightButton, -25);
    statusOvalLabelFormData.top = new FormAttachment(rightButton, 0, SWT.CENTER);
    statusOvalLabel.setLayoutData(statusOvalLabelFormData);

    // attach right button to right of banner and center vertically on
    // toolbar
    FormData rightButtonFormData = new FormData();
    rightButtonFormData.right = new FormAttachment(100, -10);
    rightButtonFormData.top = new FormAttachment(titleToolBar, 0, SWT.CENTER);
    rightButton.setLayoutData(rightButtonFormData);

    //property action
    IAction propertyAction = new Action("Property") { //$NON-NLS-1$
        @Override
        public void run() {
            log.info("[Login view] PM response: " + UserInfoBean.pmResponse()); //$NON-NLS-1$
            JFrame frame = new DisplayXmlMessageDialog(UserInfoBean.pmResponse());
            frame.setTitle(Messages.getString("LoginView.PMXMLResponse")); //$NON-NLS-1$
            frame.setVisible(true);
        }
    };

    getViewSite().getActionBars().setGlobalActionHandler("properties", propertyAction); //$NON-NLS-1$
}

From source file:org.apache.axis2.deployment.util.Utils.java

public static DeploymentClassLoader createClassLoader(File serviceFile, boolean isChildFirstClassLoading)
        throws MalformedURLException {
    ClassLoader contextClassLoader = (ClassLoader) org.apache.axis2.java.security.AccessController
            .doPrivileged(new PrivilegedAction() {
                public Object run() {
                    return Thread.currentThread().getContextClassLoader();
                }//from  ww  w  . j  a  v  a2 s . c o m
            });
    return createDeploymentClassLoader(new URL[] { serviceFile.toURL() }, contextClassLoader, new ArrayList(),
            isChildFirstClassLoading);
}

From source file:edu.harvard.i2b2.navigator.CRCNavigator.java

/**
 * @return new thread to show broswer with logger html file
 *///from   w ww.  j a  v  a  2 s.  c  o m
public Thread showLoggerBrowser(Shell shell) {
    // final Button theButton = button;
    final Shell myShell = shell;
    File file = new File(logFileName);
    URL url = null;
    // Convert the file object to a URL with an absolute path
    try {
        url = file.toURL();
    } catch (MalformedURLException e) {
        log.info(e.getMessage());
    }

    final URL myurl = url;
    return new Thread() {
        public void run() {
            new HelpBrowser().run(myurl.toString(), myShell);
        }
    };
}

From source file:org.pentaho.platform.repository.solution.filebased.FileBasedSolutionRepository.java

protected String getLocaleString(final String key, String baseName, final ISolutionFile baseFile) {
    File searchDir = ((FileSolutionFile) baseFile.retrieveParent()).getFile();
    try {//from  w  w  w  .j  a  v  a2  s.  c  o  m
        boolean searching = true;
        while (searching) {
            // look to see if this exists
            URLClassLoader loader = new URLClassLoader(new URL[] { searchDir.toURL() }, null);
            String localeText = null;
            try {
                ResourceBundle rb = ResourceBundle.getBundle(baseName, getLocale(), loader);
                localeText = rb.getString(key.substring(1));
            } catch (Exception e) {
                // couldn't load bundle, move along
            }
            if (localeText != null) {
                return localeText;
            }
            // if we get to here, we couldn't use the resource bundle to find the string, so we will use this another approach
            // change the basename to messages (messages.properties) and go up a directory in our searching
            if (searching) {
                if (!baseName.equals("messages")) { //$NON-NLS-1$
                    baseName = "messages"; //$NON-NLS-1$
                } else {
                    if (searchDir.equals(rootFile)) {
                        searching = false;
                    } else {
                        searchDir = searchDir.getParentFile();
                    }
                }
            }
        }
        return null;
    } catch (Exception e) {
        error(Messages.getErrorString("SolutionRepository.ERROR_0007_COULD_NOT_READ_PROPERTIES", //$NON-NLS-1$
                baseFile.getFullPath()), e);
    }
    return null;
}

From source file:org.talend.designer.core.ui.editor.properties.controllers.WSDL2JAVAController.java

/**
 * DOC xtan Comment method "createRoutine".
 * /*  w  ww . j  av  a2  s .c o  m*/
 * @param path
 */
private RoutineItem createRoutine(final IPath path, String label, File initFile, String name) {

    Property property = PropertiesFactory.eINSTANCE.createProperty();
    property.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY))
            .getUser());
    property.setVersion(VersionUtils.DEFAULT_VERSION);
    property.setStatusCode(""); //$NON-NLS-1$
    property.setLabel(label);

    final RoutineItem routineItem = PropertiesFactory.eINSTANCE.createRoutineItem();

    routineItem.setProperty(property);

    ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
    InputStream stream = null;
    try {
        stream = initFile.toURL().openStream();
        byte[] innerContent = new byte[stream.available()];
        stream.read(innerContent);

        byteArray.setInnerContent(innerContent);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                //
            }
        }
    }
    String routineContent = new String(byteArray.getInnerContent());
    routineContent = chanageRoutinesPackage(routineContent, name);
    byteArray.setInnerContent(routineContent.getBytes());
    routineItem.setContent(byteArray);
    final IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    try {
        property.setId(repositoryFactory.getNextId());
        repositoryFactory.createParentFoldersRecursively(ERepositoryObjectType.getItemType(routineItem), path);
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                try {
                    repositoryFactory.create(routineItem, path);
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
            }

        });

    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    if (routineItem.eResource() != null) {
        addWsdlNeedLib(routineItem);
    }
    return routineItem;

}

From source file:com.collabnet.ccf.core.recovery.HospitalArtifactReplayer.java

@SuppressWarnings("deprecation")
private void loadBeanDefinitionsFromUrl(String url, GenericApplicationContext context) {
    BeanDefinitionReader reader = null;//w  w  w . j ava 2s  .  c  om
    if (url.endsWith(".xml")) {
        reader = new XmlBeanDefinitionReader(context);
    } else if (url.endsWith(".properties")) {
        reader = new PropertiesBeanDefinitionReader(context);
    }

    if (reader != null) {
        try {
            UrlResource urlResource = new UrlResource(url);
            InputStream is = urlResource.getInputStream();
            Document document = builder.parse(is);
            Element routerElement = this.getRouterElement(document);
            this.stripOffProcessors(routerElement);
            this.addGAImportComponents(document, routerElement);
            DOMImplementationRegistry registry = null;
            try {
                registry = DOMImplementationRegistry.newInstance();
            } catch (ClassCastException e) {
                log.error("error", e);
                throw new CCFRuntimeException("error", e);
            } catch (ClassNotFoundException e) {
                log.error("error", e);
                throw new CCFRuntimeException("error", e);
            } catch (InstantiationException e) {
                log.error("error", e);
                throw new CCFRuntimeException("error", e);
            } catch (IllegalAccessException e) {
                log.error("error", e);
                throw new CCFRuntimeException("error", e);
            }
            String originalConfigFileAbsolutePath = urlResource.getFile().getAbsolutePath();
            String componentName = entry.getSourceComponent();
            String configComponentIdentifier = "{" + originalConfigFileAbsolutePath + "}" + componentName;

            File outputFile = null;
            if (componentConfigFileMap.containsKey(configComponentIdentifier)) {
                outputFile = componentConfigFileMap.get(configComponentIdentifier);
            } else {
                outputFile = File.createTempFile(componentName, ".xml", replayWorkDir);
                DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
                LSSerializer writer = impl.createLSSerializer();
                LSOutput output = impl.createLSOutput();
                FileOutputStream bas = new FileOutputStream(outputFile.getAbsolutePath());
                output.setByteStream(bas);
                writer.write(document, output);
                bas.flush();
                bas.close();
                componentConfigFileMap.put(configComponentIdentifier, outputFile);
            }

            // FIXME Use of deprecated method
            UrlResource newUrlResource = new UrlResource(outputFile.toURL().toString());
            ((XmlBeanDefinitionReader) reader).registerBeanDefinitions(document, newUrlResource);
        } catch (BeansException e) {
            log.error("error", e);
            throw new RuntimeException("BeansException : " + e.getMessage(), e);
        } catch (MalformedURLException e) {
            log.error("error", e);
            throw new RuntimeException("MalformedUrlException : " + e.getMessage(), e);
        } catch (IOException e) {
            log.error("error", e);
            throw new RuntimeException("IOExceptionException : " + e.getMessage(), e);
        } catch (SAXException e) {
            log.error("error", e);
            throw new RuntimeException("SAXException : " + e.getMessage(), e);
        }
    } else {
        throw new RuntimeException("No BeanDefinitionReader associated with " + url);
    }
}