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

📄 multimediacontentimpl.java

📁 openwave公司的用于彩信开发的MM7协议实现java原代码,决对超值.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * MimeMultipart, it returns the same. If the object was created from an     * input stream containing a mime formatted message, it returns a MimeBodyPart     * if the input stream contained a single part and MimeMultipart if the stream     * contained a multipart message. If this object was created using any other     * constructors, it always returns a MimeMultipart containing the SMIL and     * the content parts.      *     * @return A MimeMultipart object containing the SMIL and the media objects     *         or a MimeBodyPart.     * @exception MessagingException The MimeMultipart object cannot be created.     * @exception InvalidSmilException A subclass of ContentException is thrown if the      *            SMIL cannot be parsed/synthesized.     */    public Object getContent() throws ContentException,                                      MessagingException {        try {            if( smilBased && changed ) {                createMultipart();            }                        return content;        } catch( ValidationException ve ) {            throw new InvalidSmilException( "smil-validation-failed",                                            ve );        } catch( MarshalException me ) {            throw new InvalidSmilException( "smil-creation-failed",                                            me );        }    }    /**     * This method returns the slides contained in the object as a List.     *     * @return The list of Slide objects.     */    public List getSlides() {        return slides;    }    /**     * This method can be used to set the slides of the object.     *     * @param slides A list of Slide objects. The existing slides will be replaced     *        by this list.     */    public void setSlides( List slides ) {        changed = true;        this.slides = slides;    }    /**     * This method returns the slide indexed by an integer.     *     * @param slideNumber The index of the slide in the list.     * @return The Slide object indexed by the slideNumber.     * @exception IndexOutOfBoundsException The list does not contain that many elements.     */    public Slide getSlide( int slideNumber )                           throws IndexOutOfBoundsException {        return ( Slide ) slides.get( slideNumber );    }    /**     * This method returns the number of slides in the object.     *     * @return The number of slides in the object.     */    public int getNumSlides() {        return slides.size();    }    /**     * This method is used to set the template for the slides in the object.     *     * @param template The template to be used for the slides in the object.     */    public void setTemplate( Template template ) {        this.template = template;    }    /**     * This method returns the Template associated with the slides in the object.     *     * @return The template associated with the slides in the object.     */    public Template getTemplate() {        return template;    }    /**     * This method is used to set the size of the viewport in which the SMIL     * presentation is rendered.     *     * @param viewportSize The size of the viewport.     */    public void setViewportSize( Dimension viewportSize ) {        this.viewportSize = viewportSize;    }    /**     * This method returns the viewport size.     *     * @return The size of the viewport.     */    public Dimension getViewportSize() {        return viewportSize;    }    /**     * This method converts the content into a JavaMail MimeMultipart object.     * It also initializes the multipart member of this class and updates     * the changed flag to false.     */    private void createMultipart() throws MessagingException,                                          ValidationException,                                          MarshalException {        changed = false;        if( template == null ) {            template = TemplateFactory.getInstance().getTemplate( null );        }        MimeMultipart multipart = new MimeMultipart( "related" );        Smil smil = new Smil();        Body body = new Body();        Head head = new Head();        Layout layout = new Layout();        RootLayout rootLayout = new RootLayout();        rootLayout.setWidth( "100%" );        rootLayout.setHeight( "100%" );        if( viewportSize != null ) {            if( viewportSize.getWidth() > 0 ) {                rootLayout.setWidth( String.valueOf( viewportSize.getWidth() ) );            }            if( viewportSize.getHeight() > 0 ) {                rootLayout.setHeight( String.valueOf( viewportSize.getHeight() ) );            }        }        layout.setRootLayout( rootLayout );        head.setLayout( layout );        smil.setHead( head );        smil.setBody( body );        List fileList = new LinkedList();        ListIterator iterator = slides.listIterator();        while( iterator.hasNext() ) {            Slide slide = ( Slide ) iterator.next();            Par par = new Par();            int duration = slide.getDuration();            if( duration > 0 ) {                par.setDur( String.valueOf( duration ) + "ms" );            }            body.addPar( par );            Text text = slide.getText();            if( text != null ) {                // check if there is a file name associated with the part                String textContentID = addMediaToMultipart( multipart, text );                com.openwave.mms.content.smil.Text textElement = new com.openwave.mms.content.smil.Text();                textElement.setSrc( "cid:" + textContentID );                int begin = text.getBegin();                if( begin > 0 ) {                    textElement.setBegin( String.valueOf( begin ) );                }                int end = text.getEnd();                if( end > 0 ) {                    textElement.setEnd( String.valueOf( end ) );                }                textElement.setAlt( text.getAlt() );                RegionAttributes textAttributes = template.getTextAttributes();                addRegion( "Text", layout, textAttributes );                textElement.setRegion( "Text" );                par.setText( textElement );            }            Video video = slide.getVideo();            if( video != null ) {                // check if there is a file name associated with the part                String videoContentID = addMediaToMultipart( multipart, video );                com.openwave.mms.content.smil.Video videoElement =                    new com.openwave.mms.content.smil.Video();                videoElement.setSrc( "cid:" + videoContentID );                int begin = video.getBegin();                if( begin > 0 ) {                    videoElement.setBegin( String.valueOf( begin ) );                }                int end = video.getEnd();                if( end > 0 ) {                    videoElement.setEnd( String.valueOf( end ) );                }                videoElement.setAlt( video.getAlt() );                //video and image share the Image smil region                RegionAttributes imageAttributes = template.getImageAttributes();                addRegion( "Image", layout, imageAttributes );                videoElement.setRegion( "Image" );                par.setVideo( videoElement );            }            Image image = slide.getImage();            if( image != null ) {                // check if there is a file name associated with the part                String imageContentID = addMediaToMultipart( multipart, image );                Img imgElement = new Img();                imgElement.setSrc( "cid:" + imageContentID );                int begin = image.getBegin();                if( begin > 0 ) {                    imgElement.setBegin( String.valueOf( begin ) );                }                int end = image.getEnd();                if( end > 0 ) {                    imgElement.setEnd( String.valueOf( end ) );                }                imgElement.setAlt( image.getAlt() );                RegionAttributes imageAttributes = template.getImageAttributes();                addRegion( "Image", layout, imageAttributes );                imgElement.setRegion( "Image" );                par.setImg( imgElement );            }            Audio audio = slide.getAudio();            if( audio != null ) {                // check if there is a file name associated with the part                String audioContentID = addMediaToMultipart( multipart, audio );                com.openwave.mms.content.smil.Audio audioElement = new com.openwave.mms.content.smil.Audio();                audioElement.setSrc( "cid:" + audioContentID );                int begin = audio.getBegin();                if( begin > 0 ) {                    audioElement.setBegin( String.valueOf( begin ) );                }                int end = audio.getEnd();                if( end > 0 ) {                    audioElement.setEnd( String.valueOf( end ) );                }                audioElement.setAlt( audio.getAlt() );                par.setAudio( audioElement );            }        }        StringWriter writer = new StringWriter();        smil.marshal( writer );        MimeBodyPart smilPart = new MimeBodyPart();        smilPart.setText( writer.toString() );        smilPart.setHeader( "Content-Type", "application/smil" );        String smilContentID = "<mms.smil>";        smilPart.setHeader( "Content-ID", smilContentID );        multipart.addBodyPart( smilPart );        content = multipart;    }    private BodyPart searchForSmilPart( MimeMultipart multipart )                                        throws MessagingException {        for( int i = 0; i < multipart.getCount(); i++ ) {            BodyPart part = multipart.getBodyPart( i );            try {                ContentType contentType = new ContentType( part.getContentType() );                if( contentType.getBaseType().equals( "application/smil" ) ) {                    return part;                }            } catch( ParseException pe ) {                return null;            }        }        return null;    }    private void createSlidesFromSmil( BodyPart smilPart,                                       MimeMultipart multipart )                                       throws IOException,                                              MarshalException,                                              ValidationException,                                              MessagingException,                                              ContentException {        Smil smil = Smil.unmarshal( new InputStreamReader( smilPart.getInputStream() ) );        createTemplate(smil);        for( int i = 0; i < smil.getBody().getParCount(); i++ ) {            Par par = smil.getBody().getPar( i );            Slide slide = SlideFactory.getInstance().newSlide();            slide.setDuration( par.getDur() );            com.openwave.mms.content.smil.Text text = par.getText();            if( text != null ) {                BodyPart textPart = getReferencedPart( text.getSrc(),                                                       multipart );                if( textPart != null ) {                    addText( slide, new Text( textPart ), text );                }            }            com.openwave.mms.content.smil.Audio audio = par.getAudio();            if( audio != null ) {                BodyPart audioPart = getReferencedPart( audio.getSrc(),                                                        multipart );                if( audioPart != null ) {                    addAudio( slide, new Audio( audioPart ), audio );                }            }            com.openwave.mms.content.smil.Img image = par.getImg();            if( image != null ) {                BodyPart imagePart = getReferencedPart( image.getSrc(),                                                        multipart );                if( imagePart != null ) {                    addImage( slide, new Image( imagePart ), image );                }            }            com.openwave.mms.content.smil.Video video = par.getVideo();            if( video != null ) {                BodyPart videoPart = getReferencedPart( video.getSrc(),                                                        multipart );                if( videoPart != null ) {                    addVideo( slide, new Video( videoPart ), video );                }            }            slides.add( slide );        }    }    private void createFromSmilFile( File smilFile )                                     throws FileNotFoundException,                                            ContentException,                                            MessagingException,                                            MarshalException,                                            ValidationException,                                            IOException {        Smil smil = Smil.unmarshal( new FileReader( smilFile ) );        createTemplate(smil);        for( int i = 0; i < smil.getBody().getParCount(); i++ ) {            Par par = smil.getBody().getPar( i );            Slide slide = SlideFactory.getInstance().newSlide();            slide.setDuration( par.getDur() );            com.openwave.mms.content.smil.Text text = par.getText();            if( text != null ) {                Text textContent = new Text( new File( smilFile.getParent(), text.getSrc() ),                                             MimeUtility.mimeCharset(                                                 MimeUtility.getDefaultJavaCharset()                                             )                                           );                addText( slide, textContent, text );            }            com.openwave.mms.content.smil.Audio audio = par.getAudio();            if( audio != null ) {                Audio audioContent = new Audio( new File( smilFile.getParent(),                                                          audio.getSrc()                                                        )                                              );                addAudio( slide, audioContent, audio );            }            com.openwave.mms.content.smil.Img image = par.getImg();            if( image != null ) {                Image imageContent = new Image( new File( smilFile.getParent(),                                                          image.getSrc()                                                        )                                              );                addImage( slide, imageContent, image );            }            com.openwave.mms.content.smil.Video video = par.getVideo();            if( video != null ) {                Video videoContent = new Video( new File( smilFile.getParent(),

⌨️ 快捷键说明

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