आप CSSBox कोशिश कर सकते हैं। पैकेज में निहित कंप्यूट स्टाइल डेमो पर एक नज़र डालें (डेमो चलाने के बारे में जानकारी के लिए वितरण पैकेज में दस्तावेज़/उदाहरण/README फ़ाइल देखें)। यह सभी शैलियों की गणना करता है और संबंधित इनलाइन शैली परिभाषाओं के साथ एक नया HTML दस्तावेज़ (एक डोम द्वारा प्रतिनिधित्व) बनाता है।
स्रोत src/org/fit/cssbox/डेमो/ComputeStyles.java में है और यह बहुत छोटा है। असल में, यह मुख्य नौकरी करने के लिए jStyleParser का उपयोग करता है, सीएसएसबॉक्स सिर्फ इसके लिए एक अच्छा इंटरफ़ेस प्रदान करता है।
//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();
एएके! यह AppEngine में काम नहीं करता है! आपको Google पर अभिशाप! – Chloe
@radkovo स्रोत को स्ट्रिंग इनपुट = " ..." (URL के बजाय) में इस उदाहरण को कैसे संशोधित किया जाएगा? अच्छा काम बीटीडब्ल्यू! – athspk
@athspk आपको अपना खुद का दस्तावेज़ स्रोत कार्यान्वयन लिखना होगा जो किसी URL की बजाय स्ट्रिंग से इनपुट स्ट्रीम बनाता है। यह काफी सरल होना चाहिए, बस मूल DefaultDocumentSource कार्यान्वयन पर एक नज़र डालें। [यहां] (http://stackoverflow.com/questions/247161/how-do-i-turn-a-string-into-a-stream-in-java) आप स्ट्रिंग से इनपुट स्ट्रीम कैसे बना सकते हैं । – radkovo