⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadasset.java

📁 Sun公司Dream项目
💻 JAVA
字号:
/*
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the "License").  You may not use this file except
 * in compliance with the License.
 *
 * You can obtain a copy of the license at
 * http://www.opensource.org/licenses/cddl1.php
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL
 * HEADER in each file and include the License file at
 * http://www.opensource.org/licenses/cddl1.php.  If 
 * applicable, add the following below this CDDL HEADER, 
 * with the fields enclosed by brackets "[]" replaced 
 * with your own identifying information: 
 * Portions Copyright [yyyy]
 * [name of copyright owner]
 */ 

/*
 * $(@)UploadAsset.java $Revision: 1.1.1.1 $ $Date: 2006/03/15 13:12:10 $
 * 
 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
 */
package com.sun.sjc.idtv.vod.tools;

import java.io.*;
import java.text.*;
import java.util.*;

import java.net.*;
// import com.kasenna.mediabase.api.mbws.*;

import javax.naming.*; 
import javax.rmi.PortableRemoteObject;
import javax.ejb.*; 

import com.sun.sjc.idtv.vod.server.mediaprovisioning.*;
import com.sun.sjc.idtv.vod.shared.data.*;

import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;

import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;

public class UploadAsset extends DefaultHandler
{
/*    public static UploadAsset uploader;
    public static ContentIngest ingester;
    public static ContentIngestHome ingesterHome;
    public static InitialContext initContext = null; 

    public static void main(String argv[]) throws Exception
    {
//        if (argv.length < 6) {
//            System.err.println("Usage: cmd host port user passwd filename dbflag\nwhere dbflag= true|false to upload metadata in VOD database");
//            System.exit(1);
//        }
//
//	String hostname = argv[0]; // vod-xmp
//	String port = argv[1];     // 8080
//	String user = argv[2];     // mbase
//	String passwd = argv[3];   // mbase-admin
//	String xmlfile = argv[4];  // template.xml
//	boolean todb = argv[5].equals("true");

    if (argv.length < 1) {
        System.err.println("Usage: cmd xmlfile");
        System.exit(1);
    }

    String xmlfile = argv[0];
	uploader = new UploadAsset();

	try {
	    Properties env = new Properties() ;
	    //env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "java.naming.factory.initial");
	    env.put("java.naming.factory.initial",
		    "com.sun.jndi.cosnaming.CNCtxFactory");
	    env.put("java.naming.provider.url", "iiop://vod-vas:3700");

	    initContext = new javax.naming.InitialContext(env); 
	    //String JNDIName = "java:comp/env/ejb/ContentIngest"; 
	    String JNDIName = "ContentIngest"; 
	    System.out.println("Looking up: " + JNDIName); 
	    Object objref = initContext.lookup(JNDIName);

	    System.out.println(objref.getClass());

	    ingesterHome = (ContentIngestHome)PortableRemoteObject.narrow(objref, ContentIngestHome.class);
	    System.out.println("Creating the content ingest bean"); 
	    ingester = ingesterHome.create();  
	    
	    movie = uploader.parseXMLMetadata(xmlfile);
	    //uploader.uploadMetadataToXMP(hostname, port, user, passwd, movie);
	    //if (todb) {
		uploader.uploadMetadataToDB(movie);
	    //}
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }

    public Movie parseXMLMetadata(String xmlfile) throws Exception {
	
        // Use an instance of ourselves as the SAX event handler
        DefaultHandler handler = this;
        // Use the default (non-validating) parser
        SAXParserFactory factory = SAXParserFactory.newInstance();

	System.out.println("Parsing xml file: " + xmlfile);
	
	// Set up output stream
	out = new OutputStreamWriter(System.out, "UTF8");
	    
	// Parse the input
	SAXParser saxParser = factory.newSAXParser();
	saxParser.parse( new File(xmlfile), handler);

	//System.out.println("---\n" + movie.toString());

	return movie;
    }

    public void uploadMetadataToXMP(String hostname, String port, String user, String passwd, Movie movie) throws Exception {
    }
*/
/*    public void uploadMetadataToXMP(String hostname, String port, String user, String passwd, Movie movie) throws Exception {

	JglueServiceLocator service = new JglueServiceLocator();
	Jglue vs = service.getJglue(new java.net.URL("http://" + hostname + ":" + port + "/axis/services/Jglue"));
	System.out.println("Version = " + vs.getVersion());

	// default mode. No Authentication required
	NameValue[] nv = new NameValue[2];
	nv[0] = new NameValue();
	nv[0].setName("username");
	nv[0].setValue(user);
	nv[1] = new NameValue();
	nv[1].setName("password");
	nv[1].setValue(passwd);

	String xmpVersion = vs.getVersion();
	System.out.println("Server version: " + xmpVersion);

	String sessionId = vs.login(nv);
	System.out.println("Got Session ID: " + sessionId);

	String[] assets = vs.listAssets(sessionId);
	System.out.println("Current assets: " + java.util.Arrays.asList(assets).toString());

	String assetName = movie.shorttitle.trim();

	System.out.println("Deleting asset: " + assetName);

	// delete asset
	try {
	    vs.deleteAsset(sessionId, assetName, true);
	} catch (Exception e) {
	    System.out.println("Could not delete asset: " + assetName);
	}

	// add an asset
	String keywords = "mpeg";
	String assetGroup = "System Asset Group";
	boolean synchronous = true;
	NameValue[] optionalNameValues = new NameValue[0];
	MovieMetadata movieMetadata = new MovieMetadata();

	System.out.println("Adding asset: " + assetName);

	String opid = vs.addAsset(sessionId, assetName, assetGroup, movie.enctype, movie.sourcefile, keywords, synchronous, optionalNameValues, movieMetadata);
	//String opid = vs.addAsset(sessionId, movie.shorttitle, assetGroup, movie.enctype, movie.sourcefile, keywords, synchronous, null, null);
	    
	assets = vs.listAssets(sessionId);
	System.out.println("New assets: " + java.util.Arrays.asList(assets).toString());

    }
*/
/*
    public void uploadMetadataToDB(Movie movie) throws Exception {

	ingester.store(movie);
    }



    static private Writer  out;

    //===========================================================
    // SAX DocumentHandler methods
    //===========================================================

    public void startDocument()
    throws SAXException
    {
        emit("<?xml version='1.0' encoding='UTF-8'?>");
        nl();
    }

    public void endDocument()
    throws SAXException
    {
        try {
            nl();
            out.flush();
        } catch (IOException e) {
            throw new SAXException("I/O error", e);
        }
    }

    String element = null;
    static Movie movie = null;
    DateFormat dateformat = DateFormat.getDateInstance();

    public void startElement(String namespaceURI,
                             String lName, // local name
                             String qName, // qualified name
                             Attributes attrs)
    throws SAXException
    {
        String eName = lName; // element name
        if ("".equals(eName)) eName = qName; // namespaceAware = false
        emit("<"+eName);

	if (!eName.equals("Name") && !eName.equals("Url")) element = eName;
	if (element.equals("Asset")) {
	    movie = new Movie();
	    movie.id = Long.parseLong(attrs.getValue(0));
	}
	
        if (attrs != null) {
            for (int i = 0; i < attrs.getLength(); i++) {
                String aName = attrs.getLocalName(i); // Attr name 
                if ("".equals(aName)) aName = attrs.getQName(i);
                emit(" ");
                emit(aName+"=\""+attrs.getValue(i)+"\"");
            }
        }
        emit(">");
    }

    public void endElement(String namespaceURI,
                           String sName, // simple name
                           String qName  // qualified name
                          )
    throws SAXException
    {
	if (!qName.equals("Name") && !qName.equals("Url")) {
	    element = null;
	}
	
	emit("</"+sName+">");
    }

    public void characters(char buf[], int offset, int len)
    throws SAXException
    {
        String s = new String(buf, offset, len);
        emit(s);

	if (element == null) return;

	try {

	if (element.equals("ExternalId")) { movie.externalid = s; }
	else if (element.equals("FullTitle")) { movie.fulltitle = s; }
	else if (element.equals("OriginalTitle")) { movie.origtitle = s; }
	else if (element.equals("ShortTitle")) { movie.shorttitle = s; }
	else if (element.equals("ShortDescription")) { movie.shortdescr = s; }
	else if (element.equals("LongDescription")) { movie.longdescr = s; }
	else if (element.equals("Version")) { movie.version = Integer.parseInt(s); }
	else if (element.equals("Genre")) { movie.genreid = getGenreIdByName(s); }
	else if (element.equals("ProductionCompany")) { movie.prodcompany = s; }
	else if (element.equals("ProductionDate")) { movie.proddate = dateformat.parse(s); }
	else if (element.equals("ReleaseDate")) { movie.releasedate = s; }
	else if (element.equals("Country")) { movie.country = s; }
	else if (element.equals("ScreenFormat")) { movie.screenformat = getScreenFormatByName(s); }
	else if (element.equals("Showing")) { movie.showing = s; }
	else if (element.equals("BoxOfficeRating")) { movie.boxofficeratingid = getBoxOfficeRatingIdByName(s); movie.boxofficerating = s; }
	else if (element.equals("ParentalRating")) { movie.parentratingid = getParentalRatingIdByName(s); movie.parentrating = s; }
	else if (element.equals("Duration")) { movie.duration = Integer.parseInt(s); }
	else if (element.equals("Color")) { movie.color = s.equals("1"); }
	else if (element.equals("Stereo")) { movie.stereo = s.equals("1"); }
	else if (element.equals("Surround")) { movie.surround = s.equals("1"); }
	else if (element.equals("Dolby")) { movie.dolby = s.equals("1"); }
	else if (element.equals("DVBContent")) { movie.dvbcontent = s; }
	else if (element.equals("StartDate")) { movie.startdate = dateformat.parse(s); }
	else if (element.equals("EndDate")) { movie.enddate = dateformat.parse(s); }
	else if (element.equals("StandardPrice")) { movie.stdprice = Float.parseFloat(s); }
	else if (element.equals("MinimumPrice")) { movie.minprice = Float.parseFloat(s); }
	else if (element.equals("MovieURL")) { movie.movieurl = s; }
	else if (element.equals("PosterURL")) { movie.posterurl = s; }
	else if (element.equals("Actors")) { movie.actors = addToArray(movie.actors, s); }
	else if (element.equals("Producers")) { movie.producers = addToArray(movie.producers, s); }
	else if (element.equals("Directors")) { movie.directors = addToArray(movie.directors, s); }
	else if (element.equals("Composers")) { movie.composers = addToArray(movie.composers, s); }
	else if (element.equals("Snapshots")) { movie.imageurls = addToArray(movie.imageurls, s); }
	else if (element.equals("Trailers")) { movie.trailerurls = addToArray(movie.trailerurls, s); }
	else if (element.equals("EncodingType")) { movie.enctype = s; }
	else if (element.equals("SourceFile")) { movie.sourcefile = s; }
	
	} catch (Exception e ) {
	    
	    e.printStackTrace();
	    throw new SAXException(e.getMessage());
	}
    }

    public String[] addToArray(String[] arr, String s) {

	ArrayList list = new ArrayList(Arrays.asList(arr));
	list.add(s);
	arr = (String[]) list.toArray(arr);
	return arr;
    }

    public int getGenreIdByName(String s) {

	int i = 0;
	// ...
	return i;
    }

    public int getScreenFormatByName(String s) {

	if (s.equals("4/3")) {
	    return 0;
	} else {
	    return 1;
	}
    }

    public int getBoxOfficeRatingIdByName(String s) {

	int i = 0;
	// ...
	return i;
    }

    public int getParentalRatingIdByName(String s) {

	int i = 0;
	// ...
	return i;
    }

    

    //===========================================================
    // Utility Methods ...
    //===========================================================

    // Wrap I/O exceptions in SAX exceptions, to
    // suit handler signature requirements
    private void emit(String s)
    throws SAXException
    {
        try {
            out.write(s);
            out.flush();
        } catch (IOException e) {
            throw new SAXException("I/O error", e);
        }
    }

    // Start a new line
    private void nl()
    throws SAXException
    {
        String lineEnd =  System.getProperty("line.separator");
        try {
            out.write(lineEnd);
        } catch (IOException e) {
            throw new SAXException("I/O error", e);
        }
    }
*/
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -