本文整理汇总了Java中org.apache.batik.dom.svg.SAXSVGDocumentFactory.createSVGDocument方法的典型用法代码示例。如果您正苦于以下问题:Java SAXSVGDocumentFactory.createSVGDocument方法的具体用法?Java SAXSVGDocumentFactory.createSVGDocument怎么用?Java SAXSVGDocumentFactory.createSVGDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.batik.dom.svg.SAXSVGDocumentFactory
的用法示例。
在下文中一共展示了SAXSVGDocumentFactory.createSVGDocument方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSVGDocument
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入方法依赖的package包/类
public SVGDocument getSVGDocument() {
String xmlParser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory df = new SAXSVGDocumentFactory(xmlParser);
SVGDocument doc = null;
try {
if (this.href != null) {
if (!this.href.substring(0, 4).equalsIgnoreCase("file")) {
URL res = ExternalGraphic.class.getResource(this.href);
if (res != null) {
doc = df.createSVGDocument(
ExternalGraphic.class.getResource(this.href).toString());
}
} else {
doc = df.createSVGDocument(this.href);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return doc;
}
示例2: loadDiagramFromStream
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入方法依赖的package包/类
private static GraphicsNode loadDiagramFromStream (final InputStream in, final Dimension2D docSize) throws IOException {
final String parser = XMLResourceDescriptor.getXMLParserClassName();
final SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
final SVGDocument doc = factory.createSVGDocument("http://www.igormaznitsa.com/jhexed/svg", in);
String strDocWidth = doc.getRootElement().getAttribute("width");
String strDocHeight = doc.getRootElement().getAttribute("height");
final GVTBuilder bldr = new GVTBuilder();
final UserAgent userAgent = new UserAgentAdapter();
final DocumentLoader loader = new DocumentLoader(userAgent);
final BridgeContext ctx = new BridgeContext(userAgent, loader);
final GraphicsNode result = bldr.build(ctx, doc);
strDocWidth = strDocWidth.isEmpty() ? Double.toString(result.getSensitiveBounds().getWidth()) : strDocWidth;
strDocHeight = strDocHeight.isEmpty() ? Double.toString(result.getSensitiveBounds().getHeight()) : strDocHeight;
docSize.setSize(Double.parseDouble(strDocWidth.trim()), Double.parseDouble(strDocHeight.trim()));
return result;
}
示例3: createNode
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入方法依赖的package包/类
private GraphicsNode createNode(String svgContent) throws GeomajasException {
// batik magic
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
SVGDocument document;
try {
document = f.createSVGDocument("", new StringReader(svgContent));
} catch (IOException e) {
throw new RasterException(e, RasterException.BAD_SVG, "Cannot parse SVG");
}
UserAgent userAgent = new UserAgentAdapter();
DocumentLoader loader = new DocumentLoader(userAgent);
BridgeContext bridgeContext = new BridgeContext(userAgent, loader);
bridgeContext.setDynamic(true);
GVTBuilder builder = new GVTBuilder();
return builder.build(bridgeContext, document);
}
示例4: addPage
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入方法依赖的package包/类
public ThinReport addPage(String file, Map<String, Object> map)
throws IOException {
readTlf(file);
// System.out.println(thinReport.getSvg());
Document document = null;
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
// f.setValidating(true);
// String uri = SVGDOMImplementation.SVG_NAMESPACE_URI;
document = f.createSVGDocument(file, new ByteArrayInputStream(
thinReport.getSvg().getBytes("UTF-8")));
if (document != null) {
traceNodes(document, map);
TransformerFactory transFactory = TransformerFactory.newInstance();
try {
Transformer transformer = transFactory.newTransformer();
Source src = new DOMSource(document);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Result result = new StreamResult(out);
transformer.transform(src, result);
TranscoderInput input = new TranscoderInput();
input.setInputStream(new ByteArrayInputStream(out.toByteArray()));
thinReport.addDocument(input);
out.close();
// } catch (TransformerConfigurationException e) {
// e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
}
}
lineNo = 0;
return thinReport;
}
示例5: generateLineBlock
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入方法依赖的package包/类
protected void generateLineBlock(Node node, Map<String, Object> map,
JSONObject json, int line, double translateY) {
double height = 0;
if (json.get("height") instanceof Integer) {
height = (Integer) json.get("height");
} else {
height = (Double) json.get("height");
}
JSONObject svg = json.getJSONObject("svg");
String content = "<svg xmlns=\"http://www.w3.org/2000/svg\"><g>"
+ svg.getString("content").replace("<!-", "<!--")
.replace("->", "-->") + "</g></svg>";
System.out.println(content);
String parser = XMLResourceDescriptor.getXMLParserClassName();
try {
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
Document doc = f.createSVGDocument("g", new ByteArrayInputStream(
content.getBytes("UTF-8")));
// DocumentBuilderFactory dbfactory =
// DocumentBuilderFactory.newInstance();
// DocumentBuilder docbuilder = dbfactory.newDocumentBuilder();
// Document doc = docbuilder.parse(new
// ByteArrayInputStream(content.getBytes("UTF-8")));
traceNodes(doc, map);
Document document = node.getOwnerDocument();
Element g = document.createElement("g");
g.setAttribute("transform", "translate(0,"
+ (height * line + translateY) + ")");
Node newnode = document.importNode(doc.getFirstChild(), true);
Node parent = node.getParentNode();
parent.insertBefore(g, node);
g.appendChild(newnode);
} catch (IOException e) {
e.printStackTrace();
// } catch (ParserConfigurationException e) {
// e.printStackTrace();
// } catch (SAXException e) {
// e.printStackTrace();
}
}
示例6: getSVGImage
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入方法依赖的package包/类
/**
* Load the SVG image with the specified name. This operation may either
* create a new graphics node of returned a previously created one.
* @param name Name of the SVG file to load.
* @return GraphicsNode containing SVG image or null if none found.
*/
public static GraphicsNode getSVGImage(String name) {
if (svgCache == null) svgCache = new HashMap<String, GraphicsNode>();
GraphicsNode found = svgCache.get(name);
if (found == null) {
String fileName = SVG_DIR + name;
URL resource = SVGLoader.class.getResource(fileName);
try {
String xmlParser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory df = new SAXSVGDocumentFactory(xmlParser);
SVGDocument doc = df.createSVGDocument(resource.toString());
UserAgent userAgent = new UserAgentAdapter();
DocumentLoader loader = new DocumentLoader(userAgent);
BridgeContext ctx = new BridgeContext(userAgent, loader);
ctx.setDynamicState(BridgeContext.DYNAMIC);
GVTBuilder builder = new GVTBuilder();
found = builder.build(ctx, doc);
svgCache.put(name, found);
}
catch (Exception e) {
System.err.println("getSVGImage error: " + fileName);
e.printStackTrace(System.err);
}
}
return found;
}
示例7: getSVGTemplate
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入方法依赖的package包/类
private SVGDocument getSVGTemplate(String template) throws IOException, URISyntaxException {
template = template + ".svg";
final String uri = getBadgeFile(template).toURI().toString();
t("begin loading " + uri);
final String parser = XMLResourceDescriptor.getXMLParserClassName();
final SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
final SVGDocument doc = f.createSVGDocument(uri);
t("end loading " + uri);
return doc;
}