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:eus.ixa.ixa.pipe.convert.DSRCCorpus.java
License:Apache License
private static void DSRCToNAFNER(KAFDocument kaf, String wordsDoc, String markablesDoc) throws JDOMException, IOException { // reading the words xml file SAXBuilder sax = new SAXBuilder(); XPathFactory xFactory = XPathFactory.instance(); Document docWords = sax.build(wordsDoc); XPathExpression<Element> expr = xFactory.compile("//word", Filters.element()); List<Element> words = expr.evaluate(docWords); List<WF> sentWFs = new ArrayList<>(); List<Term> sentTerms = new ArrayList<>(); // building the NAF containing the WFs and Terms // naf sentence counter int sentCounter = 1; for (Element word : words) { // sentence id and original text String token = word.getText(); // the list contains just one list of tokens WF wf = kaf.newWF(0, token, sentCounter); final List<WF> wfTarget = new ArrayList<WF>(); wfTarget.add(wf);/*from w ww.j av a 2s . co m*/ sentWFs.add(wf); Term term = kaf.newTerm(KAFDocument.newWFSpan(wfTarget)); term.setPos("O"); term.setLemma(token); sentTerms.add(term); Matcher endMatcher = endOfSentence.matcher(token); if (endMatcher.matches()) { sentCounter++; } } // end of processing words String[] tokenIds = new String[sentWFs.size()]; for (int i = 0; i < sentWFs.size(); i++) { tokenIds[i] = sentWFs.get(i).getId(); } // processing markables document in mmax opinion expression files Document markDoc = sax.build(markablesDoc); XPathFactory markFactory = XPathFactory.instance(); XPathExpression<Element> markExpr = markFactory.compile("//ns:markable", Filters.element(), null, Namespace.getNamespace("ns", "www.eml.org/NameSpaces/OpinionExpression")); List<Element> markables = markExpr.evaluate(markDoc); for (Element markable : markables) { if (markable.getAttributeValue("annotation_type").equalsIgnoreCase("target")) { String markSpan = markable.getAttributeValue("span"); System.err.println("--> span: " + markSpan); String removeCommaSpan = markSpan.replaceAll(",word_.*", ""); System.err.println("--> newSpan: " + removeCommaSpan); String[] spanWords = removeCommaSpan.split("\\.\\."); int startIndex = Integer.parseInt(spanWords[0].replace("word_", "")); int endIndex = Integer.parseInt(spanWords[spanWords.length - 1].replace("word_", "")) + 1; List<String> wfIds = Arrays.asList(Arrays.copyOfRange(tokenIds, startIndex - 1, endIndex - 1)); List<String> wfTermIds = getWFIdsFromTerms(sentTerms); if (checkTermsRefsIntegrity(wfIds, wfTermIds)) { List<Term> nameTerms = kaf.getTermsFromWFs(wfIds); ixa.kaflib.Span<Term> neSpan = KAFDocument.newTermSpan(nameTerms); List<ixa.kaflib.Span<Term>> references = new ArrayList<ixa.kaflib.Span<Term>>(); references.add(neSpan); Entity neEntity = kaf.newEntity(references); neEntity.setType("TARGET"); System.err.println("--> target: " + neEntity.getStr()); } } // end of create entity } }
From source file:fr.rt.acy.locapic.gps.TrackService.java
License:Open Source License
/** * Methode pour creer le document JDOM de base pour le fichier GPX * Prend en parametre des valeurs pour les metadonnees GPX (contenues dans la balise <metadata>) * @param name - Nom du fichier gpx (pour les metadonnees GPX) * @param desc - Description du fichier gpx (pour les metadonnees GPX) * @param authorsName - Nom de l'autheur de la trace (pour les metadonnees GPX) * @param authorsEmail - Email de l'autheur de la trace (pour les metadonnees GPX) * @param keywords - Mots-cle pour les metadonnees GPX * @return document - Le document JDOM servant de base GPX *//* www . j a v a2s . c om*/ public Document createGpxDocTree(String name, String desc, String authorsName, String authorsEmail, String keywords) { /* Pour la date */ Calendar calendar = Calendar.getInstance(); Date date = calendar.getTime(); // Format de la date SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss"); StringBuilder dateBuilder = new StringBuilder(dateFormat.format(date)); // Pour le format GPX, T apres la date et avant l'heure, et Z a la fin dateBuilder.append("Z"); dateBuilder.insert(10, "T"); // Conversion builder => string String formattedDate = dateBuilder.toString(); Log.v(TAG, "TIME => " + formattedDate); /* Pour le reste des metadonnees perso */ String mailId; String mailDomain; if (name == null) name = "LocaPic track"; if (desc == null) desc = "GPS track logged on an Android device with an application from a project by Samuel Beaurepaire & Virgile Beguin for IUT of Annecy (Fr), RT departement."; if (authorsName == null) authorsName = "Samuel Beaurepaire"; if (authorsEmail == null) { mailId = "sjbeaurepaire"; mailDomain = "orange.fr"; } else { String[] mail = authorsEmail.split("@", 2); mailId = mail[0]; mailDomain = mail[1]; } // xsi du namespace a indique seulement pour la racine (addNamespaceDeclaratin()) Namespace XSI = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); // Creation de la racine du fichier gpx (<gpx></gpx>) sous forme d'objet de classe Element avec le namespace gpx Element xml_gpx = new Element("gpx", ns); // Namespace XSI et attributs xml_gpx.addNamespaceDeclaration(XSI); xml_gpx.setAttribute(new Attribute("schemaLocation", "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd", XSI)); xml_gpx.setAttribute(new Attribute("creator", "LocaPic")); xml_gpx.setAttribute(new Attribute("version", "1.1")); // On cree un nouveau Document JDOM base sur la racine que l'on vient de creer Document document = new Document(xml_gpx); // ~~~~~~~~~~~~~~~~ <metadata> ~~~~~~~~~~~~~~~~ Element xml_metadata = new Element("metadata", ns); xml_gpx.addContent(xml_metadata); // ~~~~~~~~~~~~~~~~ <name> ~~~~~~~~~~~~~~~~ Element xml_metadata_name = new Element("name", ns); xml_metadata_name.addContent(name); xml_metadata.addContent(xml_metadata_name); // ~~~~~~~~~~~~~~~~ <desc> ~~~~~~~~~~~~~~~~ Element xml_metadata_desc = new Element("desc", ns); xml_metadata_desc.addContent(desc); xml_metadata.addContent(xml_metadata_desc); // ~~~~~~~~~~~~~~~~ <author> ~~~~~~~~~~~~~~~~ Element xml_metadata_author = new Element("author", ns); // ~~~~~~~~~~~~~~~~ <author> ~~~~~~~~~~~~~~~~ Element xml_metadata_author_name = new Element("name", ns); xml_metadata_author_name.addContent(authorsName); xml_metadata_author.addContent(xml_metadata_author_name); // ~~~~~~~~~~~~~~~~ <email> ~~~~~~~~~~~~~~~~ Element xml_metadata_author_email = new Element("email", ns); xml_metadata_author_email.setAttribute("id", mailId); xml_metadata_author_email.setAttribute("domain", mailDomain); xml_metadata_author.addContent(xml_metadata_author_email); xml_metadata.addContent(xml_metadata_author); // ~~~~~~~~~~~~~~~~ <time> ~~~~~~~~~~~~~~~~ Element xml_metadata_time = new Element("time", ns); xml_metadata_time.addContent(formattedDate); xml_metadata.addContent(xml_metadata_time); // ~~~~~~~~~~~~~~~~ <keywords> ~~~~~~~~~~~~~~~~ if (keywords != null) { Element xml_keywords = new Element("keywords", ns); xml_keywords.addContent(keywords); xml_metadata.addContent(xml_keywords); } // ~~~~~~~~~~~~~~~~ <trk> ~~~~~~~~~~~~~~~~ Element xml_trk = new Element("trk", ns); // ~~~~~~~~~~~~~~~~ <number> ~~~~~~~~~~~~~~~~ Element xml_trk_number = new Element("number", ns); xml_trk_number.addContent("1"); xml_trk.addContent(xml_trk_number); // ~~~~~~~~~~~~~~~~ <trkseg> ~~~~~~~~~~~~~~~~ Element xml_trk_trkseg = new Element("trkseg", ns); xml_trk.addContent(xml_trk_trkseg); xml_gpx.addContent(xml_trk); return document; }
From source file:jgoose.IEC61850_GOOSE_ICD_file.java
License:Open Source License
void decodeDataSetBlock(String dataSetName, String ldInstance) throws IEC61850_GOOSE_Exception { /*/*w ww .j a va 2 s .com*/ * In this part, we decode the the DataSet block in order to find each signal in it */ boolean found_DataSet = false; GOOSESignalsList = new ArrayList<GOOSESignalAttributes>(); // Retrieves all elements named "DataSet" within IED Filter<Element> elementFilter = new ElementFilter("DataSet"); // Search for a DataSet with a matching name for (Iterator<Element> DataSet_IT = IED_section.getDescendants(elementFilter); DataSet_IT.hasNext();) { Element current_element = DataSet_IT.next(); if (current_element.getAttributeValue("name").equals(dataSetName)) { DataSet_node = current_element; found_DataSet = true; } } if (found_DataSet == false) throw new IEC61850_GOOSE_Exception("<DataSet> named" + dataSetName + "not found"); /* * Now that we found the DataSet, we are looking for the signals in it */ FCDA_nodes_LIST = DataSet_node.getChildren("FCDA", root_namespace); // Walks all FCDA nodes to retrieve the signals for (int position = 0; position < FCDA_nodes_LIST.size(); position++) { // Search for a signals, FCDA nodes, with matching ldInst if (FCDA_nodes_LIST.get(position).getAttributeValue("ldInst").contentEquals(ldInstance)) { // We found a signal with the right ldInst GOOSESignalAttributes new_GOOSESignal = new GOOSESignalAttributes(); // We save all signal information new_GOOSESignal.lnClass = FCDA_nodes_LIST.get(position).getAttributeValue("lnClass"); new_GOOSESignal.lnInst = Integer .parseInt(FCDA_nodes_LIST.get(position).getAttributeValue("lnInst")); new_GOOSESignal.doName = FCDA_nodes_LIST.get(position).getAttributeValue("doName"); new_GOOSESignal.daName = FCDA_nodes_LIST.get(position).getAttributeValue("daName"); new_GOOSESignal.fc = FCDA_nodes_LIST.get(position).getAttributeValue("fc"); // We insert the signal in the signal list GOOSESignalsList.add(new_GOOSESignal); } } if (GOOSESignalsList.size() == 0) { throw new IEC61850_GOOSE_Exception( "Could not find any signal with ldInst name: " + ldInstance + " in DataSet: " + dataSetName); } /* * Now we have to extract all signal attributes */ for (int position = 0; position < GOOSESignalsList.size(); position++) { GOOSESignalAttributes current_GOOSESignal = GOOSESignalsList.get(position); boolean found_NodeType = false; /* * Now we have to extract the lnType using the lnClass and the inst number */ boolean found_LDevice = false; // Retrieves all elements named "LDevice" within the SCL file elementFilter = new ElementFilter("LDevice"); // Search for a LDevice block with name matching ldInstance in the IED section for (Iterator<Element> LDevice_IT = IED_section.getDescendants(elementFilter); LDevice_IT.hasNext();) { Element current_element = LDevice_IT.next(); // We found one matching element if (current_element.getAttributeValue("inst").equals(ldInstance)) { // Something is wrong, its the second time we find a LDevice block with a matching name if (found_LDevice == true) throw new IEC61850_GOOSE_Exception( "There is more than one <LDevice> block named:" + ldInstance + " in the SCL file"); else found_LDevice = true; boolean found_IECData = false; // Retrieves all elements named "LN" within IED node elementFilter = new ElementFilter("LN"); // Search for a LN block with a matching lnClass and inst prefix for (Iterator<Element> LN_IT = current_element.getDescendants(elementFilter); LN_IT .hasNext();) { Element innerloop_element = LN_IT.next(); if (innerloop_element.getAttributeValue("lnClass").equals(current_GOOSESignal.lnClass) && innerloop_element.getAttributeValue("inst") .equals(String.valueOf(current_GOOSESignal.lnInst))) { /* * We found the right LN node. We save the lnType */ current_GOOSESignal.lnType_id = innerloop_element.getAttributeValue("lnType"); Element DOI_element = innerloop_element.getChild("DOI", root_namespace); if (DOI_element.getAttributeValue("name").equals(current_GOOSESignal.doName)) { Element DAI_element = DOI_element.getChild("DAI", root_namespace); if (DAI_element.getAttributeValue("name").equals(current_GOOSESignal.daName)) { Element Private_element = DAI_element.getChild("Private", root_namespace); /* * Save IEC 60870-5-104 data for every signal */ if (Private_element.getAttributeValue("type") .contentEquals("IEC_60870_5_104")) { Namespace iec_60870_5_104_namespace = Namespace.getNamespace( "IEC_60870_5_104", "http://www.iec.ch/61850-80-1/2007/SCL"); Element IEC_element = Private_element.getChild("GlobalAddress104", iec_60870_5_104_namespace); current_GOOSESignal.casdu = Integer .parseInt(IEC_element.getAttributeValue("casdu")); current_GOOSESignal.ioa = Integer .parseInt(IEC_element.getAttributeValue("ioa")); current_GOOSESignal.ti = Integer .parseInt(IEC_element.getAttributeValue("ti")); found_IECData = true; } } } } } if (found_IECData == false) throw new IEC61850_GOOSE_Exception( "<LN> block with corresponding lnClass, inst, lnType, DOI name" + "and DAI name not found in <IED> for signal " + String.valueOf(position + 1)); } } if (found_LDevice == false) throw new IEC61850_GOOSE_Exception( "There is no <LDevice> block named:" + ldInstance + " in the SCL file"); // Retrieve Node DataTypeTemplates Element dataTypeTemplate_element = xml_document.getRootElement().getChild("DataTypeTemplates", root_namespace); // Retrieves all elements named "LNodeType" within DataTypeTemplates node elementFilter = new ElementFilter("LNodeType"); // Search for a LNodeType block with a matching lnClass and id for (Iterator<Element> LNodeType_IT = dataTypeTemplate_element .getDescendants(elementFilter); LNodeType_IT.hasNext();) { Element current_element = LNodeType_IT.next(); if (current_element.getAttributeValue("lnClass").equals(current_GOOSESignal.lnClass) && current_element.getAttributeValue("id") .equals(String.valueOf(current_GOOSESignal.lnType_id))) { // Walks all DO nodes List<Element> do_nodes_LIST = current_element.getChildren("DO", root_namespace); // Walks all DO nodes to retrieve addressing data for (int do_position = 0; do_position < do_nodes_LIST.size(); do_position++) { // Looks for a DO node with the correct name if (do_nodes_LIST.get(do_position).getAttributeValue("name") .equals(current_GOOSESignal.doName)) { current_GOOSESignal.do_type = do_nodes_LIST.get(do_position).getAttributeValue("type"); found_NodeType = true; } } } } if (found_NodeType == false) throw new IEC61850_GOOSE_Exception("<DO> node within <LNodeType> block with corresponding name, " + "lnClass and id not found in <DataTypeTemplates> for signal " + String.valueOf(position + 1)); boolean found_NodebType = false; // Retrieves all elements named "DOType" within DataTypeTemplates node elementFilter = new ElementFilter("DOType"); // Search for a DOType block with a matching id for (Iterator<Element> DOType_IT = dataTypeTemplate_element.getDescendants(elementFilter); DOType_IT .hasNext();) { Element current_element = DOType_IT.next(); if (current_element.getAttributeValue("id").equals(current_GOOSESignal.do_type)) { current_GOOSESignal.cdc = current_element.getAttributeValue("cdc"); current_GOOSESignal.desc = current_element.getAttributeValue("desc"); // Walks all DA nodes List<Element> da_nodes_LIST = current_element.getChildren("DA", root_namespace); // Walks all DO nodes to retrieve addressing data for (int da_position = 0; da_position < da_nodes_LIST.size(); da_position++) { // Looks for a DA node with the correct fc and name if (da_nodes_LIST.get(da_position).getAttributeValue("fc").equals(current_GOOSESignal.fc) && da_nodes_LIST.get(da_position).getAttributeValue("name") .equals(current_GOOSESignal.daName)) { current_GOOSESignal.bType = da_nodes_LIST.get(da_position).getAttributeValue("bType"); found_NodebType = true; } } } } if (found_NodebType == false) throw new IEC61850_GOOSE_Exception("<DA> node within <DOType> block with corresponding fc, name," + " and id not found in <DataTypeTemplates> for signal " + String.valueOf(position + 1)); } return; }
From source file:jodtemplate.pptx.postprocessor.StylePostprocessor.java
License:Apache License
private Namespace getNamespace() { return Namespace.getNamespace(PPTXDocument.DRAWINGML_NAMESPACE_PREFIX, PPTXDocument.DRAWINGML_NAMESPACE); }
From source file:jodtemplate.pptx.style.HtmlStylizer.java
License:Apache License
private Namespace getDrawingmlNamespace() { return Namespace.getNamespace(PPTXDocument.DRAWINGML_NAMESPACE_PREFIX, PPTXDocument.DRAWINGML_NAMESPACE); }
From source file:jodtemplate.pptx.style.HtmlStylizer.java
License:Apache License
private Namespace getRelationshipsNamespace() { return Namespace.getNamespace(PPTXDocument.RELATIONSHIPS_NAMESPACE_PREFIX, PPTXDocument.RELATIONSHIPS_NAMESPACE); }
From source file:net.instantcom.mm7.MM7Message.java
License:Open Source License
public void setNamespace(String namespace) { this.namespace = namespace != null ? Namespace.getNamespace(mm7NamespacePrefix, namespace) : null; }
From source file:org.apache.marmotta.ldclient.provider.xml.AbstractXMLDataProvider.java
License:Apache License
/** * Parse the HTTP response entity returned by the web service call and return its contents as a Sesame RDF * repository. The content type returned by the web service is passed as argument to help the implementation * decide how to parse the data.// w w w . j a va 2 s .co m * * * * @param resource the subject of the data retrieval * @param triples *@param in input stream as returned by the remote webservice * @param contentType content type as returned in the HTTP headers of the remote webservice @return an RDF repository containing an RDF representation of the dataset located at the remote resource. * @throws java.io.IOException in case an error occurs while reading the input stream */ @Override public List<String> parseResponse(String resource, String requestUrl, Model triples, InputStream in, String contentType) throws DataRetrievalException { // build a JDOM document try { SAXBuilder parser = new SAXBuilder(XMLReaders.NONVALIDATING); Document doc = parser.build(in); Set<Namespace> namespaces = new HashSet<Namespace>(); for (Map.Entry<String, String> ns : getNamespaceMappings().entrySet()) { namespaces.add(Namespace.getNamespace(ns.getKey(), ns.getValue())); } ValueFactory vf = new ValueFactoryImpl(); Resource subject = vf.createURI(resource); for (Map.Entry<String, XPathValueMapper> mapping : getXPathMappings(requestUrl).entrySet()) { XPathExpression<Object> xpath = mapping.getValue().getCompiled(); org.openrdf.model.URI predicate = triples.getValueFactory().createURI(mapping.getKey()); for (Object value : xpath.evaluate(doc)) { String str_value; if (value instanceof Element) { str_value = ((Element) value).getValue(); } else if (value instanceof Text) { str_value = ((Text) value).getValue(); } else if (value instanceof Attribute) { str_value = ((Attribute) value).getValue(); } else if (value instanceof CDATA) { str_value = ((CDATA) value).getValue(); } else if (value instanceof Comment) { str_value = ((Comment) value).getValue(); } else { str_value = value.toString(); } List<Value> objects = mapping.getValue().map(resource, str_value, triples.getValueFactory()); for (Value object : objects) { Statement stmt = triples.getValueFactory().createStatement(subject, predicate, object); triples.add(stmt); } } } org.openrdf.model.URI ptype = triples.getValueFactory().createURI(Namespaces.NS_RDF + "type"); for (String typeUri : getTypes(vf.createURI(resource))) { Resource type_resource = vf.createURI(typeUri); triples.add(vf.createStatement(subject, ptype, type_resource)); } return Collections.emptyList(); } catch (JDOMException e) { throw new DataRetrievalException("could not parse XML response. It is not in proper XML format", e); } catch (IOException e) { throw new DataRetrievalException("I/O error while parsing XML response", e); } }
From source file:org.apache.marmotta.ldclient.provider.xml.mapping.XPathValueMapper.java
License:Apache License
protected XPathValueMapper(String xpath, Map<String, String> namespaces) { this.xpath = xpath; Set<Namespace> xnamespaces = new HashSet<Namespace>(); if (namespaces != null) { for (Map.Entry<String, String> ns : namespaces.entrySet()) { xnamespaces.add(Namespace.getNamespace(ns.getKey(), ns.getValue())); }/* w w w .j a v a 2 s .c om*/ } this.compiled = XPathFactory.instance().compile(xpath, Filters.fpassthrough(), null, xnamespaces); }
From source file:org.apache.marmotta.ucuenca.wk.provider.orcid.ORCIDRawProvider.java
License:Apache License
protected static List<Element> queryElements(Document n, String query) { return XPathFactory.instance() .compile(query, new ElementFilter(), null, Namespace.getNamespace("external-identifier", "http://www.orcid.org/ns/external-identifier"), Namespace.getNamespace("email", "http://www.orcid.org/ns/email"), Namespace.getNamespace("other-name", "http://www.orcid.org/ns/other-name"), Namespace.getNamespace("personal-details", "http://www.orcid.org/ns/personal-details"), Namespace.getNamespace("person", "http://www.orcid.org/ns/person"), Namespace.getNamespace("record", "http://www.orcid.org/ns/record"), Namespace.getNamespace("search", "http://www.orcid.org/ns/search"), Namespace.getNamespace("keyword", "http://www.orcid.org/ns/keyword"), Namespace.getNamespace("employment", "http://www.orcid.org/ns/employment"), Namespace.getNamespace("researcher-url", "http://www.orcid.org/ns/researcher-url"), Namespace.getNamespace("activities", "http://www.orcid.org/ns/activities"), Namespace.getNamespace("education", "http://www.orcid.org/ns/education"), Namespace.getNamespace("work", "http://www.orcid.org/ns/work"), Namespace.getNamespace("common", "http://www.orcid.org/ns/common")) .evaluate(n);/*from ww w.jav a2 s .c o m*/ }