repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
echocat/adam
src/main/java/org/echocat/adam/configuration/profile/Element.java
// Path: src/main/java/org/echocat/adam/configuration/IdEnabled.java // public abstract class IdEnabled implements org.echocat.jomon.runtime.util.IdEnabled<String> { // // @Nonnull // private String _id = randomUUID().toString(); // // @Override // @Nonnull // @XmlAttribute(name = "id", required = true) // public String getId() { // return _id; // } // // public void setId(@Nonnull String id) { // _id = id; // } // // } // // Path: src/main/java/org/echocat/adam/configuration/access/viewedit/ViewEditAccess.java // @XmlType(name = "viewEditAccess", namespace = SCHEMA_NAMESPACE) // public class ViewEditAccess extends ViewAccessSupport<Default, Anonymous, Owner, Administrator, Group> { // // @Override // @XmlElement(name = "default", namespace = SCHEMA_NAMESPACE, type = Default.class) // public void setDefault(@Nullable Default all) { // super.setDefault(all); // } // // @Override // @XmlElement(name = "anonymous", namespace = SCHEMA_NAMESPACE, type = Anonymous.class) // public void setAnonymous(@Nullable Anonymous anonymous) { // super.setAnonymous(anonymous); // } // // @Override // @XmlElement(name = "owner", namespace = SCHEMA_NAMESPACE, type = Owner.class) // public void setOwner(@Nullable Owner owner) { // super.setOwner(owner); // } // // @Override // @XmlElement(name = "administrator", namespace = SCHEMA_NAMESPACE, type = Administrator.class) // public void setAdministrator(@Nullable Administrator administrator) { // super.setAdministrator(administrator); // } // // @Override // @XmlElement(name = "group", namespace = SCHEMA_NAMESPACE, type = Group.class) // public void setGroups(@Nullable List<Group> groups) { // super.setGroups(groups); // } // // } // // Path: src/main/java/org/echocat/adam/configuration/localization/Localized.java // @XmlType(name = "localized", namespace = SCHEMA_NAMESPACE) // public abstract class Localized extends IdEnabled { // // @Nullable // private List<Localization> _localizations; // // @Nullable // @XmlElement(name = "localization", namespace = SCHEMA_NAMESPACE) // public List<Localization> getLocalizations() { // return _localizations; // } // // public void setLocalizations(@Nullable List<Localization> localizations) { // _localizations = localizations; // } // // // } // // Path: src/main/java/org/echocat/adam/configuration/template/Template.java // @XmlType(name = "template", namespace = SCHEMA_NAMESPACE) // public class Template extends TemplateSupport { // // @Nonnull // private String _source = ""; // @Nonnull // private TemplateFormat _format = velocity; // // @Override // @Nonnull // public String getSource() { // return _source; // } // // @XmlValue // @XmlValueExtension // public void setSource(@Nonnull String source) { // _source = source; // } // // @Override // @Nonnull // public TemplateFormat getFormat() { // return _format; // } // // @XmlAttribute(name = "format") // public void setFormat(@Nonnull TemplateFormat format) { // _format = format; // } // // } // // Path: src/main/java/org/echocat/adam/profile/element/ElementModel.java // public static enum Type { // singleLineText, // multiLineText, // emailAddress, // url, // phoneNumber, // wikiMarkup, // html // } // // Path: src/main/java/org/echocat/adam/configuration/ConfigurationContants.java // public static final String SCHEMA_NAMESPACE = "https://adam.echocat.org/schemas/configuration.xsd";
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; import java.util.List; import static org.echocat.adam.configuration.ConfigurationContants.SCHEMA_NAMESPACE; import static org.echocat.adam.profile.element.ElementModel.Type.singleLineText; import org.echocat.adam.configuration.IdEnabled; import org.echocat.adam.configuration.access.viewedit.ViewEditAccess; import org.echocat.adam.configuration.localization.Localized; import org.echocat.adam.configuration.template.Template; import org.echocat.adam.profile.element.ElementModel.Type; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.xml.bind.annotation.XmlAttribute;
/***************************************************************************************** * *** BEGIN LICENSE BLOCK ***** * * echocat Adam, Copyright (c) 2014 echocat * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * * *** END LICENSE BLOCK ***** ****************************************************************************************/ package org.echocat.adam.configuration.profile; @XmlType(name = "profileGroupElement", namespace = SCHEMA_NAMESPACE) public class Element extends Localized { @Nullable private List<ContextAttribute> _contextAttributes; @Nullable private ViewEditAccess _access; @Nonnull
// Path: src/main/java/org/echocat/adam/configuration/IdEnabled.java // public abstract class IdEnabled implements org.echocat.jomon.runtime.util.IdEnabled<String> { // // @Nonnull // private String _id = randomUUID().toString(); // // @Override // @Nonnull // @XmlAttribute(name = "id", required = true) // public String getId() { // return _id; // } // // public void setId(@Nonnull String id) { // _id = id; // } // // } // // Path: src/main/java/org/echocat/adam/configuration/access/viewedit/ViewEditAccess.java // @XmlType(name = "viewEditAccess", namespace = SCHEMA_NAMESPACE) // public class ViewEditAccess extends ViewAccessSupport<Default, Anonymous, Owner, Administrator, Group> { // // @Override // @XmlElement(name = "default", namespace = SCHEMA_NAMESPACE, type = Default.class) // public void setDefault(@Nullable Default all) { // super.setDefault(all); // } // // @Override // @XmlElement(name = "anonymous", namespace = SCHEMA_NAMESPACE, type = Anonymous.class) // public void setAnonymous(@Nullable Anonymous anonymous) { // super.setAnonymous(anonymous); // } // // @Override // @XmlElement(name = "owner", namespace = SCHEMA_NAMESPACE, type = Owner.class) // public void setOwner(@Nullable Owner owner) { // super.setOwner(owner); // } // // @Override // @XmlElement(name = "administrator", namespace = SCHEMA_NAMESPACE, type = Administrator.class) // public void setAdministrator(@Nullable Administrator administrator) { // super.setAdministrator(administrator); // } // // @Override // @XmlElement(name = "group", namespace = SCHEMA_NAMESPACE, type = Group.class) // public void setGroups(@Nullable List<Group> groups) { // super.setGroups(groups); // } // // } // // Path: src/main/java/org/echocat/adam/configuration/localization/Localized.java // @XmlType(name = "localized", namespace = SCHEMA_NAMESPACE) // public abstract class Localized extends IdEnabled { // // @Nullable // private List<Localization> _localizations; // // @Nullable // @XmlElement(name = "localization", namespace = SCHEMA_NAMESPACE) // public List<Localization> getLocalizations() { // return _localizations; // } // // public void setLocalizations(@Nullable List<Localization> localizations) { // _localizations = localizations; // } // // // } // // Path: src/main/java/org/echocat/adam/configuration/template/Template.java // @XmlType(name = "template", namespace = SCHEMA_NAMESPACE) // public class Template extends TemplateSupport { // // @Nonnull // private String _source = ""; // @Nonnull // private TemplateFormat _format = velocity; // // @Override // @Nonnull // public String getSource() { // return _source; // } // // @XmlValue // @XmlValueExtension // public void setSource(@Nonnull String source) { // _source = source; // } // // @Override // @Nonnull // public TemplateFormat getFormat() { // return _format; // } // // @XmlAttribute(name = "format") // public void setFormat(@Nonnull TemplateFormat format) { // _format = format; // } // // } // // Path: src/main/java/org/echocat/adam/profile/element/ElementModel.java // public static enum Type { // singleLineText, // multiLineText, // emailAddress, // url, // phoneNumber, // wikiMarkup, // html // } // // Path: src/main/java/org/echocat/adam/configuration/ConfigurationContants.java // public static final String SCHEMA_NAMESPACE = "https://adam.echocat.org/schemas/configuration.xsd"; // Path: src/main/java/org/echocat/adam/configuration/profile/Element.java import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; import java.util.List; import static org.echocat.adam.configuration.ConfigurationContants.SCHEMA_NAMESPACE; import static org.echocat.adam.profile.element.ElementModel.Type.singleLineText; import org.echocat.adam.configuration.IdEnabled; import org.echocat.adam.configuration.access.viewedit.ViewEditAccess; import org.echocat.adam.configuration.localization.Localized; import org.echocat.adam.configuration.template.Template; import org.echocat.adam.profile.element.ElementModel.Type; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.xml.bind.annotation.XmlAttribute; /***************************************************************************************** * *** BEGIN LICENSE BLOCK ***** * * echocat Adam, Copyright (c) 2014 echocat * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * * *** END LICENSE BLOCK ***** ****************************************************************************************/ package org.echocat.adam.configuration.profile; @XmlType(name = "profileGroupElement", namespace = SCHEMA_NAMESPACE) public class Element extends Localized { @Nullable private List<ContextAttribute> _contextAttributes; @Nullable private ViewEditAccess _access; @Nonnull
private Type _type = singleLineText;
echocat/adam
src/main/java/org/echocat/adam/configuration/profile/Element.java
// Path: src/main/java/org/echocat/adam/configuration/IdEnabled.java // public abstract class IdEnabled implements org.echocat.jomon.runtime.util.IdEnabled<String> { // // @Nonnull // private String _id = randomUUID().toString(); // // @Override // @Nonnull // @XmlAttribute(name = "id", required = true) // public String getId() { // return _id; // } // // public void setId(@Nonnull String id) { // _id = id; // } // // } // // Path: src/main/java/org/echocat/adam/configuration/access/viewedit/ViewEditAccess.java // @XmlType(name = "viewEditAccess", namespace = SCHEMA_NAMESPACE) // public class ViewEditAccess extends ViewAccessSupport<Default, Anonymous, Owner, Administrator, Group> { // // @Override // @XmlElement(name = "default", namespace = SCHEMA_NAMESPACE, type = Default.class) // public void setDefault(@Nullable Default all) { // super.setDefault(all); // } // // @Override // @XmlElement(name = "anonymous", namespace = SCHEMA_NAMESPACE, type = Anonymous.class) // public void setAnonymous(@Nullable Anonymous anonymous) { // super.setAnonymous(anonymous); // } // // @Override // @XmlElement(name = "owner", namespace = SCHEMA_NAMESPACE, type = Owner.class) // public void setOwner(@Nullable Owner owner) { // super.setOwner(owner); // } // // @Override // @XmlElement(name = "administrator", namespace = SCHEMA_NAMESPACE, type = Administrator.class) // public void setAdministrator(@Nullable Administrator administrator) { // super.setAdministrator(administrator); // } // // @Override // @XmlElement(name = "group", namespace = SCHEMA_NAMESPACE, type = Group.class) // public void setGroups(@Nullable List<Group> groups) { // super.setGroups(groups); // } // // } // // Path: src/main/java/org/echocat/adam/configuration/localization/Localized.java // @XmlType(name = "localized", namespace = SCHEMA_NAMESPACE) // public abstract class Localized extends IdEnabled { // // @Nullable // private List<Localization> _localizations; // // @Nullable // @XmlElement(name = "localization", namespace = SCHEMA_NAMESPACE) // public List<Localization> getLocalizations() { // return _localizations; // } // // public void setLocalizations(@Nullable List<Localization> localizations) { // _localizations = localizations; // } // // // } // // Path: src/main/java/org/echocat/adam/configuration/template/Template.java // @XmlType(name = "template", namespace = SCHEMA_NAMESPACE) // public class Template extends TemplateSupport { // // @Nonnull // private String _source = ""; // @Nonnull // private TemplateFormat _format = velocity; // // @Override // @Nonnull // public String getSource() { // return _source; // } // // @XmlValue // @XmlValueExtension // public void setSource(@Nonnull String source) { // _source = source; // } // // @Override // @Nonnull // public TemplateFormat getFormat() { // return _format; // } // // @XmlAttribute(name = "format") // public void setFormat(@Nonnull TemplateFormat format) { // _format = format; // } // // } // // Path: src/main/java/org/echocat/adam/profile/element/ElementModel.java // public static enum Type { // singleLineText, // multiLineText, // emailAddress, // url, // phoneNumber, // wikiMarkup, // html // } // // Path: src/main/java/org/echocat/adam/configuration/ConfigurationContants.java // public static final String SCHEMA_NAMESPACE = "https://adam.echocat.org/schemas/configuration.xsd";
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; import java.util.List; import static org.echocat.adam.configuration.ConfigurationContants.SCHEMA_NAMESPACE; import static org.echocat.adam.profile.element.ElementModel.Type.singleLineText; import org.echocat.adam.configuration.IdEnabled; import org.echocat.adam.configuration.access.viewedit.ViewEditAccess; import org.echocat.adam.configuration.localization.Localized; import org.echocat.adam.configuration.template.Template; import org.echocat.adam.profile.element.ElementModel.Type; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.xml.bind.annotation.XmlAttribute;
/***************************************************************************************** * *** BEGIN LICENSE BLOCK ***** * * echocat Adam, Copyright (c) 2014 echocat * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * * *** END LICENSE BLOCK ***** ****************************************************************************************/ package org.echocat.adam.configuration.profile; @XmlType(name = "profileGroupElement", namespace = SCHEMA_NAMESPACE) public class Element extends Localized { @Nullable private List<ContextAttribute> _contextAttributes; @Nullable private ViewEditAccess _access; @Nonnull private Type _type = singleLineText; @Nullable
// Path: src/main/java/org/echocat/adam/configuration/IdEnabled.java // public abstract class IdEnabled implements org.echocat.jomon.runtime.util.IdEnabled<String> { // // @Nonnull // private String _id = randomUUID().toString(); // // @Override // @Nonnull // @XmlAttribute(name = "id", required = true) // public String getId() { // return _id; // } // // public void setId(@Nonnull String id) { // _id = id; // } // // } // // Path: src/main/java/org/echocat/adam/configuration/access/viewedit/ViewEditAccess.java // @XmlType(name = "viewEditAccess", namespace = SCHEMA_NAMESPACE) // public class ViewEditAccess extends ViewAccessSupport<Default, Anonymous, Owner, Administrator, Group> { // // @Override // @XmlElement(name = "default", namespace = SCHEMA_NAMESPACE, type = Default.class) // public void setDefault(@Nullable Default all) { // super.setDefault(all); // } // // @Override // @XmlElement(name = "anonymous", namespace = SCHEMA_NAMESPACE, type = Anonymous.class) // public void setAnonymous(@Nullable Anonymous anonymous) { // super.setAnonymous(anonymous); // } // // @Override // @XmlElement(name = "owner", namespace = SCHEMA_NAMESPACE, type = Owner.class) // public void setOwner(@Nullable Owner owner) { // super.setOwner(owner); // } // // @Override // @XmlElement(name = "administrator", namespace = SCHEMA_NAMESPACE, type = Administrator.class) // public void setAdministrator(@Nullable Administrator administrator) { // super.setAdministrator(administrator); // } // // @Override // @XmlElement(name = "group", namespace = SCHEMA_NAMESPACE, type = Group.class) // public void setGroups(@Nullable List<Group> groups) { // super.setGroups(groups); // } // // } // // Path: src/main/java/org/echocat/adam/configuration/localization/Localized.java // @XmlType(name = "localized", namespace = SCHEMA_NAMESPACE) // public abstract class Localized extends IdEnabled { // // @Nullable // private List<Localization> _localizations; // // @Nullable // @XmlElement(name = "localization", namespace = SCHEMA_NAMESPACE) // public List<Localization> getLocalizations() { // return _localizations; // } // // public void setLocalizations(@Nullable List<Localization> localizations) { // _localizations = localizations; // } // // // } // // Path: src/main/java/org/echocat/adam/configuration/template/Template.java // @XmlType(name = "template", namespace = SCHEMA_NAMESPACE) // public class Template extends TemplateSupport { // // @Nonnull // private String _source = ""; // @Nonnull // private TemplateFormat _format = velocity; // // @Override // @Nonnull // public String getSource() { // return _source; // } // // @XmlValue // @XmlValueExtension // public void setSource(@Nonnull String source) { // _source = source; // } // // @Override // @Nonnull // public TemplateFormat getFormat() { // return _format; // } // // @XmlAttribute(name = "format") // public void setFormat(@Nonnull TemplateFormat format) { // _format = format; // } // // } // // Path: src/main/java/org/echocat/adam/profile/element/ElementModel.java // public static enum Type { // singleLineText, // multiLineText, // emailAddress, // url, // phoneNumber, // wikiMarkup, // html // } // // Path: src/main/java/org/echocat/adam/configuration/ConfigurationContants.java // public static final String SCHEMA_NAMESPACE = "https://adam.echocat.org/schemas/configuration.xsd"; // Path: src/main/java/org/echocat/adam/configuration/profile/Element.java import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; import java.util.List; import static org.echocat.adam.configuration.ConfigurationContants.SCHEMA_NAMESPACE; import static org.echocat.adam.profile.element.ElementModel.Type.singleLineText; import org.echocat.adam.configuration.IdEnabled; import org.echocat.adam.configuration.access.viewedit.ViewEditAccess; import org.echocat.adam.configuration.localization.Localized; import org.echocat.adam.configuration.template.Template; import org.echocat.adam.profile.element.ElementModel.Type; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.xml.bind.annotation.XmlAttribute; /***************************************************************************************** * *** BEGIN LICENSE BLOCK ***** * * echocat Adam, Copyright (c) 2014 echocat * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * * *** END LICENSE BLOCK ***** ****************************************************************************************/ package org.echocat.adam.configuration.profile; @XmlType(name = "profileGroupElement", namespace = SCHEMA_NAMESPACE) public class Element extends Localized { @Nullable private List<ContextAttribute> _contextAttributes; @Nullable private ViewEditAccess _access; @Nonnull private Type _type = singleLineText; @Nullable
private Template _template;
echocat/adam
src/main/java/org/echocat/adam/configuration/profile/Element.java
// Path: src/main/java/org/echocat/adam/configuration/IdEnabled.java // public abstract class IdEnabled implements org.echocat.jomon.runtime.util.IdEnabled<String> { // // @Nonnull // private String _id = randomUUID().toString(); // // @Override // @Nonnull // @XmlAttribute(name = "id", required = true) // public String getId() { // return _id; // } // // public void setId(@Nonnull String id) { // _id = id; // } // // } // // Path: src/main/java/org/echocat/adam/configuration/access/viewedit/ViewEditAccess.java // @XmlType(name = "viewEditAccess", namespace = SCHEMA_NAMESPACE) // public class ViewEditAccess extends ViewAccessSupport<Default, Anonymous, Owner, Administrator, Group> { // // @Override // @XmlElement(name = "default", namespace = SCHEMA_NAMESPACE, type = Default.class) // public void setDefault(@Nullable Default all) { // super.setDefault(all); // } // // @Override // @XmlElement(name = "anonymous", namespace = SCHEMA_NAMESPACE, type = Anonymous.class) // public void setAnonymous(@Nullable Anonymous anonymous) { // super.setAnonymous(anonymous); // } // // @Override // @XmlElement(name = "owner", namespace = SCHEMA_NAMESPACE, type = Owner.class) // public void setOwner(@Nullable Owner owner) { // super.setOwner(owner); // } // // @Override // @XmlElement(name = "administrator", namespace = SCHEMA_NAMESPACE, type = Administrator.class) // public void setAdministrator(@Nullable Administrator administrator) { // super.setAdministrator(administrator); // } // // @Override // @XmlElement(name = "group", namespace = SCHEMA_NAMESPACE, type = Group.class) // public void setGroups(@Nullable List<Group> groups) { // super.setGroups(groups); // } // // } // // Path: src/main/java/org/echocat/adam/configuration/localization/Localized.java // @XmlType(name = "localized", namespace = SCHEMA_NAMESPACE) // public abstract class Localized extends IdEnabled { // // @Nullable // private List<Localization> _localizations; // // @Nullable // @XmlElement(name = "localization", namespace = SCHEMA_NAMESPACE) // public List<Localization> getLocalizations() { // return _localizations; // } // // public void setLocalizations(@Nullable List<Localization> localizations) { // _localizations = localizations; // } // // // } // // Path: src/main/java/org/echocat/adam/configuration/template/Template.java // @XmlType(name = "template", namespace = SCHEMA_NAMESPACE) // public class Template extends TemplateSupport { // // @Nonnull // private String _source = ""; // @Nonnull // private TemplateFormat _format = velocity; // // @Override // @Nonnull // public String getSource() { // return _source; // } // // @XmlValue // @XmlValueExtension // public void setSource(@Nonnull String source) { // _source = source; // } // // @Override // @Nonnull // public TemplateFormat getFormat() { // return _format; // } // // @XmlAttribute(name = "format") // public void setFormat(@Nonnull TemplateFormat format) { // _format = format; // } // // } // // Path: src/main/java/org/echocat/adam/profile/element/ElementModel.java // public static enum Type { // singleLineText, // multiLineText, // emailAddress, // url, // phoneNumber, // wikiMarkup, // html // } // // Path: src/main/java/org/echocat/adam/configuration/ConfigurationContants.java // public static final String SCHEMA_NAMESPACE = "https://adam.echocat.org/schemas/configuration.xsd";
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; import java.util.List; import static org.echocat.adam.configuration.ConfigurationContants.SCHEMA_NAMESPACE; import static org.echocat.adam.profile.element.ElementModel.Type.singleLineText; import org.echocat.adam.configuration.IdEnabled; import org.echocat.adam.configuration.access.viewedit.ViewEditAccess; import org.echocat.adam.configuration.localization.Localized; import org.echocat.adam.configuration.template.Template; import org.echocat.adam.profile.element.ElementModel.Type; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.xml.bind.annotation.XmlAttribute;
} @XmlAttribute(name = "searchable") public boolean isSearchable() { return _searchable; } public void setSearchable(boolean searchable) { _searchable = searchable; } @XmlAttribute(name = "visibleIfEmpty") public boolean isVisibleIfEmpty() { return _visibleIfEmpty; } public void setVisibleIfEmpty(boolean visibleIfEmpty) { _visibleIfEmpty = visibleIfEmpty; } @XmlAttribute(name = "defaultForReports") public Boolean getDefaultForReports() { return _defaultForReports; } public void setDefaultForReports(Boolean defaultForReports) { _defaultForReports = defaultForReports; } @XmlType(name = "profileGroupElementContextAttribute", namespace = SCHEMA_NAMESPACE)
// Path: src/main/java/org/echocat/adam/configuration/IdEnabled.java // public abstract class IdEnabled implements org.echocat.jomon.runtime.util.IdEnabled<String> { // // @Nonnull // private String _id = randomUUID().toString(); // // @Override // @Nonnull // @XmlAttribute(name = "id", required = true) // public String getId() { // return _id; // } // // public void setId(@Nonnull String id) { // _id = id; // } // // } // // Path: src/main/java/org/echocat/adam/configuration/access/viewedit/ViewEditAccess.java // @XmlType(name = "viewEditAccess", namespace = SCHEMA_NAMESPACE) // public class ViewEditAccess extends ViewAccessSupport<Default, Anonymous, Owner, Administrator, Group> { // // @Override // @XmlElement(name = "default", namespace = SCHEMA_NAMESPACE, type = Default.class) // public void setDefault(@Nullable Default all) { // super.setDefault(all); // } // // @Override // @XmlElement(name = "anonymous", namespace = SCHEMA_NAMESPACE, type = Anonymous.class) // public void setAnonymous(@Nullable Anonymous anonymous) { // super.setAnonymous(anonymous); // } // // @Override // @XmlElement(name = "owner", namespace = SCHEMA_NAMESPACE, type = Owner.class) // public void setOwner(@Nullable Owner owner) { // super.setOwner(owner); // } // // @Override // @XmlElement(name = "administrator", namespace = SCHEMA_NAMESPACE, type = Administrator.class) // public void setAdministrator(@Nullable Administrator administrator) { // super.setAdministrator(administrator); // } // // @Override // @XmlElement(name = "group", namespace = SCHEMA_NAMESPACE, type = Group.class) // public void setGroups(@Nullable List<Group> groups) { // super.setGroups(groups); // } // // } // // Path: src/main/java/org/echocat/adam/configuration/localization/Localized.java // @XmlType(name = "localized", namespace = SCHEMA_NAMESPACE) // public abstract class Localized extends IdEnabled { // // @Nullable // private List<Localization> _localizations; // // @Nullable // @XmlElement(name = "localization", namespace = SCHEMA_NAMESPACE) // public List<Localization> getLocalizations() { // return _localizations; // } // // public void setLocalizations(@Nullable List<Localization> localizations) { // _localizations = localizations; // } // // // } // // Path: src/main/java/org/echocat/adam/configuration/template/Template.java // @XmlType(name = "template", namespace = SCHEMA_NAMESPACE) // public class Template extends TemplateSupport { // // @Nonnull // private String _source = ""; // @Nonnull // private TemplateFormat _format = velocity; // // @Override // @Nonnull // public String getSource() { // return _source; // } // // @XmlValue // @XmlValueExtension // public void setSource(@Nonnull String source) { // _source = source; // } // // @Override // @Nonnull // public TemplateFormat getFormat() { // return _format; // } // // @XmlAttribute(name = "format") // public void setFormat(@Nonnull TemplateFormat format) { // _format = format; // } // // } // // Path: src/main/java/org/echocat/adam/profile/element/ElementModel.java // public static enum Type { // singleLineText, // multiLineText, // emailAddress, // url, // phoneNumber, // wikiMarkup, // html // } // // Path: src/main/java/org/echocat/adam/configuration/ConfigurationContants.java // public static final String SCHEMA_NAMESPACE = "https://adam.echocat.org/schemas/configuration.xsd"; // Path: src/main/java/org/echocat/adam/configuration/profile/Element.java import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; import java.util.List; import static org.echocat.adam.configuration.ConfigurationContants.SCHEMA_NAMESPACE; import static org.echocat.adam.profile.element.ElementModel.Type.singleLineText; import org.echocat.adam.configuration.IdEnabled; import org.echocat.adam.configuration.access.viewedit.ViewEditAccess; import org.echocat.adam.configuration.localization.Localized; import org.echocat.adam.configuration.template.Template; import org.echocat.adam.profile.element.ElementModel.Type; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.xml.bind.annotation.XmlAttribute; } @XmlAttribute(name = "searchable") public boolean isSearchable() { return _searchable; } public void setSearchable(boolean searchable) { _searchable = searchable; } @XmlAttribute(name = "visibleIfEmpty") public boolean isVisibleIfEmpty() { return _visibleIfEmpty; } public void setVisibleIfEmpty(boolean visibleIfEmpty) { _visibleIfEmpty = visibleIfEmpty; } @XmlAttribute(name = "defaultForReports") public Boolean getDefaultForReports() { return _defaultForReports; } public void setDefaultForReports(Boolean defaultForReports) { _defaultForReports = defaultForReports; } @XmlType(name = "profileGroupElementContextAttribute", namespace = SCHEMA_NAMESPACE)
public static class ContextAttribute extends IdEnabled {}
echocat/adam
src/main/java/org/echocat/adam/view/ViewSupport.java
// Path: src/main/java/org/echocat/adam/localization/LocalizedSupport.java // public abstract class LocalizedSupport implements Localized { // // @Override // @Nullable // public Map<Locale, Localization> getLocalizations() { // final Map<Locale, Localization> result; // final Collection<org.echocat.adam.configuration.localization.Localization> localizationElements = getConfigurationBasedLocalizations(); // if (localizationElements != null) { // result = new LinkedHashMap<>(localizationElements.size(), 1f); // for (final org.echocat.adam.configuration.localization.Localization localizationElement : localizationElements) { // result.put(localizationElement.getLocale(), localizationElement); // } // } else { // result = null; // } // return result; // } // // @Nullable // protected Collection<org.echocat.adam.configuration.localization.Localization> getConfigurationBasedLocalizations() { // return null; // } // // } // // Path: src/main/java/org/echocat/adam/profile/Group.java // public interface Group extends Localized, Iterable<ElementModel> { // // @Nonnull // public ViewAccess getAccess(); // // }
import org.echocat.adam.profile.Group; import javax.xml.bind.annotation.XmlTransient; import org.echocat.adam.localization.LocalizedSupport;
/***************************************************************************************** * *** BEGIN LICENSE BLOCK ***** * * echocat Adam, Copyright (c) 2014 echocat * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * * *** END LICENSE BLOCK ***** ****************************************************************************************/ package org.echocat.adam.view; @XmlTransient public abstract class ViewSupport extends LocalizedSupport implements View { @Override public boolean equals(Object o) { final boolean result; if (this == o) { result = true;
// Path: src/main/java/org/echocat/adam/localization/LocalizedSupport.java // public abstract class LocalizedSupport implements Localized { // // @Override // @Nullable // public Map<Locale, Localization> getLocalizations() { // final Map<Locale, Localization> result; // final Collection<org.echocat.adam.configuration.localization.Localization> localizationElements = getConfigurationBasedLocalizations(); // if (localizationElements != null) { // result = new LinkedHashMap<>(localizationElements.size(), 1f); // for (final org.echocat.adam.configuration.localization.Localization localizationElement : localizationElements) { // result.put(localizationElement.getLocale(), localizationElement); // } // } else { // result = null; // } // return result; // } // // @Nullable // protected Collection<org.echocat.adam.configuration.localization.Localization> getConfigurationBasedLocalizations() { // return null; // } // // } // // Path: src/main/java/org/echocat/adam/profile/Group.java // public interface Group extends Localized, Iterable<ElementModel> { // // @Nonnull // public ViewAccess getAccess(); // // } // Path: src/main/java/org/echocat/adam/view/ViewSupport.java import org.echocat.adam.profile.Group; import javax.xml.bind.annotation.XmlTransient; import org.echocat.adam.localization.LocalizedSupport; /***************************************************************************************** * *** BEGIN LICENSE BLOCK ***** * * echocat Adam, Copyright (c) 2014 echocat * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * * *** END LICENSE BLOCK ***** ****************************************************************************************/ package org.echocat.adam.view; @XmlTransient public abstract class ViewSupport extends LocalizedSupport implements View { @Override public boolean equals(Object o) { final boolean result; if (this == o) { result = true;
} else if (!(o instanceof Group)) {
echocat/adam
src/main/java/org/echocat/adam/synchronization/LdapDirectorySynchronizationJob.java
// Path: src/main/java/org/echocat/adam/synchronization/LdapDirectorySynchronizer.java // public static class Result { // // @Nonnegative // private final int _numberOfSynchronizedUsers; // @Nonnull // private final Set<String> _synchronizedAttributes; // @Nonnull // private final Duration _duration; // // public Result(@Nonnegative int numberOfSynchronizedUsers, @Nonnull Set<String> synchronizedAttributes, @Nonnull Duration duration) { // _numberOfSynchronizedUsers = numberOfSynchronizedUsers; // _synchronizedAttributes = synchronizedAttributes; // _duration = duration; // } // // @Nonnegative // public int getNumberOfSynchronizedUsers() { // return _numberOfSynchronizedUsers; // } // // @Nonnull // public Set<String> getSynchronizedAttributes() { // return _synchronizedAttributes; // } // // @Nonnull // public Duration getDuration() { // return _duration; // } // // @Override // public String toString() { // return "Synchronized " + _numberOfSynchronizedUsers + " user(s) with attributes " + _synchronizedAttributes + " in " + _duration + "."; // } // // }
import static org.echocat.adam.synchronization.LdapDirectorySynchronizer.Result; import com.atlassian.confluence.event.events.ConfluenceEvent; import com.atlassian.event.api.EventPublisher; import com.atlassian.quartz.jobs.AbstractJob; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.Nonnull;
/***************************************************************************************** * *** BEGIN LICENSE BLOCK ***** * * echocat Adam, Copyright (c) 2014 echocat * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * * *** END LICENSE BLOCK ***** ****************************************************************************************/ package org.echocat.adam.synchronization; public class LdapDirectorySynchronizationJob extends AbstractJob { private static final Logger LOG = LoggerFactory.getLogger(LdapDirectorySynchronizationJob.class); @Nonnull private final LdapDirectorySynchronizer _synchronizer; @Nonnull private final EventPublisher _eventPublisher; public LdapDirectorySynchronizationJob(@Nonnull LdapDirectorySynchronizer synchronizer, @Nonnull EventPublisher eventPublisher) { _synchronizer = synchronizer; _eventPublisher = eventPublisher; } @Override public void doExecute(@Nonnull JobExecutionContext jobExecutionContext) throws JobExecutionException { LOG.info("Synchronization of all LDAP users started."); try {
// Path: src/main/java/org/echocat/adam/synchronization/LdapDirectorySynchronizer.java // public static class Result { // // @Nonnegative // private final int _numberOfSynchronizedUsers; // @Nonnull // private final Set<String> _synchronizedAttributes; // @Nonnull // private final Duration _duration; // // public Result(@Nonnegative int numberOfSynchronizedUsers, @Nonnull Set<String> synchronizedAttributes, @Nonnull Duration duration) { // _numberOfSynchronizedUsers = numberOfSynchronizedUsers; // _synchronizedAttributes = synchronizedAttributes; // _duration = duration; // } // // @Nonnegative // public int getNumberOfSynchronizedUsers() { // return _numberOfSynchronizedUsers; // } // // @Nonnull // public Set<String> getSynchronizedAttributes() { // return _synchronizedAttributes; // } // // @Nonnull // public Duration getDuration() { // return _duration; // } // // @Override // public String toString() { // return "Synchronized " + _numberOfSynchronizedUsers + " user(s) with attributes " + _synchronizedAttributes + " in " + _duration + "."; // } // // } // Path: src/main/java/org/echocat/adam/synchronization/LdapDirectorySynchronizationJob.java import static org.echocat.adam.synchronization.LdapDirectorySynchronizer.Result; import com.atlassian.confluence.event.events.ConfluenceEvent; import com.atlassian.event.api.EventPublisher; import com.atlassian.quartz.jobs.AbstractJob; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; /***************************************************************************************** * *** BEGIN LICENSE BLOCK ***** * * echocat Adam, Copyright (c) 2014 echocat * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * * *** END LICENSE BLOCK ***** ****************************************************************************************/ package org.echocat.adam.synchronization; public class LdapDirectorySynchronizationJob extends AbstractJob { private static final Logger LOG = LoggerFactory.getLogger(LdapDirectorySynchronizationJob.class); @Nonnull private final LdapDirectorySynchronizer _synchronizer; @Nonnull private final EventPublisher _eventPublisher; public LdapDirectorySynchronizationJob(@Nonnull LdapDirectorySynchronizer synchronizer, @Nonnull EventPublisher eventPublisher) { _synchronizer = synchronizer; _eventPublisher = eventPublisher; } @Override public void doExecute(@Nonnull JobExecutionContext jobExecutionContext) throws JobExecutionException { LOG.info("Synchronization of all LDAP users started."); try {
final Result result = _synchronizer.synchronize();
echocat/adam
src/main/java/org/echocat/adam/profile/Group.java
// Path: src/main/java/org/echocat/adam/access/ViewAccess.java // public interface ViewAccess { // // @Nonnull // public Visibility checkView(@Nullable User forUser, @Nullable User target); // // public static enum Visibility { // allowed, // masked, // forbidden; // // public boolean isViewAllowed() { // return this == allowed || this == masked; // } // // public boolean isMasked() { // return this == masked; // } // // public boolean isBetterThen(@Nonnull Visibility other) { // return other == null || ordinal() < other.ordinal(); // } // // public boolean isBest() { // return ordinal() == 0; // } // // public static boolean isBestVisibility(@Nullable Visibility what) { // return what != null && what.isBest(); // } // // public static boolean isBetterVisibility(@Nullable Visibility what, @Nullable Visibility then) { // return what != null && what.isBetterThen(then); // } // } // // } // // Path: src/main/java/org/echocat/adam/localization/Localized.java // public interface Localized extends IdEnabled<String> { // // @Nullable // public Map<Locale, Localization> getLocalizations(); // // } // // Path: src/main/java/org/echocat/adam/profile/element/ElementModel.java // public interface ElementModel extends Localized { // // @Nonnull // public static final String PERSONAL_INFORMATION_ELEMENT_ID = "personalInformation"; // @Nonnull // public static final String FULL_NAME_ELEMENT_ID = "fullName"; // @Nonnull // public static final String USER_NAME_ELEMENT_ID = "username"; // @Nonnull // public static final String EMAIL_ELEMENT_ID = "email"; // @Nonnull // public static final String WEBSITE_ELEMENT_ID = "website"; // @Nonnull // public static final String PHONE_ELEMENT_ID = "phone"; // // public boolean isStandard(); // // public boolean isDefaultForReports(); // // @Nullable // public List<String> getContextAttributeKeys(); // // public boolean isSearchable(); // // public boolean isVisibleIfEmpty(); // // @Nonnull // public ViewEditAccess getAccess(); // // @Nonnull // public Type getType(); // // @Nullable // public Template getTemplate(); // // public static enum Type { // singleLineText, // multiLineText, // emailAddress, // url, // phoneNumber, // wikiMarkup, // html // } // // }
import org.echocat.adam.localization.Localized; import org.echocat.adam.profile.element.ElementModel; import javax.annotation.Nonnull; import org.echocat.adam.access.ViewAccess;
/***************************************************************************************** * *** BEGIN LICENSE BLOCK ***** * * echocat Adam, Copyright (c) 2014 echocat * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * * *** END LICENSE BLOCK ***** ****************************************************************************************/ package org.echocat.adam.profile; public interface Group extends Localized, Iterable<ElementModel> { @Nonnull
// Path: src/main/java/org/echocat/adam/access/ViewAccess.java // public interface ViewAccess { // // @Nonnull // public Visibility checkView(@Nullable User forUser, @Nullable User target); // // public static enum Visibility { // allowed, // masked, // forbidden; // // public boolean isViewAllowed() { // return this == allowed || this == masked; // } // // public boolean isMasked() { // return this == masked; // } // // public boolean isBetterThen(@Nonnull Visibility other) { // return other == null || ordinal() < other.ordinal(); // } // // public boolean isBest() { // return ordinal() == 0; // } // // public static boolean isBestVisibility(@Nullable Visibility what) { // return what != null && what.isBest(); // } // // public static boolean isBetterVisibility(@Nullable Visibility what, @Nullable Visibility then) { // return what != null && what.isBetterThen(then); // } // } // // } // // Path: src/main/java/org/echocat/adam/localization/Localized.java // public interface Localized extends IdEnabled<String> { // // @Nullable // public Map<Locale, Localization> getLocalizations(); // // } // // Path: src/main/java/org/echocat/adam/profile/element/ElementModel.java // public interface ElementModel extends Localized { // // @Nonnull // public static final String PERSONAL_INFORMATION_ELEMENT_ID = "personalInformation"; // @Nonnull // public static final String FULL_NAME_ELEMENT_ID = "fullName"; // @Nonnull // public static final String USER_NAME_ELEMENT_ID = "username"; // @Nonnull // public static final String EMAIL_ELEMENT_ID = "email"; // @Nonnull // public static final String WEBSITE_ELEMENT_ID = "website"; // @Nonnull // public static final String PHONE_ELEMENT_ID = "phone"; // // public boolean isStandard(); // // public boolean isDefaultForReports(); // // @Nullable // public List<String> getContextAttributeKeys(); // // public boolean isSearchable(); // // public boolean isVisibleIfEmpty(); // // @Nonnull // public ViewEditAccess getAccess(); // // @Nonnull // public Type getType(); // // @Nullable // public Template getTemplate(); // // public static enum Type { // singleLineText, // multiLineText, // emailAddress, // url, // phoneNumber, // wikiMarkup, // html // } // // } // Path: src/main/java/org/echocat/adam/profile/Group.java import org.echocat.adam.localization.Localized; import org.echocat.adam.profile.element.ElementModel; import javax.annotation.Nonnull; import org.echocat.adam.access.ViewAccess; /***************************************************************************************** * *** BEGIN LICENSE BLOCK ***** * * echocat Adam, Copyright (c) 2014 echocat * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. * * *** END LICENSE BLOCK ***** ****************************************************************************************/ package org.echocat.adam.profile; public interface Group extends Localized, Iterable<ElementModel> { @Nonnull
public ViewAccess getAccess();
amymcgovern/spacesettlers
src/spacesettlers/actions/PurchaseTypes.java
// Path: src/spacesettlers/objects/powerups/SpaceSettlersPowerupEnum.java // public enum SpaceSettlersPowerupEnum { // TOGGLE_SHIELD, // FIRE_EMP, // LAY_MINE, // FIRE_TURRET, // FIRE_MISSILE, // FIRE_HEAT_SEEKING_MISSILE, // DOUBLE_BASE_HEALING_SPEED, // DOUBLE_MAX_ENERGY, // DOUBLE_WEAPON_CAPACITY, // DRONE, //herr0861 edit // CORE, // }
import spacesettlers.objects.powerups.SpaceSettlersPowerupEnum;
package spacesettlers.actions; /** * Enum with the types of purchases that a team can make and a map to the right powerup. * * @author amy */ public enum PurchaseTypes { BASE(), SHIP(),
// Path: src/spacesettlers/objects/powerups/SpaceSettlersPowerupEnum.java // public enum SpaceSettlersPowerupEnum { // TOGGLE_SHIELD, // FIRE_EMP, // LAY_MINE, // FIRE_TURRET, // FIRE_MISSILE, // FIRE_HEAT_SEEKING_MISSILE, // DOUBLE_BASE_HEALING_SPEED, // DOUBLE_MAX_ENERGY, // DOUBLE_WEAPON_CAPACITY, // DRONE, //herr0861 edit // CORE, // } // Path: src/spacesettlers/actions/PurchaseTypes.java import spacesettlers.objects.powerups.SpaceSettlersPowerupEnum; package spacesettlers.actions; /** * Enum with the types of purchases that a team can make and a map to the right powerup. * * @author amy */ public enum PurchaseTypes { BASE(), SHIP(),
POWERUP_SHIELD(SpaceSettlersPowerupEnum.TOGGLE_SHIELD),
amymcgovern/spacesettlers
src/spacesettlers/graphics/EMPGraphics.java
// Path: src/spacesettlers/utilities/Position.java // public class Position { // double x, y, orientation, angularVelocity; // Vector2D velocity; // // public Position(double x, double y) { // super(); // this.x = x; // this.y = y; // velocity = new Vector2D(); // } // // public Position(double x, double y, double orientation) { // super(); // this.x = x; // this.y = y; // this.orientation = orientation; // velocity = new Vector2D(); // } // // public Position(Vector2D vec) { // super(); // this.x = vec.getXValue(); // this.y = vec.getYValue(); // orientation = 0; // velocity = new Vector2D(); // } // // public Position deepCopy() { // Position newPosition = new Position(x, y, orientation); // newPosition.velocity = new Vector2D(velocity); // newPosition.angularVelocity = angularVelocity; // // return newPosition; // } // // public double getX() { // return x; // } // // public double getY() { // return y; // } // // public double getOrientation() { // return orientation; // } // // public void setX(double x) { // this.x = x; // } // // public void setY(double y) { // this.y = y; // } // // public double getTotalTranslationalVelocity() { // return velocity.getTotal(); // } // // public double getTranslationalVelocityX() { // return velocity.getXValue(); // } // // public double getTranslationalVelocityY() { // return velocity.getYValue(); // } // // public Vector2D getTranslationalVelocity() { // return velocity; // } // // public void setTranslationalVelocity(Vector2D newVel) { // this.velocity = newVel; // } // // public double getAngularVelocity() { // return angularVelocity; // } // // public void setOrientation(double orientation) { // this.orientation = orientation; // } // // public double getxVelocity() { // return velocity.getXValue(); // } // // public double getyVelocity() { // return velocity.getYValue(); // } // // public void setAngularVelocity(double angularVelocity) { // this.angularVelocity = angularVelocity; // } // // public String toString() { // String str = "(" + x + " , " + y + ", " + orientation + ") velocity: " + velocity + ", " + angularVelocity; // return str; // } // // /** // * Compares positions on location (x,y) only and ignores orientation and velocities // * // * @param newPosition // * @return // */ // public boolean equalsLocationOnly(Position newPosition) { // if (newPosition.getX() == x && newPosition.getY() == y) { // return true; // } else { // return false; // } // } // // /** // * Verifies that all components of the position are finite and not NaN // * @return true if the position is valid (finite and a number, doesn't check world size) and false otherwise // */ // public boolean isValid() { // if (Double.isFinite(x) && Double.isFinite(y) && // Double.isFinite(angularVelocity) && Double.isFinite(orientation) && // velocity.isValid()) { // return true; // } else { // return false; // } // } // // }
import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; import spacesettlers.objects.weapons.EMP; import spacesettlers.utilities.Position;
package spacesettlers.graphics; /** * Draw a EMP (looks like a missile but different color, and with stripes) * @author amy * */ public class EMPGraphics extends SpacewarGraphics { EMP emp; //public static final Color EMP_OUTER_COLOR = new Color(200, 0, 200); public static final Color EMP_INNER_COLOR = new Color(200, 200, 200); Color outerColor; public EMPGraphics(EMP emp) { super((int)(emp.getRadius() * 2), (int)(emp.getRadius() * 2)); outerColor = emp.getFiringShip().getTeamColor(); this.emp = emp; } /** * Return the position of the emp */
// Path: src/spacesettlers/utilities/Position.java // public class Position { // double x, y, orientation, angularVelocity; // Vector2D velocity; // // public Position(double x, double y) { // super(); // this.x = x; // this.y = y; // velocity = new Vector2D(); // } // // public Position(double x, double y, double orientation) { // super(); // this.x = x; // this.y = y; // this.orientation = orientation; // velocity = new Vector2D(); // } // // public Position(Vector2D vec) { // super(); // this.x = vec.getXValue(); // this.y = vec.getYValue(); // orientation = 0; // velocity = new Vector2D(); // } // // public Position deepCopy() { // Position newPosition = new Position(x, y, orientation); // newPosition.velocity = new Vector2D(velocity); // newPosition.angularVelocity = angularVelocity; // // return newPosition; // } // // public double getX() { // return x; // } // // public double getY() { // return y; // } // // public double getOrientation() { // return orientation; // } // // public void setX(double x) { // this.x = x; // } // // public void setY(double y) { // this.y = y; // } // // public double getTotalTranslationalVelocity() { // return velocity.getTotal(); // } // // public double getTranslationalVelocityX() { // return velocity.getXValue(); // } // // public double getTranslationalVelocityY() { // return velocity.getYValue(); // } // // public Vector2D getTranslationalVelocity() { // return velocity; // } // // public void setTranslationalVelocity(Vector2D newVel) { // this.velocity = newVel; // } // // public double getAngularVelocity() { // return angularVelocity; // } // // public void setOrientation(double orientation) { // this.orientation = orientation; // } // // public double getxVelocity() { // return velocity.getXValue(); // } // // public double getyVelocity() { // return velocity.getYValue(); // } // // public void setAngularVelocity(double angularVelocity) { // this.angularVelocity = angularVelocity; // } // // public String toString() { // String str = "(" + x + " , " + y + ", " + orientation + ") velocity: " + velocity + ", " + angularVelocity; // return str; // } // // /** // * Compares positions on location (x,y) only and ignores orientation and velocities // * // * @param newPosition // * @return // */ // public boolean equalsLocationOnly(Position newPosition) { // if (newPosition.getX() == x && newPosition.getY() == y) { // return true; // } else { // return false; // } // } // // /** // * Verifies that all components of the position are finite and not NaN // * @return true if the position is valid (finite and a number, doesn't check world size) and false otherwise // */ // public boolean isValid() { // if (Double.isFinite(x) && Double.isFinite(y) && // Double.isFinite(angularVelocity) && Double.isFinite(orientation) && // velocity.isValid()) { // return true; // } else { // return false; // } // } // // } // Path: src/spacesettlers/graphics/EMPGraphics.java import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; import spacesettlers.objects.weapons.EMP; import spacesettlers.utilities.Position; package spacesettlers.graphics; /** * Draw a EMP (looks like a missile but different color, and with stripes) * @author amy * */ public class EMPGraphics extends SpacewarGraphics { EMP emp; //public static final Color EMP_OUTER_COLOR = new Color(200, 0, 200); public static final Color EMP_INNER_COLOR = new Color(200, 200, 200); Color outerColor; public EMPGraphics(EMP emp) { super((int)(emp.getRadius() * 2), (int)(emp.getRadius() * 2)); outerColor = emp.getFiringShip().getTeamColor(); this.emp = emp; } /** * Return the position of the emp */
public Position getActualLocation() {
amymcgovern/spacesettlers
src/spacesettlers/graphics/StarGraphics.java
// Path: src/spacesettlers/utilities/Position.java // public class Position { // double x, y, orientation, angularVelocity; // Vector2D velocity; // // public Position(double x, double y) { // super(); // this.x = x; // this.y = y; // velocity = new Vector2D(); // } // // public Position(double x, double y, double orientation) { // super(); // this.x = x; // this.y = y; // this.orientation = orientation; // velocity = new Vector2D(); // } // // public Position(Vector2D vec) { // super(); // this.x = vec.getXValue(); // this.y = vec.getYValue(); // orientation = 0; // velocity = new Vector2D(); // } // // public Position deepCopy() { // Position newPosition = new Position(x, y, orientation); // newPosition.velocity = new Vector2D(velocity); // newPosition.angularVelocity = angularVelocity; // // return newPosition; // } // // public double getX() { // return x; // } // // public double getY() { // return y; // } // // public double getOrientation() { // return orientation; // } // // public void setX(double x) { // this.x = x; // } // // public void setY(double y) { // this.y = y; // } // // public double getTotalTranslationalVelocity() { // return velocity.getTotal(); // } // // public double getTranslationalVelocityX() { // return velocity.getXValue(); // } // // public double getTranslationalVelocityY() { // return velocity.getYValue(); // } // // public Vector2D getTranslationalVelocity() { // return velocity; // } // // public void setTranslationalVelocity(Vector2D newVel) { // this.velocity = newVel; // } // // public double getAngularVelocity() { // return angularVelocity; // } // // public void setOrientation(double orientation) { // this.orientation = orientation; // } // // public double getxVelocity() { // return velocity.getXValue(); // } // // public double getyVelocity() { // return velocity.getYValue(); // } // // public void setAngularVelocity(double angularVelocity) { // this.angularVelocity = angularVelocity; // } // // public String toString() { // String str = "(" + x + " , " + y + ", " + orientation + ") velocity: " + velocity + ", " + angularVelocity; // return str; // } // // /** // * Compares positions on location (x,y) only and ignores orientation and velocities // * // * @param newPosition // * @return // */ // public boolean equalsLocationOnly(Position newPosition) { // if (newPosition.getX() == x && newPosition.getY() == y) { // return true; // } else { // return false; // } // } // // /** // * Verifies that all components of the position are finite and not NaN // * @return true if the position is valid (finite and a number, doesn't check world size) and false otherwise // */ // public boolean isValid() { // if (Double.isFinite(x) && Double.isFinite(y) && // Double.isFinite(angularVelocity) && Double.isFinite(orientation) && // velocity.isValid()) { // return true; // } else { // return false; // } // } // // }
import java.awt.Color; import java.awt.Graphics2D; import java.awt.Polygon; import java.awt.Shape; import java.awt.geom.AffineTransform; import spacesettlers.utilities.Position;
package spacesettlers.graphics; /** * Draws a star in the specified location and using the specified color. * * Star coordinates came from: * * http://flylib.com/books/1/226/1/html/2/images/fig217_01.jpg * * Translated to 0,0 in the middle by Amy * * @author amy * */ public class StarGraphics extends SpacewarGraphics { private int radius; Color color;
// Path: src/spacesettlers/utilities/Position.java // public class Position { // double x, y, orientation, angularVelocity; // Vector2D velocity; // // public Position(double x, double y) { // super(); // this.x = x; // this.y = y; // velocity = new Vector2D(); // } // // public Position(double x, double y, double orientation) { // super(); // this.x = x; // this.y = y; // this.orientation = orientation; // velocity = new Vector2D(); // } // // public Position(Vector2D vec) { // super(); // this.x = vec.getXValue(); // this.y = vec.getYValue(); // orientation = 0; // velocity = new Vector2D(); // } // // public Position deepCopy() { // Position newPosition = new Position(x, y, orientation); // newPosition.velocity = new Vector2D(velocity); // newPosition.angularVelocity = angularVelocity; // // return newPosition; // } // // public double getX() { // return x; // } // // public double getY() { // return y; // } // // public double getOrientation() { // return orientation; // } // // public void setX(double x) { // this.x = x; // } // // public void setY(double y) { // this.y = y; // } // // public double getTotalTranslationalVelocity() { // return velocity.getTotal(); // } // // public double getTranslationalVelocityX() { // return velocity.getXValue(); // } // // public double getTranslationalVelocityY() { // return velocity.getYValue(); // } // // public Vector2D getTranslationalVelocity() { // return velocity; // } // // public void setTranslationalVelocity(Vector2D newVel) { // this.velocity = newVel; // } // // public double getAngularVelocity() { // return angularVelocity; // } // // public void setOrientation(double orientation) { // this.orientation = orientation; // } // // public double getxVelocity() { // return velocity.getXValue(); // } // // public double getyVelocity() { // return velocity.getYValue(); // } // // public void setAngularVelocity(double angularVelocity) { // this.angularVelocity = angularVelocity; // } // // public String toString() { // String str = "(" + x + " , " + y + ", " + orientation + ") velocity: " + velocity + ", " + angularVelocity; // return str; // } // // /** // * Compares positions on location (x,y) only and ignores orientation and velocities // * // * @param newPosition // * @return // */ // public boolean equalsLocationOnly(Position newPosition) { // if (newPosition.getX() == x && newPosition.getY() == y) { // return true; // } else { // return false; // } // } // // /** // * Verifies that all components of the position are finite and not NaN // * @return true if the position is valid (finite and a number, doesn't check world size) and false otherwise // */ // public boolean isValid() { // if (Double.isFinite(x) && Double.isFinite(y) && // Double.isFinite(angularVelocity) && Double.isFinite(orientation) && // velocity.isValid()) { // return true; // } else { // return false; // } // } // // } // Path: src/spacesettlers/graphics/StarGraphics.java import java.awt.Color; import java.awt.Graphics2D; import java.awt.Polygon; import java.awt.Shape; import java.awt.geom.AffineTransform; import spacesettlers.utilities.Position; package spacesettlers.graphics; /** * Draws a star in the specified location and using the specified color. * * Star coordinates came from: * * http://flylib.com/books/1/226/1/html/2/images/fig217_01.jpg * * Translated to 0,0 in the middle by Amy * * @author amy * */ public class StarGraphics extends SpacewarGraphics { private int radius; Color color;
Position currentPosition;
amymcgovern/spacesettlers
src/spacesettlers/objects/AbstractActionableObject.java
// Path: src/spacesettlers/objects/powerups/SpaceSettlersPowerupEnum.java // public enum SpaceSettlersPowerupEnum { // TOGGLE_SHIELD, // FIRE_EMP, // LAY_MINE, // FIRE_TURRET, // FIRE_MISSILE, // FIRE_HEAT_SEEKING_MISSILE, // DOUBLE_BASE_HEALING_SPEED, // DOUBLE_MAX_ENERGY, // DOUBLE_WEAPON_CAPACITY, // DRONE, //herr0861 edit // CORE, // } // // Path: src/spacesettlers/utilities/Position.java // public class Position { // double x, y, orientation, angularVelocity; // Vector2D velocity; // // public Position(double x, double y) { // super(); // this.x = x; // this.y = y; // velocity = new Vector2D(); // } // // public Position(double x, double y, double orientation) { // super(); // this.x = x; // this.y = y; // this.orientation = orientation; // velocity = new Vector2D(); // } // // public Position(Vector2D vec) { // super(); // this.x = vec.getXValue(); // this.y = vec.getYValue(); // orientation = 0; // velocity = new Vector2D(); // } // // public Position deepCopy() { // Position newPosition = new Position(x, y, orientation); // newPosition.velocity = new Vector2D(velocity); // newPosition.angularVelocity = angularVelocity; // // return newPosition; // } // // public double getX() { // return x; // } // // public double getY() { // return y; // } // // public double getOrientation() { // return orientation; // } // // public void setX(double x) { // this.x = x; // } // // public void setY(double y) { // this.y = y; // } // // public double getTotalTranslationalVelocity() { // return velocity.getTotal(); // } // // public double getTranslationalVelocityX() { // return velocity.getXValue(); // } // // public double getTranslationalVelocityY() { // return velocity.getYValue(); // } // // public Vector2D getTranslationalVelocity() { // return velocity; // } // // public void setTranslationalVelocity(Vector2D newVel) { // this.velocity = newVel; // } // // public double getAngularVelocity() { // return angularVelocity; // } // // public void setOrientation(double orientation) { // this.orientation = orientation; // } // // public double getxVelocity() { // return velocity.getXValue(); // } // // public double getyVelocity() { // return velocity.getYValue(); // } // // public void setAngularVelocity(double angularVelocity) { // this.angularVelocity = angularVelocity; // } // // public String toString() { // String str = "(" + x + " , " + y + ", " + orientation + ") velocity: " + velocity + ", " + angularVelocity; // return str; // } // // /** // * Compares positions on location (x,y) only and ignores orientation and velocities // * // * @param newPosition // * @return // */ // public boolean equalsLocationOnly(Position newPosition) { // if (newPosition.getX() == x && newPosition.getY() == y) { // return true; // } else { // return false; // } // } // // /** // * Verifies that all components of the position are finite and not NaN // * @return true if the position is valid (finite and a number, doesn't check world size) and false otherwise // */ // public boolean isValid() { // if (Double.isFinite(x) && Double.isFinite(y) && // Double.isFinite(angularVelocity) && Double.isFinite(orientation) && // velocity.isValid()) { // return true; // } else { // return false; // } // } // // }
import java.util.LinkedHashSet; import java.util.Set; import spacesettlers.objects.powerups.SpaceSettlersPowerupEnum; import spacesettlers.utilities.Position;
package spacesettlers.objects; /** * This class is the super class for all Space Settlers objects that can take actions (right now * that is ships and bases). It contains the power ups for these objects. * * @author amy * */ abstract public class AbstractActionableObject extends AbstractObject { /** * Maximum number of bullets (or other weapons) simultaneously in the simulator. * This keeps ships from simply firing at every step */ public static final int INITIAL_WEAPON_CAPACITY = 5; /** Maximum energy for any tags (if it goes above this we drop any tags) */ public static final int TAG_MAX_ENERGY = 1500; /** * Does the item have a shield and is it using it? */ boolean isShielded; /** * The set of current power ups for this agent */
// Path: src/spacesettlers/objects/powerups/SpaceSettlersPowerupEnum.java // public enum SpaceSettlersPowerupEnum { // TOGGLE_SHIELD, // FIRE_EMP, // LAY_MINE, // FIRE_TURRET, // FIRE_MISSILE, // FIRE_HEAT_SEEKING_MISSILE, // DOUBLE_BASE_HEALING_SPEED, // DOUBLE_MAX_ENERGY, // DOUBLE_WEAPON_CAPACITY, // DRONE, //herr0861 edit // CORE, // } // // Path: src/spacesettlers/utilities/Position.java // public class Position { // double x, y, orientation, angularVelocity; // Vector2D velocity; // // public Position(double x, double y) { // super(); // this.x = x; // this.y = y; // velocity = new Vector2D(); // } // // public Position(double x, double y, double orientation) { // super(); // this.x = x; // this.y = y; // this.orientation = orientation; // velocity = new Vector2D(); // } // // public Position(Vector2D vec) { // super(); // this.x = vec.getXValue(); // this.y = vec.getYValue(); // orientation = 0; // velocity = new Vector2D(); // } // // public Position deepCopy() { // Position newPosition = new Position(x, y, orientation); // newPosition.velocity = new Vector2D(velocity); // newPosition.angularVelocity = angularVelocity; // // return newPosition; // } // // public double getX() { // return x; // } // // public double getY() { // return y; // } // // public double getOrientation() { // return orientation; // } // // public void setX(double x) { // this.x = x; // } // // public void setY(double y) { // this.y = y; // } // // public double getTotalTranslationalVelocity() { // return velocity.getTotal(); // } // // public double getTranslationalVelocityX() { // return velocity.getXValue(); // } // // public double getTranslationalVelocityY() { // return velocity.getYValue(); // } // // public Vector2D getTranslationalVelocity() { // return velocity; // } // // public void setTranslationalVelocity(Vector2D newVel) { // this.velocity = newVel; // } // // public double getAngularVelocity() { // return angularVelocity; // } // // public void setOrientation(double orientation) { // this.orientation = orientation; // } // // public double getxVelocity() { // return velocity.getXValue(); // } // // public double getyVelocity() { // return velocity.getYValue(); // } // // public void setAngularVelocity(double angularVelocity) { // this.angularVelocity = angularVelocity; // } // // public String toString() { // String str = "(" + x + " , " + y + ", " + orientation + ") velocity: " + velocity + ", " + angularVelocity; // return str; // } // // /** // * Compares positions on location (x,y) only and ignores orientation and velocities // * // * @param newPosition // * @return // */ // public boolean equalsLocationOnly(Position newPosition) { // if (newPosition.getX() == x && newPosition.getY() == y) { // return true; // } else { // return false; // } // } // // /** // * Verifies that all components of the position are finite and not NaN // * @return true if the position is valid (finite and a number, doesn't check world size) and false otherwise // */ // public boolean isValid() { // if (Double.isFinite(x) && Double.isFinite(y) && // Double.isFinite(angularVelocity) && Double.isFinite(orientation) && // velocity.isValid()) { // return true; // } else { // return false; // } // } // // } // Path: src/spacesettlers/objects/AbstractActionableObject.java import java.util.LinkedHashSet; import java.util.Set; import spacesettlers.objects.powerups.SpaceSettlersPowerupEnum; import spacesettlers.utilities.Position; package spacesettlers.objects; /** * This class is the super class for all Space Settlers objects that can take actions (right now * that is ships and bases). It contains the power ups for these objects. * * @author amy * */ abstract public class AbstractActionableObject extends AbstractObject { /** * Maximum number of bullets (or other weapons) simultaneously in the simulator. * This keeps ships from simply firing at every step */ public static final int INITIAL_WEAPON_CAPACITY = 5; /** Maximum energy for any tags (if it goes above this we drop any tags) */ public static final int TAG_MAX_ENERGY = 1500; /** * Does the item have a shield and is it using it? */ boolean isShielded; /** * The set of current power ups for this agent */
Set<SpaceSettlersPowerupEnum> currentPowerups;
tltv/gantt
gantt-addon/src/main/java/org/tltv/gantt/client/SubStepConnector.java
// Path: gantt-addon/src/main/java/org/tltv/gantt/SubStepComponent.java // public class SubStepComponent extends AbstractStepComponent { // // public SubStepComponent(StepComponent stepComponent, SubStep data) { // if (data.getUid() == null) { // data.setUid(UUID.randomUUID().toString()); // } // setParent(stepComponent); // getState().step = data; // } // // @Override // public SubStepState getState() { // return (SubStepState) super.getState(); // } // // @Override // public SubStepState getState(boolean markAsDirty) { // return (SubStepState) super.getState(markAsDirty); // } // // } // // Path: gantt-addon/src/main/java/org/tltv/gantt/client/shared/SubStepState.java // public class SubStepState extends com.vaadin.shared.AbstractComponentState { // // public SubStep step; // // }
import org.tltv.gantt.SubStepComponent; import org.tltv.gantt.client.shared.SubStepState; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.TooltipInfo; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.ContentMode;
/* * Copyright 2015 Tomi Virtanen * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.tltv.gantt.client; @Connect(SubStepComponent.class) public class SubStepConnector extends AbstractComponentConnector { private StepWidget step; @Override protected Widget createWidget() { return GWT.create(SubStepWidget.class); } @Override public SubStepWidget getWidget() { return (SubStepWidget) super.getWidget(); } @Override
// Path: gantt-addon/src/main/java/org/tltv/gantt/SubStepComponent.java // public class SubStepComponent extends AbstractStepComponent { // // public SubStepComponent(StepComponent stepComponent, SubStep data) { // if (data.getUid() == null) { // data.setUid(UUID.randomUUID().toString()); // } // setParent(stepComponent); // getState().step = data; // } // // @Override // public SubStepState getState() { // return (SubStepState) super.getState(); // } // // @Override // public SubStepState getState(boolean markAsDirty) { // return (SubStepState) super.getState(markAsDirty); // } // // } // // Path: gantt-addon/src/main/java/org/tltv/gantt/client/shared/SubStepState.java // public class SubStepState extends com.vaadin.shared.AbstractComponentState { // // public SubStep step; // // } // Path: gantt-addon/src/main/java/org/tltv/gantt/client/SubStepConnector.java import org.tltv.gantt.SubStepComponent; import org.tltv.gantt.client.shared.SubStepState; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.TooltipInfo; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.ContentMode; /* * Copyright 2015 Tomi Virtanen * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.tltv.gantt.client; @Connect(SubStepComponent.class) public class SubStepConnector extends AbstractComponentConnector { private StepWidget step; @Override protected Widget createWidget() { return GWT.create(SubStepWidget.class); } @Override public SubStepWidget getWidget() { return (SubStepWidget) super.getWidget(); } @Override
public SubStepState getState() {
tltv/gantt
gantt-addon/src/main/java/org/tltv/gantt/client/BgGridSvgElement.java
// Path: gantt-addon/src/main/java/org/tltv/gantt/client/SvgUtil.java // public static Element createSVGElementNS(String tag) { // return createElementNS(SVG_NS, tag); // } // // Path: gantt-addon/src/main/java/org/tltv/gantt/client/SvgUtil.java // public static native void setAttributeNS(String uri, Element elem, // String attr, String value) // /*-{ // elem.setAttributeNS(uri, attr, value); // }-*/;
import static org.tltv.gantt.client.SvgUtil.createSVGElementNS; import static org.tltv.gantt.client.SvgUtil.setAttributeNS; import com.google.gwt.dom.client.Element;
package org.tltv.gantt.client; /** * Background Grid SVG implementation. */ public class BgGridSvgElement extends BgGridCssElement implements BgGridElement { public static final String STYLE_BG_GRID = "bg-grid"; private Element svgElement; private Element content; private Element pattern; private Element path; private double gridBlockWidthPx; private double gridBlockHeightPx; @Override public void init(Element container, Element content) { this.content = content;
// Path: gantt-addon/src/main/java/org/tltv/gantt/client/SvgUtil.java // public static Element createSVGElementNS(String tag) { // return createElementNS(SVG_NS, tag); // } // // Path: gantt-addon/src/main/java/org/tltv/gantt/client/SvgUtil.java // public static native void setAttributeNS(String uri, Element elem, // String attr, String value) // /*-{ // elem.setAttributeNS(uri, attr, value); // }-*/; // Path: gantt-addon/src/main/java/org/tltv/gantt/client/BgGridSvgElement.java import static org.tltv.gantt.client.SvgUtil.createSVGElementNS; import static org.tltv.gantt.client.SvgUtil.setAttributeNS; import com.google.gwt.dom.client.Element; package org.tltv.gantt.client; /** * Background Grid SVG implementation. */ public class BgGridSvgElement extends BgGridCssElement implements BgGridElement { public static final String STYLE_BG_GRID = "bg-grid"; private Element svgElement; private Element content; private Element pattern; private Element path; private double gridBlockWidthPx; private double gridBlockHeightPx; @Override public void init(Element container, Element content) { this.content = content;
svgElement = createSVGElementNS("svg");
tltv/gantt
gantt-addon/src/main/java/org/tltv/gantt/client/BgGridSvgElement.java
// Path: gantt-addon/src/main/java/org/tltv/gantt/client/SvgUtil.java // public static Element createSVGElementNS(String tag) { // return createElementNS(SVG_NS, tag); // } // // Path: gantt-addon/src/main/java/org/tltv/gantt/client/SvgUtil.java // public static native void setAttributeNS(String uri, Element elem, // String attr, String value) // /*-{ // elem.setAttributeNS(uri, attr, value); // }-*/;
import static org.tltv.gantt.client.SvgUtil.createSVGElementNS; import static org.tltv.gantt.client.SvgUtil.setAttributeNS; import com.google.gwt.dom.client.Element;
package org.tltv.gantt.client; /** * Background Grid SVG implementation. */ public class BgGridSvgElement extends BgGridCssElement implements BgGridElement { public static final String STYLE_BG_GRID = "bg-grid"; private Element svgElement; private Element content; private Element pattern; private Element path; private double gridBlockWidthPx; private double gridBlockHeightPx; @Override public void init(Element container, Element content) { this.content = content; svgElement = createSVGElementNS("svg");
// Path: gantt-addon/src/main/java/org/tltv/gantt/client/SvgUtil.java // public static Element createSVGElementNS(String tag) { // return createElementNS(SVG_NS, tag); // } // // Path: gantt-addon/src/main/java/org/tltv/gantt/client/SvgUtil.java // public static native void setAttributeNS(String uri, Element elem, // String attr, String value) // /*-{ // elem.setAttributeNS(uri, attr, value); // }-*/; // Path: gantt-addon/src/main/java/org/tltv/gantt/client/BgGridSvgElement.java import static org.tltv.gantt.client.SvgUtil.createSVGElementNS; import static org.tltv.gantt.client.SvgUtil.setAttributeNS; import com.google.gwt.dom.client.Element; package org.tltv.gantt.client; /** * Background Grid SVG implementation. */ public class BgGridSvgElement extends BgGridCssElement implements BgGridElement { public static final String STYLE_BG_GRID = "bg-grid"; private Element svgElement; private Element content; private Element pattern; private Element path; private double gridBlockWidthPx; private double gridBlockHeightPx; @Override public void init(Element container, Element content) { this.content = content; svgElement = createSVGElementNS("svg");
setAttributeNS(svgElement, "width", "110%");
tltv/gantt
gantt-addon/src/main/java/org/tltv/gantt/SubStepComponent.java
// Path: gantt-addon/src/main/java/org/tltv/gantt/client/shared/SubStep.java // public class SubStep extends AbstractStep { // // public SubStep() { // } // // public SubStep(String caption) { // super(caption); // } // // public SubStep(String caption, CaptionMode captionMode) { // super(caption, captionMode); // } // // private Step owner; // // public Step getOwner() { // return owner; // } // // protected void setOwner(Step owner) { // this.owner = owner; // } // // } // // Path: gantt-addon/src/main/java/org/tltv/gantt/client/shared/SubStepState.java // public class SubStepState extends com.vaadin.shared.AbstractComponentState { // // public SubStep step; // // }
import java.util.UUID; import org.tltv.gantt.client.shared.SubStep; import org.tltv.gantt.client.shared.SubStepState;
package org.tltv.gantt; /** * Component representing a Sub-Step in the Gantt chart. * * @author Tltv * */ public class SubStepComponent extends AbstractStepComponent { public SubStepComponent(StepComponent stepComponent, SubStep data) { if (data.getUid() == null) { data.setUid(UUID.randomUUID().toString()); } setParent(stepComponent); getState().step = data; } @Override
// Path: gantt-addon/src/main/java/org/tltv/gantt/client/shared/SubStep.java // public class SubStep extends AbstractStep { // // public SubStep() { // } // // public SubStep(String caption) { // super(caption); // } // // public SubStep(String caption, CaptionMode captionMode) { // super(caption, captionMode); // } // // private Step owner; // // public Step getOwner() { // return owner; // } // // protected void setOwner(Step owner) { // this.owner = owner; // } // // } // // Path: gantt-addon/src/main/java/org/tltv/gantt/client/shared/SubStepState.java // public class SubStepState extends com.vaadin.shared.AbstractComponentState { // // public SubStep step; // // } // Path: gantt-addon/src/main/java/org/tltv/gantt/SubStepComponent.java import java.util.UUID; import org.tltv.gantt.client.shared.SubStep; import org.tltv.gantt.client.shared.SubStepState; package org.tltv.gantt; /** * Component representing a Sub-Step in the Gantt chart. * * @author Tltv * */ public class SubStepComponent extends AbstractStepComponent { public SubStepComponent(StepComponent stepComponent, SubStep data) { if (data.getUid() == null) { data.setUid(UUID.randomUUID().toString()); } setParent(stepComponent); getState().step = data; } @Override
public SubStepState getState() {
fredszaq/Rezenerator
rezenerator-core/src/test/java/com/tlorrain/android/rezenerator/core/utils/PNGFileUtilsTest.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // }
import java.io.File; import org.fest.assertions.Assertions; import org.junit.Test; import com.tlorrain.android.rezenerator.core.Dimensions;
package com.tlorrain.android.rezenerator.core.utils; public class PNGFileUtilsTest { @Test public void getDimensions_validPNGFile() throws Exception { Assertions.assertThat(PNGFileUtils.getDimensions(new File("src/test/resources/utils/png512x512.png")))
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // Path: rezenerator-core/src/test/java/com/tlorrain/android/rezenerator/core/utils/PNGFileUtilsTest.java import java.io.File; import org.fest.assertions.Assertions; import org.junit.Test; import com.tlorrain.android.rezenerator.core.Dimensions; package com.tlorrain.android.rezenerator.core.utils; public class PNGFileUtilsTest { @Test public void getDimensions_validPNGFile() throws Exception { Assertions.assertThat(PNGFileUtils.getDimensions(new File("src/test/resources/utils/png512x512.png")))
.isEqualTo(new Dimensions(512));
fredszaq/Rezenerator
rezenerator-core/src/test/java/com/tlorrain/android/rezenerator/core/utils/JPGFileUtilsTest.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // }
import java.io.File; import org.fest.assertions.Assertions; import org.junit.Test; import com.tlorrain.android.rezenerator.core.Dimensions;
package com.tlorrain.android.rezenerator.core.utils; public class JPGFileUtilsTest { @Test public void getDimensions_validJPGFile() throws Exception { Assertions.assertThat(JPGFileUtils.getDimensions(new File("src/test/resources/utils/jpg500x500.jpg")))
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // Path: rezenerator-core/src/test/java/com/tlorrain/android/rezenerator/core/utils/JPGFileUtilsTest.java import java.io.File; import org.fest.assertions.Assertions; import org.junit.Test; import com.tlorrain.android.rezenerator.core.Dimensions; package com.tlorrain.android.rezenerator.core.utils; public class JPGFileUtilsTest { @Test public void getDimensions_validJPGFile() throws Exception { Assertions.assertThat(JPGFileUtils.getDimensions(new File("src/test/resources/utils/jpg500x500.jpg")))
.isEqualTo(new Dimensions(500));
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/JPGFileUtils.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/StreamUtils.java // static int readIntBigEndianOnTwoBytes(final InputStream is) throws IOException { // int ret = 0; // ret |= is.read() << 8; // ret |= is.read(); // return ret; // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // }
import static com.tlorrain.android.rezenerator.core.utils.StreamUtils.readIntBigEndianOnTwoBytes; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import org.apache.commons.io.IOUtils; import com.tlorrain.android.rezenerator.core.Dimensions;
package com.tlorrain.android.rezenerator.core.utils; public class JPGFileUtils { public static Dimensions getDimensions(final File outFile) throws FileNotFoundException, IOException { // this code is largely inspired from // http://blog.jaimon.co.uk/simpleimageinfo/SimpleImageInfo.java.html // credits to him (Apache 2 Licence) Dimensions dimensions = null; final FileInputStream is = new FileInputStream(outFile); try { // JPG file if (is.read() == 0xFF && is.read() == 0xD8) { int height = -1; int width = -1; while (is.read() == 255) { final int marker = is.read();
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/StreamUtils.java // static int readIntBigEndianOnTwoBytes(final InputStream is) throws IOException { // int ret = 0; // ret |= is.read() << 8; // ret |= is.read(); // return ret; // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/JPGFileUtils.java import static com.tlorrain.android.rezenerator.core.utils.StreamUtils.readIntBigEndianOnTwoBytes; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import org.apache.commons.io.IOUtils; import com.tlorrain.android.rezenerator.core.Dimensions; package com.tlorrain.android.rezenerator.core.utils; public class JPGFileUtils { public static Dimensions getDimensions(final File outFile) throws FileNotFoundException, IOException { // this code is largely inspired from // http://blog.jaimon.co.uk/simpleimageinfo/SimpleImageInfo.java.html // credits to him (Apache 2 Licence) Dimensions dimensions = null; final FileInputStream is = new FileInputStream(outFile); try { // JPG file if (is.read() == 0xFF && is.read() == 0xD8) { int height = -1; int width = -1; while (is.read() == 255) { final int marker = is.read();
final int len = readIntBigEndianOnTwoBytes(is);
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/ExternalProcessProcessor.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/ExternalProcessUtils.java // public class ExternalProcessUtils { // private static class AsyncStreamPrinter extends Thread { // // private final InputStream inputStream; // private Printer printer; // // AsyncStreamPrinter(InputStream inputStream, Printer printer) { // this.inputStream = inputStream; // this.printer = printer; // } // // @Override // public void run() { // BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); // String line = ""; // try { // while ((line = br.readLine()) != null) { // printer.print(line); // } // } catch (IOException e) { // e.printStackTrace(); // } // } // } // // private static interface Printer { // void print(String toPrint); // } // // private static class ErrorPrinter implements Printer { // private Logger logger; // // public ErrorPrinter(Logger logger) { // this.logger = logger; // } // // @Override // public void print(String toPrint) { // logger.error(toPrint); // // } // } // // private static class StandardPrinter implements Printer { // private Logger logger; // // public StandardPrinter(Logger logger) { // this.logger = logger; // } // // @Override // public void print(String toPrint) { // logger.info(toPrint); // // } // } // // public static int executeProcess(ProcessBuilder pb, Logger logger) { // try { // Process process = pb.start(); // AsyncStreamPrinter stardardOutputThread = new AsyncStreamPrinter(process.getInputStream(), new StandardPrinter(logger)); // stardardOutputThread.start(); // AsyncStreamPrinter errorOutputThread = new AsyncStreamPrinter(process.getErrorStream(), new ErrorPrinter(logger)); // errorOutputThread.start(); // stardardOutputThread.join(); // errorOutputThread.join(); // return process.waitFor(); // } catch (Exception e) { // throw new RuntimeException("error while excecuting " + pb.command(), e); // } // } // }
import java.io.File; import com.tlorrain.android.rezenerator.core.Dimensions; import com.tlorrain.android.rezenerator.core.log.Logger; import com.tlorrain.android.rezenerator.core.utils.ExternalProcessUtils;
package com.tlorrain.android.rezenerator.core.processor; public abstract class ExternalProcessProcessor extends BaseProcessor { // TODO add a timeout ? @Override
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/ExternalProcessUtils.java // public class ExternalProcessUtils { // private static class AsyncStreamPrinter extends Thread { // // private final InputStream inputStream; // private Printer printer; // // AsyncStreamPrinter(InputStream inputStream, Printer printer) { // this.inputStream = inputStream; // this.printer = printer; // } // // @Override // public void run() { // BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); // String line = ""; // try { // while ((line = br.readLine()) != null) { // printer.print(line); // } // } catch (IOException e) { // e.printStackTrace(); // } // } // } // // private static interface Printer { // void print(String toPrint); // } // // private static class ErrorPrinter implements Printer { // private Logger logger; // // public ErrorPrinter(Logger logger) { // this.logger = logger; // } // // @Override // public void print(String toPrint) { // logger.error(toPrint); // // } // } // // private static class StandardPrinter implements Printer { // private Logger logger; // // public StandardPrinter(Logger logger) { // this.logger = logger; // } // // @Override // public void print(String toPrint) { // logger.info(toPrint); // // } // } // // public static int executeProcess(ProcessBuilder pb, Logger logger) { // try { // Process process = pb.start(); // AsyncStreamPrinter stardardOutputThread = new AsyncStreamPrinter(process.getInputStream(), new StandardPrinter(logger)); // stardardOutputThread.start(); // AsyncStreamPrinter errorOutputThread = new AsyncStreamPrinter(process.getErrorStream(), new ErrorPrinter(logger)); // errorOutputThread.start(); // stardardOutputThread.join(); // errorOutputThread.join(); // return process.waitFor(); // } catch (Exception e) { // throw new RuntimeException("error while excecuting " + pb.command(), e); // } // } // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/ExternalProcessProcessor.java import java.io.File; import com.tlorrain.android.rezenerator.core.Dimensions; import com.tlorrain.android.rezenerator.core.log.Logger; import com.tlorrain.android.rezenerator.core.utils.ExternalProcessUtils; package com.tlorrain.android.rezenerator.core.processor; public abstract class ExternalProcessProcessor extends BaseProcessor { // TODO add a timeout ? @Override
public boolean process(final File inFile, final File outFile, final Dimensions outDims, final Logger logger) {
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/ExternalProcessProcessor.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/ExternalProcessUtils.java // public class ExternalProcessUtils { // private static class AsyncStreamPrinter extends Thread { // // private final InputStream inputStream; // private Printer printer; // // AsyncStreamPrinter(InputStream inputStream, Printer printer) { // this.inputStream = inputStream; // this.printer = printer; // } // // @Override // public void run() { // BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); // String line = ""; // try { // while ((line = br.readLine()) != null) { // printer.print(line); // } // } catch (IOException e) { // e.printStackTrace(); // } // } // } // // private static interface Printer { // void print(String toPrint); // } // // private static class ErrorPrinter implements Printer { // private Logger logger; // // public ErrorPrinter(Logger logger) { // this.logger = logger; // } // // @Override // public void print(String toPrint) { // logger.error(toPrint); // // } // } // // private static class StandardPrinter implements Printer { // private Logger logger; // // public StandardPrinter(Logger logger) { // this.logger = logger; // } // // @Override // public void print(String toPrint) { // logger.info(toPrint); // // } // } // // public static int executeProcess(ProcessBuilder pb, Logger logger) { // try { // Process process = pb.start(); // AsyncStreamPrinter stardardOutputThread = new AsyncStreamPrinter(process.getInputStream(), new StandardPrinter(logger)); // stardardOutputThread.start(); // AsyncStreamPrinter errorOutputThread = new AsyncStreamPrinter(process.getErrorStream(), new ErrorPrinter(logger)); // errorOutputThread.start(); // stardardOutputThread.join(); // errorOutputThread.join(); // return process.waitFor(); // } catch (Exception e) { // throw new RuntimeException("error while excecuting " + pb.command(), e); // } // } // }
import java.io.File; import com.tlorrain.android.rezenerator.core.Dimensions; import com.tlorrain.android.rezenerator.core.log.Logger; import com.tlorrain.android.rezenerator.core.utils.ExternalProcessUtils;
package com.tlorrain.android.rezenerator.core.processor; public abstract class ExternalProcessProcessor extends BaseProcessor { // TODO add a timeout ? @Override
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/ExternalProcessUtils.java // public class ExternalProcessUtils { // private static class AsyncStreamPrinter extends Thread { // // private final InputStream inputStream; // private Printer printer; // // AsyncStreamPrinter(InputStream inputStream, Printer printer) { // this.inputStream = inputStream; // this.printer = printer; // } // // @Override // public void run() { // BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); // String line = ""; // try { // while ((line = br.readLine()) != null) { // printer.print(line); // } // } catch (IOException e) { // e.printStackTrace(); // } // } // } // // private static interface Printer { // void print(String toPrint); // } // // private static class ErrorPrinter implements Printer { // private Logger logger; // // public ErrorPrinter(Logger logger) { // this.logger = logger; // } // // @Override // public void print(String toPrint) { // logger.error(toPrint); // // } // } // // private static class StandardPrinter implements Printer { // private Logger logger; // // public StandardPrinter(Logger logger) { // this.logger = logger; // } // // @Override // public void print(String toPrint) { // logger.info(toPrint); // // } // } // // public static int executeProcess(ProcessBuilder pb, Logger logger) { // try { // Process process = pb.start(); // AsyncStreamPrinter stardardOutputThread = new AsyncStreamPrinter(process.getInputStream(), new StandardPrinter(logger)); // stardardOutputThread.start(); // AsyncStreamPrinter errorOutputThread = new AsyncStreamPrinter(process.getErrorStream(), new ErrorPrinter(logger)); // errorOutputThread.start(); // stardardOutputThread.join(); // errorOutputThread.join(); // return process.waitFor(); // } catch (Exception e) { // throw new RuntimeException("error while excecuting " + pb.command(), e); // } // } // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/ExternalProcessProcessor.java import java.io.File; import com.tlorrain.android.rezenerator.core.Dimensions; import com.tlorrain.android.rezenerator.core.log.Logger; import com.tlorrain.android.rezenerator.core.utils.ExternalProcessUtils; package com.tlorrain.android.rezenerator.core.processor; public abstract class ExternalProcessProcessor extends BaseProcessor { // TODO add a timeout ? @Override
public boolean process(final File inFile, final File outFile, final Dimensions outDims, final Logger logger) {
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/ExternalProcessProcessor.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/ExternalProcessUtils.java // public class ExternalProcessUtils { // private static class AsyncStreamPrinter extends Thread { // // private final InputStream inputStream; // private Printer printer; // // AsyncStreamPrinter(InputStream inputStream, Printer printer) { // this.inputStream = inputStream; // this.printer = printer; // } // // @Override // public void run() { // BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); // String line = ""; // try { // while ((line = br.readLine()) != null) { // printer.print(line); // } // } catch (IOException e) { // e.printStackTrace(); // } // } // } // // private static interface Printer { // void print(String toPrint); // } // // private static class ErrorPrinter implements Printer { // private Logger logger; // // public ErrorPrinter(Logger logger) { // this.logger = logger; // } // // @Override // public void print(String toPrint) { // logger.error(toPrint); // // } // } // // private static class StandardPrinter implements Printer { // private Logger logger; // // public StandardPrinter(Logger logger) { // this.logger = logger; // } // // @Override // public void print(String toPrint) { // logger.info(toPrint); // // } // } // // public static int executeProcess(ProcessBuilder pb, Logger logger) { // try { // Process process = pb.start(); // AsyncStreamPrinter stardardOutputThread = new AsyncStreamPrinter(process.getInputStream(), new StandardPrinter(logger)); // stardardOutputThread.start(); // AsyncStreamPrinter errorOutputThread = new AsyncStreamPrinter(process.getErrorStream(), new ErrorPrinter(logger)); // errorOutputThread.start(); // stardardOutputThread.join(); // errorOutputThread.join(); // return process.waitFor(); // } catch (Exception e) { // throw new RuntimeException("error while excecuting " + pb.command(), e); // } // } // }
import java.io.File; import com.tlorrain.android.rezenerator.core.Dimensions; import com.tlorrain.android.rezenerator.core.log.Logger; import com.tlorrain.android.rezenerator.core.utils.ExternalProcessUtils;
package com.tlorrain.android.rezenerator.core.processor; public abstract class ExternalProcessProcessor extends BaseProcessor { // TODO add a timeout ? @Override public boolean process(final File inFile, final File outFile, final Dimensions outDims, final Logger logger) {
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/ExternalProcessUtils.java // public class ExternalProcessUtils { // private static class AsyncStreamPrinter extends Thread { // // private final InputStream inputStream; // private Printer printer; // // AsyncStreamPrinter(InputStream inputStream, Printer printer) { // this.inputStream = inputStream; // this.printer = printer; // } // // @Override // public void run() { // BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); // String line = ""; // try { // while ((line = br.readLine()) != null) { // printer.print(line); // } // } catch (IOException e) { // e.printStackTrace(); // } // } // } // // private static interface Printer { // void print(String toPrint); // } // // private static class ErrorPrinter implements Printer { // private Logger logger; // // public ErrorPrinter(Logger logger) { // this.logger = logger; // } // // @Override // public void print(String toPrint) { // logger.error(toPrint); // // } // } // // private static class StandardPrinter implements Printer { // private Logger logger; // // public StandardPrinter(Logger logger) { // this.logger = logger; // } // // @Override // public void print(String toPrint) { // logger.info(toPrint); // // } // } // // public static int executeProcess(ProcessBuilder pb, Logger logger) { // try { // Process process = pb.start(); // AsyncStreamPrinter stardardOutputThread = new AsyncStreamPrinter(process.getInputStream(), new StandardPrinter(logger)); // stardardOutputThread.start(); // AsyncStreamPrinter errorOutputThread = new AsyncStreamPrinter(process.getErrorStream(), new ErrorPrinter(logger)); // errorOutputThread.start(); // stardardOutputThread.join(); // errorOutputThread.join(); // return process.waitFor(); // } catch (Exception e) { // throw new RuntimeException("error while excecuting " + pb.command(), e); // } // } // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/ExternalProcessProcessor.java import java.io.File; import com.tlorrain.android.rezenerator.core.Dimensions; import com.tlorrain.android.rezenerator.core.log.Logger; import com.tlorrain.android.rezenerator.core.utils.ExternalProcessUtils; package com.tlorrain.android.rezenerator.core.processor; public abstract class ExternalProcessProcessor extends BaseProcessor { // TODO add a timeout ? @Override public boolean process(final File inFile, final File outFile, final Dimensions outDims, final Logger logger) {
return ExternalProcessUtils.executeProcess(getProcessBuilder(inFile, outFile, outDims), logger) == 0;
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/PNGFileUtils.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/StreamUtils.java // static int readIntBigEndianOnTwoBytes(final InputStream is) throws IOException { // int ret = 0; // ret |= is.read() << 8; // ret |= is.read(); // return ret; // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // }
import static com.tlorrain.android.rezenerator.core.utils.StreamUtils.readIntBigEndianOnTwoBytes; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import org.apache.commons.io.IOUtils; import com.tlorrain.android.rezenerator.core.Dimensions;
package com.tlorrain.android.rezenerator.core.utils; public class PNGFileUtils { public static Dimensions getDimensions(final File outFile) throws FileNotFoundException, IOException { // this code is largely inspired from // http://blog.jaimon.co.uk/simpleimageinfo/SimpleImageInfo.java.html // credits to him (Apache 2 Licence) Dimensions dimensions = null; final FileInputStream is = new FileInputStream(outFile); try { // PNG file if (is.read() == 137 && is.read() == 80 && is.read() == 78) { is.skip(15);
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/StreamUtils.java // static int readIntBigEndianOnTwoBytes(final InputStream is) throws IOException { // int ret = 0; // ret |= is.read() << 8; // ret |= is.read(); // return ret; // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/PNGFileUtils.java import static com.tlorrain.android.rezenerator.core.utils.StreamUtils.readIntBigEndianOnTwoBytes; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import org.apache.commons.io.IOUtils; import com.tlorrain.android.rezenerator.core.Dimensions; package com.tlorrain.android.rezenerator.core.utils; public class PNGFileUtils { public static Dimensions getDimensions(final File outFile) throws FileNotFoundException, IOException { // this code is largely inspired from // http://blog.jaimon.co.uk/simpleimageinfo/SimpleImageInfo.java.html // credits to him (Apache 2 Licence) Dimensions dimensions = null; final FileInputStream is = new FileInputStream(outFile); try { // PNG file if (is.read() == 137 && is.read() == 80 && is.read() == 78) { is.skip(15);
final int width = readIntBigEndianOnTwoBytes(is);
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/ExternalProcessUtils.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import com.tlorrain.android.rezenerator.core.log.Logger;
package com.tlorrain.android.rezenerator.core.utils; public class ExternalProcessUtils { private static class AsyncStreamPrinter extends Thread { private final InputStream inputStream; private Printer printer; AsyncStreamPrinter(InputStream inputStream, Printer printer) { this.inputStream = inputStream; this.printer = printer; } @Override public void run() { BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); String line = ""; try { while ((line = br.readLine()) != null) { printer.print(line); } } catch (IOException e) { e.printStackTrace(); } } } private static interface Printer { void print(String toPrint); } private static class ErrorPrinter implements Printer {
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/ExternalProcessUtils.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import com.tlorrain.android.rezenerator.core.log.Logger; package com.tlorrain.android.rezenerator.core.utils; public class ExternalProcessUtils { private static class AsyncStreamPrinter extends Thread { private final InputStream inputStream; private Printer printer; AsyncStreamPrinter(InputStream inputStream, Printer printer) { this.inputStream = inputStream; this.printer = printer; } @Override public void run() { BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); String line = ""; try { while ((line = br.readLine()) != null) { printer.print(line); } } catch (IOException e) { e.printStackTrace(); } } } private static interface Printer { void print(String toPrint); } private static class ErrorPrinter implements Printer {
private Logger logger;
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/Inkscape.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // }
import java.io.File; import java.io.IOException; import com.tlorrain.android.rezenerator.core.Dimensions;
package com.tlorrain.android.rezenerator.core.processor; public class Inkscape extends ExternalProcessProcessor { @Override
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/Inkscape.java import java.io.File; import java.io.IOException; import com.tlorrain.android.rezenerator.core.Dimensions; package com.tlorrain.android.rezenerator.core.processor; public class Inkscape extends ExternalProcessProcessor { @Override
public ProcessBuilder getProcessBuilder(File inFile, File outFile, Dimensions outDims) {
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/ImageMagick.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // }
import java.io.File; import java.io.IOException; import com.tlorrain.android.rezenerator.core.Dimensions;
package com.tlorrain.android.rezenerator.core.processor; public class ImageMagick extends ExternalProcessProcessor { @Override
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/ImageMagick.java import java.io.File; import java.io.IOException; import com.tlorrain.android.rezenerator.core.Dimensions; package com.tlorrain.android.rezenerator.core.processor; public class ImageMagick extends ExternalProcessProcessor { @Override
public ProcessBuilder getProcessBuilder(final File inFile, final File outFile, final Dimensions outDims) {
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Configuration.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/NoopLogger.java // public class NoopLogger implements Logger { // // @Override // public void info(String info) { // } // // @Override // public void verbose(String debug) { // } // // @Override // public void error(String error) { // } // // @Override // public void verbose(Exception exception) { // } // // }
import java.io.File; import java.util.LinkedList; import java.util.List; import com.tlorrain.android.rezenerator.core.log.Logger; import com.tlorrain.android.rezenerator.core.log.NoopLogger;
package com.tlorrain.android.rezenerator.core; public class Configuration { /** * The directory containing the image files to process */ private File inDir; /** * The base directory where processed files should be output (eg the * directory containing the mdpi, hdpi ... folders) */ private File baseOutDir; /** * Whether Rezenerator should be verbose or not */ private boolean verbose = true; /** * If set to true, all files will be regenerated. */ private boolean forceUpdate = false; /** * Packages containing extra processors */ private List<String> scannedPackages = new LinkedList<String>(); /** * Logger to use */
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/NoopLogger.java // public class NoopLogger implements Logger { // // @Override // public void info(String info) { // } // // @Override // public void verbose(String debug) { // } // // @Override // public void error(String error) { // } // // @Override // public void verbose(Exception exception) { // } // // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Configuration.java import java.io.File; import java.util.LinkedList; import java.util.List; import com.tlorrain.android.rezenerator.core.log.Logger; import com.tlorrain.android.rezenerator.core.log.NoopLogger; package com.tlorrain.android.rezenerator.core; public class Configuration { /** * The directory containing the image files to process */ private File inDir; /** * The base directory where processed files should be output (eg the * directory containing the mdpi, hdpi ... folders) */ private File baseOutDir; /** * Whether Rezenerator should be verbose or not */ private boolean verbose = true; /** * If set to true, all files will be regenerated. */ private boolean forceUpdate = false; /** * Packages containing extra processors */ private List<String> scannedPackages = new LinkedList<String>(); /** * Logger to use */
private Logger logger = new NoopLogger();
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Configuration.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/NoopLogger.java // public class NoopLogger implements Logger { // // @Override // public void info(String info) { // } // // @Override // public void verbose(String debug) { // } // // @Override // public void error(String error) { // } // // @Override // public void verbose(Exception exception) { // } // // }
import java.io.File; import java.util.LinkedList; import java.util.List; import com.tlorrain.android.rezenerator.core.log.Logger; import com.tlorrain.android.rezenerator.core.log.NoopLogger;
package com.tlorrain.android.rezenerator.core; public class Configuration { /** * The directory containing the image files to process */ private File inDir; /** * The base directory where processed files should be output (eg the * directory containing the mdpi, hdpi ... folders) */ private File baseOutDir; /** * Whether Rezenerator should be verbose or not */ private boolean verbose = true; /** * If set to true, all files will be regenerated. */ private boolean forceUpdate = false; /** * Packages containing extra processors */ private List<String> scannedPackages = new LinkedList<String>(); /** * Logger to use */
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/NoopLogger.java // public class NoopLogger implements Logger { // // @Override // public void info(String info) { // } // // @Override // public void verbose(String debug) { // } // // @Override // public void error(String error) { // } // // @Override // public void verbose(Exception exception) { // } // // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Configuration.java import java.io.File; import java.util.LinkedList; import java.util.List; import com.tlorrain.android.rezenerator.core.log.Logger; import com.tlorrain.android.rezenerator.core.log.NoopLogger; package com.tlorrain.android.rezenerator.core; public class Configuration { /** * The directory containing the image files to process */ private File inDir; /** * The base directory where processed files should be output (eg the * directory containing the mdpi, hdpi ... folders) */ private File baseOutDir; /** * Whether Rezenerator should be verbose or not */ private boolean verbose = true; /** * If set to true, all files will be regenerated. */ private boolean forceUpdate = false; /** * Packages containing extra processors */ private List<String> scannedPackages = new LinkedList<String>(); /** * Logger to use */
private Logger logger = new NoopLogger();
fredszaq/Rezenerator
rezenerator-core/src/test/java/com/tlorrain/android/rezenerator/core/RezeneratorRunnerTest.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/PNGFileUtils.java // public class PNGFileUtils { // // public static Dimensions getDimensions(final File outFile) throws FileNotFoundException, IOException { // // this code is largely inspired from // // http://blog.jaimon.co.uk/simpleimageinfo/SimpleImageInfo.java.html // // credits to him (Apache 2 Licence) // Dimensions dimensions = null; // final FileInputStream is = new FileInputStream(outFile); // try { // // PNG file // if (is.read() == 137 && is.read() == 80 && is.read() == 78) { // is.skip(15); // final int width = readIntBigEndianOnTwoBytes(is); // is.skip(2); // final int height = readIntBigEndianOnTwoBytes(is); // dimensions = new Dimensions(height, width); // } // } finally { // IOUtils.closeQuietly(is); // } // return dimensions; // } // // }
import static org.fest.assertions.Assertions.assertThat; import java.io.File; import java.util.Map; import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Test; import com.google.common.collect.ImmutableMap; import com.tlorrain.android.rezenerator.core.utils.PNGFileUtils;
File hdpi = getOutFile(outDir, "hdpi"); File xhdpi = getOutFile(outDir, "xhdpi"); File xxhdpi = getOutFile(outDir, "xxhdpi"); long lastModifiedMdpi = mdpi.lastModified(); long lastModifiedHdpi = hdpi.lastModified(); long lastModifiedXhdpi = xhdpi.lastModified(); long lastModifiedXxhdpi = xxhdpi.lastModified(); Thread.sleep(1000); // time resolution on some files systems is 1s, so // lets wait that to be sure assertThat(rezeneratorRunner.run(config().setForceUpdate(true)).isSuccessful()).isTrue(); assertThat(mdpi.lastModified()).isGreaterThan(lastModifiedMdpi); assertThat(hdpi.lastModified()).isGreaterThan(lastModifiedHdpi); assertThat(xhdpi.lastModified()).isGreaterThan(lastModifiedXhdpi); assertThat(xxhdpi.lastModified()).isGreaterThan(lastModifiedXxhdpi); checkOutDir(outDir); } private Configuration config() { return new Configuration().setInDir(new File("src/test/resources/runner")).setBaseOutDir(outDir).addScannedPackage("com.tlorrain.android"); } private void checkOutDir(File outDir) throws Exception { Map<String, Integer> dims = ImmutableMap.of("mdpi", 48, "hdpi", 72, "xhdpi", 96, "xxhdpi", 144); for (String subDir : dims.keySet()) { File outFile = getOutFile(outDir, subDir);
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/utils/PNGFileUtils.java // public class PNGFileUtils { // // public static Dimensions getDimensions(final File outFile) throws FileNotFoundException, IOException { // // this code is largely inspired from // // http://blog.jaimon.co.uk/simpleimageinfo/SimpleImageInfo.java.html // // credits to him (Apache 2 Licence) // Dimensions dimensions = null; // final FileInputStream is = new FileInputStream(outFile); // try { // // PNG file // if (is.read() == 137 && is.read() == 80 && is.read() == 78) { // is.skip(15); // final int width = readIntBigEndianOnTwoBytes(is); // is.skip(2); // final int height = readIntBigEndianOnTwoBytes(is); // dimensions = new Dimensions(height, width); // } // } finally { // IOUtils.closeQuietly(is); // } // return dimensions; // } // // } // Path: rezenerator-core/src/test/java/com/tlorrain/android/rezenerator/core/RezeneratorRunnerTest.java import static org.fest.assertions.Assertions.assertThat; import java.io.File; import java.util.Map; import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Test; import com.google.common.collect.ImmutableMap; import com.tlorrain.android.rezenerator.core.utils.PNGFileUtils; File hdpi = getOutFile(outDir, "hdpi"); File xhdpi = getOutFile(outDir, "xhdpi"); File xxhdpi = getOutFile(outDir, "xxhdpi"); long lastModifiedMdpi = mdpi.lastModified(); long lastModifiedHdpi = hdpi.lastModified(); long lastModifiedXhdpi = xhdpi.lastModified(); long lastModifiedXxhdpi = xxhdpi.lastModified(); Thread.sleep(1000); // time resolution on some files systems is 1s, so // lets wait that to be sure assertThat(rezeneratorRunner.run(config().setForceUpdate(true)).isSuccessful()).isTrue(); assertThat(mdpi.lastModified()).isGreaterThan(lastModifiedMdpi); assertThat(hdpi.lastModified()).isGreaterThan(lastModifiedHdpi); assertThat(xhdpi.lastModified()).isGreaterThan(lastModifiedXhdpi); assertThat(xxhdpi.lastModified()).isGreaterThan(lastModifiedXxhdpi); checkOutDir(outDir); } private Configuration config() { return new Configuration().setInDir(new File("src/test/resources/runner")).setBaseOutDir(outDir).addScannedPackage("com.tlorrain.android"); } private void checkOutDir(File outDir) throws Exception { Map<String, Integer> dims = ImmutableMap.of("mdpi", 48, "hdpi", 72, "xhdpi", 96, "xxhdpi", 144); for (String subDir : dims.keySet()) { File outFile = getOutFile(outDir, subDir);
assertThat(PNGFileUtils.getDimensions(outFile)).isEqualTo(new Dimensions(dims.get(subDir)));
fredszaq/Rezenerator
rezenerator-core/src/test/java/com/tlorrain/android/rezenerator/core/definition/DefinitionReaderTest.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // }
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.MapAssert.entry; import java.util.Properties; import org.fest.assertions.MapAssert.Entry; import org.junit.Test; import com.tlorrain.android.rezenerator.core.Dimensions;
package com.tlorrain.android.rezenerator.core.definition; public class DefinitionReaderTest { @Test public void val() throws Exception { test(props( // "rezenerator.val.mdpi", "48", // "rezenerator.val.hdpi", "45x90"), //
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // Path: rezenerator-core/src/test/java/com/tlorrain/android/rezenerator/core/definition/DefinitionReaderTest.java import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.MapAssert.entry; import java.util.Properties; import org.fest.assertions.MapAssert.Entry; import org.junit.Test; import com.tlorrain.android.rezenerator.core.Dimensions; package com.tlorrain.android.rezenerator.core.definition; public class DefinitionReaderTest { @Test public void val() throws Exception { test(props( // "rezenerator.val.mdpi", "48", // "rezenerator.val.hdpi", "45x90"), //
entry("mdpi", new Dimensions(48)), //
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/definition/DefinitionReader.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // }
import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; import com.tlorrain.android.rezenerator.core.Dimensions;
package com.tlorrain.android.rezenerator.core.definition; public class DefinitionReader { private final Properties definition; public DefinitionReader(Properties definition) throws FileNotFoundException, IOException { this.definition = definition; } public static final String PREFIX_VAL = "rezenerator.val."; public static final String PREFIX_DEF = "rezenerator.def.";
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/definition/DefinitionReader.java import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; import com.tlorrain.android.rezenerator.core.Dimensions; package com.tlorrain.android.rezenerator.core.definition; public class DefinitionReader { private final Properties definition; public DefinitionReader(Properties definition) throws FileNotFoundException, IOException { this.definition = definition; } public static final String PREFIX_VAL = "rezenerator.val."; public static final String PREFIX_DEF = "rezenerator.def.";
public Map<String, Dimensions> getConfigurations() {
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/InkscapeMagick.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // }
import java.io.File; import com.tlorrain.android.rezenerator.core.Dimensions; import com.tlorrain.android.rezenerator.core.log.Logger;
package com.tlorrain.android.rezenerator.core.processor; /** * A processor that uses Inkscape to get an image twice the required size and * then shrink it down using Image Magick. This may come in handy if the * {@link Inkscape} processor output aliased images * */ public class InkscapeMagick extends BaseProcessor { @Override
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/InkscapeMagick.java import java.io.File; import com.tlorrain.android.rezenerator.core.Dimensions; import com.tlorrain.android.rezenerator.core.log.Logger; package com.tlorrain.android.rezenerator.core.processor; /** * A processor that uses Inkscape to get an image twice the required size and * then shrink it down using Image Magick. This may come in handy if the * {@link Inkscape} processor output aliased images * */ public class InkscapeMagick extends BaseProcessor { @Override
public boolean process(final File inFile, final File outFile, final Dimensions outDims, final Logger logger) {
fredszaq/Rezenerator
rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/InkscapeMagick.java
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // }
import java.io.File; import com.tlorrain.android.rezenerator.core.Dimensions; import com.tlorrain.android.rezenerator.core.log.Logger;
package com.tlorrain.android.rezenerator.core.processor; /** * A processor that uses Inkscape to get an image twice the required size and * then shrink it down using Image Magick. This may come in handy if the * {@link Inkscape} processor output aliased images * */ public class InkscapeMagick extends BaseProcessor { @Override
// Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/Dimensions.java // public class Dimensions { // private final int height, width; // // public Dimensions(final int height, final int width) { // this.height = height; // this.width = width; // } // // public Dimensions(final int squareSize) { // this(squareSize, squareSize); // } // // public int getHeight() { // return height; // } // // public int getWidth() { // return width; // } // // public Dimensions multiply(final int factor) { // return new Dimensions(height * factor, width * factor); // } // // public Dimensions divide(final int divisor) { // return new Dimensions(height / divisor, width / divisor); // } // // public Dimensions scaleToWidth(final int newWidth) { // return new Dimensions(height * newWidth / width, newWidth); // } // // public Dimensions scaleToHeight(final int newHeight) { // return new Dimensions(newHeight, width * newHeight / height); // } // // @Override // public int hashCode() { // final int prime = 31; // int result = 1; // result = prime * result + height; // result = prime * result + width; // return result; // } // // @Override // public boolean equals(final Object obj) { // if (this == obj) { // return true; // } // if (obj == null) { // return false; // } // if (getClass() != obj.getClass()) { // return false; // } // final Dimensions other = (Dimensions) obj; // if (height != other.height) { // return false; // } // if (width != other.width) { // return false; // } // return true; // } // // @Override // public String toString() { // return "Dimensions [height=" + height + ", width=" + width + "]"; // } // // private static final Pattern PATTERN_SIMPLE = Pattern.compile("\\d+"); // private static final Pattern PATTERN_X = Pattern.compile("(\\d+)[xX](\\d+)"); // // public static Dimensions fromString(final String string) { // if (string.matches(PATTERN_SIMPLE.pattern())) { // return new Dimensions(Integer.parseInt(string)); // } else if (string.matches(PATTERN_X.pattern())) { // final Matcher matcher = PATTERN_X.matcher(string); // matcher.find(); // return new Dimensions(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); // } // throw new IllegalArgumentException(string); // } // } // // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/log/Logger.java // public interface Logger { // void info(String info); // // void verbose(String debug); // // void verbose(Exception exception); // // void error(String error); // } // Path: rezenerator-core/src/main/java/com/tlorrain/android/rezenerator/core/processor/InkscapeMagick.java import java.io.File; import com.tlorrain.android.rezenerator.core.Dimensions; import com.tlorrain.android.rezenerator.core.log.Logger; package com.tlorrain.android.rezenerator.core.processor; /** * A processor that uses Inkscape to get an image twice the required size and * then shrink it down using Image Magick. This may come in handy if the * {@link Inkscape} processor output aliased images * */ public class InkscapeMagick extends BaseProcessor { @Override
public boolean process(final File inFile, final File outFile, final Dimensions outDims, final Logger logger) {
Anchormen/sql4es
src/main/java/nl/anchormen/sql4es/model/Heading.java
// Path: src/main/java/nl/anchormen/sql4es/model/Column.java // public enum Operation {NONE, AVG, SUM, MIN, MAX, COUNT, HIGHLIGHT, COUNT_DISTINCT}
import java.math.BigDecimal; import java.sql.Array; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; import java.sql.Types; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import nl.anchormen.sql4es.model.Column.Operation;
package nl.anchormen.sql4es.model; /** * Represents all the columns and their column index in the {@link ResultSet}. In addition it keeps track * of special scenarios such as 'select * from ..' in which all available columns should be returned or * when client side calculations must be done like sum(column)/10. To support these calculations a Heading might * have invisible columns used to store data not accessible to the client. * * @author cversloot * */ public class Heading { public final static String ID = "_id"; public final static String INDEX = "_index"; public final static String TYPE = "_type"; public static final String SCORE = "_score"; public static final String SEARCH = "_search"; private List<Column> columns = new ArrayList<Column>(); private HashMap<String, Column> fieldIndex = new HashMap<String, Column>(); private HashMap<String, Column> aliasIndex = new HashMap<String, Column>(); private HashMap<String, Integer> labelToColNr = new HashMap<String, Integer>(); private HashMap<Integer, Integer> columnToColIndex = new HashMap<Integer, Integer>(); private Map<String, Integer> typeIndex = new HashMap<String, Integer>(); private boolean allColumns = false; private boolean indexed = false; public Heading(){} /** * Adds a column to this heading, checking if the column exists as well as adding its type. * @param column */ public void add(Column column) { String colName = column.getColumn(); // remove .* at the end to convert 'field.*' just to 'field' which will be expanded during result parsing if(colName.endsWith(".*")) column.setColumn(colName.substring(0, colName.length()-2));
// Path: src/main/java/nl/anchormen/sql4es/model/Column.java // public enum Operation {NONE, AVG, SUM, MIN, MAX, COUNT, HIGHLIGHT, COUNT_DISTINCT} // Path: src/main/java/nl/anchormen/sql4es/model/Heading.java import java.math.BigDecimal; import java.sql.Array; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; import java.sql.Types; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import nl.anchormen.sql4es.model.Column.Operation; package nl.anchormen.sql4es.model; /** * Represents all the columns and their column index in the {@link ResultSet}. In addition it keeps track * of special scenarios such as 'select * from ..' in which all available columns should be returned or * when client side calculations must be done like sum(column)/10. To support these calculations a Heading might * have invisible columns used to store data not accessible to the client. * * @author cversloot * */ public class Heading { public final static String ID = "_id"; public final static String INDEX = "_index"; public final static String TYPE = "_type"; public static final String SCORE = "_score"; public static final String SEARCH = "_search"; private List<Column> columns = new ArrayList<Column>(); private HashMap<String, Column> fieldIndex = new HashMap<String, Column>(); private HashMap<String, Column> aliasIndex = new HashMap<String, Column>(); private HashMap<String, Integer> labelToColNr = new HashMap<String, Integer>(); private HashMap<Integer, Integer> columnToColIndex = new HashMap<Integer, Integer>(); private Map<String, Integer> typeIndex = new HashMap<String, Integer>(); private boolean allColumns = false; private boolean indexed = false; public Heading(){} /** * Adds a column to this heading, checking if the column exists as well as adding its type. * @param column */ public void add(Column column) { String colName = column.getColumn(); // remove .* at the end to convert 'field.*' just to 'field' which will be expanded during result parsing if(colName.endsWith(".*")) column.setColumn(colName.substring(0, colName.length()-2));
if(column.getColumn().equals("*") && column.getOp() == Operation.NONE) {
Anchormen/sql4es
src/main/java/nl/anchormen/sql4es/model/Column.java
// Path: src/main/java/nl/anchormen/sql4es/model/expression/ICalculation.java // public interface ICalculation { // // public Number evaluate(ESResultSet result, int rowNr); // // public ICalculation setSign(Sign sign); // // }
import java.sql.Types; import nl.anchormen.sql4es.model.expression.ICalculation;
package nl.anchormen.sql4es.model; /** * Represents a single column (field) to be fetched and parsed from elasticsearch. * * @author cversloot * */ public class Column implements Comparable<Column>{ public enum Operation {NONE, AVG, SUM, MIN, MAX, COUNT, HIGHLIGHT, COUNT_DISTINCT} private String columnName; private String tableName; private String tableAlias; private Operation op = Operation.NONE; private String alias = null; private int index = -1; private int sqlType = Types.OTHER;
// Path: src/main/java/nl/anchormen/sql4es/model/expression/ICalculation.java // public interface ICalculation { // // public Number evaluate(ESResultSet result, int rowNr); // // public ICalculation setSign(Sign sign); // // } // Path: src/main/java/nl/anchormen/sql4es/model/Column.java import java.sql.Types; import nl.anchormen.sql4es.model.expression.ICalculation; package nl.anchormen.sql4es.model; /** * Represents a single column (field) to be fetched and parsed from elasticsearch. * * @author cversloot * */ public class Column implements Comparable<Column>{ public enum Operation {NONE, AVG, SUM, MIN, MAX, COUNT, HIGHLIGHT, COUNT_DISTINCT} private String columnName; private String tableName; private String tableAlias; private Operation op = Operation.NONE; private String alias = null; private int index = -1; private int sqlType = Types.OTHER;
private ICalculation calculation = null;
Anchormen/sql4es
src/main/java/nl/anchormen/sql4es/model/BasicQueryState.java
// Path: src/main/java/nl/anchormen/sql4es/QueryState.java // public interface QueryState { // // /** // * Provides the original query provided to the driver // * @return // */ // public String originalSql(); // // /** // * Returns the heading build for the query // * @return // */ // public Heading getHeading(); // // /** // * Adds exception to this state signaling something went wrong while traversing the AST // * @param msg // */ // public void addException(String msg); // // /** // * // * @return true if an exception has been set (typically a flag to stop work and return) // */ // public boolean hasException(); // // /** // * @return the SQLExceptoin set in this state or NULL if it has no exception // */ // public SQLException getException(); // // /** // * Gets the specified integer property // * @param name // * @param def // * @return // */ // public int getIntProp(String name, int def); // // /** // * Gets the specified string property // * @param name // * @param def // * @return // */ // public String getProperty(String name, String def); // // /** // * Gets the property with the given name or NULL if it does not exist // * @param name // * @return // */ // public Object getProperty(String name); // // /** // * Gets set of relations being accessed in the query (if any) // * @return // */ // public List<QuerySource> getSources(); // // public QueryState setKeyValue(String key, Object value); // // public Object getValue(String key); // // public String getStringValue(String key); // // public boolean isCountDistinct(); // // } // // Path: src/main/java/nl/anchormen/sql4es/model/Column.java // public enum Operation {NONE, AVG, SUM, MIN, MAX, COUNT, HIGHLIGHT, COUNT_DISTINCT}
import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Properties; import nl.anchormen.sql4es.QueryState; import nl.anchormen.sql4es.model.Column.Operation;
return this.props.getProperty(name); } catch (Exception e) { return def; } } @Override public Object getProperty(String name) { return this.props.get(name); } @Override public QueryState setKeyValue(String key, Object value) { kvStore.put(key, value); return this; } @Override public Object getValue(String key) { return kvStore.get(key); } @Override public String getStringValue(String key) { return (String)kvStore.get(key); } @Override public boolean isCountDistinct() { for(Column col : getHeading().columns()){
// Path: src/main/java/nl/anchormen/sql4es/QueryState.java // public interface QueryState { // // /** // * Provides the original query provided to the driver // * @return // */ // public String originalSql(); // // /** // * Returns the heading build for the query // * @return // */ // public Heading getHeading(); // // /** // * Adds exception to this state signaling something went wrong while traversing the AST // * @param msg // */ // public void addException(String msg); // // /** // * // * @return true if an exception has been set (typically a flag to stop work and return) // */ // public boolean hasException(); // // /** // * @return the SQLExceptoin set in this state or NULL if it has no exception // */ // public SQLException getException(); // // /** // * Gets the specified integer property // * @param name // * @param def // * @return // */ // public int getIntProp(String name, int def); // // /** // * Gets the specified string property // * @param name // * @param def // * @return // */ // public String getProperty(String name, String def); // // /** // * Gets the property with the given name or NULL if it does not exist // * @param name // * @return // */ // public Object getProperty(String name); // // /** // * Gets set of relations being accessed in the query (if any) // * @return // */ // public List<QuerySource> getSources(); // // public QueryState setKeyValue(String key, Object value); // // public Object getValue(String key); // // public String getStringValue(String key); // // public boolean isCountDistinct(); // // } // // Path: src/main/java/nl/anchormen/sql4es/model/Column.java // public enum Operation {NONE, AVG, SUM, MIN, MAX, COUNT, HIGHLIGHT, COUNT_DISTINCT} // Path: src/main/java/nl/anchormen/sql4es/model/BasicQueryState.java import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Properties; import nl.anchormen.sql4es.QueryState; import nl.anchormen.sql4es.model.Column.Operation; return this.props.getProperty(name); } catch (Exception e) { return def; } } @Override public Object getProperty(String name) { return this.props.get(name); } @Override public QueryState setKeyValue(String key, Object value) { kvStore.put(key, value); return this; } @Override public Object getValue(String key) { return kvStore.get(key); } @Override public String getStringValue(String key) { return (String)kvStore.get(key); } @Override public boolean isCountDistinct() { for(Column col : getHeading().columns()){
if(col.getOp() == Operation.COUNT_DISTINCT) return true;
kdgregory/pomutil
app-version/src/main/java/com/kdgregory/pomutil/version/Main.java
// Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Utils.java // public class Utils // { // /** // * Builds a list of files from the provided list of files and/or directories. // * The provided files are added to this list without change; directories are // * recursively examined, and any file named "pom.xml" is added to the list. // */ // public static List<File> buildFileListFromStringList(List<String> sources) // { // List<File> sourceFiles = new ArrayList<File>(sources.size()); // for (String source : sources) // { // sourceFiles.add(new File(source)); // } // return buildFileList(sourceFiles); // } // // // /** // * Builds a list of files from the provided list of files and/or directories. // * The provided files are added to this list without change; directories are // * recursively examined, and any file named "pom.xml" is added to the list. // */ // public static List<File> buildFileList(List<File> sources) // { // List<File> result = new ArrayList<File>(); // for (File source : sources) // { // if (source.isDirectory()) // { // for (File child : source.listFiles()) // { // if (child.isDirectory()) // { // result.addAll(buildFileList(Arrays.asList(child))); // } // else if (child.getName().equals("pom.xml")) // { // result.add(child); // } // } // } // else // { // result.add(source); // } // } // return result; // } // // // /** // * Given a JAR, finds all entries that represent classes and converts them to classnames. // */ // public static List<String> extractClassesFromJar(File jarFile) // throws IOException // { // List<String> result = new ArrayList<String>(); // JarFile jar = null; // try // { // jar = new JarFile(jarFile); // for (Enumeration<JarEntry> entryItx = jar.entries() ; entryItx.hasMoreElements() ; ) // { // JarEntry entry = entryItx.nextElement(); // String filename = entry.getName(); // if (! filename.endsWith(".class")) // continue; // filename = filename.substring(0, filename.length() - 6); // filename = filename.replace('/', '.'); // filename = filename.replace('$', '.'); // result.add(filename); // } // return result; // } // finally // { // if (jar != null) // { // try // { // jar.close(); // } // catch (IOException ignored) // { // // ignored // } // } // } // } // // // /** // * Removes all children from the passed element, storing them in an // * order-preserving map keyed by the child's localName. // * // * @throws IllegalStateException if there's more than one child with the // * same localName (this should be considered an unrecoverable // * error, as the element will already have been mutated). // */ // public static Map<String,Element> removeChildrenToMap(Element elem) // { // Map<String,Element> children = new LinkedHashMap<String,Element>(); // for (Element child : DomUtil.getChildren(elem)) // { // String localName = DomUtil.getLocalName(child); // Element prev = children.put(localName, child); // if (prev != null) // throw new IllegalStateException("duplicate child name: " + localName); // elem.removeChild(child); // } // return children; // } // // // /** // * Reconstructs the passed element, ordering its children according to their // * localNames as specified by the <code>childOrder</code> array. Any children // * whose names are not in the array are appended to the end of the element. // * <p> // * WARNING: only one child must exist with a given name! // */ // public static Element reconstruct(Element elem, String... childOrder) // { // return reconstruct(elem, removeChildrenToMap(elem), childOrder); // } // // // /** // * Updates the specified element with children from the map, in the specified // * order. Any elements in the map that do not correspond to specified order // * will be appended at the end of the element. // */ // public static Element reconstruct(Element elem, Map<String,Element> children, String... childOrder) // { // for (String name : childOrder) // { // Element child = children.remove(name); // if (child != null) // elem.appendChild(child); // } // // // rebuild anything left over // for (Element child : children.values()) // { // elem.appendChild(child); // } // // return elem; // } // }
import java.io.File; import java.util.List; import net.sf.kdgcommons.collections.CollectionUtil; import com.kdgregory.pomutil.util.Utils;
// Copyright Keith D Gregory // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.kdgregory.pomutil.version; /** * Driver program for POM version changes. See README for invocation instructions. * <p> * Successful execution results in a 0 return code. Any exception will be written * to StdErr, and the program will terminate with a non-zero return code. */ public class Main { public static void main(String[] argv) throws Exception { CommandLine commandLine = new CommandLine(argv); if (! commandLine.isValid()) { System.err.println("usage: java -jar target/app-version-*.jar OPTIONS FILES_OR_DIRECTORIES..."); System.err.println(); System.err.println("where OPTIONS are:"); System.err.println(commandLine.getHelp()); System.exit(1); }
// Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Utils.java // public class Utils // { // /** // * Builds a list of files from the provided list of files and/or directories. // * The provided files are added to this list without change; directories are // * recursively examined, and any file named "pom.xml" is added to the list. // */ // public static List<File> buildFileListFromStringList(List<String> sources) // { // List<File> sourceFiles = new ArrayList<File>(sources.size()); // for (String source : sources) // { // sourceFiles.add(new File(source)); // } // return buildFileList(sourceFiles); // } // // // /** // * Builds a list of files from the provided list of files and/or directories. // * The provided files are added to this list without change; directories are // * recursively examined, and any file named "pom.xml" is added to the list. // */ // public static List<File> buildFileList(List<File> sources) // { // List<File> result = new ArrayList<File>(); // for (File source : sources) // { // if (source.isDirectory()) // { // for (File child : source.listFiles()) // { // if (child.isDirectory()) // { // result.addAll(buildFileList(Arrays.asList(child))); // } // else if (child.getName().equals("pom.xml")) // { // result.add(child); // } // } // } // else // { // result.add(source); // } // } // return result; // } // // // /** // * Given a JAR, finds all entries that represent classes and converts them to classnames. // */ // public static List<String> extractClassesFromJar(File jarFile) // throws IOException // { // List<String> result = new ArrayList<String>(); // JarFile jar = null; // try // { // jar = new JarFile(jarFile); // for (Enumeration<JarEntry> entryItx = jar.entries() ; entryItx.hasMoreElements() ; ) // { // JarEntry entry = entryItx.nextElement(); // String filename = entry.getName(); // if (! filename.endsWith(".class")) // continue; // filename = filename.substring(0, filename.length() - 6); // filename = filename.replace('/', '.'); // filename = filename.replace('$', '.'); // result.add(filename); // } // return result; // } // finally // { // if (jar != null) // { // try // { // jar.close(); // } // catch (IOException ignored) // { // // ignored // } // } // } // } // // // /** // * Removes all children from the passed element, storing them in an // * order-preserving map keyed by the child's localName. // * // * @throws IllegalStateException if there's more than one child with the // * same localName (this should be considered an unrecoverable // * error, as the element will already have been mutated). // */ // public static Map<String,Element> removeChildrenToMap(Element elem) // { // Map<String,Element> children = new LinkedHashMap<String,Element>(); // for (Element child : DomUtil.getChildren(elem)) // { // String localName = DomUtil.getLocalName(child); // Element prev = children.put(localName, child); // if (prev != null) // throw new IllegalStateException("duplicate child name: " + localName); // elem.removeChild(child); // } // return children; // } // // // /** // * Reconstructs the passed element, ordering its children according to their // * localNames as specified by the <code>childOrder</code> array. Any children // * whose names are not in the array are appended to the end of the element. // * <p> // * WARNING: only one child must exist with a given name! // */ // public static Element reconstruct(Element elem, String... childOrder) // { // return reconstruct(elem, removeChildrenToMap(elem), childOrder); // } // // // /** // * Updates the specified element with children from the map, in the specified // * order. Any elements in the map that do not correspond to specified order // * will be appended at the end of the element. // */ // public static Element reconstruct(Element elem, Map<String,Element> children, String... childOrder) // { // for (String name : childOrder) // { // Element child = children.remove(name); // if (child != null) // elem.appendChild(child); // } // // // rebuild anything left over // for (Element child : children.values()) // { // elem.appendChild(child); // } // // return elem; // } // } // Path: app-version/src/main/java/com/kdgregory/pomutil/version/Main.java import java.io.File; import java.util.List; import net.sf.kdgcommons.collections.CollectionUtil; import com.kdgregory.pomutil.util.Utils; // Copyright Keith D Gregory // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.kdgregory.pomutil.version; /** * Driver program for POM version changes. See README for invocation instructions. * <p> * Successful execution results in a 0 return code. Any exception will be written * to StdErr, and the program will terminate with a non-zero return code. */ public class Main { public static void main(String[] argv) throws Exception { CommandLine commandLine = new CommandLine(argv); if (! commandLine.isValid()) { System.err.println("usage: java -jar target/app-version-*.jar OPTIONS FILES_OR_DIRECTORIES..."); System.err.println(); System.err.println("where OPTIONS are:"); System.err.println(commandLine.getHelp()); System.exit(1); }
List<File> files = Utils.buildFileListFromStringList(commandLine.getParameters());
kdgregory/pomutil
app-dependency/src/main/java/com/kdgregory/pomutil/dependency/Reporter.java
// Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Artifact.java // public class Artifact // extends GAV // { // /** // * For artifacts that represent dependencies, identifies the scope to which the // * dependency applies. The order of these elements defines the outermost sort // * order for {@link #ScopedComparator}. // */ // public enum Scope // { // IMPORT, COMPILE, RUNTIME, TEST, SYSTEM, PROVIDED // } // // // //---------------------------------------------------------------------------- // // Instance variables and constructor // //---------------------------------------------------------------------------- // // public String classifier = ""; // public String packaging = "jar"; // public Scope scope = Scope.COMPILE; // public boolean optional; // // // /** // * Base constructor, allowing explicit specification of all fields. // * // * @throws IllegalArgumentException if passed a scope that does not match // * one of the enumerated values. // */ // public Artifact(String groupId, String artifactId, String version, // String classifier, String packaging, String scope, boolean isOptional) // { // super(groupId, artifactId, version); // this.classifier = classifier; // this.packaging = packaging.toLowerCase(); // this.scope = lookupScope(scope); // this.optional = isOptional; // } // // // /** // * Convenience constructor, used for arbitrary compile-scope artifacts. // */ // public Artifact(String groupId, String artifactId, String version, String packaging) // { // super(groupId, artifactId, version); // this.packaging = packaging; // } // // // /** // * Convenience constructor, used for compile-scope JARs. // */ // public Artifact(String groupId, String artifactId, String version) // { // super(groupId, artifactId, version); // } // // // /** // * Dependency constructor, which extracts all values from XML. // */ // public Artifact(Element dependency) // { // super(dependency); // for (Element child : DomUtil.getChildren(dependency)) // { // String localName = DomUtil.getLocalName(child); // String value = StringUtil.trim(DomUtil.getText(child)); // // if (localName.equals("type")) // this.packaging = value.toLowerCase(); // else if (localName.equals("classifier")) // this.classifier = value; // else if (localName.equals("scope")) // this.scope = lookupScope(value); // else if (localName.equals("optional")) // this.optional = value.equalsIgnoreCase("true"); // } // } // // // /** // * Internal constructor, used for the various copy operations. // */ // public Artifact(Artifact that) // { // super(that.groupId, that.artifactId, that.version); // this.classifier = that.classifier; // this.packaging = that.packaging; // this.scope = that.scope; // this.optional = that.optional; // } // // // private static Scope lookupScope(String scope) // { // if (StringUtil.isBlank(scope)) // { // return Scope.COMPILE; // } // else // { // return Scope.valueOf(scope.toUpperCase()); // } // } // // // //---------------------------------------------------------------------------- // // Other Public methods // //---------------------------------------------------------------------------- // // /** // * Returns the groupId/artifactId of this artifact, to key a dependency // * map. // */ // public GAKey toGAKey() // { // return new GAKey(groupId, artifactId); // } // // // /** // * Returns a new artifact, representing the POM for this artifact. // */ // public Artifact toPom() // { // return new Artifact(groupId, artifactId, version, "", "pom", "", optional); // } // // // /** // * Returns a copy of this artifact, with a different version. // */ // public Artifact withVersion(String newVersion) // { // return new Artifact(groupId, artifactId, newVersion, classifier, packaging, scope.name(), optional); // } // // //---------------------------------------------------------------------------- // // Object overrides // //---------------------------------------------------------------------------- // // /** // * Returns a string that is useful for debugging. // */ // @Override // public String toString() // { // return groupId + ":" + artifactId + ":" + version + ":" + packaging; // } // // // //---------------------------------------------------------------------------- // // Additional utility classes // //---------------------------------------------------------------------------- // // /** // * A comparator that does a first-order comparison based on scope, then // * falls back to the built-in comparator. // */ // public static class ScopedComparator // implements Comparator<Artifact>, Serializable // { // private static final long serialVersionUID = 1L; // // @Override // public int compare(Artifact o1, Artifact o2) // { // int cmp = o1.scope.compareTo(o2.scope); // return (cmp != 0) // ? cmp // : o1.compareTo(o2); // } // } // }
import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Set; import java.util.TreeSet; import net.sf.kdgcommons.collections.CollectionUtil; import com.kdgregory.pomutil.util.Artifact;
PrintWriter out = new PrintWriter(new OutputStreamWriter(out0, "UTF-8")); outputMissingDependencies(out); outputUnusedDependencies(out); outputIncorrectDependencies(out); out.flush(); } //---------------------------------------------------------------------------- // Internals //---------------------------------------------------------------------------- private void outputMissingDependencies(PrintWriter out) { Set<String> missingDependencies = CollectionUtil.combine(new TreeSet<String>(), checker.getUnsupportedMainlinePackages(), checker.getUnsupportedTestPackages()); for (String pkg : missingDependencies) { out.format(OUTPUT_FORMAT, "PACKAGE_MISSING_DEPENDENCY", pkg); } } private void outputUnusedDependencies(PrintWriter out) {
// Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Artifact.java // public class Artifact // extends GAV // { // /** // * For artifacts that represent dependencies, identifies the scope to which the // * dependency applies. The order of these elements defines the outermost sort // * order for {@link #ScopedComparator}. // */ // public enum Scope // { // IMPORT, COMPILE, RUNTIME, TEST, SYSTEM, PROVIDED // } // // // //---------------------------------------------------------------------------- // // Instance variables and constructor // //---------------------------------------------------------------------------- // // public String classifier = ""; // public String packaging = "jar"; // public Scope scope = Scope.COMPILE; // public boolean optional; // // // /** // * Base constructor, allowing explicit specification of all fields. // * // * @throws IllegalArgumentException if passed a scope that does not match // * one of the enumerated values. // */ // public Artifact(String groupId, String artifactId, String version, // String classifier, String packaging, String scope, boolean isOptional) // { // super(groupId, artifactId, version); // this.classifier = classifier; // this.packaging = packaging.toLowerCase(); // this.scope = lookupScope(scope); // this.optional = isOptional; // } // // // /** // * Convenience constructor, used for arbitrary compile-scope artifacts. // */ // public Artifact(String groupId, String artifactId, String version, String packaging) // { // super(groupId, artifactId, version); // this.packaging = packaging; // } // // // /** // * Convenience constructor, used for compile-scope JARs. // */ // public Artifact(String groupId, String artifactId, String version) // { // super(groupId, artifactId, version); // } // // // /** // * Dependency constructor, which extracts all values from XML. // */ // public Artifact(Element dependency) // { // super(dependency); // for (Element child : DomUtil.getChildren(dependency)) // { // String localName = DomUtil.getLocalName(child); // String value = StringUtil.trim(DomUtil.getText(child)); // // if (localName.equals("type")) // this.packaging = value.toLowerCase(); // else if (localName.equals("classifier")) // this.classifier = value; // else if (localName.equals("scope")) // this.scope = lookupScope(value); // else if (localName.equals("optional")) // this.optional = value.equalsIgnoreCase("true"); // } // } // // // /** // * Internal constructor, used for the various copy operations. // */ // public Artifact(Artifact that) // { // super(that.groupId, that.artifactId, that.version); // this.classifier = that.classifier; // this.packaging = that.packaging; // this.scope = that.scope; // this.optional = that.optional; // } // // // private static Scope lookupScope(String scope) // { // if (StringUtil.isBlank(scope)) // { // return Scope.COMPILE; // } // else // { // return Scope.valueOf(scope.toUpperCase()); // } // } // // // //---------------------------------------------------------------------------- // // Other Public methods // //---------------------------------------------------------------------------- // // /** // * Returns the groupId/artifactId of this artifact, to key a dependency // * map. // */ // public GAKey toGAKey() // { // return new GAKey(groupId, artifactId); // } // // // /** // * Returns a new artifact, representing the POM for this artifact. // */ // public Artifact toPom() // { // return new Artifact(groupId, artifactId, version, "", "pom", "", optional); // } // // // /** // * Returns a copy of this artifact, with a different version. // */ // public Artifact withVersion(String newVersion) // { // return new Artifact(groupId, artifactId, newVersion, classifier, packaging, scope.name(), optional); // } // // //---------------------------------------------------------------------------- // // Object overrides // //---------------------------------------------------------------------------- // // /** // * Returns a string that is useful for debugging. // */ // @Override // public String toString() // { // return groupId + ":" + artifactId + ":" + version + ":" + packaging; // } // // // //---------------------------------------------------------------------------- // // Additional utility classes // //---------------------------------------------------------------------------- // // /** // * A comparator that does a first-order comparison based on scope, then // * falls back to the built-in comparator. // */ // public static class ScopedComparator // implements Comparator<Artifact>, Serializable // { // private static final long serialVersionUID = 1L; // // @Override // public int compare(Artifact o1, Artifact o2) // { // int cmp = o1.scope.compareTo(o2.scope); // return (cmp != 0) // ? cmp // : o1.compareTo(o2); // } // } // } // Path: app-dependency/src/main/java/com/kdgregory/pomutil/dependency/Reporter.java import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Set; import java.util.TreeSet; import net.sf.kdgcommons.collections.CollectionUtil; import com.kdgregory.pomutil.util.Artifact; PrintWriter out = new PrintWriter(new OutputStreamWriter(out0, "UTF-8")); outputMissingDependencies(out); outputUnusedDependencies(out); outputIncorrectDependencies(out); out.flush(); } //---------------------------------------------------------------------------- // Internals //---------------------------------------------------------------------------- private void outputMissingDependencies(PrintWriter out) { Set<String> missingDependencies = CollectionUtil.combine(new TreeSet<String>(), checker.getUnsupportedMainlinePackages(), checker.getUnsupportedTestPackages()); for (String pkg : missingDependencies) { out.format(OUTPUT_FORMAT, "PACKAGE_MISSING_DEPENDENCY", pkg); } } private void outputUnusedDependencies(PrintWriter out) {
for (Artifact artifact : checker.getUnusedMainlineDependencies())
kdgregory/pomutil
app-version/src/test/java/com/kdgregory/pomutil/version/TestCommandLine.java
// Path: app-version/src/main/java/com/kdgregory/pomutil/version/CommandLine.java // public enum Options // { // GROUP_ID, ARTIFACT_ID, OLD_VERSION, NEW_VERSION, AUTO_VERSION, UPDATE_PARENT, UPDATE_DEPENDENCIES // }
import java.util.Arrays; import org.junit.Test; import static org.junit.Assert.*; import net.sf.kdgcommons.collections.CollectionUtil; import com.kdgregory.pomutil.version.CommandLine.Options;
package com.kdgregory.pomutil.version; public class TestCommandLine { @Test public void testBasicInvocation() throws Exception { CommandLine c = new CommandLine("--groupId", "com.example", "--artifactId", "ix", "--fromVersion", "1.0", "--toVersion", "2.0", "foo.xml", "bar.xml"); assertTrue("command line is valid", c.isValid());
// Path: app-version/src/main/java/com/kdgregory/pomutil/version/CommandLine.java // public enum Options // { // GROUP_ID, ARTIFACT_ID, OLD_VERSION, NEW_VERSION, AUTO_VERSION, UPDATE_PARENT, UPDATE_DEPENDENCIES // } // Path: app-version/src/test/java/com/kdgregory/pomutil/version/TestCommandLine.java import java.util.Arrays; import org.junit.Test; import static org.junit.Assert.*; import net.sf.kdgcommons.collections.CollectionUtil; import com.kdgregory.pomutil.version.CommandLine.Options; package com.kdgregory.pomutil.version; public class TestCommandLine { @Test public void testBasicInvocation() throws Exception { CommandLine c = new CommandLine("--groupId", "com.example", "--artifactId", "ix", "--fromVersion", "1.0", "--toVersion", "2.0", "foo.xml", "bar.xml"); assertTrue("command line is valid", c.isValid());
assertEquals("groupId", Arrays.asList("com.example"), c.getOptionValues(Options.GROUP_ID));
kdgregory/pomutil
app-dependency/src/test/java/com/kdgregory/pomutil/dependency/TestDependencyCheck.java
// Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Artifact.java // public class Artifact // extends GAV // { // /** // * For artifacts that represent dependencies, identifies the scope to which the // * dependency applies. The order of these elements defines the outermost sort // * order for {@link #ScopedComparator}. // */ // public enum Scope // { // IMPORT, COMPILE, RUNTIME, TEST, SYSTEM, PROVIDED // } // // // //---------------------------------------------------------------------------- // // Instance variables and constructor // //---------------------------------------------------------------------------- // // public String classifier = ""; // public String packaging = "jar"; // public Scope scope = Scope.COMPILE; // public boolean optional; // // // /** // * Base constructor, allowing explicit specification of all fields. // * // * @throws IllegalArgumentException if passed a scope that does not match // * one of the enumerated values. // */ // public Artifact(String groupId, String artifactId, String version, // String classifier, String packaging, String scope, boolean isOptional) // { // super(groupId, artifactId, version); // this.classifier = classifier; // this.packaging = packaging.toLowerCase(); // this.scope = lookupScope(scope); // this.optional = isOptional; // } // // // /** // * Convenience constructor, used for arbitrary compile-scope artifacts. // */ // public Artifact(String groupId, String artifactId, String version, String packaging) // { // super(groupId, artifactId, version); // this.packaging = packaging; // } // // // /** // * Convenience constructor, used for compile-scope JARs. // */ // public Artifact(String groupId, String artifactId, String version) // { // super(groupId, artifactId, version); // } // // // /** // * Dependency constructor, which extracts all values from XML. // */ // public Artifact(Element dependency) // { // super(dependency); // for (Element child : DomUtil.getChildren(dependency)) // { // String localName = DomUtil.getLocalName(child); // String value = StringUtil.trim(DomUtil.getText(child)); // // if (localName.equals("type")) // this.packaging = value.toLowerCase(); // else if (localName.equals("classifier")) // this.classifier = value; // else if (localName.equals("scope")) // this.scope = lookupScope(value); // else if (localName.equals("optional")) // this.optional = value.equalsIgnoreCase("true"); // } // } // // // /** // * Internal constructor, used for the various copy operations. // */ // public Artifact(Artifact that) // { // super(that.groupId, that.artifactId, that.version); // this.classifier = that.classifier; // this.packaging = that.packaging; // this.scope = that.scope; // this.optional = that.optional; // } // // // private static Scope lookupScope(String scope) // { // if (StringUtil.isBlank(scope)) // { // return Scope.COMPILE; // } // else // { // return Scope.valueOf(scope.toUpperCase()); // } // } // // // //---------------------------------------------------------------------------- // // Other Public methods // //---------------------------------------------------------------------------- // // /** // * Returns the groupId/artifactId of this artifact, to key a dependency // * map. // */ // public GAKey toGAKey() // { // return new GAKey(groupId, artifactId); // } // // // /** // * Returns a new artifact, representing the POM for this artifact. // */ // public Artifact toPom() // { // return new Artifact(groupId, artifactId, version, "", "pom", "", optional); // } // // // /** // * Returns a copy of this artifact, with a different version. // */ // public Artifact withVersion(String newVersion) // { // return new Artifact(groupId, artifactId, newVersion, classifier, packaging, scope.name(), optional); // } // // //---------------------------------------------------------------------------- // // Object overrides // //---------------------------------------------------------------------------- // // /** // * Returns a string that is useful for debugging. // */ // @Override // public String toString() // { // return groupId + ":" + artifactId + ":" + version + ":" + packaging; // } // // // //---------------------------------------------------------------------------- // // Additional utility classes // //---------------------------------------------------------------------------- // // /** // * A comparator that does a first-order comparison based on scope, then // * falls back to the built-in comparator. // */ // public static class ScopedComparator // implements Comparator<Artifact>, Serializable // { // private static final long serialVersionUID = 1L; // // @Override // public int compare(Artifact o1, Artifact o2) // { // int cmp = o1.scope.compareTo(o2.scope); // return (cmp != 0) // ? cmp // : o1.compareTo(o2); // } // } // }
import java.util.Collection; import java.util.Set; import java.util.TreeSet; import org.junit.Test; import static org.junit.Assert.*; import com.kdgregory.pomutil.util.Artifact;
// Copyright Keith D Gregory // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.kdgregory.pomutil.dependency; public class TestDependencyCheck { //---------------------------------------------------------------------------- // Support code //----------------------------------------------------------------------------
// Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Artifact.java // public class Artifact // extends GAV // { // /** // * For artifacts that represent dependencies, identifies the scope to which the // * dependency applies. The order of these elements defines the outermost sort // * order for {@link #ScopedComparator}. // */ // public enum Scope // { // IMPORT, COMPILE, RUNTIME, TEST, SYSTEM, PROVIDED // } // // // //---------------------------------------------------------------------------- // // Instance variables and constructor // //---------------------------------------------------------------------------- // // public String classifier = ""; // public String packaging = "jar"; // public Scope scope = Scope.COMPILE; // public boolean optional; // // // /** // * Base constructor, allowing explicit specification of all fields. // * // * @throws IllegalArgumentException if passed a scope that does not match // * one of the enumerated values. // */ // public Artifact(String groupId, String artifactId, String version, // String classifier, String packaging, String scope, boolean isOptional) // { // super(groupId, artifactId, version); // this.classifier = classifier; // this.packaging = packaging.toLowerCase(); // this.scope = lookupScope(scope); // this.optional = isOptional; // } // // // /** // * Convenience constructor, used for arbitrary compile-scope artifacts. // */ // public Artifact(String groupId, String artifactId, String version, String packaging) // { // super(groupId, artifactId, version); // this.packaging = packaging; // } // // // /** // * Convenience constructor, used for compile-scope JARs. // */ // public Artifact(String groupId, String artifactId, String version) // { // super(groupId, artifactId, version); // } // // // /** // * Dependency constructor, which extracts all values from XML. // */ // public Artifact(Element dependency) // { // super(dependency); // for (Element child : DomUtil.getChildren(dependency)) // { // String localName = DomUtil.getLocalName(child); // String value = StringUtil.trim(DomUtil.getText(child)); // // if (localName.equals("type")) // this.packaging = value.toLowerCase(); // else if (localName.equals("classifier")) // this.classifier = value; // else if (localName.equals("scope")) // this.scope = lookupScope(value); // else if (localName.equals("optional")) // this.optional = value.equalsIgnoreCase("true"); // } // } // // // /** // * Internal constructor, used for the various copy operations. // */ // public Artifact(Artifact that) // { // super(that.groupId, that.artifactId, that.version); // this.classifier = that.classifier; // this.packaging = that.packaging; // this.scope = that.scope; // this.optional = that.optional; // } // // // private static Scope lookupScope(String scope) // { // if (StringUtil.isBlank(scope)) // { // return Scope.COMPILE; // } // else // { // return Scope.valueOf(scope.toUpperCase()); // } // } // // // //---------------------------------------------------------------------------- // // Other Public methods // //---------------------------------------------------------------------------- // // /** // * Returns the groupId/artifactId of this artifact, to key a dependency // * map. // */ // public GAKey toGAKey() // { // return new GAKey(groupId, artifactId); // } // // // /** // * Returns a new artifact, representing the POM for this artifact. // */ // public Artifact toPom() // { // return new Artifact(groupId, artifactId, version, "", "pom", "", optional); // } // // // /** // * Returns a copy of this artifact, with a different version. // */ // public Artifact withVersion(String newVersion) // { // return new Artifact(groupId, artifactId, newVersion, classifier, packaging, scope.name(), optional); // } // // //---------------------------------------------------------------------------- // // Object overrides // //---------------------------------------------------------------------------- // // /** // * Returns a string that is useful for debugging. // */ // @Override // public String toString() // { // return groupId + ":" + artifactId + ":" + version + ":" + packaging; // } // // // //---------------------------------------------------------------------------- // // Additional utility classes // //---------------------------------------------------------------------------- // // /** // * A comparator that does a first-order comparison based on scope, then // * falls back to the built-in comparator. // */ // public static class ScopedComparator // implements Comparator<Artifact>, Serializable // { // private static final long serialVersionUID = 1L; // // @Override // public int compare(Artifact o1, Artifact o2) // { // int cmp = o1.scope.compareTo(o2.scope); // return (cmp != 0) // ? cmp // : o1.compareTo(o2); // } // } // } // Path: app-dependency/src/test/java/com/kdgregory/pomutil/dependency/TestDependencyCheck.java import java.util.Collection; import java.util.Set; import java.util.TreeSet; import org.junit.Test; import static org.junit.Assert.*; import com.kdgregory.pomutil.util.Artifact; // Copyright Keith D Gregory // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.kdgregory.pomutil.dependency; public class TestDependencyCheck { //---------------------------------------------------------------------------- // Support code //----------------------------------------------------------------------------
private Set<String> extractArtifactIds(Collection<Artifact> artifacts)
kdgregory/pomutil
app-dependency/src/test/java/com/kdgregory/pomutil/dependency/TestDependencyScanner.java
// Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Artifact.java // public class Artifact // extends GAV // { // /** // * For artifacts that represent dependencies, identifies the scope to which the // * dependency applies. The order of these elements defines the outermost sort // * order for {@link #ScopedComparator}. // */ // public enum Scope // { // IMPORT, COMPILE, RUNTIME, TEST, SYSTEM, PROVIDED // } // // // //---------------------------------------------------------------------------- // // Instance variables and constructor // //---------------------------------------------------------------------------- // // public String classifier = ""; // public String packaging = "jar"; // public Scope scope = Scope.COMPILE; // public boolean optional; // // // /** // * Base constructor, allowing explicit specification of all fields. // * // * @throws IllegalArgumentException if passed a scope that does not match // * one of the enumerated values. // */ // public Artifact(String groupId, String artifactId, String version, // String classifier, String packaging, String scope, boolean isOptional) // { // super(groupId, artifactId, version); // this.classifier = classifier; // this.packaging = packaging.toLowerCase(); // this.scope = lookupScope(scope); // this.optional = isOptional; // } // // // /** // * Convenience constructor, used for arbitrary compile-scope artifacts. // */ // public Artifact(String groupId, String artifactId, String version, String packaging) // { // super(groupId, artifactId, version); // this.packaging = packaging; // } // // // /** // * Convenience constructor, used for compile-scope JARs. // */ // public Artifact(String groupId, String artifactId, String version) // { // super(groupId, artifactId, version); // } // // // /** // * Dependency constructor, which extracts all values from XML. // */ // public Artifact(Element dependency) // { // super(dependency); // for (Element child : DomUtil.getChildren(dependency)) // { // String localName = DomUtil.getLocalName(child); // String value = StringUtil.trim(DomUtil.getText(child)); // // if (localName.equals("type")) // this.packaging = value.toLowerCase(); // else if (localName.equals("classifier")) // this.classifier = value; // else if (localName.equals("scope")) // this.scope = lookupScope(value); // else if (localName.equals("optional")) // this.optional = value.equalsIgnoreCase("true"); // } // } // // // /** // * Internal constructor, used for the various copy operations. // */ // public Artifact(Artifact that) // { // super(that.groupId, that.artifactId, that.version); // this.classifier = that.classifier; // this.packaging = that.packaging; // this.scope = that.scope; // this.optional = that.optional; // } // // // private static Scope lookupScope(String scope) // { // if (StringUtil.isBlank(scope)) // { // return Scope.COMPILE; // } // else // { // return Scope.valueOf(scope.toUpperCase()); // } // } // // // //---------------------------------------------------------------------------- // // Other Public methods // //---------------------------------------------------------------------------- // // /** // * Returns the groupId/artifactId of this artifact, to key a dependency // * map. // */ // public GAKey toGAKey() // { // return new GAKey(groupId, artifactId); // } // // // /** // * Returns a new artifact, representing the POM for this artifact. // */ // public Artifact toPom() // { // return new Artifact(groupId, artifactId, version, "", "pom", "", optional); // } // // // /** // * Returns a copy of this artifact, with a different version. // */ // public Artifact withVersion(String newVersion) // { // return new Artifact(groupId, artifactId, newVersion, classifier, packaging, scope.name(), optional); // } // // //---------------------------------------------------------------------------- // // Object overrides // //---------------------------------------------------------------------------- // // /** // * Returns a string that is useful for debugging. // */ // @Override // public String toString() // { // return groupId + ":" + artifactId + ":" + version + ":" + packaging; // } // // // //---------------------------------------------------------------------------- // // Additional utility classes // //---------------------------------------------------------------------------- // // /** // * A comparator that does a first-order comparison based on scope, then // * falls back to the built-in comparator. // */ // public static class ScopedComparator // implements Comparator<Artifact>, Serializable // { // private static final long serialVersionUID = 1L; // // @Override // public int compare(Artifact o1, Artifact o2) // { // int cmp = o1.scope.compareTo(o2.scope); // return (cmp != 0) // ? cmp // : o1.compareTo(o2); // } // } // } // // Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Artifact.java // public enum Scope // { // IMPORT, COMPILE, RUNTIME, TEST, SYSTEM, PROVIDED // }
import java.io.File; import java.util.Collection; import java.util.Map; import java.util.TreeMap; import org.junit.Test; import static org.junit.Assert.*; import com.kdgregory.pomutil.util.Artifact; import com.kdgregory.pomutil.util.Artifact.Scope;
// Copyright Keith D Gregory // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.kdgregory.pomutil.dependency; public class TestDependencyScanner { //---------------------------------------------------------------------------- // Support Code //---------------------------------------------------------------------------- /** * Converts a collection of Artifacts into a form easier to assert. */
// Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Artifact.java // public class Artifact // extends GAV // { // /** // * For artifacts that represent dependencies, identifies the scope to which the // * dependency applies. The order of these elements defines the outermost sort // * order for {@link #ScopedComparator}. // */ // public enum Scope // { // IMPORT, COMPILE, RUNTIME, TEST, SYSTEM, PROVIDED // } // // // //---------------------------------------------------------------------------- // // Instance variables and constructor // //---------------------------------------------------------------------------- // // public String classifier = ""; // public String packaging = "jar"; // public Scope scope = Scope.COMPILE; // public boolean optional; // // // /** // * Base constructor, allowing explicit specification of all fields. // * // * @throws IllegalArgumentException if passed a scope that does not match // * one of the enumerated values. // */ // public Artifact(String groupId, String artifactId, String version, // String classifier, String packaging, String scope, boolean isOptional) // { // super(groupId, artifactId, version); // this.classifier = classifier; // this.packaging = packaging.toLowerCase(); // this.scope = lookupScope(scope); // this.optional = isOptional; // } // // // /** // * Convenience constructor, used for arbitrary compile-scope artifacts. // */ // public Artifact(String groupId, String artifactId, String version, String packaging) // { // super(groupId, artifactId, version); // this.packaging = packaging; // } // // // /** // * Convenience constructor, used for compile-scope JARs. // */ // public Artifact(String groupId, String artifactId, String version) // { // super(groupId, artifactId, version); // } // // // /** // * Dependency constructor, which extracts all values from XML. // */ // public Artifact(Element dependency) // { // super(dependency); // for (Element child : DomUtil.getChildren(dependency)) // { // String localName = DomUtil.getLocalName(child); // String value = StringUtil.trim(DomUtil.getText(child)); // // if (localName.equals("type")) // this.packaging = value.toLowerCase(); // else if (localName.equals("classifier")) // this.classifier = value; // else if (localName.equals("scope")) // this.scope = lookupScope(value); // else if (localName.equals("optional")) // this.optional = value.equalsIgnoreCase("true"); // } // } // // // /** // * Internal constructor, used for the various copy operations. // */ // public Artifact(Artifact that) // { // super(that.groupId, that.artifactId, that.version); // this.classifier = that.classifier; // this.packaging = that.packaging; // this.scope = that.scope; // this.optional = that.optional; // } // // // private static Scope lookupScope(String scope) // { // if (StringUtil.isBlank(scope)) // { // return Scope.COMPILE; // } // else // { // return Scope.valueOf(scope.toUpperCase()); // } // } // // // //---------------------------------------------------------------------------- // // Other Public methods // //---------------------------------------------------------------------------- // // /** // * Returns the groupId/artifactId of this artifact, to key a dependency // * map. // */ // public GAKey toGAKey() // { // return new GAKey(groupId, artifactId); // } // // // /** // * Returns a new artifact, representing the POM for this artifact. // */ // public Artifact toPom() // { // return new Artifact(groupId, artifactId, version, "", "pom", "", optional); // } // // // /** // * Returns a copy of this artifact, with a different version. // */ // public Artifact withVersion(String newVersion) // { // return new Artifact(groupId, artifactId, newVersion, classifier, packaging, scope.name(), optional); // } // // //---------------------------------------------------------------------------- // // Object overrides // //---------------------------------------------------------------------------- // // /** // * Returns a string that is useful for debugging. // */ // @Override // public String toString() // { // return groupId + ":" + artifactId + ":" + version + ":" + packaging; // } // // // //---------------------------------------------------------------------------- // // Additional utility classes // //---------------------------------------------------------------------------- // // /** // * A comparator that does a first-order comparison based on scope, then // * falls back to the built-in comparator. // */ // public static class ScopedComparator // implements Comparator<Artifact>, Serializable // { // private static final long serialVersionUID = 1L; // // @Override // public int compare(Artifact o1, Artifact o2) // { // int cmp = o1.scope.compareTo(o2.scope); // return (cmp != 0) // ? cmp // : o1.compareTo(o2); // } // } // } // // Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Artifact.java // public enum Scope // { // IMPORT, COMPILE, RUNTIME, TEST, SYSTEM, PROVIDED // } // Path: app-dependency/src/test/java/com/kdgregory/pomutil/dependency/TestDependencyScanner.java import java.io.File; import java.util.Collection; import java.util.Map; import java.util.TreeMap; import org.junit.Test; import static org.junit.Assert.*; import com.kdgregory.pomutil.util.Artifact; import com.kdgregory.pomutil.util.Artifact.Scope; // Copyright Keith D Gregory // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.kdgregory.pomutil.dependency; public class TestDependencyScanner { //---------------------------------------------------------------------------- // Support Code //---------------------------------------------------------------------------- /** * Converts a collection of Artifacts into a form easier to assert. */
public Map<String,Scope> mapArtifacts(Collection<Artifact> artifacts)
kdgregory/pomutil
app-dependency/src/test/java/com/kdgregory/pomutil/dependency/TestDependencyScanner.java
// Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Artifact.java // public class Artifact // extends GAV // { // /** // * For artifacts that represent dependencies, identifies the scope to which the // * dependency applies. The order of these elements defines the outermost sort // * order for {@link #ScopedComparator}. // */ // public enum Scope // { // IMPORT, COMPILE, RUNTIME, TEST, SYSTEM, PROVIDED // } // // // //---------------------------------------------------------------------------- // // Instance variables and constructor // //---------------------------------------------------------------------------- // // public String classifier = ""; // public String packaging = "jar"; // public Scope scope = Scope.COMPILE; // public boolean optional; // // // /** // * Base constructor, allowing explicit specification of all fields. // * // * @throws IllegalArgumentException if passed a scope that does not match // * one of the enumerated values. // */ // public Artifact(String groupId, String artifactId, String version, // String classifier, String packaging, String scope, boolean isOptional) // { // super(groupId, artifactId, version); // this.classifier = classifier; // this.packaging = packaging.toLowerCase(); // this.scope = lookupScope(scope); // this.optional = isOptional; // } // // // /** // * Convenience constructor, used for arbitrary compile-scope artifacts. // */ // public Artifact(String groupId, String artifactId, String version, String packaging) // { // super(groupId, artifactId, version); // this.packaging = packaging; // } // // // /** // * Convenience constructor, used for compile-scope JARs. // */ // public Artifact(String groupId, String artifactId, String version) // { // super(groupId, artifactId, version); // } // // // /** // * Dependency constructor, which extracts all values from XML. // */ // public Artifact(Element dependency) // { // super(dependency); // for (Element child : DomUtil.getChildren(dependency)) // { // String localName = DomUtil.getLocalName(child); // String value = StringUtil.trim(DomUtil.getText(child)); // // if (localName.equals("type")) // this.packaging = value.toLowerCase(); // else if (localName.equals("classifier")) // this.classifier = value; // else if (localName.equals("scope")) // this.scope = lookupScope(value); // else if (localName.equals("optional")) // this.optional = value.equalsIgnoreCase("true"); // } // } // // // /** // * Internal constructor, used for the various copy operations. // */ // public Artifact(Artifact that) // { // super(that.groupId, that.artifactId, that.version); // this.classifier = that.classifier; // this.packaging = that.packaging; // this.scope = that.scope; // this.optional = that.optional; // } // // // private static Scope lookupScope(String scope) // { // if (StringUtil.isBlank(scope)) // { // return Scope.COMPILE; // } // else // { // return Scope.valueOf(scope.toUpperCase()); // } // } // // // //---------------------------------------------------------------------------- // // Other Public methods // //---------------------------------------------------------------------------- // // /** // * Returns the groupId/artifactId of this artifact, to key a dependency // * map. // */ // public GAKey toGAKey() // { // return new GAKey(groupId, artifactId); // } // // // /** // * Returns a new artifact, representing the POM for this artifact. // */ // public Artifact toPom() // { // return new Artifact(groupId, artifactId, version, "", "pom", "", optional); // } // // // /** // * Returns a copy of this artifact, with a different version. // */ // public Artifact withVersion(String newVersion) // { // return new Artifact(groupId, artifactId, newVersion, classifier, packaging, scope.name(), optional); // } // // //---------------------------------------------------------------------------- // // Object overrides // //---------------------------------------------------------------------------- // // /** // * Returns a string that is useful for debugging. // */ // @Override // public String toString() // { // return groupId + ":" + artifactId + ":" + version + ":" + packaging; // } // // // //---------------------------------------------------------------------------- // // Additional utility classes // //---------------------------------------------------------------------------- // // /** // * A comparator that does a first-order comparison based on scope, then // * falls back to the built-in comparator. // */ // public static class ScopedComparator // implements Comparator<Artifact>, Serializable // { // private static final long serialVersionUID = 1L; // // @Override // public int compare(Artifact o1, Artifact o2) // { // int cmp = o1.scope.compareTo(o2.scope); // return (cmp != 0) // ? cmp // : o1.compareTo(o2); // } // } // } // // Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Artifact.java // public enum Scope // { // IMPORT, COMPILE, RUNTIME, TEST, SYSTEM, PROVIDED // }
import java.io.File; import java.util.Collection; import java.util.Map; import java.util.TreeMap; import org.junit.Test; import static org.junit.Assert.*; import com.kdgregory.pomutil.util.Artifact; import com.kdgregory.pomutil.util.Artifact.Scope;
// Copyright Keith D Gregory // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.kdgregory.pomutil.dependency; public class TestDependencyScanner { //---------------------------------------------------------------------------- // Support Code //---------------------------------------------------------------------------- /** * Converts a collection of Artifacts into a form easier to assert. */
// Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Artifact.java // public class Artifact // extends GAV // { // /** // * For artifacts that represent dependencies, identifies the scope to which the // * dependency applies. The order of these elements defines the outermost sort // * order for {@link #ScopedComparator}. // */ // public enum Scope // { // IMPORT, COMPILE, RUNTIME, TEST, SYSTEM, PROVIDED // } // // // //---------------------------------------------------------------------------- // // Instance variables and constructor // //---------------------------------------------------------------------------- // // public String classifier = ""; // public String packaging = "jar"; // public Scope scope = Scope.COMPILE; // public boolean optional; // // // /** // * Base constructor, allowing explicit specification of all fields. // * // * @throws IllegalArgumentException if passed a scope that does not match // * one of the enumerated values. // */ // public Artifact(String groupId, String artifactId, String version, // String classifier, String packaging, String scope, boolean isOptional) // { // super(groupId, artifactId, version); // this.classifier = classifier; // this.packaging = packaging.toLowerCase(); // this.scope = lookupScope(scope); // this.optional = isOptional; // } // // // /** // * Convenience constructor, used for arbitrary compile-scope artifacts. // */ // public Artifact(String groupId, String artifactId, String version, String packaging) // { // super(groupId, artifactId, version); // this.packaging = packaging; // } // // // /** // * Convenience constructor, used for compile-scope JARs. // */ // public Artifact(String groupId, String artifactId, String version) // { // super(groupId, artifactId, version); // } // // // /** // * Dependency constructor, which extracts all values from XML. // */ // public Artifact(Element dependency) // { // super(dependency); // for (Element child : DomUtil.getChildren(dependency)) // { // String localName = DomUtil.getLocalName(child); // String value = StringUtil.trim(DomUtil.getText(child)); // // if (localName.equals("type")) // this.packaging = value.toLowerCase(); // else if (localName.equals("classifier")) // this.classifier = value; // else if (localName.equals("scope")) // this.scope = lookupScope(value); // else if (localName.equals("optional")) // this.optional = value.equalsIgnoreCase("true"); // } // } // // // /** // * Internal constructor, used for the various copy operations. // */ // public Artifact(Artifact that) // { // super(that.groupId, that.artifactId, that.version); // this.classifier = that.classifier; // this.packaging = that.packaging; // this.scope = that.scope; // this.optional = that.optional; // } // // // private static Scope lookupScope(String scope) // { // if (StringUtil.isBlank(scope)) // { // return Scope.COMPILE; // } // else // { // return Scope.valueOf(scope.toUpperCase()); // } // } // // // //---------------------------------------------------------------------------- // // Other Public methods // //---------------------------------------------------------------------------- // // /** // * Returns the groupId/artifactId of this artifact, to key a dependency // * map. // */ // public GAKey toGAKey() // { // return new GAKey(groupId, artifactId); // } // // // /** // * Returns a new artifact, representing the POM for this artifact. // */ // public Artifact toPom() // { // return new Artifact(groupId, artifactId, version, "", "pom", "", optional); // } // // // /** // * Returns a copy of this artifact, with a different version. // */ // public Artifact withVersion(String newVersion) // { // return new Artifact(groupId, artifactId, newVersion, classifier, packaging, scope.name(), optional); // } // // //---------------------------------------------------------------------------- // // Object overrides // //---------------------------------------------------------------------------- // // /** // * Returns a string that is useful for debugging. // */ // @Override // public String toString() // { // return groupId + ":" + artifactId + ":" + version + ":" + packaging; // } // // // //---------------------------------------------------------------------------- // // Additional utility classes // //---------------------------------------------------------------------------- // // /** // * A comparator that does a first-order comparison based on scope, then // * falls back to the built-in comparator. // */ // public static class ScopedComparator // implements Comparator<Artifact>, Serializable // { // private static final long serialVersionUID = 1L; // // @Override // public int compare(Artifact o1, Artifact o2) // { // int cmp = o1.scope.compareTo(o2.scope); // return (cmp != 0) // ? cmp // : o1.compareTo(o2); // } // } // } // // Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Artifact.java // public enum Scope // { // IMPORT, COMPILE, RUNTIME, TEST, SYSTEM, PROVIDED // } // Path: app-dependency/src/test/java/com/kdgregory/pomutil/dependency/TestDependencyScanner.java import java.io.File; import java.util.Collection; import java.util.Map; import java.util.TreeMap; import org.junit.Test; import static org.junit.Assert.*; import com.kdgregory.pomutil.util.Artifact; import com.kdgregory.pomutil.util.Artifact.Scope; // Copyright Keith D Gregory // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.kdgregory.pomutil.dependency; public class TestDependencyScanner { //---------------------------------------------------------------------------- // Support Code //---------------------------------------------------------------------------- /** * Converts a collection of Artifacts into a form easier to assert. */
public Map<String,Scope> mapArtifacts(Collection<Artifact> artifacts)
kdgregory/pomutil
app-cleaner/src/main/java/com/kdgregory/pomutil/cleaner/Main.java
// Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Utils.java // public class Utils // { // /** // * Builds a list of files from the provided list of files and/or directories. // * The provided files are added to this list without change; directories are // * recursively examined, and any file named "pom.xml" is added to the list. // */ // public static List<File> buildFileListFromStringList(List<String> sources) // { // List<File> sourceFiles = new ArrayList<File>(sources.size()); // for (String source : sources) // { // sourceFiles.add(new File(source)); // } // return buildFileList(sourceFiles); // } // // // /** // * Builds a list of files from the provided list of files and/or directories. // * The provided files are added to this list without change; directories are // * recursively examined, and any file named "pom.xml" is added to the list. // */ // public static List<File> buildFileList(List<File> sources) // { // List<File> result = new ArrayList<File>(); // for (File source : sources) // { // if (source.isDirectory()) // { // for (File child : source.listFiles()) // { // if (child.isDirectory()) // { // result.addAll(buildFileList(Arrays.asList(child))); // } // else if (child.getName().equals("pom.xml")) // { // result.add(child); // } // } // } // else // { // result.add(source); // } // } // return result; // } // // // /** // * Given a JAR, finds all entries that represent classes and converts them to classnames. // */ // public static List<String> extractClassesFromJar(File jarFile) // throws IOException // { // List<String> result = new ArrayList<String>(); // JarFile jar = null; // try // { // jar = new JarFile(jarFile); // for (Enumeration<JarEntry> entryItx = jar.entries() ; entryItx.hasMoreElements() ; ) // { // JarEntry entry = entryItx.nextElement(); // String filename = entry.getName(); // if (! filename.endsWith(".class")) // continue; // filename = filename.substring(0, filename.length() - 6); // filename = filename.replace('/', '.'); // filename = filename.replace('$', '.'); // result.add(filename); // } // return result; // } // finally // { // if (jar != null) // { // try // { // jar.close(); // } // catch (IOException ignored) // { // // ignored // } // } // } // } // // // /** // * Removes all children from the passed element, storing them in an // * order-preserving map keyed by the child's localName. // * // * @throws IllegalStateException if there's more than one child with the // * same localName (this should be considered an unrecoverable // * error, as the element will already have been mutated). // */ // public static Map<String,Element> removeChildrenToMap(Element elem) // { // Map<String,Element> children = new LinkedHashMap<String,Element>(); // for (Element child : DomUtil.getChildren(elem)) // { // String localName = DomUtil.getLocalName(child); // Element prev = children.put(localName, child); // if (prev != null) // throw new IllegalStateException("duplicate child name: " + localName); // elem.removeChild(child); // } // return children; // } // // // /** // * Reconstructs the passed element, ordering its children according to their // * localNames as specified by the <code>childOrder</code> array. Any children // * whose names are not in the array are appended to the end of the element. // * <p> // * WARNING: only one child must exist with a given name! // */ // public static Element reconstruct(Element elem, String... childOrder) // { // return reconstruct(elem, removeChildrenToMap(elem), childOrder); // } // // // /** // * Updates the specified element with children from the map, in the specified // * order. Any elements in the map that do not correspond to specified order // * will be appended at the end of the element. // */ // public static Element reconstruct(Element elem, Map<String,Element> children, String... childOrder) // { // for (String name : childOrder) // { // Element child = children.remove(name); // if (child != null) // elem.appendChild(child); // } // // // rebuild anything left over // for (Element child : children.values()) // { // elem.appendChild(child); // } // // return elem; // } // }
import java.io.File; import java.util.List; import com.kdgregory.pomutil.util.Utils;
// Copyright Keith D Gregory // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.kdgregory.pomutil.cleaner; /** * Driver program for POM cleanup. * <p> * Successful execution results in a 0 return code. Any exception will be written * to StdErr, and the program will terminate with a non-zero return code. */ public class Main { public static void main(String[] argv) throws Exception { CommandLine commandLine = new CommandLine(argv);
// Path: lib-common/src/main/java/com/kdgregory/pomutil/util/Utils.java // public class Utils // { // /** // * Builds a list of files from the provided list of files and/or directories. // * The provided files are added to this list without change; directories are // * recursively examined, and any file named "pom.xml" is added to the list. // */ // public static List<File> buildFileListFromStringList(List<String> sources) // { // List<File> sourceFiles = new ArrayList<File>(sources.size()); // for (String source : sources) // { // sourceFiles.add(new File(source)); // } // return buildFileList(sourceFiles); // } // // // /** // * Builds a list of files from the provided list of files and/or directories. // * The provided files are added to this list without change; directories are // * recursively examined, and any file named "pom.xml" is added to the list. // */ // public static List<File> buildFileList(List<File> sources) // { // List<File> result = new ArrayList<File>(); // for (File source : sources) // { // if (source.isDirectory()) // { // for (File child : source.listFiles()) // { // if (child.isDirectory()) // { // result.addAll(buildFileList(Arrays.asList(child))); // } // else if (child.getName().equals("pom.xml")) // { // result.add(child); // } // } // } // else // { // result.add(source); // } // } // return result; // } // // // /** // * Given a JAR, finds all entries that represent classes and converts them to classnames. // */ // public static List<String> extractClassesFromJar(File jarFile) // throws IOException // { // List<String> result = new ArrayList<String>(); // JarFile jar = null; // try // { // jar = new JarFile(jarFile); // for (Enumeration<JarEntry> entryItx = jar.entries() ; entryItx.hasMoreElements() ; ) // { // JarEntry entry = entryItx.nextElement(); // String filename = entry.getName(); // if (! filename.endsWith(".class")) // continue; // filename = filename.substring(0, filename.length() - 6); // filename = filename.replace('/', '.'); // filename = filename.replace('$', '.'); // result.add(filename); // } // return result; // } // finally // { // if (jar != null) // { // try // { // jar.close(); // } // catch (IOException ignored) // { // // ignored // } // } // } // } // // // /** // * Removes all children from the passed element, storing them in an // * order-preserving map keyed by the child's localName. // * // * @throws IllegalStateException if there's more than one child with the // * same localName (this should be considered an unrecoverable // * error, as the element will already have been mutated). // */ // public static Map<String,Element> removeChildrenToMap(Element elem) // { // Map<String,Element> children = new LinkedHashMap<String,Element>(); // for (Element child : DomUtil.getChildren(elem)) // { // String localName = DomUtil.getLocalName(child); // Element prev = children.put(localName, child); // if (prev != null) // throw new IllegalStateException("duplicate child name: " + localName); // elem.removeChild(child); // } // return children; // } // // // /** // * Reconstructs the passed element, ordering its children according to their // * localNames as specified by the <code>childOrder</code> array. Any children // * whose names are not in the array are appended to the end of the element. // * <p> // * WARNING: only one child must exist with a given name! // */ // public static Element reconstruct(Element elem, String... childOrder) // { // return reconstruct(elem, removeChildrenToMap(elem), childOrder); // } // // // /** // * Updates the specified element with children from the map, in the specified // * order. Any elements in the map that do not correspond to specified order // * will be appended at the end of the element. // */ // public static Element reconstruct(Element elem, Map<String,Element> children, String... childOrder) // { // for (String name : childOrder) // { // Element child = children.remove(name); // if (child != null) // elem.appendChild(child); // } // // // rebuild anything left over // for (Element child : children.values()) // { // elem.appendChild(child); // } // // return elem; // } // } // Path: app-cleaner/src/main/java/com/kdgregory/pomutil/cleaner/Main.java import java.io.File; import java.util.List; import com.kdgregory.pomutil.util.Utils; // Copyright Keith D Gregory // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.kdgregory.pomutil.cleaner; /** * Driver program for POM cleanup. * <p> * Successful execution results in a 0 return code. Any exception will be written * to StdErr, and the program will terminate with a non-zero return code. */ public class Main { public static void main(String[] argv) throws Exception { CommandLine commandLine = new CommandLine(argv);
List<File> files = Utils.buildFileListFromStringList(commandLine.getParameters());
voostindie/sprox
src/test/java/nl/ulso/sprox/RecursiveTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // }
import org.junit.Test; import java.util.List; import java.util.Optional; import static java.util.Arrays.asList; import static nl.ulso.sprox.SproxTests.testControllers;
package nl.ulso.sprox; public class RecursiveTest { @Test public void testThatRecursiveNodeIsProcessed() throws Exception {
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // Path: src/test/java/nl/ulso/sprox/RecursiveTest.java import org.junit.Test; import java.util.List; import java.util.Optional; import static java.util.Arrays.asList; import static nl.ulso.sprox.SproxTests.testControllers; package nl.ulso.sprox; public class RecursiveTest { @Test public void testThatRecursiveNodeIsProcessed() throws Exception {
testControllers(3, "<root><tag><tag><tag></tag></tag></tag></root>", new RecursiveNodeProcessor());
voostindie/sprox
src/main/java/nl/ulso/sprox/impl/ControllerMethod.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessorException.java // public class XmlProcessorException extends Exception { // public XmlProcessorException(Throwable cause) { // super(cause); // } // // public XmlProcessorException(String message) { // super(message); // } // // public XmlProcessorException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // }
import nl.ulso.sprox.XmlProcessorException; import javax.xml.namespace.QName; import javax.xml.stream.events.EndElement; import javax.xml.stream.events.StartElement; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; import java.util.Objects; import java.util.Optional; import static java.util.Collections.unmodifiableList; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked;
.ifPresent(result -> context.pushMethodResult(ownerName, method.getReturnType(), result)); } } private Object[] constructMethodParameters(ExecutionContext context) { return controllerParameters.stream() .map(controllerParameter -> { final Optional parameter = controllerParameter.resolveMethodParameter(context); if (controllerParameter.isOptional()) { //noinspection unchecked return parameter; } else if (parameter.isPresent()) { return parameter.get(); } else { return null; } }) .filter(Objects::nonNull) .toArray(); } private Optional<Object> invokeMethod(ExecutionContext context, Object[] methodParameters) { try { return Optional.ofNullable(method.invoke(context.getController(controllerClass), methodParameters)); } catch (IllegalAccessException e) { throw new IllegalStateException("Access to controller method '" + method + "' was denied.", e); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); }
// Path: src/main/java/nl/ulso/sprox/XmlProcessorException.java // public class XmlProcessorException extends Exception { // public XmlProcessorException(Throwable cause) { // super(cause); // } // // public XmlProcessorException(String message) { // super(message); // } // // public XmlProcessorException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // } // Path: src/main/java/nl/ulso/sprox/impl/ControllerMethod.java import nl.ulso.sprox.XmlProcessorException; import javax.xml.namespace.QName; import javax.xml.stream.events.EndElement; import javax.xml.stream.events.StartElement; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; import java.util.Objects; import java.util.Optional; import static java.util.Collections.unmodifiableList; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked; .ifPresent(result -> context.pushMethodResult(ownerName, method.getReturnType(), result)); } } private Object[] constructMethodParameters(ExecutionContext context) { return controllerParameters.stream() .map(controllerParameter -> { final Optional parameter = controllerParameter.resolveMethodParameter(context); if (controllerParameter.isOptional()) { //noinspection unchecked return parameter; } else if (parameter.isPresent()) { return parameter.get(); } else { return null; } }) .filter(Objects::nonNull) .toArray(); } private Optional<Object> invokeMethod(ExecutionContext context, Object[] methodParameters) { try { return Optional.ofNullable(method.invoke(context.getController(controllerClass), methodParameters)); } catch (IllegalAccessException e) { throw new IllegalStateException("Access to controller method '" + method + "' was denied.", e); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); }
throw unchecked(new XmlProcessorException("Invocation of controller method '" + method
voostindie/sprox
src/main/java/nl/ulso/sprox/impl/ControllerMethod.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessorException.java // public class XmlProcessorException extends Exception { // public XmlProcessorException(Throwable cause) { // super(cause); // } // // public XmlProcessorException(String message) { // super(message); // } // // public XmlProcessorException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // }
import nl.ulso.sprox.XmlProcessorException; import javax.xml.namespace.QName; import javax.xml.stream.events.EndElement; import javax.xml.stream.events.StartElement; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; import java.util.Objects; import java.util.Optional; import static java.util.Collections.unmodifiableList; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked;
.ifPresent(result -> context.pushMethodResult(ownerName, method.getReturnType(), result)); } } private Object[] constructMethodParameters(ExecutionContext context) { return controllerParameters.stream() .map(controllerParameter -> { final Optional parameter = controllerParameter.resolveMethodParameter(context); if (controllerParameter.isOptional()) { //noinspection unchecked return parameter; } else if (parameter.isPresent()) { return parameter.get(); } else { return null; } }) .filter(Objects::nonNull) .toArray(); } private Optional<Object> invokeMethod(ExecutionContext context, Object[] methodParameters) { try { return Optional.ofNullable(method.invoke(context.getController(controllerClass), methodParameters)); } catch (IllegalAccessException e) { throw new IllegalStateException("Access to controller method '" + method + "' was denied.", e); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); }
// Path: src/main/java/nl/ulso/sprox/XmlProcessorException.java // public class XmlProcessorException extends Exception { // public XmlProcessorException(Throwable cause) { // super(cause); // } // // public XmlProcessorException(String message) { // super(message); // } // // public XmlProcessorException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // } // Path: src/main/java/nl/ulso/sprox/impl/ControllerMethod.java import nl.ulso.sprox.XmlProcessorException; import javax.xml.namespace.QName; import javax.xml.stream.events.EndElement; import javax.xml.stream.events.StartElement; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; import java.util.Objects; import java.util.Optional; import static java.util.Collections.unmodifiableList; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked; .ifPresent(result -> context.pushMethodResult(ownerName, method.getReturnType(), result)); } } private Object[] constructMethodParameters(ExecutionContext context) { return controllerParameters.stream() .map(controllerParameter -> { final Optional parameter = controllerParameter.resolveMethodParameter(context); if (controllerParameter.isOptional()) { //noinspection unchecked return parameter; } else if (parameter.isPresent()) { return parameter.get(); } else { return null; } }) .filter(Objects::nonNull) .toArray(); } private Optional<Object> invokeMethod(ExecutionContext context, Object[] methodParameters) { try { return Optional.ofNullable(method.invoke(context.getController(controllerClass), methodParameters)); } catch (IllegalAccessException e) { throw new IllegalStateException("Access to controller method '" + method + "' was denied.", e); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); }
throw unchecked(new XmlProcessorException("Invocation of controller method '" + method
voostindie/sprox
src/main/java/nl/ulso/sprox/parsers/CharacterParser.java
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // }
import nl.ulso.sprox.Parser; import nl.ulso.sprox.ParseException;
package nl.ulso.sprox.parsers; public class CharacterParser implements Parser<Character> { @Override
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // Path: src/main/java/nl/ulso/sprox/parsers/CharacterParser.java import nl.ulso.sprox.Parser; import nl.ulso.sprox.ParseException; package nl.ulso.sprox.parsers; public class CharacterParser implements Parser<Character> { @Override
public Character fromString(String value) throws ParseException {
voostindie/sprox
src/test/java/nl/ulso/sprox/opml/OutlineFactoryTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessorBuilderFactory.java // public interface XmlProcessorBuilderFactory { // <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass); // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactoryTest.java // public static int countElements(Outline outline) { // final ElementCounter counter = new ElementCounter(); // outline.accept(counter); // return counter.count; // }
import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.XmlProcessorBuilderFactory; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import org.junit.Before; import org.junit.Test; import static nl.ulso.sprox.opml.OutlineFactoryTest.ElementCounter.countElements; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.opml; public class OutlineFactoryTest { private XmlProcessorBuilderFactory factory; public void setFactory(XmlProcessorBuilderFactory factory) { this.factory = factory; } @Before public void setUp() throws Exception {
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessorBuilderFactory.java // public interface XmlProcessorBuilderFactory { // <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass); // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactoryTest.java // public static int countElements(Outline outline) { // final ElementCounter counter = new ElementCounter(); // outline.accept(counter); // return counter.count; // } // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactoryTest.java import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.XmlProcessorBuilderFactory; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import org.junit.Before; import org.junit.Test; import static nl.ulso.sprox.opml.OutlineFactoryTest.ElementCounter.countElements; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package nl.ulso.sprox.opml; public class OutlineFactoryTest { private XmlProcessorBuilderFactory factory; public void setFactory(XmlProcessorBuilderFactory factory) { this.factory = factory; } @Before public void setUp() throws Exception {
factory = new StaxBasedXmlProcessorBuilderFactory();
voostindie/sprox
src/test/java/nl/ulso/sprox/opml/OutlineFactoryTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessorBuilderFactory.java // public interface XmlProcessorBuilderFactory { // <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass); // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactoryTest.java // public static int countElements(Outline outline) { // final ElementCounter counter = new ElementCounter(); // outline.accept(counter); // return counter.count; // }
import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.XmlProcessorBuilderFactory; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import org.junit.Before; import org.junit.Test; import static nl.ulso.sprox.opml.OutlineFactoryTest.ElementCounter.countElements; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.opml; public class OutlineFactoryTest { private XmlProcessorBuilderFactory factory; public void setFactory(XmlProcessorBuilderFactory factory) { this.factory = factory; } @Before public void setUp() throws Exception { factory = new StaxBasedXmlProcessorBuilderFactory(); } @Test public void testOutlineFactory() throws Exception {
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessorBuilderFactory.java // public interface XmlProcessorBuilderFactory { // <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass); // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactoryTest.java // public static int countElements(Outline outline) { // final ElementCounter counter = new ElementCounter(); // outline.accept(counter); // return counter.count; // } // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactoryTest.java import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.XmlProcessorBuilderFactory; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import org.junit.Before; import org.junit.Test; import static nl.ulso.sprox.opml.OutlineFactoryTest.ElementCounter.countElements; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package nl.ulso.sprox.opml; public class OutlineFactoryTest { private XmlProcessorBuilderFactory factory; public void setFactory(XmlProcessorBuilderFactory factory) { this.factory = factory; } @Before public void setUp() throws Exception { factory = new StaxBasedXmlProcessorBuilderFactory(); } @Test public void testOutlineFactory() throws Exception {
final XmlProcessor<Outline> processor = factory.createXmlProcessorBuilder(Outline.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/opml/OutlineFactoryTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessorBuilderFactory.java // public interface XmlProcessorBuilderFactory { // <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass); // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactoryTest.java // public static int countElements(Outline outline) { // final ElementCounter counter = new ElementCounter(); // outline.accept(counter); // return counter.count; // }
import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.XmlProcessorBuilderFactory; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import org.junit.Before; import org.junit.Test; import static nl.ulso.sprox.opml.OutlineFactoryTest.ElementCounter.countElements; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.opml; public class OutlineFactoryTest { private XmlProcessorBuilderFactory factory; public void setFactory(XmlProcessorBuilderFactory factory) { this.factory = factory; } @Before public void setUp() throws Exception { factory = new StaxBasedXmlProcessorBuilderFactory(); } @Test public void testOutlineFactory() throws Exception { final XmlProcessor<Outline> processor = factory.createXmlProcessorBuilder(Outline.class) .addControllerClass(OutlineFactory.class) .addParser(new Rfc822DateTimeParser()) .buildXmlProcessor(); final Outline outline = processor.execute(getClass().getResourceAsStream("/states.opml")); assertNotNull(outline); assertThat(outline.getTitle(), is("states.opml"));
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessorBuilderFactory.java // public interface XmlProcessorBuilderFactory { // <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass); // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactoryTest.java // public static int countElements(Outline outline) { // final ElementCounter counter = new ElementCounter(); // outline.accept(counter); // return counter.count; // } // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactoryTest.java import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.XmlProcessorBuilderFactory; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import org.junit.Before; import org.junit.Test; import static nl.ulso.sprox.opml.OutlineFactoryTest.ElementCounter.countElements; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package nl.ulso.sprox.opml; public class OutlineFactoryTest { private XmlProcessorBuilderFactory factory; public void setFactory(XmlProcessorBuilderFactory factory) { this.factory = factory; } @Before public void setUp() throws Exception { factory = new StaxBasedXmlProcessorBuilderFactory(); } @Test public void testOutlineFactory() throws Exception { final XmlProcessor<Outline> processor = factory.createXmlProcessorBuilder(Outline.class) .addControllerClass(OutlineFactory.class) .addParser(new Rfc822DateTimeParser()) .buildXmlProcessor(); final Outline outline = processor.execute(getClass().getResourceAsStream("/states.opml")); assertNotNull(outline); assertThat(outline.getTitle(), is("states.opml"));
assertThat(countElements(outline), is(63));
voostindie/sprox
src/test/java/nl/ulso/sprox/NodeContentTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import org.junit.Test; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Optional; import static nl.ulso.sprox.SproxTests.testControllers; import static nl.ulso.sprox.SproxTests.testProcessor; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder;
package nl.ulso.sprox; public class NodeContentTest { @Test public void testThatContentFromFirstNestedNodeIsReturned() throws Exception {
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/NodeContentTest.java import org.junit.Test; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Optional; import static nl.ulso.sprox.SproxTests.testControllers; import static nl.ulso.sprox.SproxTests.testProcessor; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; package nl.ulso.sprox; public class NodeContentTest { @Test public void testThatContentFromFirstNestedNodeIsReturned() throws Exception {
testControllers(
voostindie/sprox
src/test/java/nl/ulso/sprox/NodeContentTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import org.junit.Test; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Optional; import static nl.ulso.sprox.SproxTests.testControllers; import static nl.ulso.sprox.SproxTests.testProcessor; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder;
"value1", "<root><node>value1</node><node>value3</node></root>", new NestedNodeContentProcessor() ); } @Test public void testThatContentFromNearestNodeIsReturned() throws Exception { testControllers( "value3", "<root><subnode><node>value2</node></subnode><node>value3</node></root>", new NestedNodeContentProcessor() ); } @Test public void testThatNestedNodeContentIsIgnored() throws Exception { testControllers( "", "<root><node><subnode>value1</subnode></node></root>", new NestedNodeContentProcessor()); } @Test public void testMappingForPrimitiveBooleanInContent() throws Exception { testControllers(true, "<root><boolean>true</boolean></root>", new BooleanProcessor()); } @Test public void testMappingForCustomTypeInContent() throws Exception {
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/NodeContentTest.java import org.junit.Test; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Optional; import static nl.ulso.sprox.SproxTests.testControllers; import static nl.ulso.sprox.SproxTests.testProcessor; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; "value1", "<root><node>value1</node><node>value3</node></root>", new NestedNodeContentProcessor() ); } @Test public void testThatContentFromNearestNodeIsReturned() throws Exception { testControllers( "value3", "<root><subnode><node>value2</node></subnode><node>value3</node></root>", new NestedNodeContentProcessor() ); } @Test public void testThatNestedNodeContentIsIgnored() throws Exception { testControllers( "", "<root><node><subnode>value1</subnode></node></root>", new NestedNodeContentProcessor()); } @Test public void testMappingForPrimitiveBooleanInContent() throws Exception { testControllers(true, "<root><boolean>true</boolean></root>", new BooleanProcessor()); } @Test public void testMappingForCustomTypeInContent() throws Exception {
final XmlProcessor<Date> processor = createXmlProcessorBuilder(Date.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/NodeContentTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import org.junit.Test; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Optional; import static nl.ulso.sprox.SproxTests.testControllers; import static nl.ulso.sprox.SproxTests.testProcessor; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder;
@Test public void testThatContentFromNearestNodeIsReturned() throws Exception { testControllers( "value3", "<root><subnode><node>value2</node></subnode><node>value3</node></root>", new NestedNodeContentProcessor() ); } @Test public void testThatNestedNodeContentIsIgnored() throws Exception { testControllers( "", "<root><node><subnode>value1</subnode></node></root>", new NestedNodeContentProcessor()); } @Test public void testMappingForPrimitiveBooleanInContent() throws Exception { testControllers(true, "<root><boolean>true</boolean></root>", new BooleanProcessor()); } @Test public void testMappingForCustomTypeInContent() throws Exception { final XmlProcessor<Date> processor = createXmlProcessorBuilder(Date.class) .addControllerObject(new DateProcessor()) .addParser(new DateParser()) .buildXmlProcessor(); final Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-21");
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/NodeContentTest.java import org.junit.Test; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Optional; import static nl.ulso.sprox.SproxTests.testControllers; import static nl.ulso.sprox.SproxTests.testProcessor; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; @Test public void testThatContentFromNearestNodeIsReturned() throws Exception { testControllers( "value3", "<root><subnode><node>value2</node></subnode><node>value3</node></root>", new NestedNodeContentProcessor() ); } @Test public void testThatNestedNodeContentIsIgnored() throws Exception { testControllers( "", "<root><node><subnode>value1</subnode></node></root>", new NestedNodeContentProcessor()); } @Test public void testMappingForPrimitiveBooleanInContent() throws Exception { testControllers(true, "<root><boolean>true</boolean></root>", new BooleanProcessor()); } @Test public void testMappingForCustomTypeInContent() throws Exception { final XmlProcessor<Date> processor = createXmlProcessorBuilder(Date.class) .addControllerObject(new DateProcessor()) .addParser(new DateParser()) .buildXmlProcessor(); final Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2012-12-21");
testProcessor(date, "<root><date>2012-12-21</date></root>", processor);
voostindie/sprox
src/main/java/nl/ulso/sprox/parsers/ByteParser.java
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // }
import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser;
package nl.ulso.sprox.parsers; public class ByteParser implements Parser<Byte> { @Override
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // Path: src/main/java/nl/ulso/sprox/parsers/ByteParser.java import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; package nl.ulso.sprox.parsers; public class ByteParser implements Parser<Byte> { @Override
public Byte fromString(String value) throws ParseException {
voostindie/sprox
src/test/java/nl/ulso/sprox/SproxTests.java
// Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // }
import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import java.io.StringReader; import static java.util.Objects.requireNonNull; import static org.junit.Assert.assertEquals;
package nl.ulso.sprox; /** * Utility methods for testing Sprox */ public final class SproxTests { private SproxTests() { } public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) {
// Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // Path: src/test/java/nl/ulso/sprox/SproxTests.java import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import java.io.StringReader; import static java.util.Objects.requireNonNull; import static org.junit.Assert.assertEquals; package nl.ulso.sprox; /** * Utility methods for testing Sprox */ public final class SproxTests { private SproxTests() { } public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) {
return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass));
voostindie/sprox
src/test/java/nl/ulso/sprox/atom/TextTypeParser.java
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/test/java/nl/ulso/sprox/atom/TextType.java // public enum TextType { // TEXT, // HTML, // XHTML // }
import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; import static nl.ulso.sprox.atom.TextType.*;
package nl.ulso.sprox.atom; public class TextTypeParser implements Parser<TextType> { @Override
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/test/java/nl/ulso/sprox/atom/TextType.java // public enum TextType { // TEXT, // HTML, // XHTML // } // Path: src/test/java/nl/ulso/sprox/atom/TextTypeParser.java import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; import static nl.ulso.sprox.atom.TextType.*; package nl.ulso.sprox.atom; public class TextTypeParser implements Parser<TextType> { @Override
public TextType fromString(String value) throws ParseException {
voostindie/sprox
src/test/java/nl/ulso/sprox/movies/MovieListCreatorTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.Attribute; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.util.List; import java.util.Optional; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.movies; /** * */ public class MovieListCreatorTest { @Test public void testCreateMovieList() throws Exception {
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/movies/MovieListCreatorTest.java import nl.ulso.sprox.Attribute; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.util.List; import java.util.Optional; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package nl.ulso.sprox.movies; /** * */ public class MovieListCreatorTest { @Test public void testCreateMovieList() throws Exception {
final XmlProcessor<MovieCollection> processor = createXmlProcessorBuilder(MovieCollection.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/movies/MovieListCreatorTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.Attribute; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.util.List; import java.util.Optional; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.movies; /** * */ public class MovieListCreatorTest { @Test public void testCreateMovieList() throws Exception {
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/movies/MovieListCreatorTest.java import nl.ulso.sprox.Attribute; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.util.List; import java.util.Optional; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package nl.ulso.sprox.movies; /** * */ public class MovieListCreatorTest { @Test public void testCreateMovieList() throws Exception {
final XmlProcessor<MovieCollection> processor = createXmlProcessorBuilder(MovieCollection.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/parsers/CharacterParserTest.java
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // }
import nl.ulso.sprox.ParseException; import org.junit.Test; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.parsers; public class CharacterParserTest { private CharacterParser parser = new CharacterParser(); @Test public void testParseSingleCharacter() throws Exception { final Character result = parser.fromString("v"); assertThat(result.charValue(), is('v')); }
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // Path: src/test/java/nl/ulso/sprox/parsers/CharacterParserTest.java import nl.ulso.sprox.ParseException; import org.junit.Test; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.assertThat; package nl.ulso.sprox.parsers; public class CharacterParserTest { private CharacterParser parser = new CharacterParser(); @Test public void testParseSingleCharacter() throws Exception { final Character result = parser.fromString("v"); assertThat(result.charValue(), is('v')); }
@Test(expected = ParseException.class)
voostindie/sprox
src/main/java/nl/ulso/sprox/parsers/DoubleParser.java
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // }
import nl.ulso.sprox.Parser; import nl.ulso.sprox.ParseException;
package nl.ulso.sprox.parsers; public class DoubleParser implements Parser<Double> { @Override
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // Path: src/main/java/nl/ulso/sprox/parsers/DoubleParser.java import nl.ulso.sprox.Parser; import nl.ulso.sprox.ParseException; package nl.ulso.sprox.parsers; public class DoubleParser implements Parser<Double> { @Override
public Double fromString(String value) throws ParseException {
voostindie/sprox
src/main/java/nl/ulso/sprox/parsers/IntegerParser.java
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // }
import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser;
package nl.ulso.sprox.parsers; public class IntegerParser implements Parser<Integer> { @Override
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // Path: src/main/java/nl/ulso/sprox/parsers/IntegerParser.java import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; package nl.ulso.sprox.parsers; public class IntegerParser implements Parser<Integer> { @Override
public Integer fromString(String value) throws ParseException {
voostindie/sprox
src/test/java/nl/ulso/sprox/inputfactory/CustomXmlInputFactoryTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Outline.java // public class Outline extends Element { // private final DateTime creationDate; // private final DateTime modificationDate; // // public Outline(String title, DateTime creationDate, DateTime modificationDate, List<Element> elements) { // super(title, Optional.of(elements)); // this.creationDate = creationDate; // this.modificationDate = modificationDate; // } // // public String getTitle() { // return getText(); // } // // public DateTime getCreationDate() { // return creationDate; // } // // public DateTime getModificationDate() { // return modificationDate; // } // // @Override // public void accept(Visitor visitor) { // visitor.visit(this); // for (Element element : this) { // element.accept(visitor); // } // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactory.java // public class OutlineFactory { // // @Node // public Outline opml(@Node String title, @Node DateTime dateCreated, // @Node DateTime dateModified, List<Element> elements) { // return new Outline(title, dateCreated, dateModified, elements); // } // // @Recursive // @Node // public Element outline(@Attribute String text, Optional<List<Element>> elements) { // return new Element(text, elements); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Rfc822DateTimeParser.java // public class Rfc822DateTimeParser implements Parser<DateTime> { // // // Not sure if this pattern is completely correct, but all dates in the test data are parsed correctly. // private static final DateTimeFormatter parser = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss ZZZ"); // // public DateTime fromString(String value) throws ParseException { // try { // return parser.parseDateTime(value); // } catch (IllegalArgumentException e) { // throw new ParseException(DateTime.class, value, e); // } // } // }
import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import nl.ulso.sprox.opml.Outline; import nl.ulso.sprox.opml.OutlineFactory; import nl.ulso.sprox.opml.Rfc822DateTimeParser; import org.junit.Test; import javax.xml.stream.*; import javax.xml.stream.util.XMLEventAllocator; import javax.xml.transform.Source; import java.io.InputStream; import java.io.Reader; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.inputfactory; public class CustomXmlInputFactoryTest { @Test public void testCustomXmlInputFactory() throws Exception { final StringBuilder builder = new StringBuilder(); final XMLInputFactory factory = createXmlInputFactory(builder); assertNotNull(factory);
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Outline.java // public class Outline extends Element { // private final DateTime creationDate; // private final DateTime modificationDate; // // public Outline(String title, DateTime creationDate, DateTime modificationDate, List<Element> elements) { // super(title, Optional.of(elements)); // this.creationDate = creationDate; // this.modificationDate = modificationDate; // } // // public String getTitle() { // return getText(); // } // // public DateTime getCreationDate() { // return creationDate; // } // // public DateTime getModificationDate() { // return modificationDate; // } // // @Override // public void accept(Visitor visitor) { // visitor.visit(this); // for (Element element : this) { // element.accept(visitor); // } // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactory.java // public class OutlineFactory { // // @Node // public Outline opml(@Node String title, @Node DateTime dateCreated, // @Node DateTime dateModified, List<Element> elements) { // return new Outline(title, dateCreated, dateModified, elements); // } // // @Recursive // @Node // public Element outline(@Attribute String text, Optional<List<Element>> elements) { // return new Element(text, elements); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Rfc822DateTimeParser.java // public class Rfc822DateTimeParser implements Parser<DateTime> { // // // Not sure if this pattern is completely correct, but all dates in the test data are parsed correctly. // private static final DateTimeFormatter parser = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss ZZZ"); // // public DateTime fromString(String value) throws ParseException { // try { // return parser.parseDateTime(value); // } catch (IllegalArgumentException e) { // throw new ParseException(DateTime.class, value, e); // } // } // } // Path: src/test/java/nl/ulso/sprox/inputfactory/CustomXmlInputFactoryTest.java import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import nl.ulso.sprox.opml.Outline; import nl.ulso.sprox.opml.OutlineFactory; import nl.ulso.sprox.opml.Rfc822DateTimeParser; import org.junit.Test; import javax.xml.stream.*; import javax.xml.stream.util.XMLEventAllocator; import javax.xml.transform.Source; import java.io.InputStream; import java.io.Reader; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package nl.ulso.sprox.inputfactory; public class CustomXmlInputFactoryTest { @Test public void testCustomXmlInputFactory() throws Exception { final StringBuilder builder = new StringBuilder(); final XMLInputFactory factory = createXmlInputFactory(builder); assertNotNull(factory);
final XmlProcessor<Outline> processor = new StaxBasedXmlProcessorBuilderFactory()
voostindie/sprox
src/test/java/nl/ulso/sprox/inputfactory/CustomXmlInputFactoryTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Outline.java // public class Outline extends Element { // private final DateTime creationDate; // private final DateTime modificationDate; // // public Outline(String title, DateTime creationDate, DateTime modificationDate, List<Element> elements) { // super(title, Optional.of(elements)); // this.creationDate = creationDate; // this.modificationDate = modificationDate; // } // // public String getTitle() { // return getText(); // } // // public DateTime getCreationDate() { // return creationDate; // } // // public DateTime getModificationDate() { // return modificationDate; // } // // @Override // public void accept(Visitor visitor) { // visitor.visit(this); // for (Element element : this) { // element.accept(visitor); // } // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactory.java // public class OutlineFactory { // // @Node // public Outline opml(@Node String title, @Node DateTime dateCreated, // @Node DateTime dateModified, List<Element> elements) { // return new Outline(title, dateCreated, dateModified, elements); // } // // @Recursive // @Node // public Element outline(@Attribute String text, Optional<List<Element>> elements) { // return new Element(text, elements); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Rfc822DateTimeParser.java // public class Rfc822DateTimeParser implements Parser<DateTime> { // // // Not sure if this pattern is completely correct, but all dates in the test data are parsed correctly. // private static final DateTimeFormatter parser = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss ZZZ"); // // public DateTime fromString(String value) throws ParseException { // try { // return parser.parseDateTime(value); // } catch (IllegalArgumentException e) { // throw new ParseException(DateTime.class, value, e); // } // } // }
import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import nl.ulso.sprox.opml.Outline; import nl.ulso.sprox.opml.OutlineFactory; import nl.ulso.sprox.opml.Rfc822DateTimeParser; import org.junit.Test; import javax.xml.stream.*; import javax.xml.stream.util.XMLEventAllocator; import javax.xml.transform.Source; import java.io.InputStream; import java.io.Reader; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.inputfactory; public class CustomXmlInputFactoryTest { @Test public void testCustomXmlInputFactory() throws Exception { final StringBuilder builder = new StringBuilder(); final XMLInputFactory factory = createXmlInputFactory(builder); assertNotNull(factory);
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Outline.java // public class Outline extends Element { // private final DateTime creationDate; // private final DateTime modificationDate; // // public Outline(String title, DateTime creationDate, DateTime modificationDate, List<Element> elements) { // super(title, Optional.of(elements)); // this.creationDate = creationDate; // this.modificationDate = modificationDate; // } // // public String getTitle() { // return getText(); // } // // public DateTime getCreationDate() { // return creationDate; // } // // public DateTime getModificationDate() { // return modificationDate; // } // // @Override // public void accept(Visitor visitor) { // visitor.visit(this); // for (Element element : this) { // element.accept(visitor); // } // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactory.java // public class OutlineFactory { // // @Node // public Outline opml(@Node String title, @Node DateTime dateCreated, // @Node DateTime dateModified, List<Element> elements) { // return new Outline(title, dateCreated, dateModified, elements); // } // // @Recursive // @Node // public Element outline(@Attribute String text, Optional<List<Element>> elements) { // return new Element(text, elements); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Rfc822DateTimeParser.java // public class Rfc822DateTimeParser implements Parser<DateTime> { // // // Not sure if this pattern is completely correct, but all dates in the test data are parsed correctly. // private static final DateTimeFormatter parser = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss ZZZ"); // // public DateTime fromString(String value) throws ParseException { // try { // return parser.parseDateTime(value); // } catch (IllegalArgumentException e) { // throw new ParseException(DateTime.class, value, e); // } // } // } // Path: src/test/java/nl/ulso/sprox/inputfactory/CustomXmlInputFactoryTest.java import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import nl.ulso.sprox.opml.Outline; import nl.ulso.sprox.opml.OutlineFactory; import nl.ulso.sprox.opml.Rfc822DateTimeParser; import org.junit.Test; import javax.xml.stream.*; import javax.xml.stream.util.XMLEventAllocator; import javax.xml.transform.Source; import java.io.InputStream; import java.io.Reader; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package nl.ulso.sprox.inputfactory; public class CustomXmlInputFactoryTest { @Test public void testCustomXmlInputFactory() throws Exception { final StringBuilder builder = new StringBuilder(); final XMLInputFactory factory = createXmlInputFactory(builder); assertNotNull(factory);
final XmlProcessor<Outline> processor = new StaxBasedXmlProcessorBuilderFactory()
voostindie/sprox
src/test/java/nl/ulso/sprox/inputfactory/CustomXmlInputFactoryTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Outline.java // public class Outline extends Element { // private final DateTime creationDate; // private final DateTime modificationDate; // // public Outline(String title, DateTime creationDate, DateTime modificationDate, List<Element> elements) { // super(title, Optional.of(elements)); // this.creationDate = creationDate; // this.modificationDate = modificationDate; // } // // public String getTitle() { // return getText(); // } // // public DateTime getCreationDate() { // return creationDate; // } // // public DateTime getModificationDate() { // return modificationDate; // } // // @Override // public void accept(Visitor visitor) { // visitor.visit(this); // for (Element element : this) { // element.accept(visitor); // } // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactory.java // public class OutlineFactory { // // @Node // public Outline opml(@Node String title, @Node DateTime dateCreated, // @Node DateTime dateModified, List<Element> elements) { // return new Outline(title, dateCreated, dateModified, elements); // } // // @Recursive // @Node // public Element outline(@Attribute String text, Optional<List<Element>> elements) { // return new Element(text, elements); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Rfc822DateTimeParser.java // public class Rfc822DateTimeParser implements Parser<DateTime> { // // // Not sure if this pattern is completely correct, but all dates in the test data are parsed correctly. // private static final DateTimeFormatter parser = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss ZZZ"); // // public DateTime fromString(String value) throws ParseException { // try { // return parser.parseDateTime(value); // } catch (IllegalArgumentException e) { // throw new ParseException(DateTime.class, value, e); // } // } // }
import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import nl.ulso.sprox.opml.Outline; import nl.ulso.sprox.opml.OutlineFactory; import nl.ulso.sprox.opml.Rfc822DateTimeParser; import org.junit.Test; import javax.xml.stream.*; import javax.xml.stream.util.XMLEventAllocator; import javax.xml.transform.Source; import java.io.InputStream; import java.io.Reader; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.inputfactory; public class CustomXmlInputFactoryTest { @Test public void testCustomXmlInputFactory() throws Exception { final StringBuilder builder = new StringBuilder(); final XMLInputFactory factory = createXmlInputFactory(builder); assertNotNull(factory);
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Outline.java // public class Outline extends Element { // private final DateTime creationDate; // private final DateTime modificationDate; // // public Outline(String title, DateTime creationDate, DateTime modificationDate, List<Element> elements) { // super(title, Optional.of(elements)); // this.creationDate = creationDate; // this.modificationDate = modificationDate; // } // // public String getTitle() { // return getText(); // } // // public DateTime getCreationDate() { // return creationDate; // } // // public DateTime getModificationDate() { // return modificationDate; // } // // @Override // public void accept(Visitor visitor) { // visitor.visit(this); // for (Element element : this) { // element.accept(visitor); // } // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactory.java // public class OutlineFactory { // // @Node // public Outline opml(@Node String title, @Node DateTime dateCreated, // @Node DateTime dateModified, List<Element> elements) { // return new Outline(title, dateCreated, dateModified, elements); // } // // @Recursive // @Node // public Element outline(@Attribute String text, Optional<List<Element>> elements) { // return new Element(text, elements); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Rfc822DateTimeParser.java // public class Rfc822DateTimeParser implements Parser<DateTime> { // // // Not sure if this pattern is completely correct, but all dates in the test data are parsed correctly. // private static final DateTimeFormatter parser = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss ZZZ"); // // public DateTime fromString(String value) throws ParseException { // try { // return parser.parseDateTime(value); // } catch (IllegalArgumentException e) { // throw new ParseException(DateTime.class, value, e); // } // } // } // Path: src/test/java/nl/ulso/sprox/inputfactory/CustomXmlInputFactoryTest.java import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import nl.ulso.sprox.opml.Outline; import nl.ulso.sprox.opml.OutlineFactory; import nl.ulso.sprox.opml.Rfc822DateTimeParser; import org.junit.Test; import javax.xml.stream.*; import javax.xml.stream.util.XMLEventAllocator; import javax.xml.transform.Source; import java.io.InputStream; import java.io.Reader; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package nl.ulso.sprox.inputfactory; public class CustomXmlInputFactoryTest { @Test public void testCustomXmlInputFactory() throws Exception { final StringBuilder builder = new StringBuilder(); final XMLInputFactory factory = createXmlInputFactory(builder); assertNotNull(factory);
final XmlProcessor<Outline> processor = new StaxBasedXmlProcessorBuilderFactory()
voostindie/sprox
src/test/java/nl/ulso/sprox/inputfactory/CustomXmlInputFactoryTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Outline.java // public class Outline extends Element { // private final DateTime creationDate; // private final DateTime modificationDate; // // public Outline(String title, DateTime creationDate, DateTime modificationDate, List<Element> elements) { // super(title, Optional.of(elements)); // this.creationDate = creationDate; // this.modificationDate = modificationDate; // } // // public String getTitle() { // return getText(); // } // // public DateTime getCreationDate() { // return creationDate; // } // // public DateTime getModificationDate() { // return modificationDate; // } // // @Override // public void accept(Visitor visitor) { // visitor.visit(this); // for (Element element : this) { // element.accept(visitor); // } // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactory.java // public class OutlineFactory { // // @Node // public Outline opml(@Node String title, @Node DateTime dateCreated, // @Node DateTime dateModified, List<Element> elements) { // return new Outline(title, dateCreated, dateModified, elements); // } // // @Recursive // @Node // public Element outline(@Attribute String text, Optional<List<Element>> elements) { // return new Element(text, elements); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Rfc822DateTimeParser.java // public class Rfc822DateTimeParser implements Parser<DateTime> { // // // Not sure if this pattern is completely correct, but all dates in the test data are parsed correctly. // private static final DateTimeFormatter parser = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss ZZZ"); // // public DateTime fromString(String value) throws ParseException { // try { // return parser.parseDateTime(value); // } catch (IllegalArgumentException e) { // throw new ParseException(DateTime.class, value, e); // } // } // }
import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import nl.ulso.sprox.opml.Outline; import nl.ulso.sprox.opml.OutlineFactory; import nl.ulso.sprox.opml.Rfc822DateTimeParser; import org.junit.Test; import javax.xml.stream.*; import javax.xml.stream.util.XMLEventAllocator; import javax.xml.transform.Source; import java.io.InputStream; import java.io.Reader; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.inputfactory; public class CustomXmlInputFactoryTest { @Test public void testCustomXmlInputFactory() throws Exception { final StringBuilder builder = new StringBuilder(); final XMLInputFactory factory = createXmlInputFactory(builder); assertNotNull(factory); final XmlProcessor<Outline> processor = new StaxBasedXmlProcessorBuilderFactory() .createXmlProcessorBuilder(Outline.class)
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Outline.java // public class Outline extends Element { // private final DateTime creationDate; // private final DateTime modificationDate; // // public Outline(String title, DateTime creationDate, DateTime modificationDate, List<Element> elements) { // super(title, Optional.of(elements)); // this.creationDate = creationDate; // this.modificationDate = modificationDate; // } // // public String getTitle() { // return getText(); // } // // public DateTime getCreationDate() { // return creationDate; // } // // public DateTime getModificationDate() { // return modificationDate; // } // // @Override // public void accept(Visitor visitor) { // visitor.visit(this); // for (Element element : this) { // element.accept(visitor); // } // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactory.java // public class OutlineFactory { // // @Node // public Outline opml(@Node String title, @Node DateTime dateCreated, // @Node DateTime dateModified, List<Element> elements) { // return new Outline(title, dateCreated, dateModified, elements); // } // // @Recursive // @Node // public Element outline(@Attribute String text, Optional<List<Element>> elements) { // return new Element(text, elements); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Rfc822DateTimeParser.java // public class Rfc822DateTimeParser implements Parser<DateTime> { // // // Not sure if this pattern is completely correct, but all dates in the test data are parsed correctly. // private static final DateTimeFormatter parser = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss ZZZ"); // // public DateTime fromString(String value) throws ParseException { // try { // return parser.parseDateTime(value); // } catch (IllegalArgumentException e) { // throw new ParseException(DateTime.class, value, e); // } // } // } // Path: src/test/java/nl/ulso/sprox/inputfactory/CustomXmlInputFactoryTest.java import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import nl.ulso.sprox.opml.Outline; import nl.ulso.sprox.opml.OutlineFactory; import nl.ulso.sprox.opml.Rfc822DateTimeParser; import org.junit.Test; import javax.xml.stream.*; import javax.xml.stream.util.XMLEventAllocator; import javax.xml.transform.Source; import java.io.InputStream; import java.io.Reader; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package nl.ulso.sprox.inputfactory; public class CustomXmlInputFactoryTest { @Test public void testCustomXmlInputFactory() throws Exception { final StringBuilder builder = new StringBuilder(); final XMLInputFactory factory = createXmlInputFactory(builder); assertNotNull(factory); final XmlProcessor<Outline> processor = new StaxBasedXmlProcessorBuilderFactory() .createXmlProcessorBuilder(Outline.class)
.addControllerClass(OutlineFactory.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/inputfactory/CustomXmlInputFactoryTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Outline.java // public class Outline extends Element { // private final DateTime creationDate; // private final DateTime modificationDate; // // public Outline(String title, DateTime creationDate, DateTime modificationDate, List<Element> elements) { // super(title, Optional.of(elements)); // this.creationDate = creationDate; // this.modificationDate = modificationDate; // } // // public String getTitle() { // return getText(); // } // // public DateTime getCreationDate() { // return creationDate; // } // // public DateTime getModificationDate() { // return modificationDate; // } // // @Override // public void accept(Visitor visitor) { // visitor.visit(this); // for (Element element : this) { // element.accept(visitor); // } // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactory.java // public class OutlineFactory { // // @Node // public Outline opml(@Node String title, @Node DateTime dateCreated, // @Node DateTime dateModified, List<Element> elements) { // return new Outline(title, dateCreated, dateModified, elements); // } // // @Recursive // @Node // public Element outline(@Attribute String text, Optional<List<Element>> elements) { // return new Element(text, elements); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Rfc822DateTimeParser.java // public class Rfc822DateTimeParser implements Parser<DateTime> { // // // Not sure if this pattern is completely correct, but all dates in the test data are parsed correctly. // private static final DateTimeFormatter parser = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss ZZZ"); // // public DateTime fromString(String value) throws ParseException { // try { // return parser.parseDateTime(value); // } catch (IllegalArgumentException e) { // throw new ParseException(DateTime.class, value, e); // } // } // }
import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import nl.ulso.sprox.opml.Outline; import nl.ulso.sprox.opml.OutlineFactory; import nl.ulso.sprox.opml.Rfc822DateTimeParser; import org.junit.Test; import javax.xml.stream.*; import javax.xml.stream.util.XMLEventAllocator; import javax.xml.transform.Source; import java.io.InputStream; import java.io.Reader; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.inputfactory; public class CustomXmlInputFactoryTest { @Test public void testCustomXmlInputFactory() throws Exception { final StringBuilder builder = new StringBuilder(); final XMLInputFactory factory = createXmlInputFactory(builder); assertNotNull(factory); final XmlProcessor<Outline> processor = new StaxBasedXmlProcessorBuilderFactory() .createXmlProcessorBuilder(Outline.class) .addControllerClass(OutlineFactory.class)
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilderFactory.java // public class StaxBasedXmlProcessorBuilderFactory implements XmlProcessorBuilderFactory { // @Override // public <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilder<>(resultClass); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Outline.java // public class Outline extends Element { // private final DateTime creationDate; // private final DateTime modificationDate; // // public Outline(String title, DateTime creationDate, DateTime modificationDate, List<Element> elements) { // super(title, Optional.of(elements)); // this.creationDate = creationDate; // this.modificationDate = modificationDate; // } // // public String getTitle() { // return getText(); // } // // public DateTime getCreationDate() { // return creationDate; // } // // public DateTime getModificationDate() { // return modificationDate; // } // // @Override // public void accept(Visitor visitor) { // visitor.visit(this); // for (Element element : this) { // element.accept(visitor); // } // } // } // // Path: src/test/java/nl/ulso/sprox/opml/OutlineFactory.java // public class OutlineFactory { // // @Node // public Outline opml(@Node String title, @Node DateTime dateCreated, // @Node DateTime dateModified, List<Element> elements) { // return new Outline(title, dateCreated, dateModified, elements); // } // // @Recursive // @Node // public Element outline(@Attribute String text, Optional<List<Element>> elements) { // return new Element(text, elements); // } // } // // Path: src/test/java/nl/ulso/sprox/opml/Rfc822DateTimeParser.java // public class Rfc822DateTimeParser implements Parser<DateTime> { // // // Not sure if this pattern is completely correct, but all dates in the test data are parsed correctly. // private static final DateTimeFormatter parser = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss ZZZ"); // // public DateTime fromString(String value) throws ParseException { // try { // return parser.parseDateTime(value); // } catch (IllegalArgumentException e) { // throw new ParseException(DateTime.class, value, e); // } // } // } // Path: src/test/java/nl/ulso/sprox/inputfactory/CustomXmlInputFactoryTest.java import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.impl.StaxBasedXmlProcessorBuilderFactory; import nl.ulso.sprox.opml.Outline; import nl.ulso.sprox.opml.OutlineFactory; import nl.ulso.sprox.opml.Rfc822DateTimeParser; import org.junit.Test; import javax.xml.stream.*; import javax.xml.stream.util.XMLEventAllocator; import javax.xml.transform.Source; import java.io.InputStream; import java.io.Reader; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package nl.ulso.sprox.inputfactory; public class CustomXmlInputFactoryTest { @Test public void testCustomXmlInputFactory() throws Exception { final StringBuilder builder = new StringBuilder(); final XMLInputFactory factory = createXmlInputFactory(builder); assertNotNull(factory); final XmlProcessor<Outline> processor = new StaxBasedXmlProcessorBuilderFactory() .createXmlProcessorBuilder(Outline.class) .addControllerClass(OutlineFactory.class)
.addParser(new Rfc822DateTimeParser())
voostindie/sprox
src/test/java/nl/ulso/sprox/SingleNamespaceTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import org.junit.Test; import static nl.ulso.sprox.SproxTests.testControllers; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder;
package nl.ulso.sprox; public class SingleNamespaceTest { @Test public void testSingleNamespace() throws Exception {
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/SingleNamespaceTest.java import org.junit.Test; import static nl.ulso.sprox.SproxTests.testControllers; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; package nl.ulso.sprox; public class SingleNamespaceTest { @Test public void testSingleNamespace() throws Exception {
testControllers(
voostindie/sprox
src/test/java/nl/ulso/sprox/SingleNamespaceTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import org.junit.Test; import static nl.ulso.sprox.SproxTests.testControllers; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder;
package nl.ulso.sprox; public class SingleNamespaceTest { @Test public void testSingleNamespace() throws Exception { testControllers( "42:answer", "<root xmlns=\"namespace\" id=\"42\"><node>answer</node></root>", new SingleNamespaceProcessor()); } @Test public void testSingleNamespaceWithShorthand() throws Exception { testControllers( "42:answer", "<root xmlns=\"namespace\" id=\"42\"><node>answer</node></root>", new ShorthandNamespaceProcessor()); } @Test(expected = IllegalStateException.class) public void testThatNamespacesAreGlobalForAProcessor() throws Exception {
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/SingleNamespaceTest.java import org.junit.Test; import static nl.ulso.sprox.SproxTests.testControllers; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; package nl.ulso.sprox; public class SingleNamespaceTest { @Test public void testSingleNamespace() throws Exception { testControllers( "42:answer", "<root xmlns=\"namespace\" id=\"42\"><node>answer</node></root>", new SingleNamespaceProcessor()); } @Test public void testSingleNamespaceWithShorthand() throws Exception { testControllers( "42:answer", "<root xmlns=\"namespace\" id=\"42\"><node>answer</node></root>", new ShorthandNamespaceProcessor()); } @Test(expected = IllegalStateException.class) public void testThatNamespacesAreGlobalForAProcessor() throws Exception {
createXmlProcessorBuilder(Void.class)
voostindie/sprox
src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilder.java
// Path: src/main/java/nl/ulso/sprox/resolvers/DefaultElementNameResolver.java // public class DefaultElementNameResolver implements ElementNameResolver { // @Override // public String fromParameter(Class<?> controllerClass, Method method, Parameter parameter) { // return parameter.getName(); // } // // @Override // public String fromMethod(Class<?> controllerClass, Method method) { // return method.getName(); // } // } // // Path: src/main/java/nl/ulso/sprox/impl/ReflectionUtil.java // final class ReflectionUtil { // private static final Map<Type, Class> PRIMITIVE_PARAMETER_TYPES = Map.of( // Boolean.class, Boolean.TYPE, // Byte.class, Byte.TYPE, // Character.class, Character.TYPE, // Double.class, Double.TYPE, // Float.class, Float.TYPE, // Integer.class, Integer.TYPE, // Long.class, Long.TYPE, // Short.class, Short.TYPE); // // private ReflectionUtil() { // } // // /** // * Resolves the {@link Class} that corresponds with a {@link Type}. // * <p> // * {@code Class} is an implementation of {@code Type} but, of course, not every {@code Type} is a {@code Class}. // * Case in point here are primitive types. These can appear as method parameters. // * // * @param objectType Type to resolve. // * @return Corresponding class. // */ // static Class resolveObjectClass(Type objectType) { // final Class type = PRIMITIVE_PARAMETER_TYPES.get(objectType); // if (type != null) { // return type; // } // if (isOptionalType(objectType)) { // return resolveObjectClass(extractTypeFromOptional(objectType)); // } // try { // return (Class) objectType; // } catch (ClassCastException e) { // throw new IllegalStateException("Cannot resolve object class from type: " + objectType, e); // } // } // // static boolean isOptionalType(Type objectType) { // if (objectType instanceof ParameterizedType) { // final ParameterizedType parameterizedType = (ParameterizedType) objectType; // return parameterizedType.getRawType().equals(Optional.class); // } // return false; // } // // static Type extractTypeFromOptional(Type optionalType) { // return ((ParameterizedType) optionalType).getActualTypeArguments()[0]; // } // // static boolean isListType(Type objectType) { // if (objectType instanceof ParameterizedType) { // final ParameterizedType parameterizedType = (ParameterizedType) objectType; // return parameterizedType.getRawType().equals(List.class); // } // return false; // } // // static Type extractTypeFromList(Type listType) { // return ((ParameterizedType) listType).getActualTypeArguments()[0]; // } // }
import nl.ulso.sprox.*; import nl.ulso.sprox.parsers.*; import nl.ulso.sprox.resolvers.DefaultElementNameResolver; import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import static java.util.Arrays.stream; import static java.util.Objects.requireNonNull; import static nl.ulso.sprox.impl.ReflectionUtil.*;
package nl.ulso.sprox.impl; /** * Default {@link nl.ulso.sprox.XmlProcessorBuilder} implementation. * <p> * Whenever a controller is added, each method in the controller is scanned to see if it is annotated with * {@link nl.ulso.sprox.Node}. If so, a {@link StartNodeEventHandler} is created and stored in a list. When building * the * {@link StaxBasedXmlProcessor}, it gets passed these event handlers. */ final class StaxBasedXmlProcessorBuilder<T> implements XmlProcessorBuilder<T> { private static final String NAMESPACE_AWARE = "javax.xml.stream.isNamespaceAware"; private static final String COALESCE_CHARACTERS = "javax.xml.stream.isCoalescing"; private static final String REPLACE_INTERNAL_ENTITY_REFERENCES = "javax.xml.stream.isReplacingEntityReferences"; private static final String SUPPORT_EXTERNAL_ENTITIES = "javax.xml.stream.isSupportingExternalEntities"; private static final String SUPPORT_DTDS = "javax.xml.stream.supportDTD"; private static final String PARSER_FROM_STRING_METHOD = Parser.class.getMethods()[0].getName(); private static final String CONTROLLER_FACTORY_CREATE_METHOD = ControllerFactory.class.getMethods()[0].getName();
// Path: src/main/java/nl/ulso/sprox/resolvers/DefaultElementNameResolver.java // public class DefaultElementNameResolver implements ElementNameResolver { // @Override // public String fromParameter(Class<?> controllerClass, Method method, Parameter parameter) { // return parameter.getName(); // } // // @Override // public String fromMethod(Class<?> controllerClass, Method method) { // return method.getName(); // } // } // // Path: src/main/java/nl/ulso/sprox/impl/ReflectionUtil.java // final class ReflectionUtil { // private static final Map<Type, Class> PRIMITIVE_PARAMETER_TYPES = Map.of( // Boolean.class, Boolean.TYPE, // Byte.class, Byte.TYPE, // Character.class, Character.TYPE, // Double.class, Double.TYPE, // Float.class, Float.TYPE, // Integer.class, Integer.TYPE, // Long.class, Long.TYPE, // Short.class, Short.TYPE); // // private ReflectionUtil() { // } // // /** // * Resolves the {@link Class} that corresponds with a {@link Type}. // * <p> // * {@code Class} is an implementation of {@code Type} but, of course, not every {@code Type} is a {@code Class}. // * Case in point here are primitive types. These can appear as method parameters. // * // * @param objectType Type to resolve. // * @return Corresponding class. // */ // static Class resolveObjectClass(Type objectType) { // final Class type = PRIMITIVE_PARAMETER_TYPES.get(objectType); // if (type != null) { // return type; // } // if (isOptionalType(objectType)) { // return resolveObjectClass(extractTypeFromOptional(objectType)); // } // try { // return (Class) objectType; // } catch (ClassCastException e) { // throw new IllegalStateException("Cannot resolve object class from type: " + objectType, e); // } // } // // static boolean isOptionalType(Type objectType) { // if (objectType instanceof ParameterizedType) { // final ParameterizedType parameterizedType = (ParameterizedType) objectType; // return parameterizedType.getRawType().equals(Optional.class); // } // return false; // } // // static Type extractTypeFromOptional(Type optionalType) { // return ((ParameterizedType) optionalType).getActualTypeArguments()[0]; // } // // static boolean isListType(Type objectType) { // if (objectType instanceof ParameterizedType) { // final ParameterizedType parameterizedType = (ParameterizedType) objectType; // return parameterizedType.getRawType().equals(List.class); // } // return false; // } // // static Type extractTypeFromList(Type listType) { // return ((ParameterizedType) listType).getActualTypeArguments()[0]; // } // } // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessorBuilder.java import nl.ulso.sprox.*; import nl.ulso.sprox.parsers.*; import nl.ulso.sprox.resolvers.DefaultElementNameResolver; import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import static java.util.Arrays.stream; import static java.util.Objects.requireNonNull; import static nl.ulso.sprox.impl.ReflectionUtil.*; package nl.ulso.sprox.impl; /** * Default {@link nl.ulso.sprox.XmlProcessorBuilder} implementation. * <p> * Whenever a controller is added, each method in the controller is scanned to see if it is annotated with * {@link nl.ulso.sprox.Node}. If so, a {@link StartNodeEventHandler} is created and stored in a list. When building * the * {@link StaxBasedXmlProcessor}, it gets passed these event handlers. */ final class StaxBasedXmlProcessorBuilder<T> implements XmlProcessorBuilder<T> { private static final String NAMESPACE_AWARE = "javax.xml.stream.isNamespaceAware"; private static final String COALESCE_CHARACTERS = "javax.xml.stream.isCoalescing"; private static final String REPLACE_INTERNAL_ENTITY_REFERENCES = "javax.xml.stream.isReplacingEntityReferences"; private static final String SUPPORT_EXTERNAL_ENTITIES = "javax.xml.stream.isSupportingExternalEntities"; private static final String SUPPORT_DTDS = "javax.xml.stream.supportDTD"; private static final String PARSER_FROM_STRING_METHOD = Parser.class.getMethods()[0].getName(); private static final String CONTROLLER_FACTORY_CREATE_METHOD = ControllerFactory.class.getMethods()[0].getName();
private static final ElementNameResolver DEFAULT_RESOLVER = new DefaultElementNameResolver();
voostindie/sprox
src/test/java/nl/ulso/sprox/CdataNodeTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // }
import org.junit.Test; import static nl.ulso.sprox.SproxTests.testControllers;
package nl.ulso.sprox; /** * */ public class CdataNodeTest { @Test public void testThatCdataIsReadAsContent() throws Exception {
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // Path: src/test/java/nl/ulso/sprox/CdataNodeTest.java import org.junit.Test; import static nl.ulso.sprox.SproxTests.testControllers; package nl.ulso.sprox; /** * */ public class CdataNodeTest { @Test public void testThatCdataIsReadAsContent() throws Exception {
testControllers("content", "<root><![CDATA[content]]></root>", new NodeProcessor());
voostindie/sprox
src/main/java/nl/ulso/sprox/parsers/FloatParser.java
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // }
import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser;
package nl.ulso.sprox.parsers; public class FloatParser implements Parser<Float> { @Override
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // Path: src/main/java/nl/ulso/sprox/parsers/FloatParser.java import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; package nl.ulso.sprox.parsers; public class FloatParser implements Parser<Float> { @Override
public Float fromString(String value) throws ParseException {
voostindie/sprox
src/test/java/nl/ulso/sprox/parsers/BooleanParserTest.java
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // }
import nl.ulso.sprox.ParseException; import org.junit.Test; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.parsers; public class BooleanParserTest { private BooleanParser parser = new BooleanParser(); @Test public void testOneIsTrue() throws Exception { final Boolean result = parser.fromString("1"); assertThat(result, is(true)); } @Test public void testTrueIsTrue() throws Exception { final Boolean result = parser.fromString("true"); assertThat(result, is(true)); } @Test public void testZeroIsFalse() throws Exception { final Boolean result = parser.fromString("0"); assertThat(result, is(false)); } @Test public void testFalseIsFalse() throws Exception { final Boolean result = parser.fromString("false"); assertThat(result, is(false)); }
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // Path: src/test/java/nl/ulso/sprox/parsers/BooleanParserTest.java import nl.ulso.sprox.ParseException; import org.junit.Test; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.assertThat; package nl.ulso.sprox.parsers; public class BooleanParserTest { private BooleanParser parser = new BooleanParser(); @Test public void testOneIsTrue() throws Exception { final Boolean result = parser.fromString("1"); assertThat(result, is(true)); } @Test public void testTrueIsTrue() throws Exception { final Boolean result = parser.fromString("true"); assertThat(result, is(true)); } @Test public void testZeroIsFalse() throws Exception { final Boolean result = parser.fromString("0"); assertThat(result, is(false)); } @Test public void testFalseIsFalse() throws Exception { final Boolean result = parser.fromString("false"); assertThat(result, is(false)); }
@Test(expected = ParseException.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/CustomPrimitiveTypeParserTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // }
import org.junit.Test; import static java.lang.Integer.parseInt; import static java.lang.Math.abs; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static nl.ulso.sprox.SproxTests.testProcessor;
package nl.ulso.sprox; public class CustomPrimitiveTypeParserTest { @Test public void testCustomIntegerParserFromInnerClass() throws Exception { //noinspection Convert2Lambda
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // } // Path: src/test/java/nl/ulso/sprox/CustomPrimitiveTypeParserTest.java import org.junit.Test; import static java.lang.Integer.parseInt; import static java.lang.Math.abs; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static nl.ulso.sprox.SproxTests.testProcessor; package nl.ulso.sprox; public class CustomPrimitiveTypeParserTest { @Test public void testCustomIntegerParserFromInnerClass() throws Exception { //noinspection Convert2Lambda
final XmlProcessor<String> processor = createXmlProcessorBuilder(String.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/CustomPrimitiveTypeParserTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // }
import org.junit.Test; import static java.lang.Integer.parseInt; import static java.lang.Math.abs; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static nl.ulso.sprox.SproxTests.testProcessor;
package nl.ulso.sprox; public class CustomPrimitiveTypeParserTest { @Test public void testCustomIntegerParserFromInnerClass() throws Exception { //noinspection Convert2Lambda final XmlProcessor<String> processor = createXmlProcessorBuilder(String.class) .addControllerClass(IntegerParser.class) .addParser(new Parser<Integer>() { @Override public Integer fromString(String value) throws ParseException { return abs(parseInt(value)); } }) .buildXmlProcessor();
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // } // Path: src/test/java/nl/ulso/sprox/CustomPrimitiveTypeParserTest.java import org.junit.Test; import static java.lang.Integer.parseInt; import static java.lang.Math.abs; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static nl.ulso.sprox.SproxTests.testProcessor; package nl.ulso.sprox; public class CustomPrimitiveTypeParserTest { @Test public void testCustomIntegerParserFromInnerClass() throws Exception { //noinspection Convert2Lambda final XmlProcessor<String> processor = createXmlProcessorBuilder(String.class) .addControllerClass(IntegerParser.class) .addParser(new Parser<Integer>() { @Override public Integer fromString(String value) throws ParseException { return abs(parseInt(value)); } }) .buildXmlProcessor();
testProcessor("42", "<number value=\"-42\"/>", processor);
voostindie/sprox
src/main/java/nl/ulso/sprox/parsers/LongParser.java
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // }
import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser;
package nl.ulso.sprox.parsers; public class LongParser implements Parser<Long> { @Override
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // Path: src/main/java/nl/ulso/sprox/parsers/LongParser.java import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; package nl.ulso.sprox.parsers; public class LongParser implements Parser<Long> { @Override
public Long fromString(String value) throws ParseException {
voostindie/sprox
src/main/java/nl/ulso/sprox/impl/QNameResolver.java
// Path: src/main/java/nl/ulso/sprox/ElementNameResolver.java // public interface ElementNameResolver { // // String fromParameter(Class<?> controllerClass, Method method, Parameter parameter); // // String fromMethod(Class<?> controllerClass, Method method); // }
import nl.ulso.sprox.ElementNameResolver; import javax.xml.namespace.QName; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.function.Supplier;
package nl.ulso.sprox.impl; /** * Creates QNames for XML elements from controller class, method and parameter names. */ class QNameResolver { private final Class<?> controllerClass; private final Method method; private final NamespaceMap namespaceMap;
// Path: src/main/java/nl/ulso/sprox/ElementNameResolver.java // public interface ElementNameResolver { // // String fromParameter(Class<?> controllerClass, Method method, Parameter parameter); // // String fromMethod(Class<?> controllerClass, Method method); // } // Path: src/main/java/nl/ulso/sprox/impl/QNameResolver.java import nl.ulso.sprox.ElementNameResolver; import javax.xml.namespace.QName; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.function.Supplier; package nl.ulso.sprox.impl; /** * Creates QNames for XML elements from controller class, method and parameter names. */ class QNameResolver { private final Class<?> controllerClass; private final Method method; private final NamespaceMap namespaceMap;
private final ElementNameResolver elementNameResolver;
voostindie/sprox
src/test/java/nl/ulso/sprox/MultipleNamespacesTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // }
import org.junit.Test; import static nl.ulso.sprox.SproxTests.testControllers;
package nl.ulso.sprox; public class MultipleNamespacesTest { public static final String XML = "<root xmlns=\"rootNamespace\" xmlns:n1=\"namespace1\" xmlns:n2=\"namespace2\">" + "<n1:node id=\"node1\"><n1:content>content1</n1:content></n1:node>" + "<n2:node id=\"node2\"/>" + "<node n1:id=\"n1\" n2:id=\"n2\">content</node>" + "</root>"; @Test public void testThatProcessingXmlWithMultipleNamespacesWorksCorrectly() throws Exception {
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // Path: src/test/java/nl/ulso/sprox/MultipleNamespacesTest.java import org.junit.Test; import static nl.ulso.sprox.SproxTests.testControllers; package nl.ulso.sprox; public class MultipleNamespacesTest { public static final String XML = "<root xmlns=\"rootNamespace\" xmlns:n1=\"namespace1\" xmlns:n2=\"namespace2\">" + "<n1:node id=\"node1\"><n1:content>content1</n1:content></n1:node>" + "<n2:node id=\"node2\"/>" + "<node n1:id=\"n1\" n2:id=\"n2\">content</node>" + "</root>"; @Test public void testThatProcessingXmlWithMultipleNamespacesWorksCorrectly() throws Exception {
testControllers("n1,n2,content:node1,content1:node2", XML, MultipleNamespacesProcessor.class);
voostindie/sprox
src/test/java/nl/ulso/sprox/ObjectInjectionTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // }
import org.junit.Test; import java.util.List; import java.util.Optional; import static nl.ulso.sprox.SproxTests.testControllers; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat;
package nl.ulso.sprox; public class ObjectInjectionTest { @Test public void testThatInjectingASingleValueInjectsTheFirstFromTheList() throws Exception {
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // Path: src/test/java/nl/ulso/sprox/ObjectInjectionTest.java import org.junit.Test; import java.util.List; import java.util.Optional; import static nl.ulso.sprox.SproxTests.testControllers; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; package nl.ulso.sprox; public class ObjectInjectionTest { @Test public void testThatInjectingASingleValueInjectsTheFirstFromTheList() throws Exception {
testControllers("value1", "<root1><node1>value1</node1><node1>value2</node1></root1>", ObjectInjector.class);
voostindie/sprox
src/test/java/nl/ulso/sprox/movies/MovieTitleFinderTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.movies; public class MovieTitleFinderTest { @Test public void testFindTitleInNodeBodyForFirstMovie() throws Exception {
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/movies/MovieTitleFinderTest.java import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; package nl.ulso.sprox.movies; public class MovieTitleFinderTest { @Test public void testFindTitleInNodeBodyForFirstMovie() throws Exception {
final XmlProcessor<String> processor = createXmlProcessorBuilder(String.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/movies/MovieTitleFinderTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.movies; public class MovieTitleFinderTest { @Test public void testFindTitleInNodeBodyForFirstMovie() throws Exception {
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/movies/MovieTitleFinderTest.java import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; package nl.ulso.sprox.movies; public class MovieTitleFinderTest { @Test public void testFindTitleInNodeBodyForFirstMovie() throws Exception {
final XmlProcessor<String> processor = createXmlProcessorBuilder(String.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/movies/MovieIdFinderTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.Attribute; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.util.Optional; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.movies; public class MovieIdFinderTest { @Test public void testFindIdInAttributeOfFirstMovie() throws Exception {
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/movies/MovieIdFinderTest.java import nl.ulso.sprox.Attribute; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.util.Optional; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; package nl.ulso.sprox.movies; public class MovieIdFinderTest { @Test public void testFindIdInAttributeOfFirstMovie() throws Exception {
final XmlProcessor<String> processor = createXmlProcessorBuilder(String.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/movies/MovieIdFinderTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.Attribute; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.util.Optional; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.movies; public class MovieIdFinderTest { @Test public void testFindIdInAttributeOfFirstMovie() throws Exception {
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/movies/MovieIdFinderTest.java import nl.ulso.sprox.Attribute; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.util.Optional; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; package nl.ulso.sprox.movies; public class MovieIdFinderTest { @Test public void testFindIdInAttributeOfFirstMovie() throws Exception {
final XmlProcessor<String> processor = createXmlProcessorBuilder(String.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/atom/FeedEntryCounterTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.atom; public class FeedEntryCounterTest { @Test public void countAllEntriesInFeed() throws Exception { final FeedEntryCounter entryCounter = new FeedEntryCounter();
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/atom/FeedEntryCounterTest.java import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; package nl.ulso.sprox.atom; public class FeedEntryCounterTest { @Test public void countAllEntriesInFeed() throws Exception { final FeedEntryCounter entryCounter = new FeedEntryCounter();
final XmlProcessor<Void> processor = createXmlProcessorBuilder(Void.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/atom/FeedEntryCounterTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.atom; public class FeedEntryCounterTest { @Test public void countAllEntriesInFeed() throws Exception { final FeedEntryCounter entryCounter = new FeedEntryCounter();
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/atom/FeedEntryCounterTest.java import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; package nl.ulso.sprox.atom; public class FeedEntryCounterTest { @Test public void countAllEntriesInFeed() throws Exception { final FeedEntryCounter entryCounter = new FeedEntryCounter();
final XmlProcessor<Void> processor = createXmlProcessorBuilder(Void.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/NodeWithAttributesAndContentTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // }
import org.junit.Test; import static nl.ulso.sprox.SproxTests.testControllers;
package nl.ulso.sprox; public class NodeWithAttributesAndContentTest { @Test public void testControllerOnNodeThatPullsContentFromThatSameNode() throws Exception {
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // Path: src/test/java/nl/ulso/sprox/NodeWithAttributesAndContentTest.java import org.junit.Test; import static nl.ulso.sprox.SproxTests.testControllers; package nl.ulso.sprox; public class NodeWithAttributesAndContentTest { @Test public void testControllerOnNodeThatPullsContentFromThatSameNode() throws Exception {
testControllers(
voostindie/sprox
src/main/java/nl/ulso/sprox/parsers/BooleanParser.java
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // }
import nl.ulso.sprox.Parser; import nl.ulso.sprox.ParseException;
package nl.ulso.sprox.parsers; /** * Parses an `xsd:boolean` into a Boolean. */ public class BooleanParser implements Parser<Boolean> { @Override
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // Path: src/main/java/nl/ulso/sprox/parsers/BooleanParser.java import nl.ulso.sprox.Parser; import nl.ulso.sprox.ParseException; package nl.ulso.sprox.parsers; /** * Parses an `xsd:boolean` into a Boolean. */ public class BooleanParser implements Parser<Boolean> { @Override
public Boolean fromString(String value) throws ParseException {
voostindie/sprox
src/main/java/nl/ulso/sprox/parsers/StringParser.java
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // }
import nl.ulso.sprox.Parser; import nl.ulso.sprox.ParseException;
package nl.ulso.sprox.parsers; /** * Simple no-op parser that returns the string value itself. * <p> * Reasons for having this implementation: * </p> * <ul> * <li>It makes the implementation of the processor easier. Strings are not a special case.</li> * <li>It allows developers to replace this parser with their own.</li> * </ul> */ public class StringParser implements Parser<String> { @Override
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // Path: src/main/java/nl/ulso/sprox/parsers/StringParser.java import nl.ulso.sprox.Parser; import nl.ulso.sprox.ParseException; package nl.ulso.sprox.parsers; /** * Simple no-op parser that returns the string value itself. * <p> * Reasons for having this implementation: * </p> * <ul> * <li>It makes the implementation of the processor easier. Strings are not a special case.</li> * <li>It allows developers to replace this parser with their own.</li> * </ul> */ public class StringParser implements Parser<String> { @Override
public String fromString(String value) throws ParseException {
voostindie/sprox
src/test/java/nl/ulso/sprox/pom/MavenPomTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.io.File; import java.io.FileInputStream; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.pom; public class MavenPomTest { @Test public void testProcessMavenPom() throws Exception {
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/pom/MavenPomTest.java import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.io.File; import java.io.FileInputStream; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package nl.ulso.sprox.pom; public class MavenPomTest { @Test public void testProcessMavenPom() throws Exception {
final XmlProcessor<Project> processor = createXmlProcessorBuilder(Project.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/pom/MavenPomTest.java
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.io.File; import java.io.FileInputStream; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.pom; public class MavenPomTest { @Test public void testProcessMavenPom() throws Exception {
// Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/pom/MavenPomTest.java import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.io.File; import java.io.FileInputStream; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; package nl.ulso.sprox.pom; public class MavenPomTest { @Test public void testProcessMavenPom() throws Exception {
final XmlProcessor<Project> processor = createXmlProcessorBuilder(Project.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/opml/Rfc822DateTimeParser.java
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // }
import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter;
package nl.ulso.sprox.opml; public class Rfc822DateTimeParser implements Parser<DateTime> { // Not sure if this pattern is completely correct, but all dates in the test data are parsed correctly. private static final DateTimeFormatter parser = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss ZZZ");
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // Path: src/test/java/nl/ulso/sprox/opml/Rfc822DateTimeParser.java import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; package nl.ulso.sprox.opml; public class Rfc822DateTimeParser implements Parser<DateTime> { // Not sure if this pattern is completely correct, but all dates in the test data are parsed correctly. private static final DateTimeFormatter parser = DateTimeFormat.forPattern("EEE, dd MMM YYYY HH:mm:ss ZZZ");
public DateTime fromString(String value) throws ParseException {
voostindie/sprox
src/test/java/nl/ulso/sprox/ExceptionalSituationsTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import org.junit.Test; import static nl.ulso.sprox.SproxTests.testProcessor; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder;
package nl.ulso.sprox; public class ExceptionalSituationsTest { @Test(expected = IllegalStateException.class) public void testThatCreatingAProcessorWithZeroControllersFails() throws Exception {
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/ExceptionalSituationsTest.java import org.junit.Test; import static nl.ulso.sprox.SproxTests.testProcessor; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; package nl.ulso.sprox; public class ExceptionalSituationsTest { @Test(expected = IllegalStateException.class) public void testThatCreatingAProcessorWithZeroControllersFails() throws Exception {
createXmlProcessorBuilder(Void.class).buildXmlProcessor();
voostindie/sprox
src/test/java/nl/ulso/sprox/ExceptionalSituationsTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import org.junit.Test; import static nl.ulso.sprox.SproxTests.testProcessor; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder;
package nl.ulso.sprox; public class ExceptionalSituationsTest { @Test(expected = IllegalStateException.class) public void testThatCreatingAProcessorWithZeroControllersFails() throws Exception { createXmlProcessorBuilder(Void.class).buildXmlProcessor(); } @Test(expected = IllegalStateException.class) public void testThatCreatingAProcessorWithControllersWithoutAnnotationsFails() throws Exception { createXmlProcessorBuilder(Void.class).addControllerObject("").buildXmlProcessor(); } @Test(expected = XmlProcessorException.class) public void testThatParseExceptionResultsInFailure() throws Exception { final XmlProcessor<String> processor = createXmlProcessorBuilder(String.class) .addControllerObject(new BrokenNodeProcessor("test")) .addParser(value -> { throw new ParseException(String.class, value); }, String.class).buildXmlProcessor();
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testProcessor(T expected, String xml, XmlProcessor<T> processor) throws Exception { // final T actual = processor.execute(new StringReader(xml)); // assertEquals(expected, actual); // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/ExceptionalSituationsTest.java import org.junit.Test; import static nl.ulso.sprox.SproxTests.testProcessor; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; package nl.ulso.sprox; public class ExceptionalSituationsTest { @Test(expected = IllegalStateException.class) public void testThatCreatingAProcessorWithZeroControllersFails() throws Exception { createXmlProcessorBuilder(Void.class).buildXmlProcessor(); } @Test(expected = IllegalStateException.class) public void testThatCreatingAProcessorWithControllersWithoutAnnotationsFails() throws Exception { createXmlProcessorBuilder(Void.class).addControllerObject("").buildXmlProcessor(); } @Test(expected = XmlProcessorException.class) public void testThatParseExceptionResultsInFailure() throws Exception { final XmlProcessor<String> processor = createXmlProcessorBuilder(String.class) .addControllerObject(new BrokenNodeProcessor("test")) .addParser(value -> { throw new ParseException(String.class, value); }, String.class).buildXmlProcessor();
testProcessor("", "<root><node>value</node></root>", processor);
voostindie/sprox
src/main/java/nl/ulso/sprox/impl/ExecutionContext.java
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // }
import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; import javax.xml.namespace.QName; import java.util.List; import java.util.Map; import java.util.Optional; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked;
package nl.ulso.sprox.impl; /** * Context object that is unique to each processing run. It is passed between several objects involved in an XML * processing run, like {@link EventHandler}s, {@link ControllerMethod}s and {@link ControllerParameter}s. * <p/> * Controller methods are invoked <strong>after</strong> the associated end element is found. All data that must be * injected for the method is collected during the processing of the elements within that element. This class keeps * track of the data that is collected, and also ensures that it collects only the data that it really needs to collect. * <p/> * Different types of data can be injected, and each type must be collected a little differently: * <ul> * <li><strong>Attributes</strong>: These are known as soon as the start element is found. They only need to * be stored temporarily. When stored they must be bound to a location because the context might contain attributes * of many nodes that have been processed. The interesting case here is a recursive node structure, like: * <pre> * &lt;node attribute="1"&gt; * &lt;node attribute="2"/&gt; * &lt;/node&gt; * </pre> * When invoking the controller method for the inner node, the injected attribute must have the value {@code 2}, while * the outer node requires {@code 1}. The {@link AttributeMap} is responsible for keeping track of attributes. * </li> * <li><strong>Nodes</strong>: When node content must be read, the processor switches over to another strategy: it * collects all the data under the node, until the matching end element is found. An interesting case is that the * element we're interested in might be available many times, for example: * <pre> * &lt;root&gt; * &lt;node&gt;value1&lt;/node&gt; * &lt;subnode&gt; * &lt;node&gt;value2&lt;/node&gt; * &lt;/subnode&gt; * &lt;node&gt;value3&lt;/node&gt; * &lt;/root&gt; * </pre> * In this case: the expected result is {@code value1}, the value closest to the root. The {@link NodeContentMap} is * responsible for keeping track of nodes. * <li><strong>Method results</strong>: Method results are created by invoking controller methods. When created, they * are stored. The hierarchy of the processed XML doesn't need to match the hierarchy of the controllers: an object may * be injected several levels up, with other controller methods on intermediate levels that ignore it. The * {@link MethodResultMap} is responsible for keeping track of method results. * </li> * <li><strong>Result</strong>: The processing result is just an object created from a controller method. The last * object created by any method with the correct result type is considered to be the processing result. Typically * the result is produced by a method annotated with the root node. This method is always called last.</li> * </ul> * * @see AttributeMap * @see NodeContentMap * @see MethodResultMap */ final class ExecutionContext<T> { // Immutable data; the same across all processing runs private final Class<T> resultClass; private final Map<Class, Object> controllers;
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // } // Path: src/main/java/nl/ulso/sprox/impl/ExecutionContext.java import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; import javax.xml.namespace.QName; import java.util.List; import java.util.Map; import java.util.Optional; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked; package nl.ulso.sprox.impl; /** * Context object that is unique to each processing run. It is passed between several objects involved in an XML * processing run, like {@link EventHandler}s, {@link ControllerMethod}s and {@link ControllerParameter}s. * <p/> * Controller methods are invoked <strong>after</strong> the associated end element is found. All data that must be * injected for the method is collected during the processing of the elements within that element. This class keeps * track of the data that is collected, and also ensures that it collects only the data that it really needs to collect. * <p/> * Different types of data can be injected, and each type must be collected a little differently: * <ul> * <li><strong>Attributes</strong>: These are known as soon as the start element is found. They only need to * be stored temporarily. When stored they must be bound to a location because the context might contain attributes * of many nodes that have been processed. The interesting case here is a recursive node structure, like: * <pre> * &lt;node attribute="1"&gt; * &lt;node attribute="2"/&gt; * &lt;/node&gt; * </pre> * When invoking the controller method for the inner node, the injected attribute must have the value {@code 2}, while * the outer node requires {@code 1}. The {@link AttributeMap} is responsible for keeping track of attributes. * </li> * <li><strong>Nodes</strong>: When node content must be read, the processor switches over to another strategy: it * collects all the data under the node, until the matching end element is found. An interesting case is that the * element we're interested in might be available many times, for example: * <pre> * &lt;root&gt; * &lt;node&gt;value1&lt;/node&gt; * &lt;subnode&gt; * &lt;node&gt;value2&lt;/node&gt; * &lt;/subnode&gt; * &lt;node&gt;value3&lt;/node&gt; * &lt;/root&gt; * </pre> * In this case: the expected result is {@code value1}, the value closest to the root. The {@link NodeContentMap} is * responsible for keeping track of nodes. * <li><strong>Method results</strong>: Method results are created by invoking controller methods. When created, they * are stored. The hierarchy of the processed XML doesn't need to match the hierarchy of the controllers: an object may * be injected several levels up, with other controller methods on intermediate levels that ignore it. The * {@link MethodResultMap} is responsible for keeping track of method results. * </li> * <li><strong>Result</strong>: The processing result is just an object created from a controller method. The last * object created by any method with the correct result type is considered to be the processing result. Typically * the result is produced by a method annotated with the root node. This method is always called last.</li> * </ul> * * @see AttributeMap * @see NodeContentMap * @see MethodResultMap */ final class ExecutionContext<T> { // Immutable data; the same across all processing runs private final Class<T> resultClass; private final Map<Class, Object> controllers;
private final Map<Class<?>, Parser<?>> parsers;
voostindie/sprox
src/main/java/nl/ulso/sprox/impl/ExecutionContext.java
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // }
import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; import javax.xml.namespace.QName; import java.util.List; import java.util.Map; import java.util.Optional; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked;
package nl.ulso.sprox.impl; /** * Context object that is unique to each processing run. It is passed between several objects involved in an XML * processing run, like {@link EventHandler}s, {@link ControllerMethod}s and {@link ControllerParameter}s. * <p/> * Controller methods are invoked <strong>after</strong> the associated end element is found. All data that must be * injected for the method is collected during the processing of the elements within that element. This class keeps * track of the data that is collected, and also ensures that it collects only the data that it really needs to collect. * <p/> * Different types of data can be injected, and each type must be collected a little differently: * <ul> * <li><strong>Attributes</strong>: These are known as soon as the start element is found. They only need to * be stored temporarily. When stored they must be bound to a location because the context might contain attributes * of many nodes that have been processed. The interesting case here is a recursive node structure, like: * <pre> * &lt;node attribute="1"&gt; * &lt;node attribute="2"/&gt; * &lt;/node&gt; * </pre> * When invoking the controller method for the inner node, the injected attribute must have the value {@code 2}, while * the outer node requires {@code 1}. The {@link AttributeMap} is responsible for keeping track of attributes. * </li> * <li><strong>Nodes</strong>: When node content must be read, the processor switches over to another strategy: it * collects all the data under the node, until the matching end element is found. An interesting case is that the * element we're interested in might be available many times, for example: * <pre> * &lt;root&gt; * &lt;node&gt;value1&lt;/node&gt; * &lt;subnode&gt; * &lt;node&gt;value2&lt;/node&gt; * &lt;/subnode&gt; * &lt;node&gt;value3&lt;/node&gt; * &lt;/root&gt; * </pre> * In this case: the expected result is {@code value1}, the value closest to the root. The {@link NodeContentMap} is * responsible for keeping track of nodes. * <li><strong>Method results</strong>: Method results are created by invoking controller methods. When created, they * are stored. The hierarchy of the processed XML doesn't need to match the hierarchy of the controllers: an object may * be injected several levels up, with other controller methods on intermediate levels that ignore it. The * {@link MethodResultMap} is responsible for keeping track of method results. * </li> * <li><strong>Result</strong>: The processing result is just an object created from a controller method. The last * object created by any method with the correct result type is considered to be the processing result. Typically * the result is produced by a method annotated with the root node. This method is always called last.</li> * </ul> * * @see AttributeMap * @see NodeContentMap * @see MethodResultMap */ final class ExecutionContext<T> { // Immutable data; the same across all processing runs private final Class<T> resultClass; private final Map<Class, Object> controllers; private final Map<Class<?>, Parser<?>> parsers; // Mutable data, collected during a single processing run private final AttributeMap attributeMap; private final MethodResultMap methodResultMap; private final NodeContentMap nodeContentMap; private int depth; private T result; ExecutionContext(Class<T> resultClass, Map<Class, Object> controllers, Map<Class<?>, Parser<?>> parsers) { this.resultClass = resultClass; this.controllers = controllers; this.parsers = parsers; this.attributeMap = new AttributeMap(); this.nodeContentMap = new NodeContentMap(); this.methodResultMap = new MethodResultMap(); this.depth = 0; this.result = null; } Object getController(Class controllerClass) { return controllers.get(controllerClass); } <R> R parseString(String value, Class<R> resultClass) {
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // } // Path: src/main/java/nl/ulso/sprox/impl/ExecutionContext.java import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; import javax.xml.namespace.QName; import java.util.List; import java.util.Map; import java.util.Optional; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked; package nl.ulso.sprox.impl; /** * Context object that is unique to each processing run. It is passed between several objects involved in an XML * processing run, like {@link EventHandler}s, {@link ControllerMethod}s and {@link ControllerParameter}s. * <p/> * Controller methods are invoked <strong>after</strong> the associated end element is found. All data that must be * injected for the method is collected during the processing of the elements within that element. This class keeps * track of the data that is collected, and also ensures that it collects only the data that it really needs to collect. * <p/> * Different types of data can be injected, and each type must be collected a little differently: * <ul> * <li><strong>Attributes</strong>: These are known as soon as the start element is found. They only need to * be stored temporarily. When stored they must be bound to a location because the context might contain attributes * of many nodes that have been processed. The interesting case here is a recursive node structure, like: * <pre> * &lt;node attribute="1"&gt; * &lt;node attribute="2"/&gt; * &lt;/node&gt; * </pre> * When invoking the controller method for the inner node, the injected attribute must have the value {@code 2}, while * the outer node requires {@code 1}. The {@link AttributeMap} is responsible for keeping track of attributes. * </li> * <li><strong>Nodes</strong>: When node content must be read, the processor switches over to another strategy: it * collects all the data under the node, until the matching end element is found. An interesting case is that the * element we're interested in might be available many times, for example: * <pre> * &lt;root&gt; * &lt;node&gt;value1&lt;/node&gt; * &lt;subnode&gt; * &lt;node&gt;value2&lt;/node&gt; * &lt;/subnode&gt; * &lt;node&gt;value3&lt;/node&gt; * &lt;/root&gt; * </pre> * In this case: the expected result is {@code value1}, the value closest to the root. The {@link NodeContentMap} is * responsible for keeping track of nodes. * <li><strong>Method results</strong>: Method results are created by invoking controller methods. When created, they * are stored. The hierarchy of the processed XML doesn't need to match the hierarchy of the controllers: an object may * be injected several levels up, with other controller methods on intermediate levels that ignore it. The * {@link MethodResultMap} is responsible for keeping track of method results. * </li> * <li><strong>Result</strong>: The processing result is just an object created from a controller method. The last * object created by any method with the correct result type is considered to be the processing result. Typically * the result is produced by a method annotated with the root node. This method is always called last.</li> * </ul> * * @see AttributeMap * @see NodeContentMap * @see MethodResultMap */ final class ExecutionContext<T> { // Immutable data; the same across all processing runs private final Class<T> resultClass; private final Map<Class, Object> controllers; private final Map<Class<?>, Parser<?>> parsers; // Mutable data, collected during a single processing run private final AttributeMap attributeMap; private final MethodResultMap methodResultMap; private final NodeContentMap nodeContentMap; private int depth; private T result; ExecutionContext(Class<T> resultClass, Map<Class, Object> controllers, Map<Class<?>, Parser<?>> parsers) { this.resultClass = resultClass; this.controllers = controllers; this.parsers = parsers; this.attributeMap = new AttributeMap(); this.nodeContentMap = new NodeContentMap(); this.methodResultMap = new MethodResultMap(); this.depth = 0; this.result = null; } Object getController(Class controllerClass) { return controllers.get(controllerClass); } <R> R parseString(String value, Class<R> resultClass) {
@SuppressWarnings("unchecked")
voostindie/sprox
src/main/java/nl/ulso/sprox/impl/ExecutionContext.java
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // }
import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; import javax.xml.namespace.QName; import java.util.List; import java.util.Map; import java.util.Optional; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked;
// Mutable data, collected during a single processing run private final AttributeMap attributeMap; private final MethodResultMap methodResultMap; private final NodeContentMap nodeContentMap; private int depth; private T result; ExecutionContext(Class<T> resultClass, Map<Class, Object> controllers, Map<Class<?>, Parser<?>> parsers) { this.resultClass = resultClass; this.controllers = controllers; this.parsers = parsers; this.attributeMap = new AttributeMap(); this.nodeContentMap = new NodeContentMap(); this.methodResultMap = new MethodResultMap(); this.depth = 0; this.result = null; } Object getController(Class controllerClass) { return controllers.get(controllerClass); } <R> R parseString(String value, Class<R> resultClass) { @SuppressWarnings("unchecked") final Parser<R> parser = (Parser<R>) parsers.get(resultClass); if (parser == null) { throw new IllegalStateException("No parser available for type: " + resultClass); } try { return parser.fromString(value);
// Path: src/main/java/nl/ulso/sprox/ParseException.java // public final class ParseException extends XmlProcessorException { // public ParseException(Class resultClass, String value) { // super(createMessage(resultClass, value)); // } // // public ParseException(Class resultClass, String value, Throwable cause) { // super(createMessage(resultClass, value), cause); // } // // private static String createMessage(Class resultClass, String value) { // return "Could not parse string \"" + value + "\" into a value of type \"" + resultClass + "\""; // } // } // // Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // } // Path: src/main/java/nl/ulso/sprox/impl/ExecutionContext.java import nl.ulso.sprox.ParseException; import nl.ulso.sprox.Parser; import javax.xml.namespace.QName; import java.util.List; import java.util.Map; import java.util.Optional; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked; // Mutable data, collected during a single processing run private final AttributeMap attributeMap; private final MethodResultMap methodResultMap; private final NodeContentMap nodeContentMap; private int depth; private T result; ExecutionContext(Class<T> resultClass, Map<Class, Object> controllers, Map<Class<?>, Parser<?>> parsers) { this.resultClass = resultClass; this.controllers = controllers; this.parsers = parsers; this.attributeMap = new AttributeMap(); this.nodeContentMap = new NodeContentMap(); this.methodResultMap = new MethodResultMap(); this.depth = 0; this.result = null; } Object getController(Class controllerClass) { return controllers.get(controllerClass); } <R> R parseString(String value, Class<R> resultClass) { @SuppressWarnings("unchecked") final Parser<R> parser = (Parser<R>) parsers.get(resultClass); if (parser == null) { throw new IllegalStateException("No parser available for type: " + resultClass); } try { return parser.fromString(value);
} catch (ParseException e) {
voostindie/sprox
src/test/java/nl/ulso/sprox/NodeAttributesFromParameterNamesTest.java
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // }
import org.junit.Test; import java.util.StringJoiner; import static nl.ulso.sprox.SproxTests.testControllers;
package nl.ulso.sprox; public class NodeAttributesFromParameterNamesTest { @Test public void testNodeAttributesFromParameterNames() throws Exception {
// Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> void testControllers(T expected, String xml, Object... controllers) throws Exception { // @SuppressWarnings("unchecked") // final XmlProcessorBuilder<Object> builder = (XmlProcessorBuilder<Object>) createXmlProcessorBuilder(expected.getClass()); // for (Object controller : controllers) { // if (controller instanceof Class) { // builder.addControllerClass((Class) controller); // } else if (controller instanceof ControllerFactory) { // builder.addControllerFactory((ControllerFactory<?>) controller); // } else { // builder.addControllerObject(controller); // } // } // final XmlProcessor<Object> processor = builder.buildXmlProcessor(); // testProcessor(expected, xml, processor); // } // Path: src/test/java/nl/ulso/sprox/NodeAttributesFromParameterNamesTest.java import org.junit.Test; import java.util.StringJoiner; import static nl.ulso.sprox.SproxTests.testControllers; package nl.ulso.sprox; public class NodeAttributesFromParameterNamesTest { @Test public void testNodeAttributesFromParameterNames() throws Exception {
testControllers(
voostindie/sprox
src/test/java/nl/ulso/sprox/movies/MovieCounterTest.java
// Path: src/main/java/nl/ulso/sprox/ControllerFactory.java // public interface ControllerFactory<T> { // // /** // * Creates a controller of type {@code T}; called exactly once per processor execution. // * // * @return The controller to use. // */ // T createController(); // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.ControllerFactory; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.io.InputStream; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.movies; public class MovieCounterTest { @Test public void testCountAllMovies() throws Exception {
// Path: src/main/java/nl/ulso/sprox/ControllerFactory.java // public interface ControllerFactory<T> { // // /** // * Creates a controller of type {@code T}; called exactly once per processor execution. // * // * @return The controller to use. // */ // T createController(); // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/movies/MovieCounterTest.java import nl.ulso.sprox.ControllerFactory; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.io.InputStream; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; package nl.ulso.sprox.movies; public class MovieCounterTest { @Test public void testCountAllMovies() throws Exception {
final XmlProcessor<Integer> processor = createXmlProcessorBuilder(Integer.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/movies/MovieCounterTest.java
// Path: src/main/java/nl/ulso/sprox/ControllerFactory.java // public interface ControllerFactory<T> { // // /** // * Creates a controller of type {@code T}; called exactly once per processor execution. // * // * @return The controller to use. // */ // T createController(); // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.ControllerFactory; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.io.InputStream; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.movies; public class MovieCounterTest { @Test public void testCountAllMovies() throws Exception {
// Path: src/main/java/nl/ulso/sprox/ControllerFactory.java // public interface ControllerFactory<T> { // // /** // * Creates a controller of type {@code T}; called exactly once per processor execution. // * // * @return The controller to use. // */ // T createController(); // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/movies/MovieCounterTest.java import nl.ulso.sprox.ControllerFactory; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.io.InputStream; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; package nl.ulso.sprox.movies; public class MovieCounterTest { @Test public void testCountAllMovies() throws Exception {
final XmlProcessor<Integer> processor = createXmlProcessorBuilder(Integer.class)
voostindie/sprox
src/test/java/nl/ulso/sprox/movies/MovieCounterTest.java
// Path: src/main/java/nl/ulso/sprox/ControllerFactory.java // public interface ControllerFactory<T> { // // /** // * Creates a controller of type {@code T}; called exactly once per processor execution. // * // * @return The controller to use. // */ // T createController(); // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // }
import nl.ulso.sprox.ControllerFactory; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.io.InputStream; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat;
package nl.ulso.sprox.movies; public class MovieCounterTest { @Test public void testCountAllMovies() throws Exception { final XmlProcessor<Integer> processor = createXmlProcessorBuilder(Integer.class) .addControllerClass(MovieCounter.class) .buildXmlProcessor(); final Integer count = processor.execute(getMoviesResource()); assertThat(count, is(5)); } @Test public void testCountAllMoviesUsingControllerFactoryFromInnerClass() throws Exception { //noinspection Convert2Lambda,Anonymous2MethodRef final XmlProcessor<Integer> processor = createXmlProcessorBuilder(Integer.class)
// Path: src/main/java/nl/ulso/sprox/ControllerFactory.java // public interface ControllerFactory<T> { // // /** // * Creates a controller of type {@code T}; called exactly once per processor execution. // * // * @return The controller to use. // */ // T createController(); // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/test/java/nl/ulso/sprox/SproxTests.java // public static <T> XmlProcessorBuilder<T> createXmlProcessorBuilder(Class<T> resultClass) { // return new StaxBasedXmlProcessorBuilderFactory().createXmlProcessorBuilder(requireNonNull(resultClass)); // } // Path: src/test/java/nl/ulso/sprox/movies/MovieCounterTest.java import nl.ulso.sprox.ControllerFactory; import nl.ulso.sprox.Node; import nl.ulso.sprox.XmlProcessor; import org.junit.Test; import java.io.InputStream; import static nl.ulso.sprox.SproxTests.createXmlProcessorBuilder; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; package nl.ulso.sprox.movies; public class MovieCounterTest { @Test public void testCountAllMovies() throws Exception { final XmlProcessor<Integer> processor = createXmlProcessorBuilder(Integer.class) .addControllerClass(MovieCounter.class) .buildXmlProcessor(); final Integer count = processor.execute(getMoviesResource()); assertThat(count, is(5)); } @Test public void testCountAllMoviesUsingControllerFactoryFromInnerClass() throws Exception { //noinspection Convert2Lambda,Anonymous2MethodRef final XmlProcessor<Integer> processor = createXmlProcessorBuilder(Integer.class)
.addControllerFactory(new ControllerFactory<MovieCounter>() {
voostindie/sprox
src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessor.java
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessorException.java // public class XmlProcessorException extends Exception { // public XmlProcessorException(Throwable cause) { // super(cause); // } // // public XmlProcessorException(String message) { // super(message); // } // // public XmlProcessorException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // }
import nl.ulso.sprox.Parser; import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.XmlProcessorException; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; import java.io.InputStream; import java.io.Reader; import java.util.*; import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked;
package nl.ulso.sprox.impl; /** * Default implementation of the {@link nl.ulso.sprox.XmlProcessor} interface on top of the JDKs built-in StAX * parser. * <p> * On construction, a processor is initialized with an initial list of event handlers, all based on annotated * controller * methods. When the processor goes through a document, it implements the following algorithm: * <p> * <ul> * <li>Copy the initial list of event handlers to a new list, specifically for this execution</li> * <li>Go through the document, event by event</li> * <li>For every event, check if it matches one of the event handlers in the list, from back to front. If so: * <ul> * <li>Remove the event handler from the list.</li> * <li>Let the event handler process the event.</li> * <li>Add the resulting event handler to the back of the list, giving it the highest priority.</li> * </ul> * </li> * </ul> */ final class StaxBasedXmlProcessor<T> implements XmlProcessor<T> { private final Class<T> resultClass; private final Map<Class, ControllerProvider> controllerProviders; private final XMLInputFactory inputFactory; private final List<EventHandler> initialEventHandlers;
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessorException.java // public class XmlProcessorException extends Exception { // public XmlProcessorException(Throwable cause) { // super(cause); // } // // public XmlProcessorException(String message) { // super(message); // } // // public XmlProcessorException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // } // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessor.java import nl.ulso.sprox.Parser; import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.XmlProcessorException; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; import java.io.InputStream; import java.io.Reader; import java.util.*; import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked; package nl.ulso.sprox.impl; /** * Default implementation of the {@link nl.ulso.sprox.XmlProcessor} interface on top of the JDKs built-in StAX * parser. * <p> * On construction, a processor is initialized with an initial list of event handlers, all based on annotated * controller * methods. When the processor goes through a document, it implements the following algorithm: * <p> * <ul> * <li>Copy the initial list of event handlers to a new list, specifically for this execution</li> * <li>Go through the document, event by event</li> * <li>For every event, check if it matches one of the event handlers in the list, from back to front. If so: * <ul> * <li>Remove the event handler from the list.</li> * <li>Let the event handler process the event.</li> * <li>Add the resulting event handler to the back of the list, giving it the highest priority.</li> * </ul> * </li> * </ul> */ final class StaxBasedXmlProcessor<T> implements XmlProcessor<T> { private final Class<T> resultClass; private final Map<Class, ControllerProvider> controllerProviders; private final XMLInputFactory inputFactory; private final List<EventHandler> initialEventHandlers;
private final Map<Class<?>, Parser<?>> parsers;
voostindie/sprox
src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessor.java
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessorException.java // public class XmlProcessorException extends Exception { // public XmlProcessorException(Throwable cause) { // super(cause); // } // // public XmlProcessorException(String message) { // super(message); // } // // public XmlProcessorException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // }
import nl.ulso.sprox.Parser; import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.XmlProcessorException; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; import java.io.InputStream; import java.io.Reader; import java.util.*; import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked;
package nl.ulso.sprox.impl; /** * Default implementation of the {@link nl.ulso.sprox.XmlProcessor} interface on top of the JDKs built-in StAX * parser. * <p> * On construction, a processor is initialized with an initial list of event handlers, all based on annotated * controller * methods. When the processor goes through a document, it implements the following algorithm: * <p> * <ul> * <li>Copy the initial list of event handlers to a new list, specifically for this execution</li> * <li>Go through the document, event by event</li> * <li>For every event, check if it matches one of the event handlers in the list, from back to front. If so: * <ul> * <li>Remove the event handler from the list.</li> * <li>Let the event handler process the event.</li> * <li>Add the resulting event handler to the back of the list, giving it the highest priority.</li> * </ul> * </li> * </ul> */ final class StaxBasedXmlProcessor<T> implements XmlProcessor<T> { private final Class<T> resultClass; private final Map<Class, ControllerProvider> controllerProviders; private final XMLInputFactory inputFactory; private final List<EventHandler> initialEventHandlers; private final Map<Class<?>, Parser<?>> parsers; StaxBasedXmlProcessor(Class<T> resultClass, Map<Class, ControllerProvider> controllerProviders, List<EventHandler> eventHandlers, Map<Class<?>, Parser<?>> parsers, XMLInputFactory inputFactory) { this.resultClass = resultClass; this.controllerProviders = unmodifiableMap(new HashMap<>(controllerProviders)); this.initialEventHandlers = unmodifiableList(new ArrayList<>(eventHandlers)); this.parsers = unmodifiableMap(new HashMap<>(parsers)); this.inputFactory = inputFactory; } @Override
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessorException.java // public class XmlProcessorException extends Exception { // public XmlProcessorException(Throwable cause) { // super(cause); // } // // public XmlProcessorException(String message) { // super(message); // } // // public XmlProcessorException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // } // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessor.java import nl.ulso.sprox.Parser; import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.XmlProcessorException; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; import java.io.InputStream; import java.io.Reader; import java.util.*; import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked; package nl.ulso.sprox.impl; /** * Default implementation of the {@link nl.ulso.sprox.XmlProcessor} interface on top of the JDKs built-in StAX * parser. * <p> * On construction, a processor is initialized with an initial list of event handlers, all based on annotated * controller * methods. When the processor goes through a document, it implements the following algorithm: * <p> * <ul> * <li>Copy the initial list of event handlers to a new list, specifically for this execution</li> * <li>Go through the document, event by event</li> * <li>For every event, check if it matches one of the event handlers in the list, from back to front. If so: * <ul> * <li>Remove the event handler from the list.</li> * <li>Let the event handler process the event.</li> * <li>Add the resulting event handler to the back of the list, giving it the highest priority.</li> * </ul> * </li> * </ul> */ final class StaxBasedXmlProcessor<T> implements XmlProcessor<T> { private final Class<T> resultClass; private final Map<Class, ControllerProvider> controllerProviders; private final XMLInputFactory inputFactory; private final List<EventHandler> initialEventHandlers; private final Map<Class<?>, Parser<?>> parsers; StaxBasedXmlProcessor(Class<T> resultClass, Map<Class, ControllerProvider> controllerProviders, List<EventHandler> eventHandlers, Map<Class<?>, Parser<?>> parsers, XMLInputFactory inputFactory) { this.resultClass = resultClass; this.controllerProviders = unmodifiableMap(new HashMap<>(controllerProviders)); this.initialEventHandlers = unmodifiableList(new ArrayList<>(eventHandlers)); this.parsers = unmodifiableMap(new HashMap<>(parsers)); this.inputFactory = inputFactory; } @Override
public T execute(Reader reader) throws XmlProcessorException {
voostindie/sprox
src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessor.java
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessorException.java // public class XmlProcessorException extends Exception { // public XmlProcessorException(Throwable cause) { // super(cause); // } // // public XmlProcessorException(String message) { // super(message); // } // // public XmlProcessorException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // }
import nl.ulso.sprox.Parser; import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.XmlProcessorException; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; import java.io.InputStream; import java.io.Reader; import java.util.*; import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked;
return createReturnValue(context); } private Map<Class, Object> provideControllers() { return controllerProviders.entrySet().stream().collect( HashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue().getController()), Map::putAll ); } private EventHandler popFirstMatchingEventHandler(List<EventHandler> eventHandlers, XMLEvent event, ExecutionContext executionContext) { final Iterator<EventHandler> iterator = eventHandlers.iterator(); while (iterator.hasNext()) { final EventHandler handler = iterator.next(); if (handler.matches(event, executionContext)) { iterator.remove(); return handler; } } return null; } private T createReturnValue(ExecutionContext<T> context) { final Optional<T> result = context.getResult(); if (result.isPresent()) { return result.get(); } if (!Void.class.equals(resultClass)) {
// Path: src/main/java/nl/ulso/sprox/Parser.java // public interface Parser<T> { // // /** // * Parses a string value into a specific type. // * // * @param value String value to parse. // * @return The result of parsing the value. // * @throws ParseException If the value could not be parsed. // */ // T fromString(String value) throws ParseException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessor.java // public interface XmlProcessor<T> { // // /** // * Process XML by pulling it from a reader. The reader is not closed. If buffering is needed, this must be // * provided by the caller. // * // * @param reader The reader to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(Reader reader) throws XmlProcessorException; // // /** // * Process XML by pulling it from an input stream. The input stream is not closed. If buffering is needed, this // * must be provided by the caller. // * // * @param inputStream The stream to pull the XML from. // * @return The result of processing the XML; is {@code null} only if {@code T} is {@link java.lang.Void}. // * @throws XmlProcessorException If an error occurred while processing the XML // */ // T execute(InputStream inputStream) throws XmlProcessorException; // } // // Path: src/main/java/nl/ulso/sprox/XmlProcessorException.java // public class XmlProcessorException extends Exception { // public XmlProcessorException(Throwable cause) { // super(cause); // } // // public XmlProcessorException(String message) { // super(message); // } // // public XmlProcessorException(String message, Throwable cause) { // super(message, cause); // } // } // // Path: src/main/java/nl/ulso/sprox/impl/UncheckedXmlProcessorException.java // static UncheckedXmlProcessorException unchecked(XmlProcessorException exception) { // return new UncheckedXmlProcessorException(exception); // } // Path: src/main/java/nl/ulso/sprox/impl/StaxBasedXmlProcessor.java import nl.ulso.sprox.Parser; import nl.ulso.sprox.XmlProcessor; import nl.ulso.sprox.XmlProcessorException; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; import java.io.InputStream; import java.io.Reader; import java.util.*; import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; import static nl.ulso.sprox.impl.UncheckedXmlProcessorException.unchecked; return createReturnValue(context); } private Map<Class, Object> provideControllers() { return controllerProviders.entrySet().stream().collect( HashMap::new, (map, entry) -> map.put(entry.getKey(), entry.getValue().getController()), Map::putAll ); } private EventHandler popFirstMatchingEventHandler(List<EventHandler> eventHandlers, XMLEvent event, ExecutionContext executionContext) { final Iterator<EventHandler> iterator = eventHandlers.iterator(); while (iterator.hasNext()) { final EventHandler handler = iterator.next(); if (handler.matches(event, executionContext)) { iterator.remove(); return handler; } } return null; } private T createReturnValue(ExecutionContext<T> context) { final Optional<T> result = context.getResult(); if (result.isPresent()) { return result.get(); } if (!Void.class.equals(resultClass)) {
throw unchecked(new XmlProcessorException("No result collected of type " + resultClass.getName()));