本文整理汇总了Java中org.fit.cssbox.css.DOMAnalyzer.getStyleSheets方法的典型用法代码示例。如果您正苦于以下问题:Java DOMAnalyzer.getStyleSheets方法的具体用法?Java DOMAnalyzer.getStyleSheets怎么用?Java DOMAnalyzer.getStyleSheets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.fit.cssbox.css.DOMAnalyzer
的用法示例。
在下文中一共展示了DOMAnalyzer.getStyleSheets方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: analyze
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
@Override
public ElementBox analyze(DocumentSource docSource, Dimension dim)
throws Exception
{
DOMSource parser = new DefaultDOMSource(docSource);
w3cdoc = parser.parse();
// Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(w3cdoc, docSource.getURL());
da.attributesToStyles();
da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT);
da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT);
da.getStyleSheets();
BufferedImage tmpImg = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
canvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
canvas.setImage(tmpImg);
canvas.getConfig().setLoadImages(true);
canvas.getConfig().setLoadBackgroundImages(true);
canvas.createLayout(dim);
return canvas.getViewport();
}
示例2: StyleImport
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
public StyleImport(String urlstring) throws IOException, SAXException
{
//Open the network connection
DocumentSource docSource = new DefaultDocumentSource(urlstring);
//Parse the input document
DOMSource parser = new DefaultDOMSource(docSource);
doc = parser.parse();
//Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
da.getStyleSheets(); //load the author style sheets
da.localizeStyles(); //put the style sheets into the document header
docSource.close();
}
示例3: main
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
/**
* @param args the command line arguments
*/
public static void main(String args[])
{
if (args.length != 1)
{
System.err.println("Usage: SimpleBrowser <url>");
System.exit(0);
}
try {
//Open the network connection
DocumentSource docSource = new DefaultDocumentSource(args[0]);
//Parse the input document
DOMSource parser = new DefaultDOMSource(docSource);
Document doc = parser.parse();
//Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
da.addStyleSheet(null, CSSNorm.formsStyleSheet(), DOMAnalyzer.Origin.AGENT); //render form fields using css
da.getStyleSheets(); //load the author style sheets
//Display the result
SimpleBrowser test = new SimpleBrowser(da.getRoot(), docSource.getURL(), da);
test.setSize(1275, 750);
test.setVisible(true);
docSource.close();
} catch (Exception e) {
System.out.println("Error: "+e.getMessage());
e.printStackTrace();
}
}
示例4: renderDocument
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
private BufferedImage renderDocument(Document doc)
{
//create the media specification
MediaSpec media = new MediaSpec(mediaType);
media.setDimensions(windowSize.width, windowSize.height);
media.setDeviceDimensions(windowSize.width, windowSize.height);
//Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
da.setMediaSpec(media);
da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
da.addStyleSheet(null, CSSNorm.formsStyleSheet(), DOMAnalyzer.Origin.AGENT); //render form fields using css
da.getStyleSheets(); //load the author style sheets
BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
contentCanvas.setAutoMediaUpdate(false); //we have a correct media specification, do not update
contentCanvas.getConfig().setClipViewport(cropWindow);
contentCanvas.getConfig().setLoadImages(loadImages);
contentCanvas.getConfig().setLoadBackgroundImages(loadBackgroundImages);
contentCanvas.createLayout(windowSize);
return contentCanvas.getImage();
}
示例5: createDecoder
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
private void createDecoder()
{
decoder = new DOMAnalyzer(doc, base);
if (encoding == null)
encoding = decoder.getCharacterEncoding();
decoder.setDefaultEncoding(encoding);
decoder.attributesToStyles();
decoder.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT);
decoder.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT);
decoder.getStyleSheets();
}
示例6: analyze
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
@Override
public Viewport analyze(DocumentSource docSource, Dimension dim)
throws Exception
{
DOMSource parser = new DefaultDOMSource(docSource);
w3cdoc = parser.parse();
// Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(w3cdoc, docSource.getURL());
da.attributesToStyles();
da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT);
da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT);
da.getStyleSheets();
BufferedImage tmpImg = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
canvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
canvas.setImage(tmpImg);
canvas.getConfig().setLoadImages(true);
canvas.getConfig().setLoadBackgroundImages(true);
canvas.createLayout(dim);
return canvas.getViewport();
}
示例7: main
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
/**
* @param args the command line arguments
*/
public static void main(String args[])
{
if (args.length != 1)
{
System.err.println("Usage: SimpleBrowser <url>");
System.exit(0);
}
try {
//Open the network connection
DocumentSource docSource = new DefaultDocumentSource(args[0]);
//Parse the input document
DOMSource parser = new DefaultDOMSource(docSource);
Document doc = parser.parse();
//Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
da.getStyleSheets(); //load the author style sheets
//Display the result
SimpleBrowser test = new SimpleBrowser(da.getRoot(), docSource.getURL(), da);
test.setSize(1275, 750);
test.setVisible(true);
docSource.close();
} catch (Exception e) {
System.out.println("Error: "+e.getMessage());
e.printStackTrace();
}
}
示例8: analyze
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
@Override
public Viewport analyze(DocumentSource d, Dimension dim)
throws Exception
{
@SuppressWarnings("resource")
InputStream is = (d != null)? d.getInputStream() : null;
if (!(is instanceof DocumentInputStream)) {
return super.analyze(d, dim);
}
DocumentInputStream dIs = (DocumentInputStream) is;
w3cdoc = dIs.getDocument();
URL address = ((Html5DocumentImpl)w3cdoc).getAddress();
// Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(w3cdoc, address);
da.attributesToStyles();
da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT);
da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT);
da.getStyleSheets();
BufferedImage tmpImg = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
canvas = new BrowserCanvas(da.getRoot(), da, address);
canvas.setImage(tmpImg);
canvas.getConfig().setLoadImages(true);
canvas.getConfig().setLoadBackgroundImages(true);
canvas.createLayout(dim);
return canvas.getViewport();
}
示例9: applyEffectiveStylesToStyleAttributes
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
private static void applyEffectiveStylesToStyleAttributes(final Document doc, final URL relativeUrl) {
DOMAnalyzer da = new DOMAnalyzer(doc, relativeUrl);
da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
da.getStyleSheets(); //load the author style sheets
da.stylesToDomInherited();
}
示例10: main
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args)
{
if (args.length != 2)
{
System.err.println("Usage: ComputeStyles <url> <output_file>");
System.exit(0);
}
try {
//Open the network connection
DocumentSource docSource = new DefaultDocumentSource(args[0]);
//Parse the input document
DOMSource parser = new DefaultDOMSource(docSource);
Document doc = parser.parse();
//Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
da.getStyleSheets(); //load the author style sheets
//Compute the styles
System.err.println("Computing style...");
da.stylesToDomInherited();
//Save the output
PrintStream os = new PrintStream(new FileOutputStream(args[1]));
Output out = new NormalOutput(doc);
out.dumpTo(os);
os.close();
docSource.close();
System.err.println("Done.");
} catch (Exception e) {
System.err.println("Error: "+e.getMessage());
e.printStackTrace();
}
}
示例11: main
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
/**
* main method
*/
public static void main(String[] args)
{
if (args.length != 1)
{
System.err.println("Usage: TextBoxes <url>");
System.exit(0);
}
try {
//Open the network connection
DocumentSource docSource = new DefaultDocumentSource(args[0]);
//Parse the input document
DOMSource parser = new DefaultDOMSource(docSource);
Document doc = parser.parse();
//Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
da.getStyleSheets(); //load the author style sheets
//Create the browser canvas
BrowserCanvas browser = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
//Disable the image loading
browser.getConfig().setLoadImages(false);
browser.getConfig().setLoadBackgroundImages(false);
//Create the layout for 1000x600 pixels
browser.createLayout(new java.awt.Dimension(1000, 600));
//Display the result
printTextBoxes(browser.getViewport());
docSource.close();
} catch (Exception e) {
System.err.println("Error: "+e.getMessage());
e.printStackTrace();
}
}
示例12: renderURL
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
/**
* Renders the URL and prints the result to the specified output stream in the specified
* format.
* @param urlstring the source URL
* @param out output stream
* @param type output type
* @return true in case of success, false otherwise
* @throws SAXException
*/
public boolean renderURL(String urlstring, OutputStream out, Type type, String pageFormat) throws IOException, SAXException
{
if (!urlstring.startsWith("http:") &&
!urlstring.startsWith("ftp:") &&
!urlstring.startsWith("file:"))
urlstring = "http://" + urlstring;
//Open the network connection
DocumentSource docSource = new DefaultDocumentSource(urlstring);
//Parse the input document
DOMSource parser = new DefaultDOMSource(docSource);
Document doc = parser.parse();
//create the media specification
MediaSpec media = new MediaSpec(mediaType);
media.setDimensions(windowSize.width, windowSize.height);
media.setDeviceDimensions(windowSize.width, windowSize.height);
//Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
da.setMediaSpec(media);
da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
da.addStyleSheet(null, CSSNorm.formsStyleSheet(), DOMAnalyzer.Origin.AGENT); //render form fields using css
da.getStyleSheets(); //load the author style sheets
BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
contentCanvas.setAutoMediaUpdate(false); //we have a correct media specification, do not update
contentCanvas.getConfig().setClipViewport(cropWindow);
contentCanvas.getConfig().setLoadImages(loadImages);
contentCanvas.getConfig().setLoadBackgroundImages(loadBackgroundImages);
if (type == Type.PNG)
{
contentCanvas.createLayout(windowSize);
ImageIO.write(contentCanvas.getImage(), "png", out);
}
else if (type == Type.SVG)
{
setDefaultFonts(contentCanvas.getConfig());
contentCanvas.createLayout(windowSize);
Writer w = new OutputStreamWriter(out, "utf-8");
writeSVG(contentCanvas.getViewport(), w);
w.close();
}
else if (type == Type.PDF)
{
setDefaultFonts(contentCanvas.getConfig());
contentCanvas.createLayout(windowSize);
writePDF(contentCanvas.getViewport(), out, pageFormat);
}
docSource.close();
return true;
}
示例13: renderURL
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
/**
* Renders the URL and prints the result to the specified output stream in
* the specified format.
*
* @param urlstring
* the source URL
* @param out
* output stream
* @param type
* output type
* @return true in case of success, false otherwise
* @throws SAXException
*/
private boolean renderURL(URL urlstring, URL baseUrl, OutputStream out)
throws IOException, SAXException {
// Open the network connection
DocumentSource docSource = new DefaultDocumentSource(urlstring);
// Parse the input document
DOMSource parser = new DefaultDOMSource(docSource);
Document doc = parser.parse();
// create the media specification
MediaSpec media = new MediaSpec(mediaType);
media.setDimensions(windowSize.width, windowSize.height);
media.setDeviceDimensions(windowSize.width, windowSize.height);
// Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(doc, baseUrl);
da.setMediaSpec(media);
da.attributesToStyles(); // convert the HTML presentation attributes to
// inline styles
da.addStyleSheet(baseUrl, CSSNorm.stdStyleSheet(),
DOMAnalyzer.Origin.AGENT); // use the standard style sheet
da.addStyleSheet(null, CSSNorm.userStyleSheet(),
DOMAnalyzer.Origin.AGENT); // use the additional style sheet
da.addStyleSheet(null, CSSNorm.formsStyleSheet(),
DOMAnalyzer.Origin.AGENT); // render form fields using css
da.getStyleSheets(); // load the author style sheets
BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da,
baseUrl);
// contentCanvas.setAutoMediaUpdate(false); // we have a correct media
// // specification, do not
// // update
contentCanvas.getConfig().setClipViewport(cropWindow);
contentCanvas.getConfig().setLoadImages(loadImages);
contentCanvas.getConfig().setLoadBackgroundImages(loadBackgroundImages);
contentCanvas.setPreferredSize(new Dimension(windowSize.width, 10));
contentCanvas.setAutoSizeUpdate(true);
setDefaultFonts(contentCanvas.getConfig());
contentCanvas.createLayout(windowSize);
contentCanvas.validate();
ImageIO.write(contentCanvas.getImage(), "png", out);
// Image image = contentCanvas.createImage(windowSize.width,
// windowSize.height);
docSource.close();
return true;
}
示例14: renderURL
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
/**
* Renders the URL and prints the result to the specified output stream in the specified
* format.
* @param urlstring the source URL
* @param out output stream
* @param type output type
* @return true in case of success, false otherwise
* @throws SAXException
*/
public boolean renderURL(String urlstring, OutputStream out, Type type) throws IOException, SAXException
{
if (!urlstring.startsWith("http:") &&
!urlstring.startsWith("https:") &&
!urlstring.startsWith("ftp:") &&
!urlstring.startsWith("file:"))
urlstring = "http://" + urlstring;
//Open the network connection
DocumentSource docSource = new DefaultDocumentSource(urlstring);
//Parse the input document
DOMSource parser = new DefaultDOMSource(docSource);
Document doc = parser.parse();
//create the media specification
MediaSpec media = new MediaSpec(mediaType);
media.setDimensions(windowSize.width, windowSize.height);
media.setDeviceDimensions(windowSize.width, windowSize.height);
//Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
da.setMediaSpec(media);
da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
da.addStyleSheet(null, CSSNorm.formsStyleSheet(), DOMAnalyzer.Origin.AGENT); //render form fields using css
da.getStyleSheets(); //load the author style sheets
BrowserCanvas contentCanvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
contentCanvas.setAutoMediaUpdate(false); //we have a correct media specification, do not update
contentCanvas.getConfig().setClipViewport(cropWindow);
contentCanvas.getConfig().setLoadImages(loadImages);
contentCanvas.getConfig().setLoadBackgroundImages(loadBackgroundImages);
if (type == Type.PNG)
{
contentCanvas.createLayout(windowSize);
ImageIO.write(contentCanvas.getImage(), "png", out);
}
else if (type == Type.SVG)
{
setDefaultFonts(contentCanvas.getConfig());
contentCanvas.createLayout(windowSize);
Writer w = new OutputStreamWriter(out, "utf-8");
writeSVG(contentCanvas.getViewport(), w);
w.close();
}
docSource.close();
return true;
}
示例15: main
import org.fit.cssbox.css.DOMAnalyzer; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args)
{
if (args.length != 2)
{
System.err.println("Usage: ComputeStyles <url> <output_file>");
System.exit(0);
}
try {
//Open the network connection
DocumentSource docSource = new DefaultDocumentSource(args[0]);
//Parse the input document
DOMSource parser = new DefaultDOMSource(docSource);
Document doc = parser.parse();
//Create the CSS analyzer
DOMAnalyzer da = new DOMAnalyzer(doc, docSource.getURL());
da.attributesToStyles(); //convert the HTML presentation attributes to inline styles
da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the standard style sheet
da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT); //use the additional style sheet
da.getStyleSheets(); //load the author style sheets
//Compute the styles
System.err.println("Computing style...");
da.stylesToDomInherited();
//Save the output
OutputStream os = new FileOutputStream(args[1]);
Output out = new NormalOutput(doc);
out.dumpTo(os);
os.close();
docSource.close();
System.err.println("Done.");
} catch (Exception e) {
System.err.println("Error: "+e.getMessage());
e.printStackTrace();
}
}