incubator-odf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Devin Han <devin...@apache.org>
Subject Re: OdfDrawImage from OdfTableCell
Date Tue, 06 Dec 2011 10:31:40 GMT
Sure, you can use ODFDOM in Simple API. See the following code, is it
enough simple and clean?

       TextDocument odt;
        try {
            odt = TextDocument.loadDocument("goodbad-generated.odt");
            Node node = odt.getContentRoot().getFirstChild();
            int h=0;
            int p=0;
            int t=0;
            while(node !=null){
                if(node instanceof TextHElement){
                    TextHElement headerEle = (TextHElement)node;
                    System.out.println("Header "+(++h)+" = " +
headerEle.getTextContent());
                } else if(node instanceof TextPElement){
                    TextPElement paraEle = (TextPElement)node;
                    System.out.println("Paragraph "+(++p)+" = " +
paraEle.getTextContent());
                } else if(node instanceof TableTableElement){
                    TableTableElement tableEle = (TableTableElement)node;
                    //System.out.println("table = " + table);
                    Table table = Table.getInstance(tableEle);
                    Cell cell = table.getCellByPosition(0, 0);
                    //System.out.println("cell = " + cell);
                    //System.out.println("cell.valueType = " +
cell.getValueType());
                    Image image = cell.getImage();
                    System.out.println("Image in Table "+(++t)+" href =
"    + image.getOdfElement().getXlinkHrefAttribute());
                }
                node = node.getNextSibling();
            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



2011/12/5 ikeamanual <ikeamanual@gmail.com>

> Hi Devin,
>
>
> > >You need a document component navigator, isn't it?
> >
> Yes
>
> >
> >
> > >We need "level" parameter, such as level 1 returns all of the
> components,
> > >which are the child of document root element, while level 2 contians the
> > >child of level 1...
> >
> Yes, that would do it, but I also like this style of searching from your
> current position:
>
> TableTableElement table = OdfElement.findNextChildNode(
> TableTableElement.class, secondHeader);
>
> If we have this on the Simple level :
>
> thisTypeVar = myCurrentElement.findNextChildNode(ofThisType)
> thisTypeVar = myCurrentElement.findPrevChildNode(ofThisType)
> thisTypeVar = myCurrentElement.findNextSiblingNode(ofThisType)
> thisTypeVar = myCurrentElement.findPrevSiblingNode(ofThisType)
>
> then you can navigate and null check your expectations of the document
> structure.
>
> >
> > >For your use case, I think you can use Simple API iterates over all
> > Tables,
> > >Paragraphs, Section, and get their OdfElements using method
> > >getOdfElement(), then use ODFDOM to iterate the document and give these
> > >components a right sort according to the location of their OdfElements.
> >
>
> Yes, I Simple iterated over the paragraph headers and then dropped down to
> ODFDOM but this
> did not add much advantage so I switched to ODFDOM for the reading.
>
> Thanks,
> Jan
>
>
> >
> > > thanks,
> > > Jan
> > >
> > > On Sun, Dec 4, 2011 at 7:27 AM, Devin Han <devinhan@apache.org> wrote:
> > >
> > > > Hi Jan,
> > > >
> > > > I suppose you are using ODFDOM doc API, isn't it?
> > > > OK, ODFDOM doc API is deprecated in the coming release and we will
> not
> > > > maintain it in future.
> > > >
> > > > I suggest you replace it with Simple API[1], which is a new
> convenient
> > > API
> > > > for ODF Documnet and has very simliar design with ODFDOM doc API. But
> > > > Simple API has more powerful features and more performance tuning.
> You
> > > can
> > > > migrate to Simple API very easy.
> > > >
> > > > Let's back your question. If you migrate to Simple API, you can use
> the
> > > > following simple code:
> > > >
> > > > Image Cell.getImage() ;
> > > > Image.getOdfEelment();
> > > >
> > > > More information please reference the cookbook[2].
> > > >
> > > > Hope my answer can help you.
> > > >
> > > > [1] http://incubator.apache.org/odftoolkit/simple/index.html
> > > > [2]
> > > >
> > > >
> > >
> >
> http://incubator.apache.org/odftoolkit/simple/document/cookbook/Cell.html#Set%20image
> > > >
> > > >
> > > > 2011/12/3 ikeamanual <ikeamanual@gmail.com>
> > > >
> > > > > Hi,
> > > > >
> > > > > I have a odf cell:
> > > > >
> > > > > OdfTableCell cell = table.getCellByPosition(0, 1);
> > > > >
> > > > > and in the document the cell only has a picture/Image inside.
> > > > >
> > > > > How to I get an OdfDrawImage from the cell?
> > > > >
> > > > > thanks,
> > > > > Jan
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > -Devin
> > > >
> > >
> >
> >
> >
> > --
> > -Devin
> >
>



-- 
-Devin

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message