本文整理汇总了Java中org.apache.batik.dom.svg.SAXSVGDocumentFactory类的典型用法代码示例。如果您正苦于以下问题:Java SAXSVGDocumentFactory类的具体用法?Java SAXSVGDocumentFactory怎么用?Java SAXSVGDocumentFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SAXSVGDocumentFactory类属于org.apache.batik.dom.svg包,在下文中一共展示了SAXSVGDocumentFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: loadDocument
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入依赖的package包/类
private void loadDocument() {
transcoder = null;
failedToLoadDocument = true;
if (uri == null) {
return;
}
String parser = XMLResourceDescriptor.getXMLParserClassName();
parser = parser != null ? parser : "org.apache.xerces.parsers.SAXParser";
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
try {
Document document;
if (documentsMap.containsKey(uri))
document = documentsMap.get(uri);
else {
document = factory.createDocument(uri);
documentsMap.put(uri, document);
}
transcoder = new SimpleImageTranscoder(document, translateX, translateY);
failedToLoadDocument = false;
} catch (IOException e) {
TriqEditorPlugin.logError("Error loading SVG file", e);
}
}
示例4: loadDocument
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入依赖的package包/类
private void loadDocument() {
transcoder = null;
failedToLoadDocument = true;
if (uri == null) {
return;
}
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
try {
Document document;
if (documentsMap.containsKey(uri))
document = documentsMap.get(uri);
else {
document = factory.createDocument(uri);
documentsMap.put(uri, document);
}
transcoder = new SimpleImageTranscoder(document);
failedToLoadDocument = false;
} catch (IOException e) {
JaspersoftStudioPlugin.getInstance().logError("Error loading SVG file", e);
}
}
示例5: 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);
}
示例6: 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;
}
示例7: 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();
}
}
示例8: 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;
}
示例9: SvgImage
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入依赖的package包/类
public SvgImage(InputStream inputStream)
throws IOException, ParserConfigurationException, SAXException {
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
svgDocument = (SVGDocument) factory.createDocument(null, inputStream);
// svgDocument.getElementById(parser)
}
示例10: determineExtremeBounds
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入依赖的package包/类
/**
*
* @param uri
* @return [minX, minY, width,height] of the contained SVG
* @throws IOException
*/
private Rectangle determineExtremeBounds(String uri) throws IOException {
LOGGER.trace("SVG determineExtremeBounds - entry - for {}", uri);
String parser = XMLResourceDescriptor.getXMLParserClassName();
parser = parser != null ? parser : "org.apache.xerces.parsers.SAXParser";
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
Document doc = factory.createDocument(uri);
UserAgent agent = new UserAgentAdapter();
DocumentLoader loader = new DocumentLoader(agent);
BridgeContext context = new BridgeContext(agent, loader);
context.setDynamic(true);
GVTBuilder builder = new GVTBuilder();
GraphicsNode root = builder.build(context, doc);
// Add 1 pixel for height and width as it seems batik's size calculation
// for svg shapes that have negative and positive coordinates
// forgets about the pixel needed for 0.
// E.g. polygons going from x=-15 to x=15 return 30 as width.
// And the result is that lines at x=15 are not drawn/shown in the resulting image :-(
int height = (int) root.getGeometryBounds().getHeight()+1;
int width = (int) root.getGeometryBounds().getWidth()+1;
int minX = (int) root.getGeometryBounds().getMinX();
int minY = (int) root.getGeometryBounds().getMinY();
Rectangle result = new Rectangle(minX, minY, width, height);
LOGGER.trace("SVG determineExtremeBounds - exit - for {} - bounds {}", uri, result);
return result;
}
示例11: buildSVGFromDot
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入依赖的package包/类
private SVGDocument buildSVGFromDot(NotationElement notationElement) {
StringBuilder dotGraph = new StringBuilder();
dotGraph.append("graph ").append(notationElement.getId()).append(" {\n rankdir=\"LR\";\n");
DotNotationBuilder dotBuilder = new DotNotationBuilder();
dotGraph.append(dotBuilder.create(notationElement));
dotGraph.append(" }\n");
Document doc = null;
String fullPath;
if (inCDO) {
String loc = "file:/" + System.getProperty("java.io.tmpdir") + "temp.svg";
fullPath = loc.replaceAll("\\\\", "/");
} else {
fullPath = Controller.INSTANCE.getEcoreModel().eResource().getURI().toFileString()+".svg";
}
try {
ByteArrayInputStream input = new ByteArrayInputStream(dotGraph.toString().getBytes());
// GraphViz.generate(input, "svg", new Point(200, 200), new Path(Controller.INSTANCE.getEcoreModel().eResource().getURI().toFileString()+".svg"));
runDot(input, new Path(fullPath));
// String svgLocation = Controller.INSTANCE.getEcoreModel().eResource().getURI().toString() + ".svg";
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
if (inCDO) {
doc = f.createDocument(fullPath);
} else {
java.io.File file = new java.io.File(fullPath);
doc = f.createDocument(file.toURL().toString());
}
} catch (IOException e) {
e.printStackTrace();
}
return (SVGDocument) doc;
}
示例12: generateDefaultSvg
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入依赖的package包/类
public void generateDefaultSvg() {
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
// set up a kinnate namespace so that the ego list and kin type strings can have more permanent storage places
// in order to add the extra namespaces to the svg document we use a string and parse it
// other methods have been tried but this is the most readable and the only one that actually works
// I think this is mainly due to the way the svg dom would otherwise be constructed
// others include:
// doc.getDomConfig()
// doc.getDocumentElement().setAttributeNS(DataStoreSvg.kinDataNameSpaceLocation, "kin:version", "");
// doc.getDocumentElement().setAttribute("xmlns:" + DataStoreSvg.kinDataNameSpace, DataStoreSvg.kinDataNameSpaceLocation); // this method of declaring multiple namespaces looks to me to be wrong but it is the only method that does not get stripped out by the transformer on save
// Document doc = impl.createDocument(svgNS, "svg", null);
// SVGDocument doc = svgCanvas.getSVGDocument();
String templateXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:kin=\"http://mpi.nl/tla/kin\" "
+ "xmlns=\"http://www.w3.org/2000/svg\" contentScriptType=\"text/ecmascript\" "
+ " zoomAndPan=\"magnify\" contentStyleType=\"text/css\" "
+ "preserveAspectRatio=\"xMidYMid meet\" version=\"1.0\"/>";
// DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
// doc = (SVGDocument) impl.createDocument(svgNameSpace, "svg", null);
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory documentFactory = new SAXSVGDocumentFactory(parser);
doc = (SVGDocument) documentFactory.createDocument(svgNameSpace, new StringReader(templateXml));
entitySvg.updateSymbolsElement(doc, svgNameSpace);
configureDiagramGroups();
dataStoreSvg.indexParameters.symbolFieldsFields.setAvailableValues(entitySvg.listSymbolNames(doc, this.svgNameSpace));
svgCanvas.setSVGDocument(doc);
symbolGraphic = new SymbolGraphic(doc);
dataStoreSvg.graphData = new GraphSorter();
} catch (IOException exception) {
BugCatcherManager.getBugCatcher().logError(exception);
}
}
示例13: toDocument
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入依赖的package包/类
private Document toDocument(String svg, Dimension dimensions)
throws IOException {
// Turn back into DOM
String parserName = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parserName);
Document doc = f.createDocument("file:///test.svg",
new CharArrayReader(svg.toCharArray()));
scaleSvg(doc, dimensions);
return doc;
}
示例14: loadDocument
import org.apache.batik.dom.svg.SAXSVGDocumentFactory; //导入依赖的package包/类
@Override
protected Object loadDocument(File svgFile) throws Exception {
String xmlParser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory svgFactory = new SAXSVGDocumentFactory(xmlParser);
String uri = Utilities.toURI(svgFile).toURL().toString();
Document document = svgFactory.createDocument(uri);
return document;
}
示例15: 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;
}