Example usage for org.jdom2 Document getBaseURI

List of usage examples for org.jdom2 Document getBaseURI

Introduction

In this page you can find the example usage for org.jdom2 Document getBaseURI.

Prototype

public final String getBaseURI() 

Source Link

Document

Returns the URI from which this document was loaded, or null if this is not known.

Usage

From source file:com.bennavetta.util.tycho.XmlWrapDescriptorParser.java

License:Apache License

public WrapRequest createRequest(Document doc) throws Exception {
    log.info("Parsing wrapper configuration {} from {}", doc, doc.getBaseURI());

    DefaultWrapRequest req = new DefaultWrapRequest();

    if (doc.getRootElement().getChild("repositories") != null) {
        for (Element repoDescriptor : doc.getRootElement().getChild("repositories").getChildren("repository")) {
            Repository repo = new Repository();
            repo.setId(repoDescriptor.getAttributeValue("id"));
            repo.setLayout(repoDescriptor.getAttributeValue("layout", "default"));
            repo.setName(repoDescriptor.getAttributeValue("name"));
            repo.setUrl(repoDescriptor.getAttributeValue("url"));
            log.debug("Adding repository {}", repo);
            req.addRepository(repo);/*  ww w .  ja v a2  s  .c o m*/
        }
    }

    String bndDir = doc.getRootElement().getChildText("bndDir");
    if (bndDir != null) {
        req.setBndDirectory(new File(bndDir));
        log.debug("Bnd directory: {}", bndDir);
    }

    Model parent = Maven.createModel(new File(doc.getRootElement().getChildText("parent")));
    req.setParent(parent);
    log.debug("Parent: {}", parent);
    for (Element artifactDescriptor : doc.getRootElement().getChild("artifacts").getChildren("artifact")) {
        String groupId = artifactDescriptor.getAttributeValue("groupId");
        String artifactId = artifactDescriptor.getAttributeValue("artifactId");
        String version = artifactDescriptor.getAttributeValue("version");
        log.debug("Adding artifact {}:{}:{}", groupId, artifactId, version);
        DefaultArtifactInfo info = new DefaultArtifactInfo(
                new DefaultArtifact(groupId + ":" + artifactId + ":" + version),
                artifactDescriptor.getAttributeValue("symbolicName"));
        req.addArtifact(info);
    }
    return req;
}

From source file:com.c4om.utils.xmlutils.XMLLibsShortcuts.java

License:Apache License

/**
 * This method takes an {@link Object} and tries to get an equivalent Saxon {@link XdmValue}. This is 
 * useful, for example, if the value is going to be set to a variable in a XQuery query.<p/>
 * Currently, those object kinds are supported:
 * <ol>/*  ww w.  j a v  a 2s  .c  om*/
 * <li>Any of the ones suitable to construct a {@link XdmAtomicValue} (look at {@link XdmAtomicValue} constructors for details), except for the Saxon-specific ones (AtomicValue, QName).</li>
 * <li>A {@link org.w3c.dom.Document} or a {@link org.w3c.dom.Node} <b>whose {@link org.w3c.dom.Node#getOwnerDocument()} returns a valid owner document.</b></li>
 * <li>An array of the types described at points 1 and 2.</li>
 * <li>An {@link Iterable} whose returned objects are of the types described at points 1 or 2 (it means, an {@link Iterable} that first returns an {@link String} and then a {@link Boolean} would be valid, for example).</li>
 * </ol>
 * @param variableValue any object following the aforementioned restrictions.
 * @param configuration Saxon {@link Configuration} used to build the {@link Processor} used.
 * @return An equivalent {@link XdmValue}
 * @throws IllegalArgumentException if the value or any of it subvalues (if it was an array or an {@link Iterable}) cannot be transformed into a suitable {@link XdmValue}.
 */
protected static XdmValue generateXdmValueForObject(Object variableValue, Configuration configuration) {
    XdmValue xdmValueForVariable;
    if (variableValue instanceof XdmValue) {
        xdmValueForVariable = (XdmValue) variableValue;
    } else if (variableValue instanceof BigDecimal) {
        xdmValueForVariable = new XdmAtomicValue((BigDecimal) variableValue);
    } else if (variableValue instanceof Boolean) {
        xdmValueForVariable = new XdmAtomicValue((Boolean) variableValue);
    } else if (variableValue instanceof Double) {
        xdmValueForVariable = new XdmAtomicValue((Double) variableValue);
    } else if (variableValue instanceof Float) {
        xdmValueForVariable = new XdmAtomicValue((Float) variableValue);
    } else if (variableValue instanceof Long) {
        xdmValueForVariable = new XdmAtomicValue((Long) variableValue);
    } else if (variableValue instanceof String) {
        xdmValueForVariable = new XdmAtomicValue((String) variableValue);
    } else if (variableValue instanceof URI) {
        xdmValueForVariable = new XdmAtomicValue((URI) variableValue);
    } else if (variableValue instanceof BigDecimal[]) {
        List<?> variableValueList = Arrays.asList(variableValue);
        xdmValueForVariable = getXdmValueFromIterable(variableValueList, configuration);
    } else if (variableValue instanceof Boolean[]) {
        List<?> variableValueList = Arrays.asList(variableValue);
        xdmValueForVariable = getXdmValueFromIterable(variableValueList, configuration);
    } else if (variableValue instanceof Double[]) {
        List<?> variableValueList = Arrays.asList(variableValue);
        xdmValueForVariable = getXdmValueFromIterable(variableValueList, configuration);
    } else if (variableValue instanceof Float[]) {
        List<?> variableValueList = Arrays.asList(variableValue);
        xdmValueForVariable = getXdmValueFromIterable(variableValueList, configuration);
    } else if (variableValue instanceof Long[]) {
        List<?> variableValueList = Arrays.asList(variableValue);
        xdmValueForVariable = getXdmValueFromIterable(variableValueList, configuration);
    } else if (variableValue instanceof String[]) {
        List<?> variableValueList = Arrays.asList(variableValue);
        xdmValueForVariable = getXdmValueFromIterable(variableValueList, configuration);
    } else if (variableValue instanceof URI[]) {
        List<?> variableValueList = Arrays.asList(variableValue);
        xdmValueForVariable = getXdmValueFromIterable(variableValueList, configuration);
    } else if (variableValue instanceof org.w3c.dom.Document) {
        org.w3c.dom.Document variableValueDocument = (org.w3c.dom.Document) variableValue;
        DocumentWrapper wrapper = new DocumentWrapper(variableValueDocument, variableValueDocument.getBaseURI(),
                configuration);
        xdmValueForVariable = new XdmNode(wrapper);
    } else if (variableValue instanceof org.w3c.dom.Node) {
        org.w3c.dom.Node variableValueNode = (org.w3c.dom.Node) variableValue;
        DocumentWrapper documentWrapper = new DocumentWrapper(variableValueNode.getOwnerDocument(),
                variableValueNode.getBaseURI(), configuration);
        DOMNodeWrapper wrapper = documentWrapper.wrap(variableValueNode);
        xdmValueForVariable = new XdmNode(wrapper);
    } else if (variableValue instanceof Iterable<?>) {
        Iterable<?> variableValueIterable = (Iterable<?>) variableValue;
        xdmValueForVariable = getXdmValueFromIterable(variableValueIterable, configuration);
    } else {
        throw new IllegalArgumentException("Non recognized variable value type.");
    }
    return xdmValueForVariable;
}

From source file:de.altimos.util.asset.ext.XmlDocument.java

License:Apache License

@SuppressWarnings("rawtypes")
public XmlDocument(AssetKey key, Document doc) {
    super();/*  w  w w  .  j  ava2  s .c om*/
    if (doc != null) {
        setDocType(doc.getDocType());
        setBaseURI(doc.getBaseURI());
        setContent(doc.getRootElement().detach());
    }
    this.key = key;
}

From source file:edu.byu.ece.rapidSmith.device.creation.DeviceGenerator.java

License:Open Source License

/**
 * Creates a map from pad bel name -> corresponding package pin. This
 * information is needed when generating Tincr Checkpoints from
 * RS to be loaded into Vivado.//from   ww  w.  j a  v a2  s .c om
 */
private static void createPackagePins(Device device, Document deviceInfo) {
    Element pinMapRootEl = deviceInfo.getRootElement().getChild("package_pins");

    if (pinMapRootEl == null) {
        throw new Exceptions.ParseException("No package pin information found in device info file: "
                + deviceInfo.getBaseURI() + ".\n"
                + "Either add the package pin mappings, or remove the device info file and regenerate.");
    }

    // Add the package pins to the device
    pinMapRootEl
            .getChildren("package_pin").stream().map(ppEl -> new PackagePin(ppEl.getChildText("name"),
                    ppEl.getChildText("bel"), ppEl.getChild("is_clock") != null))
            .forEach(packagePin -> device.addPackagePin(packagePin));

    if (device.getPackagePins().isEmpty()) {
        throw new Exceptions.ParseException("No package pin information found in device info file: "
                + deviceInfo.getBaseURI() + ".\n"
                + "Either add the package pin mappings, or remove the device info file and regenerate.");
    }
}

From source file:se.miun.itm.input.util.xml.SAXUtil.java

License:Open Source License

private static se.miun.itm.input.model.Document getWrapper(Document document) {
    DocType dt = document.getDocType();//w  w  w .j a  va 2 s.  c o  m
    document.setDocType(null);
    Element root = document.getRootElement();
    // a new root is just added to change the context.
    document.setRootElement(new Element(Q.SEED));
    return new se.miun.itm.input.model.Document(root, dt, document.getBaseURI());
}

From source file:TVShowTimelineMaker.util.XML.TopLevelXMLWriter.java

private static Show createShowFromDocument(Document inShowDocument) {
    Element rootElement = inShowDocument.getRootElement();
    Attribute namespaceAttribute = rootElement.getAttribute("namespace");
    Show newShow;//  w  ww . j  a v  a 2 s .c om
    if (namespaceAttribute != null) {
        newShow = new Show(namespaceAttribute.getValue());
    } else {
        String baseURI = inShowDocument.getBaseURI();
        int beginIndex = baseURI.lastIndexOf('/');
        int endIndex = baseURI.lastIndexOf('.');
        if (beginIndex < 0) {
            beginIndex = 1;
        } else {
            beginIndex += 1;
        }
        if ((endIndex < 0) || (endIndex <= beginIndex)) {
            endIndex = baseURI.length();
        }
        baseURI = baseURI.substring(beginIndex, endIndex).replaceAll("%20", " ");
        if (baseURI != null) {
            newShow = new Show(baseURI);
        } else {
            newShow = new Show(defualtNameSpace);
        }
    }
    defualtNameSpace = newShow.getNameSpace();
    Timeline newTimeline = newShow.getTimeLine();
    Element EventsElement = rootElement.getChild("Events");
    //todo: make mutithreaded
    List<Event> collectedEvents = EventsElement.getChildren().parallelStream()
            .filter((Element curEventElement) -> XMLWriterImp.getXMLWriter(
                    MyLittePonyMaps.getEventClassForFriendlyString(curEventElement.getName())) != null)
            .map((Element curEventElement) -> {
                XMLWriter EventXMLWriter = XMLWriterImp.getXMLWriter(
                        MyLittePonyMaps.getEventClassForFriendlyString(curEventElement.getName()));
                return EventXMLWriter.readElements(curEventElement);
            }).filter((Object o) -> o instanceof Event).map((Object o) -> (Event) o)
            .collect(Collectors.toList());
    newTimeline.addEvents(collectedEvents);
    EventImp.addEventsToEventMap(collectedEvents);
    Element CharactersElement = rootElement.getChild("Characters");
    XMLWriter<NamedCharacter> NamedCharacterXMLWriter = XMLWriterImp.getXMLWriter(NamedCharacter.class);
    List<NamedCharacter> collectedCharacters = CharactersElement.getChildren().parallelStream()
            .map(NamedCharacterXMLWriter::readElements).collect(Collectors.toList());
    newShow.addCharacters(collectedCharacters);
    NamedCharacter.addCharactersIntoCharacterMap(collectedCharacters);
    Element EpisodesElement = rootElement.getChild("Episodes");
    XMLWriter<Episode> EpisodeXMLWriter = XMLWriterImp.getXMLWriter(Episode.class);
    //todo: make mutithreaded
    List<Episode> collectedEpisodes = EpisodesElement.getChildren().parallelStream()
            .map(EpisodeXMLWriter::readElements).collect(Collectors.toList());
    newShow.addEpisodes(collectedEpisodes);
    Element ConstraintsElement = rootElement.getChild("Constraints");
    //todo: make mutithreaded
    newTimeline.addTimeConstraints(ConstraintsElement.getChildren().parallelStream()
            .filter((Element curElement) -> XMLWriterImp.getXMLWriter(
                    MyLittePonyMaps.getConstraintClassForFriendlyString(curElement.getName())) != null)
            .map((Element curElement) -> {
                XMLWriter ConstraintXMLWriter = XMLWriterImp.getXMLWriter(
                        MyLittePonyMaps.getConstraintClassForFriendlyString(curElement.getName()));
                return (TimeConstraint) ConstraintXMLWriter.readElements(curElement);
            }).collect(Collectors.toList()));
    return newShow;
}