protected TranscoderHandler in Java

Drawing QR in Java protected TranscoderHandler

protected TranscoderHandler
Draw QR In Java
Using Barcode creator for Java Control to generate, create QR Code ISO/IEC18004 image in Java applications.
Quick Response Code Reader In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
protected TranscoderParser parser; protected Map deviceProfile; protected String protected InputStream protected String protected List protected boolean protected boolean protected Locale deviceName; inputStream; pageName; modificators = new ArrayList(); disableTagRemoving; isMobileApplication = true; locale;
Generate Barcode In Java
Using Barcode encoder for Java Control to generate, create barcode image in Java applications.
Read Bar Code In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
protected HttpServletRequest servletRequest; protected HttpServletResponse servletResponse; protected HttpServlet // servlet;
QR Code Maker In Visual C#
Using Barcode printer for .NET framework Control to generate, create QR Code image in VS .NET applications.
QR Code JIS X 0510 Generator In VS .NET
Using Barcode creation for ASP.NET Control to generate, create QR Code 2d barcode image in ASP.NET applications.
public void parse() { try { String handlerClass = (String)deviceProfileget(HANDLER_CLASS); if(handlerClass == null) { handlerC lass = HtmlTranscoderHandlerclassgetName(); } try { handler = (TranscoderHandler)RTSFactoryManagergetInstanceForAbstract(handlerClass); } catch(Exception e) { RTSTrackerhandleException(ERROR_MESSAGE_PREFIX,e); copyStreams(); return; } handlersetWriter(writer); handlermodificators = modificators; String supportedTagList = (String)deviceProfileget(SUPPORTED_TAGS); if(supportedTagList == null) { RTSTrackerdisplayString(ERROR_MESSAGE_PREFIX + "Failed to get " + SUPPORTED_TAGS + " property for " + deviceName); copyStreams(); return; } Map tagList = TagListLoadergetTagList(supportedTagList); if(tagList == null) { copyStreams(); return; } handlersetTagList(tagList); handlersetDeviceProfile(deviceProfile); handlersetPageName(pageName); handlersetTagRemovingDisabled(disableTagRemoving); handlersetIsMobileAppliction(isMobileApplication); handlersetLocale(locale); 646
Generating QR-Code In Visual Studio .NET
Using Barcode generator for VS .NET Control to generate, create QR image in Visual Studio .NET applications.
Draw Quick Response Code In Visual Basic .NET
Using Barcode encoder for .NET framework Control to generate, create QR Code ISO/IEC18004 image in .NET applications.
handlersetTranscoder(this); parsersetDocumentHandler(handler); parsersetErrorHandler(handler); parsersetCommentHandler(handler); parsersetXmlTags(handlerisXml()); parserparse(inputStream); return; } catch(SAXNotRecognizedException e) { RTSTrackerhandleException(ERROR_MESSAGE_PREFIX + "Unrecogni zed SAX2 feature",e); } catch(SAXException e) { RTSTrackerhandleException(ERROR_MESSAGE_PREFIX + "SAX exception",e); } catch(IOException e) { RTSTrackerhandleException(ERROR_MESSAGE_PREFIX + "IO Exception",e); } catch(Throwable e) { RTSTrackerhandleException(ERROR_MESSAGE_PREFIX,e); } } // } After a handler is created, several other objects are instantiated and held by the handler Modificators are created and stored within the handler as is a list of the available tags All this is done based on a set of XML files that represent metadata on how elements should be manipulated by the transcoder These files define the legal tags as well as changes that may possibly be required to create the correct form of presentation Even the metadata that forms the base of how the transcoder works is based on XML The following two XML files show two samples of such metadata the first for HTML and the second for WML Here's the first example: <ROOT> <tag name="A" attributes="accesskey,charset,coords,href,hreflang, name,onblur,onfocus,rel,rev,shape,tabindex,target,type"/> <tag name="ABBR,ACRONYM,ADDRESS"/> 647
Encoding ECC200 In Java
Using Barcode drawer for Java Control to generate, create Data Matrix ECC200 image in Java applications.
Encoding Data Matrix ECC200 In Java
Using Barcode generation for Java Control to generate, create Data Matrix image in Java applications.
<tag name="APPLET" attributes="height,width,align,alt,archive,code,hspace,name,vspace"/> <tag name="AREA" attributes="alt,accesskey,coords,href,$nohref,onblur,onfocus,shape, tabindex,target"/> <tag name="B"/> <tag name="BASE" attributes="href,target"/> <tag name="BASEFONT" attributes="size,color,face,id"/> <tag name="BDO" attributes="dir,id,style,title"/> <tag name="BIG"/> <tag name="BLOCKQUOTE" attributes="cite"/> <tag name="BODY" attributes="bgcolor,background,text,link,vlink,alink,onload,onunload"/> <tag name="BR" attributes="clear" properties="empty"/> <tag name="BUTTON" attributes="accesskey,$disabled,name,onblur,onfocus,tabindex,type,value"/> <tag name="CAPTION" attributes="align"/> <tag name="CENTER,CITE,CODE"/> <tag name="COL" attributes="align,char,charoff,span,valign,width"/> <tag name="COLGROUP" attributes="align,char,charoff,span,valign,width"/> <tag name="DD"/> <tag name="DEL" attributes="cite,datetime"/> <tag name="DFN"/> <tag name="DIR" attributes="$compact"/> <tag name="DIV" attributes="align"/> <tag name="DL" attributes="$compact"/> <tag name="DT,EM,FIELDSET"/> <tag name="FONT" attributes="size,color,face"/> <tag name="FORM" attributes="action,method,enctype,accept-charset, onreset,onsubmit,target,name,id"/> <tag name="FRAME" attributes="frameborder,longdesc,marginheight,marginwidth,$noresize, scrolling,src"/> <tag name="FRAMESET" attributes="cols,onload,onunload,rows"/> <tag name="HEAD" attributes="profile"/> <tag name="H1,H2,H3,H4,H5,H6" attributes="align"/> <tag name="HR" attributes="align,size,width,$noshade,color"/> <tag name="HTML" attributes="version"/> <tag name="I"/>" <tag name="IFRAME" attributes="align,frameborder,height,longdesc,marginheight,marginwidth, 648
Code 39 Extended Generation In Java
Using Barcode creator for Java Control to generate, create Code 3/9 image in Java applications.
Code 3 Of 9 Drawer In Java
Using Barcode encoder for Java Control to generate, create Code 3 of 9 image in Java applications.
name,scrolling,src,width"/> <tag name="IMG" attributes="src,align,hspace,vspace,alt,border,usemap,ismap,width,height"/> <tag name="INPUT" attributes="accept,accesskey,align,alt,$checked, $disabled,maxlength,name,onblur,onchange,onfocus,onselect,$readonly,size, src,tabindex,type,usemap,value"/> <tag name="INS" attributes="cite,datatime"/> <tag name="ISINDEX" attributes="prompt"/> <tag name="KBD"/> <tag name="LABEL" attributes="accesskey,for,onblur,onfocus"/> <tag name="LEGEND" attributes="accesskey,align"/> <tag name="LI" attributes="type,value"/> <tag name="LINK" attributes="href,rel,rev,urn,methods,title,id"/> <tag name="LISTING" properties="preformatted"/> <tag name="MAP" attributes="name"/> <tag name="MENU" attributes="$compact"/> <tag name="META" attributes="name,http-equiv,content"/> <tag name="NEXTID" attributes="n"/> <tag name="NOFRAMES,NOSCRIPT"/> <tag name="OBJECT" attributes="align,archive,border,classid,codebase,codetype,data,$declare, height,hspace,name,standby,tabindex,type,usemap,vspace,width"/> <tag name="OL" attributes="type,start,$compact"/> <tag name="OPTGROUP" attributes="label,$disabled"/> <tag name="OPTION" attributes="$selected,value,$disabled,label"/> <tag name="P" attributes="align"/> <tag name="PARAM" attributes="name,id,type,value,valuetype"/> <tag name="PLAINTEXT,XMP" properties="preformatted"/> <tag name="PRE" attributes="width" properties="preformatted"/> <tag name="Q" attributes="cite"/> <tag name="S,SAMP"/> <tag name="SCRIPT" attributes="type,charset,$defer,language,src, title"/> <tag name="SELECT" attributes="name,size,$multiple,$disabled,onblur,onchange,onfocus, tabindex"/> <tag name="SMALL,STRIKE,STRONG"/> <tag name="STYLE" attributes="type,media,title"/> <tag name="SUB,SUP"/> <!-<tag name="SPAN" attributes="class,id"/> --> 649 <tag name="TABLE"
Make Case Code In Java
Using Barcode creation for Java Control to generate, create EAN / UCC - 14 image in Java applications.
Code 128 Creator In None
Using Barcode creation for Office Excel Control to generate, create Code 128 image in Microsoft Excel applications.
attributes="align,border,width,cellspacing,cellpadding,frame,summary, bgcolor"/> <tag name="TBODY" attributes="align,char,charoff,valign"/> <tag name="TD" attributes="abbr,align,axis,bgcolor,char,charoff, colspan,headers,height,$nowrap,rowspan,scope,valign,width"/> <tag name="TEXTAREA" attributes="cols,rows,accesskey, $disables,name,onblur,onchange,onfocus,onselect,$readonly,tabindex" properties="alwaysClosed"/> <tag name="TFOOT" attributes="align,char,charoff,valign"/> <tag name="TH" attributes="abbr,align,axis,bgcolor,char,charoff,colspan,headers,height, $nowrap,rowspan,scope,valign,width"/> <tag name="THEAD" attributes="align,char,charoff,valign"/> <tag name="TITLE"/> <tag name="TR" attributes="align,bgcolor,char,charoff,valign"/> <tag name="TT,U"/> <tag name="UL" attributes="type,$compact"/> <tag name="VAR"/> </ROOT> Here's the second example: <ROOT> <tag name="WML" attributes="xml:lang"/> <tag name="HEAD"/> <tag name="ACCESS" attributes="domain,path"/> <tag name="META" attributes="http-equiv,name,forua,content,scheme"/> <tag name="TEMPLATE" attributes="onenterforward,onenterbackward,ontimer"/> <tag name="CARD" attributes="onenterforward,onenterbackward,ontimer,title,newcontext, ordered,xml:lang,id"/> <tag name="SELECT" attributes="multiple,name,value,iname,ivalue, title,tabindex,xml:lang"/> <tag name="OPTION" attributes="value,title,onpick,xml:lang"/> <tag name="OPTGROUP" attributes="title,xml:lang"/> <tag name="INPUT" attributes="name,value,type,format,emptyok,size, maxlength,title,xml:lang,tabindex,accesskey" properties="empty"/> <tag name="FIELDSET" attributes="title,xml:lang"/> <tag name="TIMER" attributes="name,value"/> <tag name="EM,STRONG,I,B,U,BIG,SMALL" attributes="xml:lang"/> <tag name="P" attributes="align,mode,xml:lang"/> <tag name="BR" properties="empty"/> 650
USS Code 39 Scanner In Visual Basic .NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in VS .NET applications.
Encode UPCA In Objective-C
Using Barcode generation for iPhone Control to generate, create UCC - 12 image in iPhone applications.
<tag name="TABLE" attributes="title,align,columns,xml:lang"/> <tag name="TR"/> <tag name="TD" attributes="xml:lang"/> <tag name="PRE" attributes="xml:space" properties="preformatted"/> <tag name="IMG" attributes="alt,src,localsrc,vspace,hspace, align,height,width,xml:lang"/> <tag name="POSTFIELD,SETVAR" attributes="name,value" properties="empty"/> <tag name="GO" attributes="href,sendreferer,method,enctype,accept-charset"/> <tag name="PREV,REFRESH,NOOP"/> <tag name="DO" attributes="type,label,name,optional,xml:lang"/> <tag name="ANCHOR" attributes="title,accesskey,xml:lang"/> <tag name="A" attributes="href,title,accesskey,xml:lang"/> <tag name="ONEVENT" attributes="type"/> </ROOT> After the handler is ready, it is set into an instance variable of the parser Then the parse method is called and the parser starts doing its job An example of a parser is shown here: public class SimpleParser extends TranscoderParserImpl { protected SimpleLexer lexer = new SimpleLexer(); public void parse (InputStream stream) throws Exception { lexerreset(stream); documentHandlerstartDocument(); while (lexernextToken() != lexerTOKEN_EOF) { int type = lexergetTokenType(); if(lexermWhiteSpacecount != 0) { documentHandlercharacters( lexermWhiteSpacedata,0,lexermWhiteSpacecount); } switch(type) { case lexerTOKEN_TAG: TagInfo tag = lexermCurrentTag; if(tagisEndTag()) { documentHandlerendElement(tagmName); break; } attributeListclear(); 651
Draw Barcode In .NET
Using Barcode creation for Reporting Service Control to generate, create bar code image in Reporting Service applications.
Encoding Bar Code In None
Using Barcode drawer for Online Control to generate, create barcode image in Online applications.
for(int i = 0; i < tagparameterCount(); i++) { attributeListaddAttribute( taggetParameterName(i), null,taggetParameterValue(i)); } documentHandlerstartElement(tagmName,attributeList); if(tagisStartEndTag()) { documentHandlerendElement(tagmName); } break; case lexerTOKEN_SCRIPT: case lexerTOKEN_TEXT: if(lexermBuffercount != 0) { documentHandlercharacters(lexermBufferdata,0, lexermBuffercount); } break; case lexerTOKEN_COMMENT: if(lexermBuffercount != 0) { commentHandlercomment(lexermBuffertoString()); } } } documentHandlerendDocument(); } public void setXmlTags(boolean flag) { } } SimpleParser class that inherits from the class TrancoderParserImpl shown here: public abstract class TranscoderParserImpl implements TranscoderParser { protected DocumentHandler documentHandler; protected ErrorHandler errorHandler; protected AttributeListImpl attributeList; protected CommentHandler commentHandler; public TranscoderParserImpl() { attributeList = new AttributeListImpl(); 652
Recognize GS1-128 In Visual Basic .NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in VS .NET applications.
Code 128A Generator In Visual Studio .NET
Using Barcode generator for Reporting Service Control to generate, create Code 128 image in Reporting Service applications.
} public void parse (String systemId) throws SAXException, IOException { try { parse(new FileInputStream(systemId)); } catch (Exception e) { if(e instanceof IOException) { throw (IOException)e; } } } public void parse (InputSource src) throws SAXException, IOException { try { parse(srcgetByteStream()); } catch (Exception e) { if(e instanceof IOException) { throw (IOException)e; } } } public void setCommentHand ler(CommentHandler commentHandler) { thiscommentHandler = commentHandler; } public void setDocumentHandler (DocumentHandler handler) { documentHandler = handler; } public void setDTDHandler (DTDHandler handler) { } public void setEntityResolve r (EntityResolver resolver) { } public void setErrorHandler (ErrorHandler handler) { errorHandler = handler; } public void setLocale(javautilLocale locale) throws SAXException { } } This class forms the root of the transcoder parser hierarchy but is never meant to be instantiated because, as its code shows, it will do very little This base class implements the TranscoderParser, which itself extends the orgxmlsaxParser interface: 653
public interface TranscoderParser extends orgxmlsaxParser { public void parse (InputStream is) throws Exception; public void setCommentHandler(CommentHandler commentHandler); public void setXmlTags(boolean isXml); } Now things are starting to become clearer; the transcoder is based on the notion of parsing through events that is, SAX It has handlers that (through the parsers) register for events and manipulate the code If we look at the implementation of the parse method in the SimpleParser, we can see that it uses a "lexer" object to recognize tokens Based on whether the token recognized is a tag, script, or text, it will perform different tasks but always through the handler object (that's where all the intelligence resides)
Summary This chapter provided two examples on how XML can be used w ithin applications These examples are just a tip of the iceberg; the use of XML within applications is proving itself to be extremely valuable The crux of its applicability is its dynamic and hierarchical nature Most data structures in computer science are hierarchical With time, the parsers and tolls for manipulating and using XML are becoming fast, standard, and of high quality This brings with it the widespread use of XML for pretty much anything you can think of This is only natural once you get the hang of using these libraries, you will start to come back to using XML for anything that has to do with hierarchical, recursive, dynamic, or pretty much any kind of data structure manipulation
36: Application of XSL Transformations Overview The central role that the Extensible Markup Language (XML) is beginning to play in ebusiness applications is augmented by the capabilities of XSL Transformations (XSLT), a subset of the Extensible Stylesheet Language (XSL) that defines how transformations from one XML dialect to another can be phrased XSLT is of fundamental importance to the success of XML in e-business applications Because different systems and different Web sites ultimately end up with different XML structures, the ability to exchange information by bridging over semantic mismatching is perhaps the primary factor that will determine the success or failure of XML You achieve this bridging by defining conversion rules in the form of XML transformations This chapter focuses on two aspects of XSLT processing First, it shows how XSL stylesheets are used to process an XML document Then it shows you how the Java code used in a generic XSLT processor as part of an interface layer that accepts data in any XML format converts the data into a native XML format that the application can understand More Insider Trading This section continues with the insider trading example from 35 to describe how XSLT is used for processing XML documents as part of an e-business application This example uses LotusXSL, which is included in the WebSphere libraries Removing Errors In 35, we created an XML file with a listing of insider buyers Unfortunately, the file is huge (at almost 2MB) and difficult to sift through It is also not quite in the format most useful to a typical user In this and the followi ng sections, we provide a few XSLT examples that show how you can process the data until you get the format and content just right The first thing we'll do is strip out useless data, such as XML nodes of any stock for which the insiderPurchase node has an error attribute (see Figure 36-1) The error attribute is generated whenever the parsing of node traversal fails in the insider trading program Because such nodes contain no information, we can start by removing them
Figure 36-1: The error attribute in insiderPurchase node The following code shows a processing instruction, a document root, and the XSLT rules required for removing these nodes: < xml version="10" > <xsl:stylesheet xmlns:xsl="http://wwww3org/XSL/Transform/10"> <xsl:template match="/"> <insiderTrading example="1"> <xsl:apply-templates/> </insiderTrading> </xsl:template> <xsl:template match="insiderTrading/*"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="insiderPurchase[not(@error)]"> <insiderPurchase date="{@date}" price="{@price}"/> </xsl:template> </xsl:stylesheet> 656
Every XSLT file is also an XML file; therefore every XSLT file contains a processing instruction defining the XML version, followed by a single document root The document root is an element of type <xsl:stylesheet>, and all the other elements are embedded within this root element The root element contains a namespace attribute that defines the uniform resource identifier (URI) to be used for all elements that belong to the XSL namespace Because the syntax and semantics of XSLT rules are nontrivial (to say the least), we will go over each rule in detail and provide explanation as much as possible along the way The document in our example has three rules Each rule supplies a pattern for the XSLT processor to attempt to match and indicates the nodes to be processed once the pattern has been matched The first rule in the file matches the root node, designated by a slash (/), of the source XML file The second rule matches any node that is a direct descendant of the insiderTrading node The syntax of the pattern-matching rules is similar to directory structures in UNIX The third and final rule matches any insiderPurchase node that does not have an error attribute In XSL, an attribute is designated by a preceding "at" symbol (@) Therefore, the pattern-match definition of the third rule should be read as "all insiderPurchase nodes such that there does not exist an attribute by the name of error" The processing parts of the rules are fairly simple For the root node, we create an XML element called insiderTrading with a single attribute called example This element will form the root element in the resulting XML Then we apply all rules for the rest of the document from the source file The processing for the stock nodes is the easiest task We simply copy the nodes over and continue processing the children Finally, whenever we get to a purchase node that is not an error, we create an appropriate node in the output Note that the syntax surrounds a calculated value embedded in a string with curly brackets Removing Symbols That Have No Insider Purchasers Now we've managed to write our first XSLT file, and the file size is down to 1316KB from 1942KB but we can do better There are plenty of nodes with no inside trades at all (you know, companies that follow the rules), and we can get rid of those, too We need only make a small change to the pattern match of the second rule by stating that the rule is satisfied only for nodes that are child nodes of the insiderTrading nodes and have at least one insiderPurchase node: < xml version="10" > <xsl:stylesheet xmlns:xsl="http://wwww3org/XSL/Transform/10"> <xsl:template match="/"> <insiderTrading example="2"> <xsl:apply-templates/> </insiderTrading> </xsl:template> <xsl:template match="insiderTrading/*[insiderPurchase]"> <xsl:copy> <xsl:apply-templates/> 657
</xsl:copy> </xsl:template> <xsl:template match="insiderPurchase[not(@error)]"> <insiderPurchase date="{@date}" price="{@price}"/> </xsl:template> </xsl:stylesheet> Removing Nodes That Have No Prices That worked, but it didn't help much we're only down to 1306KB Now let's get rid of the nodes with no prices; if we don't know at what price the insider purchased the stock, we can't really tell whether the current price is high or low The following XSLT file brings our file size down to 1148KB: < xml version="10" > <xsl:stylesheet xmlns:xsl="http://wwww3org/XSL/Transform/10"> <xsl:template match="/"> <insiderTrading example="3"> <xsl:apply-templates/> </insiderTrading> </xsl:template> <xsl:template match="insiderTrading/*[insiderPurchase]"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="insiderPurchase[not(@price='-')]"> <insiderPurchase date="{@date}" price="{@price}"/> </xsl:template> </xsl:stylesheet> Sorting That's enough for cutting down the size The next step is to look at sorting In the following example, we sort the values by price For each stock symbol, we want the inside trades to be listed with the price values determining the order; after all, we want the lowest possible price, so we might as well compare the current price to the lowest price purchased by insiders The following sheet shows the XSLT file performing the sort Note that the sort element has an optional data-type attribute for specifying 658
how sorting should be performed In our case, we do not want an alphanumeric sort; otherwise, a price of 10 will appear before a price of 3 < xml version="10" > <xsl:stylesheet xmlns:xsl="http://wwww3org/XSL/Transform/10"> <xsl:template match="/"> <insiderTrading example="4"> <xsl:apply-templates/> </insiderTrading> </xsl:template> <xsl:template match="insiderTrading/*[insiderPurchase]"> <xsl:copy> <xsl:apply-templates select="insiderPurchase"> <xsl:sort select="@price" data-type="number"/> </xsl:apply-templates> </xsl:copy> </xsl:template> <xsl:template match="insiderPurchase"> <insiderPurchase date="{@date}" price="{@price}"/> </xsl:template> </xsl:stylesheet> Transforming the XML Document to HTML The next step is a useful one that will be practical for e-business applications We want to transform the XML file into an HTML document that will display all data in a table Sounds simple and it should be As things stand, however, there is a big problem We cannot get the value of the actual tag in XSL because in XML, the stock symbols are tags instead of data This is an important lesson, so we hope that after reading this chapter you will remember never to use data as tags To complete the program, we need to change the code of the servlet created in 35, as shown here: public static void main(String[] args) { InsiderInspector gen = new InsiderInspector(); comibmxmlparserTXDocument myDocument = new comibmxmlparserTXDocument(); try { 659
ProcessingInstruction pi = myDocument createProcessingInstruction(" xml","version=\"10 \""); myDocumentappendChild(pi); Element root = myDocumentcreateElement("insiderTrading"); rootsetAttribute("asOf", (new Date())toString()); myDocumentappendChild(root); Vector symbolVector = genretrieveAllSymbols(); for (Enumeration e = symbolVectorelements() ; ehasMoreElements() ; ) { String aSymbol = (String)enextElement(); StringBuffer htmlText = HTMLFetchergetHTMLFor( "http://bizyahoocom/t/" + aSymbolsubstring(0,1) + "/" + aSymbol + "html"); StringBuffer aBuf = HTMLTidiertidyHTML(htmlText); if (aBuf != null) { Element symbolRoot = myDocumentcreateElement("stock"); symbolRootsetAttribute("symbol",aSymbol); rootappendChild(symbolRoot); genextractInsiderInfo(aBuf, myDocument, symbolRoot); Systemerrprintln("Finished processing " + aSymbol); } } FileWriter fw = new FileWriter("insiderTradingxml"); myDocumenttoXMLString(fw); fwclose(); } catch (Exception ex) { exprintStackTrace(); } } Now when we rerun the XML generation code, we can change our XML source to look like Figure 36-2 This allows us to use the following XSLT code to produce the end result shown in Figure 36-3
Copyright © OnBarcode.com . All rights reserved.