New company, new study

Source: Internet
Author: User
Tags aop xml parser xslt xslt processor

there will always be a lot of things that you haven't been exposed to before in a new company. This means that every company will learn a lot of things.

I am no exception, recently just changed a job.

I am the project manager of the home company, I have to do everything to this company.

requirements, Design aspects: The content of the document is written differently.

Technical aspects:

cglib: I used to know only cglib, but I never used him to write code.

Cglib is an open source project.

is a powerful, high-performance, high-quality code generation Class Library, which can extend Java classes and implement Java interfaces during runtime. Hibernate uses it to realize the dynamic generation of PO byte code.

Introduction to Cglib Package

The agent provides a way to control the target object to be accessed. When an object is accessed, it introduces an indirect layer. Since the 1.3 release, the JDK has introduced dynamic proxies and is often used to dynamically create proxies. The JDK's dynamic proxy is very simple to use, and when it has a limitation, the object that uses the dynamic proxy must implement one or more interfaces. What to do if you want the proxy to have an inherited class that does not implement the interface. Now we can use the Cglib package

Cglib is a powerful, High-performance code generation package. It is widely used by many AOP frameworks, such as spring AOP and DYNAOP, to provide them with a method of interception (interception). The most popular or mapping tool hibernate also uses Cglib to broker single end single-ended (Many-to-many and one-to-one) associations (deferred fetching of collections, which are implemented by other mechanisms). Easymock and Jmock are packages that test Java code by using a mock (Moke) object. They all create mock (Moke) objects for classes that do not have interfaces by using Cglib.

The bottom of the Cglib package is to convert bytecode and generate new classes by using a small, fast bytecode to process the framework ASM. In addition to cglib packages, scripting languages such as groovy and BeanShell also use ASM to generate Java-bytecode. When you do not encourage direct use of ASM because it requires you to be familiar with the internal structure of the JVM including the format and instruction set of the class file.

JAXP: I used to be using Jdom, sax.

JAXP is the acronym for the Java API for XML processing, which is a programming interface written in the Java language for XML document processing. JAXP supports standards such as DOM, SAX, and XSLT. To enhance the flexibility of JAXP usage, the developer specifically designed a pluggability Layer for JAXP, with the support of Pluggability Layer, which allows JAXP to implement both the DOM API and the various XML parsers of the SAX API ( XML Parser, such as the Apache Xerces, work together and work together with XSLT processors that perform XSLT standards (XSLT Processor, such as Apache Xalan). It's the official sun bag.

JAXB: conversion between XML and objects. I used to write the mapping code myself. There are tools handy now.

JAXB (Java architecture for XML Binding) is an industry standard and is a technology that can generate Java classes from XML schemas. In this process, JAXB also provides a way to reverse-generate the XML instance documents to the Java object Tree and to write the contents of the Java object Tree back to the XML instance document. On the other hand, JAXB provides a quick and easy way to bind XML schemas to Java representations, making it easy for Java developers to combine XML data with processing functions in Java applications.

Netty: Open Source Network package for non-blocking, short, long connection network services programming. Code based on TCP/IP and UDP was previously written only with a class written in the. NET package in the Java API.

Netty is a Java open source framework provided by JBoss. Netty provides asynchronous, event-driven network application frameworks and tools for rapid development of high-performance, highly reliable network servers and client programs.

In other words, Netty is a NIO based client, server-side programming framework that uses Netty to ensure that you quickly and easily develop a network application, such as a client that implements some kind of protocol, a service-side application. Netty fairly simplifies and streamlines the programming of network applications, such as the development of socket services for TCP and UDP.

"Fast" and "simple" do not mean that your final application will have a maintenance or performance problem. Netty is an implementation experience that absorbs a variety of protocols, including Ftp,smpt,http, a variety of binary, text protocols, and a fairly well-designed project, and ultimately, Netty successfully found a way to ensure easy development while ensuring its application performance, Stability and scalability.

Network Architecture Optimization:

The use of cluster technology, the use of related software and hardware, this is not yet familiar with.

Was under the configuration cluster, this has not been matched before.

in a word here will be exposed to a lot of things, but also their knowledge is expanding, at the same time can only sigh technology is too much, learn also learn, sometimes just want to pursue the underlying principle, so as to faster understanding of other people's high-level things.

The following is garbled or Chinese question:

When Sax parses an RSS XML file, it encounters a not well-formed error--the edited document is not audited
Because Sax is a trigger-parsing XML stream, it is widely used in handheld devices. In Android's application development, it is natural to choose Sax to parse XML.
In making an RSS application, you have encountered a not well-formed error when parsing a baidu.com rss file. After querying the relevant data and constantly debug and log, finally determined that the file encoding encountered a problem.
I would like to say some of my understanding, if there are errors please leave a message
First, the domestic information content providers use the same RSS encoding of NetEase use gb2312, Sina Utf-8, Baidu GBK and so on.
1. When the URL request Rss.xml, through the OpenStream will return a InputStream byte stream object, the byte stream itself is not with encoded information.
(Ps. Why do you say the first 3 bytes of the byte stream, save the encoded information?) I passed the array of tests BYTE[3], which could not match the UTF8 byte array ( -17,-69,-65) whether it was UTF8 encoded or not.
2. After the word throttling, it is usually possible to directly use the InputStream object to generate a InputSource object, to SAXParser or XmlReader to parse. By default, the InputSource object that parser resolves is encoded in UTF8 encoding, so UTF8 encoded XML file parsing is normal without any processing.
3. When you encounter GBK, or gb2312 encoding, parsing ANSI characters is no problem, when parsing to Chinese, parser is resolved by the default UTF8 encoding, UTF8 is allocated 3 bytes per character, gb2312 is allocated two bytes, is bound to cause errors. At this time also reported the not well-formed error.
It was noted that InputSource had a setencoding method to tell Sarpar what encoding to use to parse the InputStream, and you could set up a GBK to parse the stream, but the resource file's encoding was UTF8, And you use GBK to parse clearly is not consistent.
4. Setencoding will not convert the encoding, just tell Sarpar how to parse, then encounter the XML encoding is GBK gb2312, you can use the InputStreamReader way,
InputStreamReader (InputStream, CharsetName) to specify a stream of coded-generated characters. There is obviously a coded conversion happening here.
And then pass the character stream object to the InputSource object, which is not setencoding when it accepts the character stream, and the reason is very simple, the character stream is encoded information, still not trust can again setencoding, (but invalid)
5. So as long as through the identification of the file encoding, and then tell Sarpar how to resolve, the program can be implemented normally.
Identification of the byte stream encoding method can be Google query a number of methods, commonly used by the Mozilla provided by an open source tool to identify. The latest is: cpdetector_1.0.8 can be downloaded to the SourceForge.
Key code:

View Code JAVA1

Xmlcontenthandler handler = new Xmlcontenthandler ();
XMLReader reader = null;
InputSource is = null;
try{
URL url = new URL (w163);
SAXParserFactory parserfactory = Saxparserfactory.newinstance ();
SAXParser saxparser = Parserfactory.newsaxparser ();
if (!isutf8 (URL)) {
InputStream stream = Url.openstream ();
InputStreamReader StreamReader = new InputStreamReader (stream, "GBK");
is = new InputSource (StreamReader);
}else{
is = new InputSource (Url.openstream ());
Is.setencoding ("UTF-8");
}
reader = Saxparser.getxmlreader ();
Reader.setcontenthandler (handler);
}catch (Exception e) {
LOG.E (TAG, "Exception Updaterss ()");
}
try {
Reader.parse (IS);
catch (IOException e) {
E.printstacktrace ();
catch (Saxexception e) {
LOG.E (TAG, E.getmessage ());
}


The isUTF8 is through the Mozilla jar package to implement, can refer to the Cpdetector use method of related articles specifically.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.