List of usage examples for org.jdom2 Namespace getNamespace
public static Namespace getNamespace(final String prefix, final String uri)
Namespace
for the supplied prefix and uri. From source file:org.goobi.production.export.ExportXmlLog.java
License:Open Source License
private List<Namespace> getNamespacesFromConfig() { List<Namespace> nss = new ArrayList<>(); try {/*from www. j a va 2s . co m*/ Path file = Paths.get(new Helper().getGoobiConfigDirectory() + "goobi_exportXml.xml"); if (StorageProvider.getInstance().isFileExists(file) && StorageProvider.getInstance().isReadable(file)) { XMLConfiguration config = new XMLConfiguration(file.toFile()); config.setListDelimiter('&'); config.setReloadingStrategy(new FileChangedReloadingStrategy()); int count = config.getMaxIndex("namespace"); for (int i = 0; i <= count; i++) { String name = config.getString("namespace(" + i + ")[@name]"); String value = config.getString("namespace(" + i + ")[@value]"); Namespace ns = Namespace.getNamespace(name, value); nss.add(ns); } } } catch (Exception e) { } return nss; }
From source file:org.jumpmind.metl.core.runtime.component.XmlFormatter.java
License:Open Source License
private final static Namespace getXmlNamespace() { return Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); }
From source file:org.kisst.cordys.caas.util.XmlNode.java
License:Open Source License
/** * This method executes the XPath on the current element. * /*from w ww.j a v a2s . c o m*/ * @param xpath The XPath to execute. * @return The list of elements that match the given XPath. */ public List<XmlNode> xpath(String xpath, String[][] namespaces) { List<XmlNode> retVal = new ArrayList<XmlNode>(); try { // Parse the name spaces List<Namespace> ns = new ArrayList<Namespace>(); if (namespaces != null) { for (String[] nsDetails : namespaces) { ns.add(Namespace.getNamespace(nsDetails[0], nsDetails[1])); } } // Create the XPath XPathExpression<Element> p = XPathFactory.instance().compile(xpath, Filters.element(), null, ns); // Execute the xpath List<Element> nodes = p.evaluate(element); // Build up the response for (Object node : nodes) { retVal.add(new XmlNode((Element) node)); } } catch (Exception e) { e.printStackTrace(); } return retVal; }
From source file:org.mycore.frontend.xeditor.MCRXEditorTransformer.java
License:Open Source License
public void addNamespace(String prefix, String uri) { MCRConstants.registerNamespace(Namespace.getNamespace(prefix, uri)); }
From source file:org.mycore.mets.tools.MCRMetsResolver.java
License:Open Source License
@Override public Source resolve(String href, String base) throws TransformerException { String id = href.substring(href.indexOf(":") + 1); LOGGER.debug("Reading METS for ID " + id); MCRObjectID objId = MCRObjectID.getInstance(id); if (!objId.getTypeId().equals("derivate")) { String derivateID = getDerivateFromObject(id); if (derivateID == null) { return new JDOMSource( new Element("mets", Namespace.getNamespace("mets", "http://www.loc.gov/METS/"))); }/*from ww w . j a va 2 s . co m*/ id = derivateID; } MCRPath metsPath = MCRPath.getPath(id, "/mets.xml"); HashSet<MCRPath> ignoreNodes = new HashSet<>(); try { if (Files.exists(metsPath)) { //TODO: generate new METS Output //ignoreNodes.add(metsFile); return new MCRPathContent(metsPath).getSource(); } Document mets = MCRMETSGenerator.getGenerator().getMETS(MCRPath.getPath(id, "/"), ignoreNodes) .asDocument(); return new JDOMSource(mets); } catch (Exception e) { throw new TransformerException(e); } }
From source file:org.rascalmpl.library.lang.xml.DOM.java
License:Open Source License
private Namespace namespaceToNamespace(IConstructor ns) { if (ns.getConstructorType() == Factory.Namespace_none) { return Namespace.NO_NAMESPACE; }/* ww w . jav a 2 s .c o m*/ IString prefix = (IString) ns.get(0); IString uri = (IString) ns.get(1); return Namespace.getNamespace(prefix.getValue(), uri.getValue()); }
From source file:org.sleuthkit.autopsy.report.ReportKML.java
License:Open Source License
/** * Generates a body file format report for use with the MAC time tool. * * @param path path to save the report/*from w w w. j av a 2s . c om*/ * @param progressPanel panel to update the report's progress */ @Override public void generateReport(String path, ReportProgressPanel progressPanel) { // Start the progress bar and setup the report progressPanel.setIndeterminate(false); progressPanel.start(); progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportKML.progress.querying")); reportPath = path + "ReportKML.kml"; //NON-NLS String reportPath2 = path + "ReportKML.txt"; //NON-NLS currentCase = Case.getCurrentCase(); skCase = currentCase.getSleuthkitCase(); progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportKML.progress.loading")); // Check if ingest has finished String ingestwarning = ""; if (IngestManager.getInstance().isIngestRunning()) { ingestwarning = NbBundle.getMessage(this.getClass(), "ReportBodyFile.ingestWarning.text"); } progressPanel.setMaximumProgress(5); progressPanel.increment(); // @@@ BC: I don't get why we do this in two passes. // Why not just print the coordinates as we find them and make some utility methods to do the printing? // Should pull out time values for all of these points and store in TimeSpan element try { BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter(reportPath2)); double lat = 0; // temp latitude double lon = 0; //temp longitude AbstractFile aFile; String geoPath = ""; // will hold values of images to put in kml String imageName = ""; File f; for (BlackboardArtifact artifact : skCase .getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_METADATA_EXIF)) { lat = 0; lon = 0; geoPath = ""; String extractedToPath; for (BlackboardAttribute attribute : artifact.getAttributes()) { if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE .getTypeID()) //latitude { lat = attribute.getValueDouble(); } if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE .getTypeID()) //longitude { lon = attribute.getValueDouble(); } } if (lon != 0 && lat != 0) { aFile = artifact.getSleuthkitCase().getAbstractFileById(artifact.getObjectID()); extractedToPath = reportPath + aFile.getName(); geoPath = extractedToPath; f = new File(extractedToPath); f.createNewFile(); copyFileUsingStream(aFile, f); imageName = aFile.getName(); out.write(String.valueOf(lat)); out.write(";"); out.write(String.valueOf(lon)); out.write(";"); out.write(String.valueOf(geoPath)); out.write(";"); out.write(String.valueOf(imageName)); out.write("\n"); // lat lon path name } } for (BlackboardArtifact artifact : skCase .getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACKPOINT)) { lat = 0; lon = 0; for (BlackboardAttribute attribute : artifact.getAttributes()) { if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE .getTypeID()) //latitude { lat = attribute.getValueDouble(); } if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE .getTypeID()) //longitude { lon = attribute.getValueDouble(); } } if (lon != 0 && lat != 0) { out.write(lat + ";" + lon + "\n"); } } for (BlackboardArtifact artifact : skCase .getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_ROUTE)) { lat = 0; lon = 0; double destlat = 0; double destlon = 0; String name = ""; String location = ""; for (BlackboardAttribute attribute : artifact.getAttributes()) { if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_START .getTypeID()) //latitude { lat = attribute.getValueDouble(); } else if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_END .getTypeID()) //longitude { destlat = attribute.getValueDouble(); } else if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_START .getTypeID()) //longitude { lon = attribute.getValueDouble(); } else if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_END .getTypeID()) //longitude { destlon = attribute.getValueDouble(); } else if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME .getTypeID()) //longitude { name = attribute.getValueString(); } else if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION .getTypeID()) //longitude { location = attribute.getValueString(); } } // @@@ Should do something more fancy with these in KML and store them as a single point. String display = name; if (display.isEmpty()) display = location; if (lon != 0 && lat != 0) { out.write(NbBundle.getMessage(this.getClass(), "ReportKML.latLongStartPoint", lat, lon, display)); } if (destlat != 0 && destlon != 0) { out.write(NbBundle.getMessage(this.getClass(), "ReportKML.latLongEndPoint", destlat, destlon, display)); } } out.flush(); out.close(); progressPanel.increment(); /* * Step 1: generate XML stub */ Namespace ns = Namespace.getNamespace("", "http://earth.google.com/kml/2.2"); //NON-NLS // kml Element kml = new Element("kml", ns); //NON-NLS Document kmlDocument = new Document(kml); // Document Element document = new Element("Document", ns); //NON-NLS kml.addContent(document); // name Element name = new Element("name", ns); //NON-NLS name.setText("Java Generated KML Document"); //NON-NLS document.addContent(name); /* * Step 2: add in Style elements */ // Style Element style = new Element("Style", ns); //NON-NLS style.setAttribute("id", "redIcon"); //NON-NLS document.addContent(style); // IconStyle Element iconStyle = new Element("IconStyle", ns); //NON-NLS style.addContent(iconStyle); // color Element color = new Element("color", ns); //NON-NLS color.setText("990000ff"); //NON-NLS iconStyle.addContent(color); // Icon Element icon = new Element("Icon", ns); //NON-NLS iconStyle.addContent(icon); // href Element href = new Element("href", ns); //NON-NLS href.setText("http://www.cs.mun.ca/~hoeber/teaching/cs4767/notes/02.1-kml/circle.png"); //NON-NLS icon.addContent(href); progressPanel.increment(); /* * Step 3: read data from source location and * add in a Placemark for each data element */ File file = new File(reportPath2); BufferedReader reader; reader = new BufferedReader(new FileReader(file)); String line = reader.readLine(); while (line != null) { String[] lineParts = line.split(";"); if (lineParts.length > 1) { String coordinates = lineParts[1].trim() + "," + lineParts[0].trim(); //lat,lon // Placemark Element placemark = new Element("Placemark", ns); //NON-NLS document.addContent(placemark); if (lineParts.length == 4) { // name Element pmName = new Element("name", ns); //NON-NLS pmName.setText(lineParts[3].trim()); placemark.addContent(pmName); String savedPath = lineParts[2].trim(); if (savedPath.isEmpty() == false) { // Path Element pmPath = new Element("Path", ns); //NON-NLS pmPath.setText(savedPath); placemark.addContent(pmPath); // description Element pmDescription = new Element("description", ns); //NON-NLS String xml = "<![CDATA[ \n" + " <img src='file:///" + savedPath + "' width='400' /><br/> \n"; //NON-NLS StringEscapeUtils.unescapeXml(xml); pmDescription.setText(xml); placemark.addContent(pmDescription); } } // styleUrl Element pmStyleUrl = new Element("styleUrl", ns); //NON-NLS pmStyleUrl.setText("#redIcon"); //NON-NLS placemark.addContent(pmStyleUrl); // Point Element pmPoint = new Element("Point", ns); //NON-NLS placemark.addContent(pmPoint); // coordinates Element pmCoordinates = new Element("coordinates", ns); //NON-NLS pmCoordinates.setText(coordinates); pmPoint.addContent(pmCoordinates); } // read the next line line = reader.readLine(); } progressPanel.increment(); /* * Step 4: write the XML file */ try { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); FileOutputStream writer = new FileOutputStream(reportPath); outputter.output(kmlDocument, writer); writer.close(); Case.getCurrentCase().addReport(reportPath, NbBundle.getMessage(this.getClass(), "ReportKML.genReport.srcModuleName.text"), ""); } catch (IOException ex) { logger.log(Level.WARNING, "Could not write the KML file.", ex); //NON-NLS } catch (TskCoreException ex) { String errorMessage = String.format("Error adding %s to case as a report", reportPath); //NON-NLS logger.log(Level.SEVERE, errorMessage, ex); } } catch (IOException ex) { logger.log(Level.WARNING, "Could not write the KML report.", ex); //NON-NLS } progressPanel.complete(); } catch (TskCoreException ex) { logger.log(Level.WARNING, "Failed to get the unique path.", ex); //NON-NLS } progressPanel.increment(); progressPanel.complete(); }
From source file:org.sleuthkit.openmobileforensics.android.KMLFileCreator.java
License:Open Source License
public void CreateKML() { reportPath = Case.getCurrentCase().getTempDirectory() + "ReportKML.kml"; //NON-NLS String reportPath2 = Case.getCurrentCase().getTempDirectory() + "ReportKML.txt"; //NON-NLS currentCase = Case.getCurrentCase(); skCase = currentCase.getSleuthkitCase(); try {// w w w.j a v a 2 s . c o m BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter(reportPath2)); String lat = ""; // temp latitude String lon = ""; //temp longitude String destlon = ""; String destlat = ""; for (BlackboardArtifact artifact : skCase .getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACKPOINT)) { lat = ""; lon = ""; for (BlackboardAttribute attribute : artifact.getAttributes()) { if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE .getTypeID()) //latitude { lat = attribute.getValueString(); } if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE .getTypeID()) //longitude { lon = attribute.getValueString(); } } if (!lon.isEmpty() && !lat.isEmpty()) { out.write(lat + ";" + lon + "\n"); } } for (BlackboardArtifact artifact : skCase .getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_ROUTE)) { lat = ""; lon = ""; for (BlackboardAttribute attribute : artifact.getAttributes()) { if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_START .getTypeID()) //latitude { lat = attribute.getValueString(); } else if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_END .getTypeID()) //longitude { destlat = attribute.getValueString(); } else if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_START .getTypeID()) //longitude { lon = attribute.getValueString(); } else if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_END .getTypeID()) //longitude { destlon = attribute.getValueString(); } } if (!lon.isEmpty() && !lat.isEmpty()) { out.write(lat + ";" + lon + "\n"); } if (!destlon.isEmpty() && !destlat.isEmpty()) { out.write(destlat + ";" + destlon + "\n"); } } out.flush(); out.close(); /* * Step 1: generate XML stub */ Namespace ns = Namespace.getNamespace("", "http://earth.google.com/kml/2.2"); //NON-NLS // kml Element kml = new Element("kml", ns); //NON-NLS Document kmlDocument = new Document(kml); // Document Element document = new Element("Document", ns); //NON-NLS kml.addContent(document); // name Element name = new Element("name", ns); //NON-NLS name.setText("Java Generated KML Document"); //NON-NLS document.addContent(name); /* * Step 2: add in Style elements */ // Style Element style = new Element("Style", ns); //NON-NLS style.setAttribute("id", "redIcon"); //NON-NLS document.addContent(style); // IconStyle Element iconStyle = new Element("IconStyle", ns); //NON-NLS style.addContent(iconStyle); // color Element color = new Element("color", ns); //NON-NLS color.setText("990000ff"); //NON-NLS iconStyle.addContent(color); // Icon Element icon = new Element("Icon", ns); //NON-NLS iconStyle.addContent(icon); // href Element href = new Element("href", ns); //NON-NLS href.setText("http://www.cs.mun.ca/~hoeber/teaching/cs4767/notes/02.1-kml/circle.png"); //NON-NLS icon.addContent(href); /* * Step 3: read data from source location and * add in a Placemark for each data element */ File file = new File(reportPath2); BufferedReader reader; reader = new BufferedReader(new FileReader(file)); String line = reader.readLine(); while (line != null) { String[] lineParts = line.split(";"); if (lineParts.length == 2) { String coordinates = lineParts[1].trim() + "," + lineParts[0].trim(); //lat,lon // Placemark Element placemark = new Element("Placemark", ns); //NON-NLS document.addContent(placemark); // styleUrl Element pmStyleUrl = new Element("styleUrl", ns); //NON-NLS pmStyleUrl.setText("#redIcon"); //NON-NLS placemark.addContent(pmStyleUrl); // Point Element pmPoint = new Element("Point", ns); //NON-NLS placemark.addContent(pmPoint); // coordinates Element pmCoordinates = new Element("coordinates", ns); //NON-NLS pmCoordinates.setText(coordinates); pmPoint.addContent(pmCoordinates); } // read the next line line = reader.readLine(); } /* * Step 4: write the XML file */ try { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); FileOutputStream writer = new FileOutputStream(reportPath); outputter.output(kmlDocument, writer); writer.close(); } catch (IOException ex) { } } catch (IOException ex) { } } catch (TskCoreException ex) { } }
From source file:org.xflatdb.xflat.convert.converters.JAXBPojoConverter.java
License:Apache License
private XPathExpression<Object> makeIdSelector(Class<?> clazz) { IdAccessor accessor = IdAccessor.forClass(clazz); if (!accessor.hasId()) { return null; }/*from ww w . jav a 2 s.c o m*/ Namespace ns = null; StringBuilder ret = new StringBuilder(clazz.getSimpleName()); XmlAttribute attribute = (XmlAttribute) accessor.getIdPropertyAnnotation(XmlAttribute.class); if (attribute != null) { ret.append("/@"); if (attribute.namespace() != null) { ns = Namespace.getNamespace("id", attribute.namespace()); ret.append(ns.getPrefix()).append(":"); } if (attribute.name() != null) { ret.append(attribute.name()); } else { ret.append(accessor.getIdPropertyName()); } } else { ret.append("/"); XmlElement element = (XmlElement) accessor.getIdPropertyAnnotation(XmlElement.class); if (element != null) { if (element.namespace() != null) { ns = Namespace.getNamespace("id", attribute.namespace()); ret.append(ns.getPrefix()).append(":"); } if (element.name() != null) { ret.append(element.name()); } else { ret.append(accessor.getIdPropertyName()); } } else { ret.append(accessor.getIdPropertyName()); } } if (ns == null) { return XPathFactory.instance().compile(ret.toString()); } return XPathFactory.instance().compile(ret.toString(), Filters.fpassthrough(), null, ns); }
From source file:org.xflatdb.xflat.db.IdAccessor.java
License:Apache License
private static XPathExpression<Object> getAlternateId(Id idPropertyAnnotation) { if (idPropertyAnnotation == null) return null; String expression = idPropertyAnnotation.value(); if (expression == null || "".equals(expression)) { return null; }/*from w ww.java2 s .co m*/ List<Namespace> namespaces = null; if (idPropertyAnnotation.namespaces() != null && idPropertyAnnotation.namespaces().length > 0) { for (String ns : idPropertyAnnotation.namespaces()) { if (!ns.startsWith("xmlns:")) { continue; } int eqIndex = ns.indexOf("="); if (eqIndex < 0 || eqIndex >= ns.length() - 1) { continue; } String prefix = ns.substring(6, eqIndex); String url = ns.substring(eqIndex + 1); if (url.startsWith("\"") || url.startsWith("'")) url = url.substring(1); if (url.endsWith("\"") || url.endsWith("'")) url = url.substring(0, url.length() - 1); if ("".equals(prefix) || "".equals(url)) continue; if (namespaces == null) namespaces = new ArrayList<>(); namespaces.add(Namespace.getNamespace(prefix, url)); } } //compile it return XPathFactory.instance().compile(expression, Filters.fpassthrough(), null, namespaces == null ? Collections.EMPTY_LIST : namespaces); }