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

📄 report.java

📁 iReport-0.4.1-src是iReport的源代码,iReport是一个开源的报表项目,可以生成PDF等格式报表
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                this.setLeftMargin(report.getLeftMargin());
                this.setBottomMargin(report.getBottomMargin());
                this.setRightMargin(report.getRightMargin());
                this.setOrientation( ( (report.getOrientation() == JRReport.ORIENTATION_PORTRAIT) ? "Portrait" : "Landscape"));
                this.setColumnCount( report.getColumnCount() );
                this.setColumnSpacing( report.getColumnSpacing());
                this.setColumnWidth( report.getColumnWidth());
                this.setQuery( ( report.getQuery() != null) ? report.getQuery().getText() : "");
                
                // Read all bands...
                net.sf.jasperreports.engine.JRField[] reportFields = report.getFields();
                for (int i=0; reportFields != null && i<reportFields.length; ++i) {
                    it.businesslogic.ireport.JRField field = 
                      new it.businesslogic.ireport.JRField(  reportFields[i].getName(), 
                                    reportFields[i].getValueClass().getClass().getName());
                    field.setDescription( reportFields[i].getDescription());
                    addField(field);
                }
                
            } else {
                DOMParser parser = new DOMParser();
                
                parser.setEntityResolver( new org.xml.sax.EntityResolver() {
                    
                    /* Code by Teodor Danciu */
                    public org.xml.sax.InputSource resolveEntity( String publicId, String systemId )
                           throws SAXException, IOException
                    {
                        org.xml.sax.InputSource inputSource = null;
                        
                        if (systemId != null) {
                            String dtd = null;
                            
                            if ( systemId.equals("http://jasperreports.sourceforge.net/dtds/jasperreport.dtd") ||
                            systemId.equals("http://www.jasperreports.com/dtds/jasperreport.dtd") ) {
                                //dtd = "dori/jasper/engine/dtds/jasperreport.dtd";
                                dtd = "net/sf/jasperreports/engine/dtds/jasperreport.dtd";
                               
                            } else if (
                            systemId.equals("http://jasperreports.sourceforge.net/dtds/jasperprint.dtd") ||
                            systemId.equals("http://www.jasperreports.com/dtds/jasperprint.dtd") ) {
                                dtd = "net/sf/jasperreports/engine/dtds/jasperprint.dtd";
                            } else {
                                return new org.xml.sax.InputSource(systemId);
                            }

                            
                            ClassLoader classLoader = this.getClass().getClassLoader();
                            java.net.URL url = null;
                            
                            if (classLoader != null) {
                                url = classLoader.getResource(dtd);
                                if (url == null) {
                                    classLoader = this.getClass().getClassLoader();
                                }
                                
                            } else {
                                // url is certainly null
                                // classLoader stays null
                            }
                     
                            
                            java.io.InputStream is = classLoader.getResourceAsStream(dtd);
                            if (is != null) {
                                java.io.InputStreamReader isr = new java.io.InputStreamReader(is);
                                inputSource = new org.xml.sax.InputSource(isr);
                            } else {
                                // dtd could not be found
                                // this error occurs e.g. when the package name / path changes to this dtd
                                // the error will be caught by MainFrame.openFile() en the report file won't open
                                throw new java.io.IOException( "iReport Internal error in report.java: Could not find: " + dtd + "\n" );
                            }
                        }
                        return inputSource;
                        
                    }
                });
                /* End Code by Teodor Danciu */
                
                    String f = new java.io.File(xmlFile).toURI().toString();
                    parser.parse( f );
                    Document document = parser.getDocument();
                    traverse(document.getDocumentElement());

            }

            /* Begin Code by Robert Lamping
             * 2 July 2004
             * Now height and width are known and a format can be guessed.
             * using PageSize.deductPageFormat();
             */
            
            this.setReportFormat( PageSize.deductPageFormat( this.getWidth(), this.getHeight()) );
            
            /* Begin Code by Robert Lamping */
            
            for (int i = 0; i < groups.size(); i++) {
                it.businesslogic.ireport.Group grp = (it.businesslogic.ireport.Group)groups.elementAt(i);
                addGroup(grp,false);
            }
            
            // Translate coords to iReport coord system...
            for (Iterator i = elements.iterator(); i.hasNext(); ) {
                ReportElement re = (ReportElement) i.next();
                re.trasform(new java.awt.Point(this.getLeftMargin()+10, this.getBandYLocation(re.getBand())+10), TransformationType.TRANSFORMATION_MOVE);
            }
            
            // Scriptlet loading....
            
            // Process custom properties (ireport.* properties).
            // We cut out ireport properties...
            //System.out.println("Analizing properties...");
            //System.out.println("Possible file: "+this.getScriptletFileName());

            for (int pk= 0; pk < this.getJRproperties().size(); ++pk) {
                JRProperty prop = (JRProperty)getJRproperties().elementAt( pk );
                
                //System.out.println(""+prop.getName());
                
                if (prop.getName().equals("ireport.scriptlethandling")) {
                    if (prop.getValue().equals("0")) {
                        this.setScriptletHandling(0);
                    } else if (prop.getValue().equals("1")) {
                        this.setScriptletHandling( this.SCRIPTLET_IREPORT_INTERNAL_HANDLING );
                        // Try to load the source file...
                        File scriptletFile = new File(this.getScriptletFileName());
                        if (scriptletFile.exists()) {
                            scripletCode = new ScriptletCode(this.getScriptletFileName());
                            //System.out.println("Caricato scriptlet");
                        }
                    }
                }
                
                if (prop.getValue().startsWith("ireport.")) {
                    getJRproperties().remove( prop );
                    pk--;
                }
            }
            
            // } catch (SAXException e) {
            //            System.err.println(e);
        } catch (IOException e) {
            System.err.println(e);
            throw e ; 
            
        } catch (net.sf.jasperreports.engine.JRException e) {
            System.err.println(e);
            
        } catch (Exception e) {
            System.err.println(e);
            e.printStackTrace();
        }
        
        this.setDirty(false);
        
    }
    
    //  Traverse DOM Tree.  Print out Element Names
    private void traverse(Node node) {
        
        if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("jasperReport")) {

            // Find encoding...
            NamedNodeMap nnm = node.getAttributes();
            
            this.setName((( nnm.getNamedItem("name") != null) ? nnm.getNamedItem("name").getNodeValue() : ""));
            
            if ( nnm.getNamedItem("columnCount") != null) {
                this.setColumnCount( Integer.parseInt(nnm.getNamedItem("columnCount").getNodeValue()));
            }
            if ( nnm.getNamedItem("printOrder") != null) {
                this.setPrintOrder( nnm.getNamedItem("printOrder").getNodeValue());
            }
            if ( nnm.getNamedItem("orientation") != null) {
                this.setOrientation( nnm.getNamedItem("orientation").getNodeValue());
            }
            if ( nnm.getNamedItem("scriptletClass") != null) {
                this.setScriptletClass( nnm.getNamedItem("scriptletClass").getNodeValue());
            }
            if ( nnm.getNamedItem("resourceBundle") != null) {
                this.setResourceBundleBaseName( nnm.getNamedItem("resourceBundle").getNodeValue());
            }
            if ( nnm.getNamedItem("pageWidth") != null) {
                this.setWidth( Integer.parseInt(nnm.getNamedItem("pageWidth").getNodeValue()));
            }
            if ( nnm.getNamedItem("pageHeight") != null) {
                this.setHeight( Integer.parseInt(nnm.getNamedItem("pageHeight").getNodeValue()));
            }
            if ( nnm.getNamedItem("columnWidth") != null) {
                this.setColumnWidth( Integer.parseInt(nnm.getNamedItem("columnWidth").getNodeValue()));
            }
            if ( nnm.getNamedItem("columnSpacing") != null) {
                this.setColumnSpacing( Integer.parseInt(nnm.getNamedItem("columnSpacing").getNodeValue()));
            }
            if ( nnm.getNamedItem("leftMargin") != null) {
                this.setLeftMargin( Integer.parseInt(nnm.getNamedItem("leftMargin").getNodeValue()));
            }
            if ( nnm.getNamedItem("rightMargin") != null) {
                this.setRightMargin( Integer.parseInt(nnm.getNamedItem("rightMargin").getNodeValue()));
            }
            if ( nnm.getNamedItem("topMargin") != null) {
                this.setTopMargin( Integer.parseInt(nnm.getNamedItem("topMargin").getNodeValue()));
            }
            if ( nnm.getNamedItem("bottomMargin") != null) {
                this.setBottomMargin( Integer.parseInt(nnm.getNamedItem("bottomMargin").getNodeValue()));
            }
            if ( nnm.getNamedItem("whenNoDataType") != null) {
                this.setWhenNoDataType( nnm.getNamedItem("whenNoDataType").getNodeValue());
            }
            if ( nnm.getNamedItem("isTitleNewPage") != null) {
                this.setIsTitleNewPage(nnm.getNamedItem("isTitleNewPage").getNodeValue().equalsIgnoreCase("true") );
            }
            if ( nnm.getNamedItem("isSummaryNewPage") != null) {
                this.setIsSummaryNewPage(  nnm.getNamedItem("isSummaryNewPage").getNodeValue().equalsIgnoreCase("true"));
            }
            
            if ( nnm.getNamedItem("isFloatColumnFooter") != null) {
                this.setFloatColumnFooter(nnm.getNamedItem("isFloatColumnFooter").getNodeValue().equalsIgnoreCase("true") );
            }
            
            
        } else if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("property")) {

            // Load report property...
            JRProperty property = new JRProperty();
            NamedNodeMap nnm = node.getAttributes();
            if ( nnm.getNamedItem("name") != null) {
                property.setName( nnm.getNamedItem("name").getNodeValue());
            }
            if ( nnm.getNamedItem("value") != null) {
                property.setValue( nnm.getNamedItem("value").getNodeValue());
            }
            
            JRproperties.addElement( property );
        } else if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("import")) {

            // Load report IMPORT...

⌨️ 快捷键说明

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