本文整理汇总了Java中org.apache.batik.util.XMLResourceDescriptor类的典型用法代码示例。如果您正苦于以下问题:Java XMLResourceDescriptor类的具体用法?Java XMLResourceDescriptor怎么用?Java XMLResourceDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XMLResourceDescriptor类属于org.apache.batik.util包,在下文中一共展示了XMLResourceDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: relativizeExternalReferences
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的package包/类
/**
* Rewrites external references contained in SVG files.
*
* @param path the path of the file to be processed
*/
public static byte[] relativizeExternalReferences(String path)
throws IOException {
// use the GenericDOMImplementation here because
// SVGDOMImplementation adds unwanted attributes to SVG elements
final SAXDocumentFactory fac = new SAXDocumentFactory(
new GenericDOMImplementation(),
XMLResourceDescriptor.getXMLParserClassName());
final URL here = new URL("file", null, new File(path).getCanonicalPath());
final StringWriter sw = new StringWriter();
try {
final Document doc = fac.createDocument(here.toString());
relativizeElement(doc.getDocumentElement());
DOMUtilities.writeDocument(doc, sw);
}
catch (DOMException e) {
throw (IOException) new IOException().initCause(e);
}
sw.flush();
return sw.toString().getBytes();
}
示例2: renderSVG
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的package包/类
private void renderSVG(String name, final double scale) throws IOException {
String uri = RenderSVGsTest.class.getResource(name).toString();
// create the document
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
Document document = f.createDocument(uri, RenderSVGsTest.class.getResourceAsStream(name));
// create the GVT
UserAgent userAgent = new UserAgentAdapter();
DocumentLoader loader = new DocumentLoader(userAgent);
BridgeContext bctx = new BridgeContext(userAgent, loader);
bctx.setDynamicState(BridgeContext.STATIC);
GVTBuilder builder = new GVTBuilder();
final GraphicsNode gvtRoot = builder.build(bctx, document);
this.exportGraphic("svg", name.replace(".svg", ""), new GraphicsExporter() {
@Override
public void draw(Graphics2D gfx) {
gfx.scale(scale, scale);
gvtRoot.paint(gfx);
}
});
}
示例3: getSVGDocument
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的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;
}
示例4: createTranscoderInput
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的package包/类
/**
* Creates the <code>TranscoderInput</code>.
*/
protected TranscoderInput createTranscoderInput() {
try {
URL url = resolveURL(inputURI);
String parser = XMLResourceDescriptor.getXMLParserClassName();
DOMImplementation impl =
GenericDOMImplementation.getDOMImplementation();
SAXDocumentFactory f = new SAXDocumentFactory(impl, parser);
Document doc = f.createDocument(url.toString());
TranscoderInput input = new TranscoderInput(doc);
input.setURI(url.toString()); // Needed for external resources
return input;
} catch (IOException ex) {
ex.printStackTrace();
throw new IllegalArgumentException(inputURI);
}
}
示例5: loadDiagramFromStream
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的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;
}
示例6: loadDocument
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的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);
}
}
示例7: loadDocument
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的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);
}
}
示例8: initialize
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的package包/类
/** {@inheritDoc} */
protected void initialize() {
if (foObjs == null && batikAvailable) {
// this sets the parser that will be used
// by default (SVGBrokenLinkProvider)
// normally the user agent value is used
try {
XMLResourceDescriptor.setXMLParserClassName(
getAParserClassName());
foObjs = new HashMap<String, Maker>();
foObjs.put("svg", new SE());
foObjs.put(DEFAULT, new SVGMaker());
} catch (Throwable t) {
log.error("Error while initializing the Batik SVG extensions", t);
// if the classes are not available
// the DISPLAY is not checked
batikAvailable = false;
}
}
}
示例9: initialize
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的package包/类
/** initialize mapping */
protected void initialize() {
if (foObjs == null && batikAvail) {
// this sets the parser that will be used
// by default (SVGBrokenLinkProvider)
// normally the user agent value is used
try {
XMLResourceDescriptor.setXMLParserClassName(
getAParserClassName());
foObjs = new HashMap<String, Maker>();
foObjs.put("batik", new SE());
foObjs.put(DEFAULT, new SVGMaker());
} catch (Throwable t) {
// if the classes are not available
// the DISPLAY is not checked
batikAvail = false;
}
}
}
示例10: createNode
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的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);
}
示例11: loadDocument
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的package包/类
public static Document loadDocument(String path)
throws IOException, ParserConfigurationException, SAXException {
File file = new File(path);
FileInputStream svgInputStream = new FileInputStream(file);
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
Document doc = factory.createDocument(parser, svgInputStream);
return doc;
}
示例12: loadDocument
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的package包/类
/**
* Load the SVG image from an input stream and replaces its color. The SVG format is a XML
* format.
*
* @param inputStream From which to load the image
* @param color The replacement color
* @return The loaded SVG image document
* @throws SAXException Parsing error
* @throws IOException Could not load the image
* @throws ParserConfigurationException Problem with XML parser
*/
public Document loadDocument (final InputStream inputStream, final Color color) throws SAXException, IOException, ParserConfigurationException
{
final String parser = XMLResourceDescriptor.getXMLParserClassName ();
final SAXSVGDocumentFactory f = new SAXSVGDocumentFactory (parser);
final SVGDocument document = f.createSVGDocument ("xxx", inputStream);
changeColorOfElement (color, document, "polygon");
changeColorOfElement (color, document, "circle");
changeColorOfElement (color, document, "path");
changeColorOfElement (color, document, "rect");
return document;
}
示例13: getXMLParserClassName
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的package包/类
/**
* Returns the class name of the XML parser.
*/
public String getXMLParserClassName() {
if (svgUserAgent != null) {
return svgUserAgent.getXMLParserClassName();
}
return XMLResourceDescriptor.getXMLParserClassName();
}
示例14: createTranscoderInput
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的package包/类
/**
* Creates the <code>TranscoderInput</code>.
*/
protected TranscoderInput createTranscoderInput() {
try {
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
Document doc = f.createDocument(resolveURL(inputURI).toString());
return new TranscoderInput(doc);
} catch (IOException ex) {
throw new IllegalArgumentException(inputURI);
}
}
示例15: runImpl
import org.apache.batik.util.XMLResourceDescriptor; //导入依赖的package包/类
public TestReport runImpl() throws Exception {
DOMImplementation impl = new SVGDOMImplementation();
Document doc = impl.createDocument(SVGConstants.SVG_NAMESPACE_URI,
"svg", null);
Element svg = doc.getDocumentElement();
Element text = doc.createElementNS(SVGConstants.SVG_NAMESPACE_URI,
"text");
svg.appendChild(text);
text.setAttributeNS(null, "id", "myText");
String unescapedContent = "You should not escape: & # \" ...";
CDATASection cdata = doc.createCDATASection(unescapedContent);
text.appendChild(cdata);
Writer stringWriter = new StringWriter();
DOMUtilities.writeDocument(doc, stringWriter);
String docString = stringWriter.toString();
System.err.println(">>>>>>>>>>> Document content \n\n" + docString + "\n\n<<<<<<<<<<<<<<<<");
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
doc = f.createDocument("http://xml.apache.org/batik/foo.svg",
new StringReader(stringWriter.toString()));
text = doc.getElementById("myText");
cdata = (CDATASection)text.getFirstChild();
if (cdata.getData().equals(unescapedContent)) {
return reportSuccess();
}
TestReport report = reportError("Unexpected CDATA read-back");
report.addDescriptionEntry("expected cdata", unescapedContent);
report.addDescriptionEntry("actual cdata", cdata.getData());
return report;
}